You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by tr...@apache.org on 2005/05/09 11:21:54 UTC
svn commit: r169259 [5/5] - in
/directory/network/branches/api_integration/src:
examples/org/apache/mina/examples/echoserver/
examples/org/apache/mina/examples/httpserver/
examples/org/apache/mina/examples/netcat/
examples/org/apache/mina/examples/reverser/
examples/org/apache/mina/examples/tennis/ java/org/apache/mina/common/
java/org/apache/mina/filter/ java/org/apache/mina/filter/codec/
java/org/apache/mina/handler/ java/org/apache/mina/io/
java/org/apache/mina/io/datagram/ java/org/apache/mina/io/filter/
java/org/apache/mina/io/handler/ java/org/apache/mina/io/socket/
java/org/apache/mina/protocol/ java/org/apache/mina/protocol/codec/
java/org/apache/mina/protocol/filter/
java/org/apache/mina/protocol/handler/ java/org/apache/mina/protocol/io/
java/org/apache/mina/protocol/vmpipe/ java/org/apache/mina/registry/
java/org/apache/mina/transport/ java/org/apache/mina/transport/socket/
java/org/apache/mina/transport/socket/bio/
java/org/apache/mina/transport/socket/nio/
java/org/apache/mina/transport/vmpipe/ java/org/apache/mina/util/
test/org/apache/mina/examples/echoserver/ test/org/apache/mina/io/
test/org/apache/mina/io/datagram/ test/org/apache/mina/io/socket/
test/org/apache/mina/protocol/ test/org/apache/mina/protocol/codec/
test/org/apache/mina/util/
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSession.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSession.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSession.java Mon May 9 02:21:50 2005
@@ -0,0 +1,176 @@
+/*
+ * @(#) $Id$
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.mina.transport.socket.nio;
+
+import java.net.SocketAddress;
+import java.nio.channels.SelectionKey;
+import java.nio.channels.SocketChannel;
+
+import org.apache.mina.common.BaseIoSession;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.IoSessionFilterChain;
+import org.apache.mina.common.IoSessionManagerFilterChain;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.util.Queue;
+
+/**
+ * An {@link IoSession} for socket transport (TCP/IP).
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class SocketSession extends BaseIoSession implements IoSession
+{
+ private final IoSessionManagerFilterChain managerFilterChain;
+
+ private final IoSessionFilterChain filterChain;
+
+ private final SocketChannel ch;
+
+ private final SocketSessionConfig config;
+
+ private final Queue writeBufferQueue;
+
+ private final IoHandler handler;
+
+ private final SocketAddress remoteAddress;
+
+ private final SocketAddress localAddress;
+
+ private SelectionKey key;
+
+ private boolean disposed;
+
+ /**
+ * Creates a new instance.
+ */
+ SocketSession( IoSessionManagerFilterChain managerFilterChain,
+ SocketChannel ch, IoHandler defaultHandler )
+ {
+ this.managerFilterChain = managerFilterChain;
+ this.filterChain = new IoSessionFilterChain( managerFilterChain );
+ this.ch = ch;
+ this.config = new SocketSessionConfig( this );
+ this.writeBufferQueue = new Queue();
+ this.handler = defaultHandler;
+ this.remoteAddress = ch.socket().getRemoteSocketAddress();
+ this.localAddress = ch.socket().getLocalSocketAddress();
+ }
+
+ IoSessionManagerFilterChain getManagerFilterChain()
+ {
+ return managerFilterChain;
+ }
+
+ public IoFilterChain getFilterChain()
+ {
+ return filterChain;
+ }
+
+ SocketChannel getChannel()
+ {
+ return ch;
+ }
+
+ SelectionKey getSelectionKey()
+ {
+ return key;
+ }
+
+ void setSelectionKey( SelectionKey key )
+ {
+ this.key = key;
+ }
+
+ public IoHandler getHandler()
+ {
+ return handler;
+ }
+
+ synchronized void notifyClose()
+ {
+ if( !disposed )
+ {
+ disposed = true;
+ notify();
+ }
+ }
+
+
+ public synchronized void close( boolean wait )
+ {
+ if( disposed )
+ {
+ return;
+ }
+
+ SocketIoProcessor.getInstance().removeSession( this );
+ if( wait )
+ {
+ while( disposed )
+ {
+ try
+ {
+ wait();
+ }
+ catch( InterruptedException e )
+ {
+ }
+ }
+ }
+ }
+
+ Queue getWriteBufferQueue()
+ {
+ return writeBufferQueue;
+ }
+
+ public void write( Object message )
+ {
+ filterChain.filterWrite( this, message );
+ }
+
+ public TransportType getTransportType()
+ {
+ return TransportType.SOCKET;
+ }
+
+ public boolean isConnected()
+ {
+ return ch.isConnected();
+ }
+
+ public IoSessionConfig getConfig()
+ {
+ return config;
+ }
+
+ public SocketAddress getRemoteAddress()
+ {
+ return remoteAddress;
+ }
+
+ public SocketAddress getLocalAddress()
+ {
+ return localAddress;
+ }
+}
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSession.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionConfig.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionConfig.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionConfig.java Mon May 9 02:21:50 2005
@@ -0,0 +1,143 @@
+/*
+ * @(#) $Id$
+ *
+ * Copyright 2004 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.mina.transport.socket.nio;
+
+import java.net.SocketException;
+
+import org.apache.mina.common.BaseIoSessionConfig;
+import org.apache.mina.common.IoSession;
+
+/**
+ * A {@link SessionConfig} for socket transport (TCP/IP).
+ * You can downcast {@link SessionConfig} instance returned by
+ * {@link IoSession#getConfig()} or {@link IoSession#getConfig()}
+ * if you've created datagram session using {@link SocketAcceptor} or
+ * {@link SocketConnector}.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$,
+ */
+public class SocketSessionConfig extends BaseIoSessionConfig
+{
+ private static final int DEFAULT_READ_BUFFER_SIZE = 1024;
+
+ private final SocketSession session;
+
+ private int readBufferSize = DEFAULT_READ_BUFFER_SIZE;
+
+ SocketSessionConfig( SocketSession session )
+ {
+ this.session = session;
+ }
+
+ public boolean getKeepAlive() throws SocketException
+ {
+ return session.getChannel().socket().getKeepAlive();
+ }
+
+ public void setKeepAlive( boolean on ) throws SocketException
+ {
+ session.getChannel().socket().setKeepAlive( on );
+ }
+
+ public boolean getOOBInline() throws SocketException
+ {
+ return session.getChannel().socket().getOOBInline();
+ }
+
+ public void setOOBInline( boolean on ) throws SocketException
+ {
+ session.getChannel().socket().setOOBInline( on );
+ }
+
+ public boolean getReuseAddress() throws SocketException
+ {
+ return session.getChannel().socket().getReuseAddress();
+ }
+
+ public void setReuseAddress( boolean on ) throws SocketException
+ {
+ session.getChannel().socket().setReuseAddress( on );
+ }
+
+ public int getSoLinger() throws SocketException
+ {
+ return session.getChannel().socket().getSoLinger();
+ }
+
+ public void setSoLinger( boolean on, int linger ) throws SocketException
+ {
+ session.getChannel().socket().setSoLinger( on, linger );
+ }
+
+ public boolean getTcpNoDelay() throws SocketException
+ {
+ return session.getChannel().socket().getTcpNoDelay();
+ }
+
+ public void setTcpNoDelay( boolean on ) throws SocketException
+ {
+ session.getChannel().socket().setTcpNoDelay( on );
+ }
+
+ public int getTrafficClass() throws SocketException
+ {
+ return session.getChannel().socket().getTrafficClass();
+ }
+
+ public void setTrafficClass( int tc ) throws SocketException
+ {
+ session.getChannel().socket().setTrafficClass( tc );
+ }
+
+ public int getSendBufferSize() throws SocketException
+ {
+ return session.getChannel().socket().getSendBufferSize();
+ }
+
+ public void setSendBufferSize( int size ) throws SocketException
+ {
+ session.getChannel().socket().setSendBufferSize( size );
+ }
+
+ public int getReceiveBufferSize() throws SocketException
+ {
+ return session.getChannel().socket().getReceiveBufferSize();
+ }
+
+ public void setReceiveBufferSize( int size ) throws SocketException
+ {
+ session.getChannel().socket().setReceiveBufferSize( size );
+ }
+
+ public int getSessionReceiveBufferSize()
+ {
+ return readBufferSize;
+ }
+
+ public void setSessionReceiveBufferSize( int size )
+ {
+ if( size <= 0 )
+ {
+ throw new IllegalArgumentException( "Invalid session receive buffer size: " + size );
+ }
+
+ this.readBufferSize = size;
+ }
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionConfig.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java Mon May 9 02:21:50 2005
@@ -0,0 +1,33 @@
+package org.apache.mina.transport.socket.nio;
+
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionManager;
+import org.apache.mina.common.IoSessionManagerFilterChain;
+import org.apache.mina.util.Queue;
+
+/**
+ * An {@link IoFilterChain} for socket transport (TCP/IP).
+ *
+ * @author The Apache Directory Project
+ */
+class SocketSessionManagerFilterChain extends IoSessionManagerFilterChain {
+
+ SocketSessionManagerFilterChain( IoSessionManager manager )
+ {
+ super( manager );
+ }
+
+ protected void doWrite( IoSession session, Object message )
+ {
+ SocketSession s = ( SocketSession ) session;
+ Queue writeBufferQueue = s.getWriteBufferQueue();
+
+ synchronized( writeBufferQueue )
+ {
+ writeBufferQueue.push( message );
+ }
+
+ SocketIoProcessor.getInstance().flushSession( s );
+ }
+}
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/AnonymousVmPipeAddress.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/AnonymousVmPipeAddress.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/AnonymousVmPipeAddress.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/AnonymousVmPipeAddress.java Mon May 9 02:21:50 2005
@@ -0,0 +1,50 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import java.net.SocketAddress;
+
+/**
+ * A {@link SocketAddress} which represents anonymous in-VM pipe port.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class AnonymousVmPipeAddress extends SocketAddress implements Comparable
+{
+ private static final long serialVersionUID = 3258135768999475512L;
+
+ static final AnonymousVmPipeAddress INSTANCE = new AnonymousVmPipeAddress();
+
+ /**
+ * Creates a new instance with the specifid port number.
+ */
+ private AnonymousVmPipeAddress()
+ {
+ }
+
+ public int hashCode()
+ {
+ return 1432482932;
+ }
+
+ public boolean equals( Object o )
+ {
+ if( o == null )
+ return false;
+ if( this == o )
+ return true;
+ return o instanceof AnonymousVmPipeAddress;
+ }
+
+ public int compareTo( Object o )
+ {
+ return this.hashCode() - ( ( AnonymousVmPipeAddress ) o ).hashCode();
+ }
+
+ public String toString()
+ {
+ return "vm:anonymous";
+ }
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/AnonymousVmPipeAddress.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java Mon May 9 02:21:50 2005
@@ -0,0 +1,100 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.mina.common.BaseIoSessionManager;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+
+/**
+ * Binds the specified {@link ProtocolProvider} to the specified
+ * {@link VmPipeAddress}.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeAcceptor extends BaseIoSessionManager implements IoAcceptor
+{
+ static final Map boundHandlers = new HashMap();
+
+ private final VmPipeSessionManagerFilterChain filterChain =
+ new VmPipeSessionManagerFilterChain( this );
+
+ /**
+ * Creates a new instance.
+ */
+ public VmPipeAcceptor()
+ {
+ filterChain.addFirst( "VMPipe", new VmPipeFilter() );
+ }
+
+ public void bind( SocketAddress address, IoHandler handler ) throws IOException
+ {
+ if( address == null )
+ throw new NullPointerException( "address" );
+ if( handler == null )
+ throw new NullPointerException( "handler" );
+ if( !( address instanceof VmPipeAddress ) )
+ throw new IllegalArgumentException(
+ "address must be VmPipeAddress." );
+
+ synchronized( boundHandlers )
+ {
+ if( boundHandlers.containsKey( address ) )
+ {
+ throw new IOException( "Address already bound: " + address );
+ }
+
+ boundHandlers.put( address,
+ new Entry( this,
+ ( VmPipeAddress ) address,
+ filterChain,
+ handler ) );
+ }
+ }
+
+ public void unbind( SocketAddress address )
+ {
+ if( address == null )
+ throw new NullPointerException( "address" );
+
+ synchronized( boundHandlers )
+ {
+ boundHandlers.remove( address );
+ }
+ }
+
+ public IoFilterChain getFilterChain()
+ {
+ return filterChain;
+ }
+
+ static class Entry
+ {
+ final VmPipeAcceptor acceptor;
+
+ final VmPipeAddress address;
+
+ final VmPipeSessionManagerFilterChain managerFilterChain;
+
+ final IoHandler handler;
+
+ private Entry( VmPipeAcceptor acceptor,
+ VmPipeAddress address,
+ VmPipeSessionManagerFilterChain managerFilterChain,
+ IoHandler handler )
+ {
+ this.acceptor = acceptor;
+ this.address = address;
+ this.managerFilterChain = managerFilterChain;
+ this.handler = handler;
+ }
+ }
+}
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java Mon May 9 02:21:50 2005
@@ -0,0 +1,65 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import java.net.SocketAddress;
+
+/**
+ * A {@link SocketAddress} which represents in-VM pipe port number.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeAddress extends SocketAddress implements Comparable
+{
+ private static final long serialVersionUID = 3257844376976830515L;
+
+ private final int port;
+
+ /**
+ * Creates a new instance with the specifid port number.
+ */
+ public VmPipeAddress( int port )
+ {
+ this.port = port;
+ }
+
+ /**
+ * Returns the port number.
+ */
+ public int getPort()
+ {
+ return port;
+ }
+
+ public int hashCode()
+ {
+ return port;
+ }
+
+ public boolean equals( Object o )
+ {
+ if( o == null )
+ return false;
+ if( this == o )
+ return true;
+ if( o instanceof VmPipeAddress )
+ {
+ VmPipeAddress that = ( VmPipeAddress ) o;
+ return this.port == that.port;
+ }
+
+ return false;
+ }
+
+ public int compareTo( Object o )
+ {
+ return this.port - ( ( VmPipeAddress ) o ).port;
+ }
+
+ public String toString()
+ {
+ return "vm:" + port;
+ }
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java Mon May 9 02:21:50 2005
@@ -0,0 +1,79 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+import org.apache.mina.common.BaseIoSessionManager;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.transport.vmpipe.VmPipeAcceptor.Entry;
+
+/**
+ * Connects to {@link IoHandler}s which is bound on the specified
+ * {@link VmPipeAddress}.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeConnector extends BaseIoSessionManager implements IoConnector
+{
+ private final VmPipeSessionManagerFilterChain filterChain =
+ new VmPipeSessionManagerFilterChain( this );
+
+ /**
+ * Creates a new instance.
+ */
+ public VmPipeConnector()
+ {
+ filterChain.addFirst( "VMPipe", new VmPipeFilter() );
+ }
+
+ public IoFilterChain getFilterChain()
+ {
+ return filterChain;
+ }
+
+ public IoSession connect( SocketAddress address, IoHandler handler ) throws IOException
+ {
+ return connect( address, null, Integer.MAX_VALUE, handler );
+ }
+
+ public IoSession connect( SocketAddress address, SocketAddress localAddress, IoHandler handler ) throws IOException
+ {
+ return connect( address, localAddress, Integer.MAX_VALUE, handler );
+ }
+
+ public IoSession connect( SocketAddress address, int timeout, IoHandler handler ) throws IOException
+ {
+ return connect( address, null, timeout, handler );
+ }
+
+ public IoSession connect( SocketAddress address, SocketAddress localAddress, int timeout, IoHandler handler ) throws IOException
+ {
+ if( address == null )
+ throw new NullPointerException( "address" );
+ if( handler == null )
+ throw new NullPointerException( "handler" );
+ if( ! ( address instanceof VmPipeAddress ) )
+ throw new IllegalArgumentException(
+ "address must be VmPipeAddress." );
+
+ Entry entry = ( Entry ) VmPipeAcceptor.boundHandlers.get( address );
+ if( entry == null )
+ throw new IOException( "Endpoint unavailable: " + address );
+
+ VmPipeSession session = new VmPipeSession( new Object(), // lock
+ AnonymousVmPipeAddress.INSTANCE,
+ filterChain,
+ handler,
+ entry );
+
+ VmPipeIdleStatusChecker.INSTANCE.addSession( session );
+ return session;
+ }
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeFilter.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeFilter.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeFilter.java Mon May 9 02:21:50 2005
@@ -0,0 +1,44 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoSession;
+
+/**
+ * Sets last(Read|Write)Time for {@link VmPipeSession}s.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class VmPipeFilter extends IoFilterAdapter
+{
+ public void messageReceived( NextFilter nextFilter,
+ IoSession session, Object message )
+ {
+ VmPipeSession vps = ( VmPipeSession ) session;
+
+ vps.setIdle( IdleStatus.BOTH_IDLE, false );
+ vps.setIdle( IdleStatus.READER_IDLE, false );
+ vps.increaseReadBytes( 1 );
+
+ // fire messageSent event first
+ vps.remoteSession.getManagerFilterChain().messageSent( vps.remoteSession, message );
+
+ // and then messageReceived
+ nextFilter.messageReceived( session, message );
+ }
+
+ public void messageSent( NextFilter nextFilter,
+ IoSession session, Object message )
+ {
+ VmPipeSession vps = ( VmPipeSession ) session;
+ vps.setIdle( IdleStatus.BOTH_IDLE, false );
+ vps.setIdle( IdleStatus.WRITER_IDLE, false );
+ vps.increaseWrittenBytes( 1 );
+
+ nextFilter.messageSent( session, message );
+ }
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeFilter.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeIdleStatusChecker.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeIdleStatusChecker.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeIdleStatusChecker.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeIdleStatusChecker.java Mon May 9 02:21:50 2005
@@ -0,0 +1,121 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.mina.common.IdleStatus;
+import org.apache.mina.common.IoSessionConfig;
+
+/**
+ * Dectects idle sessions and fires <tt>sessionIdle</tt> events to them.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class VmPipeIdleStatusChecker
+{
+ static final VmPipeIdleStatusChecker INSTANCE = new VmPipeIdleStatusChecker();
+
+ private final Map sessions = new IdentityHashMap(); // will use as a set
+
+ private final Worker worker = new Worker();
+
+ private VmPipeIdleStatusChecker()
+ {
+ worker.start();
+ }
+
+ void addSession( VmPipeSession session )
+ {
+ synchronized( sessions )
+ {
+ sessions.put( session, session );
+ }
+ }
+
+ private class Worker extends Thread
+ {
+ private Worker()
+ {
+ super( "VmPipeIdleStatusChecker" );
+ setDaemon( true );
+ }
+
+ public void run()
+ {
+ for( ;; )
+ {
+ try
+ {
+ Thread.sleep( 1000 );
+ }
+ catch( InterruptedException e )
+ {
+ }
+
+ long currentTime = System.currentTimeMillis();
+
+ synchronized( sessions )
+ {
+ Iterator it = sessions.keySet().iterator();
+ while( it.hasNext() )
+ {
+ VmPipeSession session = ( VmPipeSession ) it.next();
+ if( !session.isConnected() )
+ {
+ it.remove();
+ }
+ else
+ {
+ long idleTime;
+ IoSessionConfig config = session.getConfig();
+
+ if( !session.isIdle( IdleStatus.BOTH_IDLE ) )
+ {
+ idleTime = config
+ .getIdleTimeInMillis( IdleStatus.BOTH_IDLE );
+ session.setIdle( IdleStatus.BOTH_IDLE,
+ idleTime > 0L
+ && ( currentTime - session.getLastIoTime() ) > idleTime );
+ if( session.isIdle( IdleStatus.BOTH_IDLE ) )
+ session.getManagerFilterChain()
+ .sessionIdle( session,
+ IdleStatus.BOTH_IDLE );
+ }
+
+ if( !session.isIdle( IdleStatus.READER_IDLE ) )
+ {
+ idleTime = config
+ .getIdleTimeInMillis( IdleStatus.READER_IDLE );
+ session.setIdle( IdleStatus.READER_IDLE,
+ idleTime > 0L
+ && ( currentTime - session.getLastReadTime() ) > idleTime );
+ if( session.isIdle( IdleStatus.READER_IDLE ) )
+ session.getManagerFilterChain()
+ .sessionIdle( session,
+ IdleStatus.READER_IDLE );
+ }
+
+ if( !session.isIdle( IdleStatus.WRITER_IDLE ) )
+ {
+ idleTime = config
+ .getIdleTimeInMillis( IdleStatus.WRITER_IDLE );
+ session.setIdle( IdleStatus.WRITER_IDLE,
+ idleTime > 0L
+ && ( currentTime - session.getLastWriteTime() ) > idleTime );
+ if( session.isIdle( IdleStatus.WRITER_IDLE ) )
+ session.getManagerFilterChain()
+ .sessionIdle( session,
+ IdleStatus.WRITER_IDLE );
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeIdleStatusChecker.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java Mon May 9 02:21:50 2005
@@ -0,0 +1,172 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+import org.apache.mina.common.BaseIoSession;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.common.IoSessionFilterChain;
+import org.apache.mina.common.TransportType;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.transport.vmpipe.VmPipeAcceptor.Entry;
+import org.apache.mina.util.ExceptionUtil;
+
+/**
+ * A {@link IoSession} for in-VM transport (VM_PIPE).
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+class VmPipeSession extends BaseIoSession implements IoSession
+{
+ private final SocketAddress localAddress;
+
+ private final SocketAddress remoteAddress;
+
+ private final IoHandler handler;
+
+ private final VmPipeSessionConfig config = new VmPipeSessionConfig();
+
+ private final IoSessionFilterChain filterChain;
+
+ private final VmPipeSessionManagerFilterChain managerFilterChain;
+
+ final VmPipeSession remoteSession;
+
+ final Object lock;
+
+ boolean closed;
+
+ /**
+ * Constructor for client-side session.
+ */
+ VmPipeSession( Object lock, SocketAddress localAddress,
+ VmPipeSessionManagerFilterChain managerFilterChain,
+ IoHandler handler,
+ Entry remoteEntry ) throws IOException
+ {
+ this.lock = lock;
+ this.localAddress = localAddress;
+ this.remoteAddress = remoteEntry.address;
+ this.handler = handler;
+ this.filterChain = new IoSessionFilterChain( managerFilterChain );
+ this.managerFilterChain = managerFilterChain;
+
+ remoteSession = new VmPipeSession( this, remoteEntry );
+
+ // initialize remote session
+ try
+ {
+ remoteEntry.handler.sessionCreated( remoteSession );
+ }
+ catch( Throwable t )
+ {
+ remoteEntry.acceptor.getExceptionMonitor().exceptionCaught( remoteEntry.acceptor, t );
+ IOException e = new IOException( "Failed to initialize remote session." );
+ e.initCause( t );
+ throw e;
+ }
+
+ // initialize client session
+ try
+ {
+ handler.sessionCreated( this );
+ }
+ catch( Throwable t )
+ {
+ ExceptionUtil.throwException( t );
+ }
+
+ remoteEntry.managerFilterChain.sessionOpened( remoteSession );
+ managerFilterChain.sessionOpened( this );
+ }
+
+ /**
+ * Constructor for server-side session.
+ */
+ VmPipeSession( VmPipeSession remoteSession, Entry entry )
+ {
+ this.lock = remoteSession.lock;
+ this.localAddress = remoteSession.remoteAddress;
+ this.remoteAddress = remoteSession.localAddress;
+ this.handler = entry.handler;
+ this.managerFilterChain = entry.managerFilterChain;
+ this.filterChain = new IoSessionFilterChain( entry.managerFilterChain );
+ this.remoteSession = remoteSession;
+ }
+
+ VmPipeSessionManagerFilterChain getManagerFilterChain()
+ {
+ return managerFilterChain;
+ }
+
+ public IoFilterChain getFilterChain()
+ {
+ return filterChain;
+ }
+
+ public IoHandler getHandler()
+ {
+ return handler;
+ }
+
+ public ProtocolEncoder getEncoder()
+ {
+ return null;
+ }
+
+ public ProtocolDecoder getDecoder()
+ {
+ return null;
+ }
+
+ public void close( boolean wait )
+ {
+ synchronized( lock )
+ {
+ if( closed )
+ return;
+
+ closed = remoteSession.closed = true;
+ managerFilterChain.sessionClosed( this );
+ remoteSession.getManagerFilterChain().sessionClosed( remoteSession );
+ }
+ }
+
+ public void write( Object message )
+ {
+ this.filterChain.filterWrite( this, message );
+ }
+
+ public TransportType getTransportType()
+ {
+ return TransportType.VM_PIPE;
+ }
+
+ public boolean isConnected()
+ {
+ return !closed;
+ }
+
+ public IoSessionConfig getConfig()
+ {
+ return config;
+ }
+
+ public SocketAddress getRemoteAddress()
+ {
+ return remoteAddress;
+ }
+
+ public SocketAddress getLocalAddress()
+ {
+ return localAddress;
+ }
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionConfig.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionConfig.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionConfig.java Mon May 9 02:21:50 2005
@@ -0,0 +1,16 @@
+/*
+ * @(#) $Id$
+ */
+package org.apache.mina.transport.vmpipe;
+
+import org.apache.mina.common.BaseIoSessionConfig;
+
+/**
+ * A {@link SessionConfig} for in-VM pipe transport.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class VmPipeSessionConfig extends BaseIoSessionConfig
+{
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionConfig.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java Mon May 9 02:21:50 2005
@@ -0,0 +1,25 @@
+package org.apache.mina.transport.vmpipe;
+
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionManager;
+import org.apache.mina.common.IoSessionManagerFilterChain;
+
+class VmPipeSessionManagerFilterChain extends IoSessionManagerFilterChain {
+
+ VmPipeSessionManagerFilterChain( IoSessionManager manager )
+ {
+ super( manager );
+ }
+
+ protected void doWrite( IoSession session, Object message )
+ {
+ VmPipeSession s = ( VmPipeSession ) session;
+
+ synchronized( s.lock )
+ {
+ if( s.closed )
+ throw new IllegalStateException( "Session is closed." );
+ s.remoteSession.getManagerFilterChain().messageReceived( s.remoteSession, message );
+ }
+ }
+}
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/package.html
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/package.html?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/package.html (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/package.html Mon May 9 02:21:50 2005
@@ -0,0 +1,26 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<html>
+<head>
+</head>
+<body>
+In-VM pipe support which removes the overhead of local loopback communication.
+
+<h1>What is 'in-VM pipe'?</h1>
+<p>
+ In-VM pipe is a direct event forwarding mechanism between two
+ <a href="../ProtocolHandler.html"><code>ProtocolHandler</code></a>s in the
+ same Java Virtual Machine. Using in-VM pipe, you can remove the overhead
+ of encoding and decoding which is caused uselessly by local loopback
+ network communication. Here are some useful situations possible:
+ <ul>
+ <li>SMTP server and SPAM filtering server,</li>
+ <li>web server and Servlet/JSP container.</li>
+ </ul>
+</p>
+<p>
+ Please refer to
+ <a href="../../../../../../xref-examples/org/apache/mina/examples/tennis/Main.html">Tennis</a>
+ example.
+</p>
+</body>
+</html>
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/package.html
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Modified: directory/network/branches/api_integration/src/java/org/apache/mina/util/BaseThreadPool.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/util/BaseThreadPool.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/util/BaseThreadPool.java (original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/util/BaseThreadPool.java Mon May 9 02:21:50 2005
@@ -24,7 +24,7 @@
import java.util.Map;
import java.util.Set;
-import org.apache.mina.common.Session;
+import org.apache.mina.common.IoSession;
/**
* A base implementation of Thread-pooling filters.
@@ -170,7 +170,7 @@
}
}
- protected void fireEvent( Object nextFilter, Session session,
+ protected void fireEvent( Object nextFilter, IoSession session,
EventType type, Object data )
{
final BlockingSet readySessionBuffers = this.readySessionBuffers;
@@ -197,10 +197,10 @@
/**
* Implement this method to forward events to <tt>nextFilter</tt>.
*/
- protected abstract void processEvent( Object nextFilter, Session session,
+ protected abstract void processEvent( Object nextFilter, IoSession session,
EventType type, Object data );
- private SessionBuffer getSessionBuffer( Session session )
+ private SessionBuffer getSessionBuffer( IoSession session )
{
final Map buffers = this.buffers;
SessionBuffer buf = ( SessionBuffer ) buffers.get( session );
@@ -222,7 +222,7 @@
private void removeSessionBuffer( SessionBuffer buf )
{
final Map buffers = this.buffers;
- final Session session = buf.session;
+ final IoSession session = buf.session;
synchronized( buffers )
{
buffers.remove( session );
@@ -231,11 +231,11 @@
private static class SessionBuffer
{
- private final Session session;
+ private final IoSession session;
private final Queue eventQueue = new Queue();
- private SessionBuffer( Session session )
+ private SessionBuffer( IoSession session )
{
this.session = session;
}
@@ -326,7 +326,7 @@
private void processEvents( SessionBuffer buf )
{
- final Session session = buf.session;
+ final IoSession session = buf.session;
final Queue eventQueue = buf.eventQueue;
for( ;; )
{
Modified: directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionLog.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionLog.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionLog.java (original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionLog.java Mon May 9 02:21:50 2005
@@ -3,9 +3,7 @@
import java.util.logging.Level;
import java.util.logging.Logger;
-import org.apache.mina.common.Session;
-import org.apache.mina.io.IoSession;
-import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.common.IoSession;
/**
* Call {@link #getLogger(Session)}, {@link #log(Level,Session, String)}, and
@@ -30,7 +28,7 @@
*/
public static final String LOGGER = SessionLog.class.getName() + ".logger";
- public static Logger getLogger( Session session )
+ public static Logger getLogger( IoSession session )
{
Logger log = (Logger) session.getAttribute( LOGGER );
@@ -50,15 +48,12 @@
return log;
}
- private static String getClassName( Session session )
+ private static String getClassName( IoSession session )
{
- if( session instanceof IoSession )
- return ( ( IoSession ) session ).getHandler().getClass().getName();
- else
- return ( ( ProtocolSession ) session ).getHandler().getClass().getName();
+ return session.getHandler().getClass().getName();
}
- public static void log( Level level, Session session, String message )
+ public static void log( Level level, IoSession session, String message )
{
Logger log = getLogger( session );
if( log.isLoggable( level ) )
@@ -67,7 +62,7 @@
}
}
- public static void log( Level level, Session session, String message, Throwable cause )
+ public static void log( Level level, IoSession session, String message, Throwable cause )
{
Logger log = getLogger( session );
if( log.isLoggable( level ) )
Modified: directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionUtil.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionUtil.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionUtil.java (original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionUtil.java Mon May 9 02:21:50 2005
@@ -20,10 +20,10 @@
import java.net.SocketException;
-import org.apache.mina.common.Session;
-import org.apache.mina.common.SessionConfig;
-import org.apache.mina.io.datagram.DatagramSessionConfig;
-import org.apache.mina.io.socket.SocketSessionConfig;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
+import org.apache.mina.transport.socket.nio.DatagramSessionConfig;
+import org.apache.mina.transport.socket.nio.SocketSessionConfig;
/**
* Exception utility.
@@ -34,9 +34,9 @@
*/
public class SessionUtil
{
- public static void initialize( Session session ) throws SocketException
+ public static void initialize( IoSession session ) throws SocketException
{
- SessionConfig config = session.getConfig();
+ IoSessionConfig config = session.getConfig();
if( config instanceof SocketSessionConfig )
{
SocketSessionConfig ssc = ( SocketSessionConfig ) config;
Modified: directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java (original)
+++ directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java Mon May 9 02:21:50 2005
@@ -30,12 +30,12 @@
import org.apache.commons.net.EchoTCPClient;
import org.apache.commons.net.EchoUDPClient;
+import org.apache.mina.common.IoAcceptor;
import org.apache.mina.common.TransportType;
import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
import org.apache.mina.examples.echoserver.ssl.SSLServerSocketFactory;
import org.apache.mina.examples.echoserver.ssl.SSLSocketFactory;
-import org.apache.mina.io.IoAcceptor;
-import org.apache.mina.io.filter.SSLFilter;
+import org.apache.mina.filter.SSLFilter;
/**
* Tests echo server example.
@@ -60,7 +60,7 @@
// Add an SSL filter
SSLFilter sslFilter =
new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
- IoAcceptor acceptor = registry.getIoAcceptor( TransportType.SOCKET );
+ IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
acceptor.getFilterChain().addLast( "SSL", sslFilter );
// Create a commons-net socket factory
Modified: directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java (original)
+++ directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java Mon May 9 02:21:50 2005
@@ -25,15 +25,15 @@
import junit.framework.Assert;
import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
import org.apache.mina.common.TransportType;
import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
-import org.apache.mina.io.IoAcceptor;
-import org.apache.mina.io.IoConnector;
-import org.apache.mina.io.IoHandlerAdapter;
-import org.apache.mina.io.IoSession;
-import org.apache.mina.io.datagram.DatagramConnector;
-import org.apache.mina.io.filter.SSLFilter;
-import org.apache.mina.io.socket.SocketConnector;
+import org.apache.mina.filter.SSLFilter;
+import org.apache.mina.transport.socket.nio.DatagramConnector;
+import org.apache.mina.transport.socket.nio.SocketConnector;
import org.apache.mina.util.AvailablePortFinder;
/**
@@ -72,7 +72,7 @@
// Add an SSL filter to acceptor
SSLFilter acceptorSSLFilter =
new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
- IoAcceptor acceptor = registry.getIoAcceptor( TransportType.SOCKET );
+ IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
acceptor.getFilterChain().addLast( "SSL", acceptorSSLFilter );
// Create a connector
@@ -139,17 +139,8 @@
fillWriteBuffer( buf, i );
buf.flip();
- Object marker;
- if( ( i & 1 ) == 0 )
- {
- marker = new Integer( i );
- }
- else
- {
- marker = null;
- }
-
- session.write( buf, marker );
+ // FIXME test virtual marker
+ session.write( buf );
// This will align message arrival order in UDP
for( int j = 0; j < 30; j ++ )
@@ -205,26 +196,27 @@
private ByteBuffer readBuf = ByteBuffer.allocate( 1024 );
private int counter = 0;
- public void dataRead( IoSession session, ByteBuffer buf )
+ public void messageReceived( IoSession session, Object message )
{
- readBuf.put( buf );
+ readBuf.put( ( ByteBuffer ) message );
}
- public void dataWritten( IoSession session, Object marker )
+ public void messageSent( IoSession session, Object message )
{
- if( marker != SSLFilter.SSL_MARKER )
- {
- if( ( counter & 1 ) == 0 )
- {
- Assert.assertEquals( new Integer( counter ), marker );
- }
- else
- {
- Assert.assertNull( marker );
- }
-
- counter ++;
- }
+ // FIXME test virtual marker
+ //if( message != SSLFilter.SSL_MARKER )
+ //{
+ // if( ( counter & 1 ) == 0 )
+ // {
+ // Assert.assertEquals( new Integer( counter ), message );
+ // }
+ // else
+ // {
+ // Assert.assertNull( message );
+ // }
+ //
+ // counter ++;
+ //}
}
public void exceptionCaught( IoSession session, Throwable cause )
Modified: directory/network/branches/api_integration/src/test/org/apache/mina/io/AbstractBindTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/test/org/apache/mina/io/AbstractBindTest.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/test/org/apache/mina/io/AbstractBindTest.java (original)
+++ directory/network/branches/api_integration/src/test/org/apache/mina/io/AbstractBindTest.java Mon May 9 02:21:50 2005
@@ -25,6 +25,7 @@
import junit.framework.Assert;
import junit.framework.TestCase;
+import org.apache.mina.common.IoAcceptor;
import org.apache.mina.examples.echoserver.EchoProtocolHandler;
/**
Modified: directory/network/branches/api_integration/src/test/org/apache/mina/io/datagram/BindTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/test/org/apache/mina/io/datagram/BindTest.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/test/org/apache/mina/io/datagram/BindTest.java (original)
+++ directory/network/branches/api_integration/src/test/org/apache/mina/io/datagram/BindTest.java Mon May 9 02:21:50 2005
@@ -21,6 +21,7 @@
import java.io.IOException;
import org.apache.mina.io.AbstractBindTest;
+import org.apache.mina.transport.socket.nio.DatagramAcceptor;
/**
* Tests {@link DatagramAcceptor} resource leakage.
Modified: directory/network/branches/api_integration/src/test/org/apache/mina/io/socket/BindTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/test/org/apache/mina/io/socket/BindTest.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/test/org/apache/mina/io/socket/BindTest.java (original)
+++ directory/network/branches/api_integration/src/test/org/apache/mina/io/socket/BindTest.java Mon May 9 02:21:50 2005
@@ -21,6 +21,7 @@
import java.io.IOException;
import org.apache.mina.io.AbstractBindTest;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
/**
* Tests {@link SocketAcceptor} resource leakage.
Modified: directory/network/branches/api_integration/src/test/org/apache/mina/protocol/ProtocolFilterChainTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/test/org/apache/mina/protocol/ProtocolFilterChainTest.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/test/org/apache/mina/protocol/ProtocolFilterChainTest.java (original)
+++ directory/network/branches/api_integration/src/test/org/apache/mina/protocol/ProtocolFilterChainTest.java Mon May 9 02:21:50 2005
@@ -23,10 +23,18 @@
import junit.framework.Assert;
import junit.framework.TestCase;
-import org.apache.mina.common.BaseSession;
+import org.apache.mina.common.AbstractIoFilterChain;
+import org.apache.mina.common.BaseIoSession;
import org.apache.mina.common.IdleStatus;
-import org.apache.mina.common.SessionConfig;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
import org.apache.mina.common.TransportType;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
/**
* Tests {@link AbstractProtocolFilterChain}.
@@ -37,7 +45,7 @@
public class ProtocolFilterChainTest extends TestCase
{
private ProtocolFilterChainImpl chain;
- private ProtocolSession session;
+ private IoSession session;
private String result;
public void setUp()
@@ -101,23 +109,23 @@
return buf.toString();
}
- private class TestSession extends BaseSession implements ProtocolSession
+ private class TestSession extends BaseIoSession implements IoSession
{
- private ProtocolHandler handler = new ProtocolHandlerAdapter()
+ private IoHandler handler = new IoHandlerAdapter()
{
- public void sessionOpened(ProtocolSession session) {
+ public void sessionOpened(IoSession session) {
result += "HSO";
}
- public void sessionClosed(ProtocolSession session) {
+ public void sessionClosed(IoSession session) {
result += "HSC";
}
- public void sessionIdle(ProtocolSession session, IdleStatus status) {
+ public void sessionIdle(IoSession session, IdleStatus status) {
result += "HSI";
}
- public void exceptionCaught(ProtocolSession session, Throwable cause) {
+ public void exceptionCaught(IoSession session, Throwable cause) {
result += "HEC";
if( cause.getClass() != Exception.class )
{
@@ -125,16 +133,16 @@
}
}
- public void messageReceived(ProtocolSession session, Object message) {
+ public void messageReceived(IoSession session, Object message) {
result += "HMR";
}
- public void messageSent(ProtocolSession session, Object message) {
+ public void messageSent(IoSession session, Object message) {
result += "HMS";
}
};
- public ProtocolHandler getHandler() {
+ public IoHandler getHandler() {
return handler;
}
@@ -160,7 +168,7 @@
return false;
}
- public SessionConfig getConfig() {
+ public IoSessionConfig getConfig() {
return null;
}
@@ -172,13 +180,13 @@
return null;
}
- public ProtocolFilterChain getFilterChain()
+ public IoFilterChain getFilterChain()
{
return null;
}
}
- private class TestFilter implements ProtocolFilter
+ private class TestFilter implements IoFilter
{
private final char id;
@@ -187,49 +195,49 @@
this.id = id;
}
- public void sessionOpened(NextFilter nextFilter, ProtocolSession session) {
+ public void sessionOpened(NextFilter nextFilter, IoSession session) {
result += id + "SO";
nextFilter.sessionOpened( session );
}
- public void sessionClosed(NextFilter nextFilter, ProtocolSession session) {
+ public void sessionClosed(NextFilter nextFilter, IoSession session) {
result += id + "SC";
nextFilter.sessionClosed( session );
}
- public void sessionIdle(NextFilter nextFilter, ProtocolSession session, IdleStatus status) {
+ public void sessionIdle(NextFilter nextFilter, IoSession session, IdleStatus status) {
result += id + "SI";
nextFilter.sessionIdle( session, status );
}
- public void exceptionCaught(NextFilter nextFilter, ProtocolSession session, Throwable cause) {
+ public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) {
result += id + "EC";
nextFilter.exceptionCaught( session, cause );
}
- public void filterWrite(NextFilter nextFilter, ProtocolSession session, Object message) {
+ public void filterWrite(NextFilter nextFilter, IoSession session, Object message) {
result += id + "FW";
nextFilter.filterWrite( session, message );
}
- public void messageReceived(NextFilter nextFilter, org.apache.mina.protocol.ProtocolSession session, Object message) {
+ public void messageReceived(NextFilter nextFilter, IoSession session, Object message) {
result += id + "MR";
nextFilter.messageReceived( session, message );
}
- public void messageSent(NextFilter nextFilter, org.apache.mina.protocol.ProtocolSession session, Object message) {
+ public void messageSent(NextFilter nextFilter, IoSession session, Object message) {
result += id + "MS";
nextFilter.messageSent( session, message );
}
}
- private static class ProtocolFilterChainImpl extends AbstractProtocolFilterChain
+ private static class ProtocolFilterChainImpl extends AbstractIoFilterChain
{
protected ProtocolFilterChainImpl()
{
}
- protected void doWrite( ProtocolSession session, Object message )
+ protected void doWrite( IoSession session, Object message )
{
messageSent( session, message );
}
Modified: directory/network/branches/api_integration/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java (original)
+++ directory/network/branches/api_integration/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java Mon May 9 02:21:50 2005
@@ -25,17 +25,18 @@
import junit.framework.Assert;
import junit.framework.TestCase;
-import org.apache.mina.common.BaseSession;
+import org.apache.mina.common.BaseIoSession;
import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.SessionConfig;
+import org.apache.mina.common.IoFilterChain;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.common.IoSessionConfig;
import org.apache.mina.common.TransportType;
-import org.apache.mina.protocol.ProtocolDecoder;
-import org.apache.mina.protocol.ProtocolDecoderOutput;
-import org.apache.mina.protocol.ProtocolEncoder;
-import org.apache.mina.protocol.ProtocolHandler;
-import org.apache.mina.protocol.ProtocolFilterChain;
-import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.protocol.ProtocolViolationException;
+import org.apache.mina.filter.codec.CumulativeProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolViolationException;
/**
* Tests {@link CumulativeProtocolDecoder}.
@@ -45,7 +46,7 @@
*/
public class CumulativeProtocolDecoderTest extends TestCase
{
- private final ProtocolSession session = new ProtocolSessionImpl();
+ private final IoSession session = new IoSessionImpl();
private ByteBuffer buf;
private IntegerDecoder decoder;
private IntegerDecoderOutput output;
@@ -127,7 +128,7 @@
super( 4 );
}
- protected boolean doDecode( ProtocolSession session, ByteBuffer in,
+ protected boolean doDecode( IoSession session, ByteBuffer in,
ProtocolDecoderOutput out ) throws ProtocolViolationException
{
if( in.remaining() < 4 )
@@ -166,16 +167,16 @@
super( 4 );
}
- protected boolean doDecode( ProtocolSession session, ByteBuffer in,
+ protected boolean doDecode( IoSession session, ByteBuffer in,
ProtocolDecoderOutput out ) throws ProtocolViolationException {
return true;
}
}
- private static class ProtocolSessionImpl extends BaseSession implements ProtocolSession
+ private static class IoSessionImpl extends BaseIoSession implements IoSession
{
- public ProtocolHandler getHandler() {
+ public IoHandler getHandler() {
return null;
}
@@ -201,7 +202,7 @@
return false;
}
- public SessionConfig getConfig() {
+ public IoSessionConfig getConfig() {
return null;
}
@@ -213,7 +214,7 @@
return null;
}
- public ProtocolFilterChain getFilterChain()
+ public IoFilterChain getFilterChain()
{
return null;
}
Modified: directory/network/branches/api_integration/src/test/org/apache/mina/util/IoFilterImpl.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/test/org/apache/mina/util/IoFilterImpl.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/test/org/apache/mina/util/IoFilterImpl.java (original)
+++ directory/network/branches/api_integration/src/test/org/apache/mina/util/IoFilterImpl.java Mon May 9 02:21:50 2005
@@ -18,9 +18,9 @@
*/
package org.apache.mina.util;
-import org.apache.mina.io.IoFilter;
-import org.apache.mina.io.IoFilterAdapter;
-import org.apache.mina.io.IoFilterChain;
+import org.apache.mina.common.IoFilter;
+import org.apache.mina.common.IoFilterAdapter;
+import org.apache.mina.common.IoFilterChain;
/**
* Bogus implementation of {@link IoFilter} to test