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 [1/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/
Author: trustin
Date: Mon May 9 02:21:50 2005
New Revision: 169259
URL: http://svn.apache.org/viewcvs?rev=169259&view=rev
Log:
* Integrated I/O layer and Protocol layer
* TODO: Fix protocol layer compatibility
* TODO: Reorganize test classes
Added:
directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSession.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionConfig.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionManager.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoAcceptor.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoConnector.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilter.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilterAdapter.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilterChain.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoHandler.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoHandlerAdapter.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoSession.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoSessionConfig.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoSessionFilterChain.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoSessionManager.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/IoSessionManagerFilterChain.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/common/WriteTimeoutException.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/
directory/network/branches/api_integration/src/java/org/apache/mina/filter/BlacklistFilter.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/LoggingFilter.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/SSLByteBufferPool.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/SSLFilter.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/SSLHandler.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/ThreadPoolFilter.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/CumulativeProtocolDecoder.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/DemuxingProtocolCodecFactory.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoder.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageDecoderResult.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/MessageEncoder.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFactory.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolCodecFilter.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoder.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolDecoderOutput.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoder.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolEncoderOutput.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/ProtocolViolationException.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolDecoderOutput.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/filter/codec/SimpleProtocolEncoderOutput.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/handler/
directory/network/branches/api_integration/src/java/org/apache/mina/handler/DemuxingIoHandler.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/handler/MessageHandler.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/handler/StreamIoHandler.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/handler/UnknownMessageTypeException.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/bio/
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramAcceptor.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramConnector.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramSession.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramSessionConfig.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManager.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/DatagramSessionManagerFilterChain.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketAcceptor.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketConnector.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketIoProcessor.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSession.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionConfig.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/socket/nio/SocketSessionManagerFilterChain.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/AnonymousVmPipeAddress.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAcceptor.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeAddress.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeConnector.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeFilter.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeIdleStatusChecker.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSession.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionConfig.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/VmPipeSessionManagerFilterChain.java (with props)
directory/network/branches/api_integration/src/java/org/apache/mina/transport/vmpipe/package.html (with props)
Removed:
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/ReverseProtocolProvider.java
directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseSession.java
directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseSessionConfig.java
directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseSessionManager.java
directory/network/branches/api_integration/src/java/org/apache/mina/common/Session.java
directory/network/branches/api_integration/src/java/org/apache/mina/common/SessionConfig.java
directory/network/branches/api_integration/src/java/org/apache/mina/common/SessionManager.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/AbstractIoFilterChain.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoAcceptor.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoConnector.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoFilter.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoFilterAdapter.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoFilterChain.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoHandler.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoHandlerAdapter.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoSession.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoSessionFilterChain.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoSessionManager.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/IoSessionManagerFilterChain.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/WriteTimeoutException.java
directory/network/branches/api_integration/src/java/org/apache/mina/io/datagram/
directory/network/branches/api_integration/src/java/org/apache/mina/io/filter/
directory/network/branches/api_integration/src/java/org/apache/mina/io/handler/
directory/network/branches/api_integration/src/java/org/apache/mina/io/package.html
directory/network/branches/api_integration/src/java/org/apache/mina/io/socket/
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/AbstractProtocolFilterChain.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolAcceptor.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolCodecFactory.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolConnector.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolDecoder.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolDecoderOutput.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolEncoder.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolEncoderOutput.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolFilter.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolFilterAdapter.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolFilterChain.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolHandler.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolHandlerAdapter.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolProvider.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolSession.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolSessionFilterChain.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolSessionManager.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolSessionManagerFilterChain.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/ProtocolViolationException.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/SimpleProtocolDecoderOutput.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/SimpleProtocolEncoderOutput.java
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/codec/
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/filter/
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/handler/
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/io/
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/package.html
directory/network/branches/api_integration/src/java/org/apache/mina/protocol/vmpipe/
directory/network/branches/api_integration/src/test/org/apache/mina/io/IoFilterChainTest.java
directory/network/branches/api_integration/src/test/org/apache/mina/util/ProtocolFilterImpl.java
Modified:
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/Main.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/HttpProtocolHandler.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/Main.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/Main.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/Main.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/Main.java
directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java
directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java
directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBufferHexDumper.java
directory/network/branches/api_integration/src/java/org/apache/mina/common/IdleStatus.java
directory/network/branches/api_integration/src/java/org/apache/mina/registry/Service.java
directory/network/branches/api_integration/src/java/org/apache/mina/registry/ServiceRegistry.java
directory/network/branches/api_integration/src/java/org/apache/mina/registry/SimpleServiceRegistry.java
directory/network/branches/api_integration/src/java/org/apache/mina/util/BaseThreadPool.java
directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionLog.java
directory/network/branches/api_integration/src/java/org/apache/mina/util/SessionUtil.java
directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
directory/network/branches/api_integration/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
directory/network/branches/api_integration/src/test/org/apache/mina/io/AbstractBindTest.java
directory/network/branches/api_integration/src/test/org/apache/mina/io/datagram/BindTest.java
directory/network/branches/api_integration/src/test/org/apache/mina/io/socket/BindTest.java
directory/network/branches/api_integration/src/test/org/apache/mina/protocol/ProtocolFilterChainTest.java
directory/network/branches/api_integration/src/test/org/apache/mina/protocol/codec/CumulativeProtocolDecoderTest.java
directory/network/branches/api_integration/src/test/org/apache/mina/util/IoFilterImpl.java
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/EchoProtocolHandler.java Mon May 9 02:21:50 2005
@@ -19,11 +19,11 @@
package org.apache.mina.examples.echoserver;
import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.common.SessionConfig;
-import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.IoHandlerAdapter;
-import org.apache.mina.io.IoSession;
-import org.apache.mina.io.socket.SocketSessionConfig;
+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.transport.socket.nio.SocketSessionConfig;
/**
* {@link IoHandler} implementation for echo server.
@@ -35,7 +35,7 @@
{
public void sessionCreated( IoSession session )
{
- SessionConfig cfg = session.getConfig();
+ IoSessionConfig cfg = session.getConfig();
if( cfg instanceof SocketSessionConfig )
{
( ( SocketSessionConfig ) cfg ).setSessionReceiveBufferSize( 2048 );
@@ -47,12 +47,13 @@
session.close();
}
- public void dataRead( IoSession session, ByteBuffer rb )
+ public void messageReceived( IoSession session, Object message )
{
+ ByteBuffer rb = ( ByteBuffer ) message;
// Write the received data back to remote peer
ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
wb.put( rb );
wb.flip();
- session.write( wb, null );
+ session.write( wb );
}
}
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/Main.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/Main.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/echoserver/Main.java Mon May 9 02:21:50 2005
@@ -18,11 +18,11 @@
*/
package org.apache.mina.examples.echoserver;
+import org.apache.mina.common.IoAcceptor;
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.filter.IoLoggingFilter;
-import org.apache.mina.io.filter.SSLFilter;
+import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.filter.SSLFilter;
import org.apache.mina.registry.Service;
import org.apache.mina.registry.ServiceRegistry;
import org.apache.mina.registry.SimpleServiceRegistry;
@@ -65,15 +65,15 @@
{
SSLFilter sslFilter =
new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
- IoAcceptor acceptor = registry.getIoAcceptor( TransportType.SOCKET );
+ IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
acceptor.getFilterChain().addLast( "sslFilter", sslFilter );
System.out.println( "SSL ON" );
}
private static void addLogger( ServiceRegistry registry )
{
- IoAcceptor acceptor = registry.getIoAcceptor( TransportType.SOCKET );
- acceptor.getFilterChain().addLast( "logger", new IoLoggingFilter() );
+ IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
+ acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
System.out.println( "Logging ON" );
}
}
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/HttpProtocolHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/HttpProtocolHandler.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/HttpProtocolHandler.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/HttpProtocolHandler.java Mon May 9 02:21:50 2005
@@ -31,8 +31,8 @@
import java.util.TreeMap;
import java.util.Map.Entry;
-import org.apache.mina.io.IoSession;
-import org.apache.mina.io.handler.StreamIoHandler;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.handler.StreamIoHandler;
/**
* A simplistic HTTP protocol handler that replies back the URL and headers
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/Main.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/Main.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/httpserver/Main.java Mon May 9 02:21:50 2005
@@ -18,10 +18,10 @@
*/
package org.apache.mina.examples.httpserver;
+import org.apache.mina.common.IoAcceptor;
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.filter.SSLFilter;
+import org.apache.mina.filter.SSLFilter;
import org.apache.mina.registry.Service;
import org.apache.mina.registry.ServiceRegistry;
import org.apache.mina.registry.SimpleServiceRegistry;
@@ -35,9 +35,9 @@
public class Main
{
/** Choose your favorite port number. */
- private static final int PORT = 8081;
+ private static final int PORT = 8080;
- private static final boolean USE_SSL = true;
+ private static final boolean USE_SSL = false;
public static void main( String[] args ) throws Exception
{
@@ -63,7 +63,7 @@
System.out.println( "SSL is enabled." );
SSLFilter sslFilter =
new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
- IoAcceptor acceptor = registry.getIoAcceptor( TransportType.SOCKET );
+ IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
acceptor.getFilterChain().addLast( "sslFilter", sslFilter );
}
}
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/Main.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/Main.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/Main.java Mon May 9 02:21:50 2005
@@ -20,7 +20,7 @@
import java.net.InetSocketAddress;
-import org.apache.mina.io.socket.SocketConnector;
+import org.apache.mina.transport.socket.nio.SocketConnector;
/**
* (<b>Entry point</b>) NetCat client. NetCat client connects to the specified
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/netcat/NetCatProtocolHandler.java Mon May 9 02:21:50 2005
@@ -20,9 +20,9 @@
import org.apache.mina.common.ByteBuffer;
import org.apache.mina.common.IdleStatus;
-import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.IoHandlerAdapter;
-import org.apache.mina.io.IoSession;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
/**
* {@link IoHandler} implementation for NetCat client. This class extended
@@ -54,8 +54,9 @@
session.close();
}
- public void dataRead( IoSession session, ByteBuffer buf )
+ public void messageReceived( IoSession session, Object message )
{
+ ByteBuffer buf = ( ByteBuffer ) message;
// Print out read buffer content.
while( buf.hasRemaining() )
{
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/Main.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/Main.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/Main.java Mon May 9 02:21:50 2005
@@ -18,9 +18,9 @@
*/
package org.apache.mina.examples.reverser;
+import org.apache.mina.common.IoAcceptor;
import org.apache.mina.common.TransportType;
-import org.apache.mina.protocol.ProtocolAcceptor;
-import org.apache.mina.protocol.filter.ProtocolLoggingFilter;
+import org.apache.mina.filter.LoggingFilter;
import org.apache.mina.registry.Service;
import org.apache.mina.registry.ServiceRegistry;
import org.apache.mina.registry.SimpleServiceRegistry;
@@ -43,15 +43,15 @@
addLogger( registry );
// Bind
Service service = new Service( "reverse", TransportType.SOCKET, PORT );
- registry.bind( service, new ReverseProtocolProvider() );
+ registry.bind( service, new ReverseProtocolHandler() );
System.out.println( "Listening on port " + PORT );
}
private static void addLogger( ServiceRegistry registry )
{
- ProtocolAcceptor acceptor = registry.getProtocolAcceptor( TransportType.SOCKET );
- acceptor.getFilterChain().addLast( "logger", new ProtocolLoggingFilter() );
+ IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
+ acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
System.out.println( "Logging ON" );
}
}
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/ReverseProtocolHandler.java Mon May 9 02:21:50 2005
@@ -18,25 +18,51 @@
*/
package org.apache.mina.examples.reverser;
-import org.apache.mina.protocol.ProtocolHandler;
-import org.apache.mina.protocol.ProtocolHandlerAdapter;
-import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFactory;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolEncoder;
/**
- * {@link ProtocolHandler} implementation of reverser server protocol.
+ * {@link IoHandler} implementation of reverser server protocol.
*
* @author Trustin Lee (trustin@apache.org)
* @version $Rev$, $Date$,
*/
-public class ReverseProtocolHandler extends ProtocolHandlerAdapter
+public class ReverseProtocolHandler extends IoHandlerAdapter
{
- public void exceptionCaught( ProtocolSession session, Throwable cause )
+ private static ProtocolCodecFactory CODEC_FACTORY = new ProtocolCodecFactory()
{
+ public ProtocolEncoder newEncoder()
+ {
+ // Create a new encoder.
+ return new TextLineEncoder();
+ }
+
+ public ProtocolDecoder newDecoder()
+ {
+ // Create a new decoder.
+ return new TextLineDecoder();
+ }
+ };
+
+ public void sessionCreated( IoSession session )
+ {
+ session.getFilterChain().addFirst(
+ "codec", new ProtocolCodecFilter( CODEC_FACTORY ) );
+ }
+
+ public void exceptionCaught( IoSession session, Throwable cause )
+ {
+ cause.printStackTrace();
// Close connection when unexpected exception is caught.
session.close();
}
- public void messageReceived( ProtocolSession session, Object message )
+ public void messageReceived( IoSession session, Object message )
{
// Reverse reveiced string
String str = message.toString();
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineDecoder.java Mon May 9 02:21:50 2005
@@ -19,10 +19,10 @@
package org.apache.mina.examples.reverser;
import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.protocol.ProtocolDecoder;
-import org.apache.mina.protocol.ProtocolDecoderOutput;
-import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.protocol.ProtocolViolationException;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolDecoder;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolViolationException;
/**
* Decodes a text line into a string.
@@ -35,8 +35,8 @@
private StringBuffer decodeBuf = new StringBuffer();
- public void decode( ProtocolSession session, ByteBuffer in,
- ProtocolDecoderOutput out )
+ public void decode( IoSession session, ByteBuffer in,
+ ProtocolDecoderOutput out )
throws ProtocolViolationException
{
do
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/reverser/TextLineEncoder.java Mon May 9 02:21:50 2005
@@ -19,10 +19,10 @@
package org.apache.mina.examples.reverser;
import org.apache.mina.common.ByteBuffer;
-import org.apache.mina.protocol.ProtocolEncoder;
-import org.apache.mina.protocol.ProtocolEncoderOutput;
-import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.protocol.ProtocolViolationException;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolEncoder;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+import org.apache.mina.filter.codec.ProtocolViolationException;
/**
* Encodes a string into a text line which ends with <code>"\r\n"</code>.
@@ -33,8 +33,8 @@
public class TextLineEncoder implements ProtocolEncoder
{
- public void encode( ProtocolSession session, Object message,
- ProtocolEncoderOutput out )
+ public void encode( IoSession session, Object message,
+ ProtocolEncoderOutput out )
throws ProtocolViolationException
{
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/Main.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/Main.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/Main.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/Main.java Mon May 9 02:21:50 2005
@@ -3,13 +3,13 @@
*/
package org.apache.mina.examples.tennis;
+import org.apache.mina.common.IoSession;
import org.apache.mina.common.TransportType;
-import org.apache.mina.protocol.ProtocolSession;
-import org.apache.mina.protocol.vmpipe.VmPipeAddress;
-import org.apache.mina.protocol.vmpipe.VmPipeConnector;
import org.apache.mina.registry.Service;
import org.apache.mina.registry.ServiceRegistry;
import org.apache.mina.registry.SimpleServiceRegistry;
+import org.apache.mina.transport.vmpipe.VmPipeAddress;
+import org.apache.mina.transport.vmpipe.VmPipeConnector;
/**
* (<b>Entry point</b>) An 'in-VM pipe' example which simulates a tennis game
@@ -40,7 +40,7 @@
// Connect to the server.
VmPipeConnector connector = new VmPipeConnector();
- ProtocolSession session = connector.connect( address,
+ IoSession session = connector.connect( address,
new TennisPlayer() );
// Send the first ping message
Modified: directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java (original)
+++ directory/network/branches/api_integration/src/examples/org/apache/mina/examples/tennis/TennisPlayer.java Mon May 9 02:21:50 2005
@@ -3,74 +3,57 @@
*/
package org.apache.mina.examples.tennis;
-import org.apache.mina.protocol.ProtocolCodecFactory;
-import org.apache.mina.protocol.ProtocolHandler;
-import org.apache.mina.protocol.ProtocolHandlerAdapter;
-import org.apache.mina.protocol.ProtocolProvider;
-import org.apache.mina.protocol.ProtocolSession;
+import org.apache.mina.common.IoHandler;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
/**
- * A {@link ProtocolHandler} implementation which plays a tennis game.
+ * A {@link IoHandler} implementation which plays a tennis game.
*
* @author Trustin Lee (trustin@apache.org)
* @version $Rev$, $Date$
*/
-public class TennisPlayer implements ProtocolProvider
+public class TennisPlayer extends IoHandlerAdapter
{
- private final ProtocolHandler HANDLER = new TennisPlayerHandler();
-
- public ProtocolCodecFactory getCodecFactory()
+ private static int nextId = 0;
+
+ /** Player ID **/
+ private final int id = nextId++;
+
+ public void sessionOpened( IoSession session )
{
- throw new UnsupportedOperationException();
+ System.out.println( "Player-" + id + ": READY" );
}
- public ProtocolHandler getHandler()
+ public void sessionClosed( IoSession session )
{
- return HANDLER;
+ System.out.println( "Player-" + id + ": QUIT" );
}
- private static class TennisPlayerHandler extends ProtocolHandlerAdapter
+ public void messageReceived( IoSession session, Object message )
{
- private static int nextId = 0;
+ System.out.println( "Player-" + id + ": RCVD " + message );
- /** Player ID **/
- private final int id = nextId++;
+ TennisBall ball = ( TennisBall ) message;
- public void sessionOpened( ProtocolSession session )
- {
- System.out.println( "Player-" + id + ": READY" );
- }
+ // Stroke: TTL decreases and PING/PONG state changes.
+ ball = ball.stroke();
- public void sessionClosed( ProtocolSession session )
+ if( ball.getTTL() > 0 )
{
- System.out.println( "Player-" + id + ": QUIT" );
+ // If the ball is still alive, pass it back to peer.
+ session.write( ball );
}
-
- public void messageReceived( ProtocolSession session, Object message )
+ else
{
- System.out.println( "Player-" + id + ": RCVD " + message );
-
- TennisBall ball = ( TennisBall ) message;
-
- // Stroke: TTL decreases and PING/PONG state changes.
- ball = ball.stroke();
-
- if( ball.getTTL() > 0 )
- {
- // If the ball is still alive, pass it back to peer.
- session.write( ball );
- }
- else
- {
- // If the ball is dead, this player loses.
- System.out.println( "Player-" + id + ": LOSE" );
- session.close();
- }
+ // If the ball is dead, this player loses.
+ System.out.println( "Player-" + id + ": LOSE" );
+ session.close();
}
+ }
- public void messageSent( ProtocolSession session, Object message )
- {
- System.out.println( "Player-" + id + ": SENT " + message );
- }
+ public void messageSent( IoSession session, Object message )
+ {
+ System.out.println( "Player-" + id + ": SENT " + message );
}
}
Added: directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java Mon May 9 02:21:50 2005
@@ -0,0 +1,597 @@
+/*
+ * @(#) $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.common;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.mina.common.IoFilter.NextFilter;
+
+/**
+ * An abstract implementation of {@link IoFilterChain} that provides
+ * common operations for developers to extend protocol layer.
+ * <p>
+ * All methods has been implemented. The list of filters is maintained
+ * as a doublely linked list. You can fire any MINA events which is filtered
+ * by this chain using these public methods:
+ * <ul>
+ * <li></li>
+ * </ul>
+ *
+ * The only method a developer should implement is {@link #doWrite(IoSession, Object)}.
+ * This method is invoked when filter chain is evaluated for
+ * {@link IoFilter#filterWrite(NextFilter, IoSession, Object)} and
+ * finally to be written out.
+ *
+ * @author The Apache Directory Project
+ * @version $Rev$, $Date$
+ */
+public abstract class AbstractIoFilterChain implements IoFilterChain
+{
+ private final Map name2entry = new HashMap();
+
+ private final Map filter2entry = new IdentityHashMap();
+
+ private final Entry head;
+
+ private final Entry tail;
+
+ protected AbstractIoFilterChain()
+ {
+ head = new Entry( null, null, "head", createHeadFilter() );
+ tail = new Entry( head, null, "tail", createTailFilter() );
+ head.nextEntry = tail;
+ }
+
+ /**
+ * Override this method to create custom head of this filter chain.
+ */
+ protected IoFilter createHeadFilter()
+ {
+ return new IoFilter()
+ {
+ public void sessionOpened( NextFilter nextFilter, IoSession session )
+ {
+ nextFilter.sessionOpened( session );
+ }
+
+ public void sessionClosed( NextFilter nextFilter, IoSession session )
+ {
+ nextFilter.sessionClosed( session );
+ }
+
+ public void sessionIdle( NextFilter nextFilter, IoSession session,
+ IdleStatus status )
+ {
+ nextFilter.sessionIdle( session, status );
+ }
+
+ public void exceptionCaught( NextFilter nextFilter,
+ IoSession session, Throwable cause )
+ {
+ nextFilter.exceptionCaught( session, cause );
+ }
+
+ public void messageReceived( NextFilter nextFilter, IoSession session,
+ Object message )
+ {
+ nextFilter.messageReceived( session, message );
+ }
+
+ public void messageSent( NextFilter nextFilter, IoSession session,
+ Object message )
+ {
+ nextFilter.messageSent( session, message );
+ }
+
+ public void filterWrite( NextFilter nextFilter, IoSession session,
+ Object message )
+ {
+ if( message instanceof ByteBuffer )
+ {
+ doWrite( session, message );
+ }
+ else
+ {
+ throw new IllegalStateException( "Write requests must be transformed to ByteBuffers: " + message );
+ }
+ }
+ };
+ }
+
+ /**
+ * Override this method to create custom head of this filter chain.
+ */
+ protected IoFilter createTailFilter()
+ {
+ return new IoFilter()
+ {
+ public void sessionOpened( NextFilter nextFilter, IoSession session ) throws Exception
+ {
+ session.getHandler().sessionOpened( session );
+ }
+
+ public void sessionClosed( NextFilter nextFilter, IoSession session ) throws Exception
+ {
+ session.getHandler().sessionClosed( session );
+ }
+
+ public void sessionIdle( NextFilter nextFilter, IoSession session,
+ IdleStatus status ) throws Exception
+ {
+ session.getHandler().sessionIdle( session, status );
+ }
+
+ public void exceptionCaught( NextFilter nextFilter,
+ IoSession session, Throwable cause ) throws Exception
+ {
+ session.getHandler().exceptionCaught( session, cause );
+ }
+
+ public void messageReceived( NextFilter nextFilter, IoSession session,
+ Object message ) throws Exception
+ {
+ IoHandler handler = session.getHandler();
+ handler.messageReceived( session, message );
+ }
+
+ public void messageSent( NextFilter nextFilter, IoSession session,
+ Object message ) throws Exception
+ {
+ session.getHandler().messageSent( session, message );
+ }
+
+ public void filterWrite( NextFilter nextFilter,
+ IoSession session, Object message ) throws Exception
+ {
+ nextFilter.filterWrite( session, message );
+ }
+ };
+ }
+
+ public IoFilter getChild( String name )
+ {
+ Entry e = ( Entry ) name2entry.get( name );
+ if ( e == null )
+ {
+ return null;
+ }
+ return e.filter;
+ }
+
+ /**
+ * Adds the specified interceptor with the specified name at the beginning of this chain.
+ */
+ public synchronized void addFirst( String name,
+ IoFilter filter )
+ {
+ checkAddable( name );
+ register( head, name, filter );
+ }
+
+
+ /**
+ * Adds the specified interceptor with the specified name at the end of this chain.
+ */
+ public synchronized void addLast( String name,
+ IoFilter filter )
+ {
+ checkAddable( name );
+ register( tail.prevEntry, name, filter );
+ }
+
+
+ /**
+ * Adds the specified interceptor with the specified name just before the interceptor whose name is
+ * <code>baseName</code> in this chain.
+ */
+ public synchronized void addBefore( String baseName,
+ String name,
+ IoFilter filter )
+ {
+ Entry baseEntry = checkOldName( baseName );
+ checkAddable( name );
+ register( baseEntry, name, filter );
+ }
+
+
+ /**
+ * Adds the specified interceptor with the specified name just after the interceptor whose name is
+ * <code>baseName</code> in this chain.
+ */
+ public synchronized void addAfter( String baseName,
+ String name,
+ IoFilter filter )
+ {
+ Entry baseEntry = checkOldName( baseName );
+ checkAddable( name );
+ register( baseEntry.prevEntry, name, filter );
+ }
+
+
+ /**
+ * Removes the interceptor with the specified name from this chain.
+ */
+ public synchronized void remove( String name )
+ {
+ Entry entry = checkOldName( name );
+ Entry prevEntry = entry.prevEntry;
+ Entry nextEntry = entry.nextEntry;
+ prevEntry.nextEntry = nextEntry;
+ nextEntry.prevEntry = prevEntry;
+
+ name2entry.remove( name );
+ IoFilter filter = entry.filter;
+ filter2entry.remove( filter );
+ }
+
+
+ /**
+ * Removes all interceptors added to this chain.
+ */
+ public synchronized void clear()
+ {
+ Iterator it = new ArrayList( name2entry.keySet() ).iterator();
+ while ( it.hasNext() )
+ {
+ this.remove( ( String ) it.next() );
+ }
+ }
+
+ private void register( Entry prevEntry, String name, IoFilter filter )
+ {
+ Entry newEntry = new Entry( prevEntry, prevEntry.nextEntry, name, filter );
+ prevEntry.nextEntry.prevEntry = newEntry;
+ prevEntry.nextEntry = newEntry;
+ name2entry.put( name, newEntry );
+ filter2entry.put( filter, newEntry );
+ }
+
+ /**
+ * Throws an exception when the specified interceptor name is not registered in this chain.
+ *
+ * @return An interceptor entry with the specified name.
+ */
+ private Entry checkOldName( String baseName )
+ {
+ Entry e = ( Entry ) name2entry.get( baseName );
+ if ( e == null )
+ {
+ throw new IllegalArgumentException( "Unknown interceptor name:" +
+ baseName );
+ }
+ return e;
+ }
+
+
+ /**
+ * Checks the specified interceptor name is already taken and throws an exception if already taken.
+ */
+ private void checkAddable( String name )
+ {
+ if ( name2entry.containsKey( name ) )
+ {
+ throw new IllegalArgumentException( "Other interceptor is using name '" + name + "'" );
+ }
+ }
+
+ public void sessionOpened( IoSession session )
+ {
+ Entry head = this.head;
+ callNextSessionOpened(head, session);
+ }
+
+ private void callNextSessionOpened( Entry entry,
+ IoSession session)
+ {
+ try
+ {
+ entry.filter.sessionOpened( entry.nextFilter, session );
+ }
+ catch( Throwable e )
+ {
+ exceptionCaught( session, e );
+ }
+ }
+
+ public void sessionClosed( IoSession session )
+ {
+ Entry head = this.head;
+ callNextSessionClosed(head, session);
+ }
+
+ private void callNextSessionClosed( Entry entry,
+ IoSession session )
+ {
+ try
+ {
+ entry.filter.sessionClosed( entry.nextFilter, session );
+
+ }
+ catch( Throwable e )
+ {
+ exceptionCaught( session, e );
+ }
+ }
+
+ public void sessionIdle( IoSession session, IdleStatus status )
+ {
+ Entry head = this.head;
+ callNextSessionIdle(head, session, status);
+ }
+
+ private void callNextSessionIdle( Entry entry,
+ IoSession session,
+ IdleStatus status )
+ {
+ try
+ {
+ entry.filter.sessionIdle( entry.nextFilter, session, status );
+ }
+ catch( Throwable e )
+ {
+ exceptionCaught( session, e );
+ }
+ }
+
+ public void messageReceived( IoSession session, Object message )
+ {
+ Entry head = this.head;
+ callNextMessageReceived(head, session, message );
+ }
+
+ private void callNextMessageReceived( Entry entry,
+ IoSession session,
+ Object message )
+ {
+ try
+ {
+ entry.filter.messageReceived( entry.nextFilter, session, message );
+ }
+ catch( Throwable e )
+ {
+ exceptionCaught( session, e );
+ }
+ }
+
+ public void messageSent( IoSession session, Object message )
+ {
+ Entry head = this.head;
+ callNextMessageSent(head, session, message);
+ }
+
+ private void callNextMessageSent( Entry entry,
+ IoSession session,
+ Object message )
+ {
+ try
+ {
+ entry.filter.messageSent( entry.nextFilter, session, message );
+ }
+ catch( Throwable e )
+ {
+ exceptionCaught( session, e );
+ }
+ }
+
+ public void exceptionCaught( IoSession session, Throwable cause )
+ {
+ Entry head = this.head;
+ callNextExceptionCaught(head, session, cause);
+ }
+
+ private void callNextExceptionCaught( Entry entry,
+ IoSession session,
+ Throwable cause )
+ {
+ try
+ {
+ entry.filter.exceptionCaught( entry.nextFilter, session, cause );
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ }
+ }
+
+ public void filterWrite( IoSession session, Object message )
+ {
+ Entry tail = this.tail;
+ callPreviousFilterWrite( tail, session, message );
+ }
+
+ private void callPreviousFilterWrite( Entry entry,
+ IoSession session,
+ Object message )
+ {
+ if( message == null )
+ {
+ return;
+ }
+
+ try
+ {
+ entry.filter.filterWrite( entry.prevFilter, session, message );
+ }
+ catch( Throwable e )
+ {
+ exceptionCaught( session, e );
+ }
+ }
+
+ public List getChildren()
+ {
+ List list = new ArrayList();
+ Entry e = head.nextEntry;
+ while( e != tail )
+ {
+ list.add( e.filter );
+ e = e.nextEntry;
+ }
+
+ return list;
+ }
+
+ public List getChildrenReversed()
+ {
+ List list = new ArrayList();
+ Entry e = tail.prevEntry;
+ while( e != head )
+ {
+ list.add( e.filter );
+ e = e.prevEntry;
+ }
+ return list;
+ }
+
+ protected abstract void doWrite( IoSession session, Object message );
+
+ private class Entry
+ {
+ private Entry prevEntry;
+
+ private Entry nextEntry;
+
+ private final String name;
+
+ private final IoFilter filter;
+
+ private final NextFilter nextFilter;
+
+ private final NextFilter prevFilter;
+
+ private Entry( Entry prevEntry, Entry nextEntry,
+ String name, IoFilter filter )
+ {
+ if( filter == null )
+ {
+ throw new NullPointerException( "filter" );
+ }
+ if( name == null )
+ {
+ throw new NullPointerException( "name" );
+ }
+
+ this.prevEntry = prevEntry;
+ this.nextEntry = nextEntry;
+ this.name = name;
+ this.filter = filter;
+ this.nextFilter = new NextFilter()
+ {
+
+ public void sessionOpened( IoSession session )
+ {
+ Entry nextEntry = Entry.this.nextEntry;
+ callNextSessionOpened( nextEntry, session );
+ }
+
+ public void sessionClosed( IoSession session )
+ {
+ Entry nextEntry = Entry.this.nextEntry;
+ callNextSessionClosed( nextEntry, session );
+ }
+
+ public void sessionIdle( IoSession session, IdleStatus status )
+ {
+ Entry nextEntry = Entry.this.nextEntry;
+ callNextSessionIdle( nextEntry, session, status );
+ }
+
+ public void exceptionCaught( IoSession session,
+ Throwable cause )
+ {
+ Entry nextEntry = Entry.this.nextEntry;
+ callNextExceptionCaught( nextEntry, session, cause );
+ }
+
+ public void messageReceived( IoSession session, Object message )
+ {
+ Entry nextEntry = Entry.this.nextEntry;
+ callNextMessageReceived( nextEntry, session, message );
+ }
+
+ public void messageSent( IoSession session, Object message )
+ {
+ Entry nextEntry = Entry.this.nextEntry;
+ callNextMessageSent( nextEntry, session, message );
+ }
+
+ public void filterWrite( IoSession session, Object message )
+ {
+ throw new IllegalStateException();
+ }
+ };
+
+ this.prevFilter = new NextFilter()
+ {
+
+ public void sessionOpened( IoSession session )
+ {
+ throw new IllegalStateException();
+ }
+
+ public void sessionClosed( IoSession session )
+ {
+ throw new IllegalStateException();
+ }
+
+ public void sessionIdle( IoSession session, IdleStatus status )
+ {
+ throw new IllegalStateException();
+ }
+
+ public void exceptionCaught( IoSession session,
+ Throwable cause )
+ {
+ throw new IllegalStateException();
+ }
+
+ public void messageReceived( IoSession session, Object message )
+ {
+ throw new IllegalStateException();
+ }
+
+ public void messageSent( IoSession session, Object message )
+ {
+ throw new IllegalStateException();
+ }
+
+ public void filterWrite( IoSession session, Object message )
+ {
+ Entry nextEntry = Entry.this.prevEntry;
+ callPreviousFilterWrite( nextEntry, session, message );
+ }
+ };
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public IoFilter getFilter()
+ {
+ return filter;
+ }
+ }
+}
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/common/AbstractIoFilterChain.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSession.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSession.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSession.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSession.java Mon May 9 02:21:50 2005
@@ -0,0 +1,163 @@
+/*
+ * @(#) $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.common;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Set;
+
+/**
+ * Base implementation of {@link Session}.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class BaseIoSession implements IoSession
+{
+ private final Map attributes = new HashMap();
+
+ private long readBytes;
+
+ private long writtenBytes;
+
+ private long lastReadTime;
+
+ private long lastWriteTime;
+
+ private boolean idleForBoth;
+
+ private boolean idleForRead;
+
+ private boolean idleForWrite;
+
+
+ protected BaseIoSession()
+ {
+ }
+
+ public void close()
+ {
+ this.close( false );
+ }
+
+ public Object getAttachment()
+ {
+ return attributes.get( "" );
+ }
+
+ public Object setAttachment( Object attachment )
+ {
+ synchronized( attributes )
+ {
+ return attributes.put( "", attachment );
+ }
+ }
+
+ public Object getAttribute( String key )
+ {
+ return attributes.get( key );
+ }
+
+ public Object setAttribute( String key, Object value )
+ {
+ synchronized( attributes )
+ {
+ return attributes.put( key, value );
+ }
+ }
+
+ public Object removeAttribute( String key )
+ {
+ synchronized( attributes )
+ {
+ return attributes.remove( key );
+ }
+ }
+
+ public Set getAttributeKeys() {
+ synchronized( attributes )
+ {
+ return attributes.keySet();
+ }
+ }
+
+ public long getReadBytes()
+ {
+ return readBytes;
+ }
+
+ public long getWrittenBytes()
+ {
+ return writtenBytes;
+ }
+
+ public void increaseReadBytes( int increment )
+ {
+ readBytes += increment;
+ lastReadTime = System.currentTimeMillis();
+ }
+
+ public void increaseWrittenBytes( int increment )
+ {
+ writtenBytes += increment;
+ lastWriteTime = System.currentTimeMillis();
+ }
+
+ public long getLastIoTime()
+ {
+ return Math.max( lastReadTime, lastWriteTime );
+ }
+
+ public long getLastReadTime()
+ {
+ return lastReadTime;
+ }
+
+ public long getLastWriteTime()
+ {
+ return lastWriteTime;
+ }
+
+ public boolean isIdle( IdleStatus status )
+ {
+ if( status == IdleStatus.BOTH_IDLE )
+ return idleForBoth;
+
+ if( status == IdleStatus.READER_IDLE )
+ return idleForRead;
+
+ if( status == IdleStatus.WRITER_IDLE )
+ return idleForWrite;
+
+ throw new IllegalArgumentException( "Unknown idle status: " + status );
+ }
+
+ public void setIdle( IdleStatus status, boolean value )
+ {
+ if( status == IdleStatus.BOTH_IDLE )
+ idleForBoth = value;
+ else if( status == IdleStatus.READER_IDLE )
+ idleForRead = value;
+ else if( status == IdleStatus.WRITER_IDLE )
+ idleForWrite = value;
+ else
+ throw new IllegalArgumentException( "Unknown idle status: "
+ + status );
+ }
+}
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSession.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionConfig.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionConfig.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionConfig.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionConfig.java Mon May 9 02:21:50 2005
@@ -0,0 +1,95 @@
+/*
+ * @(#) $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.common;
+
+
+/**
+ * Base implementation of {@link SessionConfig}s.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class BaseIoSessionConfig implements IoSessionConfig
+{
+ private int idleTimeForRead;
+
+ private int idleTimeForWrite;
+
+ private int idleTimeForBoth;
+
+ private int writeTimeout;
+
+ protected BaseIoSessionConfig()
+ {
+ }
+
+ public int getIdleTime( IdleStatus status )
+ {
+ if( status == IdleStatus.BOTH_IDLE )
+ return idleTimeForBoth;
+
+ if( status == IdleStatus.READER_IDLE )
+ return idleTimeForRead;
+
+ if( status == IdleStatus.WRITER_IDLE )
+ return idleTimeForWrite;
+
+ throw new IllegalArgumentException( "Unknown idle status: " + status );
+ }
+
+ public long getIdleTimeInMillis( IdleStatus status )
+ {
+ return getIdleTime( status ) * 1000L;
+ }
+
+ public void setIdleTime( IdleStatus status, int idleTime )
+ {
+ if( idleTime < 0 )
+ throw new IllegalArgumentException( "Illegal idle time: "
+ + idleTime );
+
+ if( status == IdleStatus.BOTH_IDLE )
+ idleTimeForBoth = idleTime;
+ else if( status == IdleStatus.READER_IDLE )
+ idleTimeForRead = idleTime;
+ else if( status == IdleStatus.WRITER_IDLE )
+ idleTimeForWrite = idleTime;
+ else
+ throw new IllegalArgumentException( "Unknown idle status: "
+ + status );
+ }
+
+ public int getWriteTimeout()
+ {
+ return writeTimeout;
+ }
+
+ public long getWriteTimeoutInMillis()
+ {
+ return writeTimeout * 1000L;
+ }
+
+ public void setWriteTimeout( int writeTimeout )
+ {
+ if( writeTimeout < 0 )
+ throw new IllegalArgumentException( "Illegal write timeout: "
+ + writeTimeout );
+ this.writeTimeout = writeTimeout;
+ }
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionConfig.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionManager.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionManager.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionManager.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionManager.java Mon May 9 02:21:50 2005
@@ -0,0 +1,52 @@
+/*
+ * @(#) $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.common;
+
+/**
+ * Base implementation of {@link SessionManager}s.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public abstract class BaseIoSessionManager implements IoSessionManager {
+
+ /**
+ * Current exception monitor.
+ */
+ protected ExceptionMonitor exceptionMonitor = new DefaultExceptionMonitor();
+
+ protected BaseIoSessionManager()
+ {
+ }
+
+ public ExceptionMonitor getExceptionMonitor()
+ {
+ return exceptionMonitor;
+ }
+
+ public void setExceptionMonitor( ExceptionMonitor monitor )
+ {
+ if( monitor == null )
+ {
+ monitor = new DefaultExceptionMonitor();
+ }
+
+ this.exceptionMonitor = monitor;
+ }
+}
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/common/BaseIoSessionManager.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Modified: directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java (original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBuffer.java Mon May 9 02:21:50 2005
@@ -32,9 +32,7 @@
import java.nio.charset.CharsetEncoder;
import java.nio.charset.CoderResult;
-import org.apache.mina.io.IoHandler;
-import org.apache.mina.io.IoSession;
-import org.apache.mina.protocol.ProtocolEncoderOutput;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
import org.apache.mina.util.Stack;
/**
@@ -78,7 +76,7 @@
* <li>You pass the buffer by calling {@link ProtocolEncoderOutput#write(ByteBuffer)}.</li>
* </ul>
* And, you don't need to release any {@link ByteBuffer} which is passed as a parameter
- * of {@link IoHandler#dataRead(IoSession, ByteBuffer)} method. They are released
+ * of {@link IoHandler#messageReceived(IoSession, ByteBuffer)} method. They are released
* automatically when the method returns.
* <p>
* You have to release buffers manually by calling {@link #release()} when:
Modified: directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBufferHexDumper.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBufferHexDumper.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBufferHexDumper.java (original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/ByteBufferHexDumper.java Mon May 9 02:21:50 2005
@@ -18,7 +18,6 @@
*/
package org.apache.mina.common;
-import org.apache.mina.common.ByteBuffer;
/**
* Provides utility methods for ByteBuffers.
Modified: directory/network/branches/api_integration/src/java/org/apache/mina/common/IdleStatus.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/IdleStatus.java?rev=169259&r1=169258&r2=169259&view=diff
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/IdleStatus.java (original)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/IdleStatus.java Mon May 9 02:21:50 2005
@@ -18,12 +18,10 @@
*/
package org.apache.mina.common;
-import org.apache.mina.io.IoSession;
-import org.apache.mina.protocol.ProtocolSession;
/**
* Represents the type of idleness of {@link IoSession} or
- * {@link ProtocolSession}. There are three types of idleness:
+ * {@link IoSession}. There are three types of idleness:
* <ul>
* <li>{@link #READER_IDLE} - No data is coming from the remote peer.</li>
* <li>{@link #WRITER_IDLE} - Session is not writing any data.</li>
Added: directory/network/branches/api_integration/src/java/org/apache/mina/common/IoAcceptor.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/IoAcceptor.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/IoAcceptor.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/IoAcceptor.java Mon May 9 02:21:50 2005
@@ -0,0 +1,57 @@
+/*
+ * @(#) $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.common;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+/**
+ * Accepts incoming connection, communicates with clients, and fires events to
+ * {@link IoHandler}s.
+ * <p>
+ * Please refer to
+ * <a href="../../../../../xref-examples/org/apache/mina/examples/echoserver/Main.html">EchoServer</a>
+ * example.
+ * <p>
+ * You should bind to the desired socket address to accept incoming
+ * connections, and then events for incoming connections will be sent to
+ * the specified default {@link IoHandler}.
+ * <p>
+ * Threads accept incoming connections start automatically when
+ * {@link #bind(SocketAddress, IoHandler)} is invoked, and stop when all
+ * addresses are unbound.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface IoAcceptor extends IoSessionManager
+{
+ /**
+ * Binds to the specified <code>address</code> and handles incoming
+ * connections with the specified <code>handler</code>.
+ *
+ * @throws IOException if failed to bind
+ */
+ void bind( SocketAddress address, IoHandler handler ) throws IOException;
+
+ /**
+ * Unbinds from the specified <code>address</code>.
+ */
+ void unbind( SocketAddress address );
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/common/IoAcceptor.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/common/IoConnector.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/IoConnector.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/IoConnector.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/IoConnector.java Mon May 9 02:21:50 2005
@@ -0,0 +1,86 @@
+/*
+ * @(#) $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.common;
+
+import java.io.IOException;
+import java.net.SocketAddress;
+
+/**
+ * Connects to endpoint, communicates with the server, and fires events to
+ * {@link IoHandler}s.
+ * <p>
+ * Please refer to
+ * <a href="../../../../../xref-examples/org/apache/mina/examples/netcat/Main.html">NetCat</a>
+ * example.
+ * <p>
+ * You should connect to the desired socket address to start communication,
+ * and then events for incoming connections will be sent to the specified
+ * default {@link IoHandler}.
+ * <p>
+ * Threads connect to endpoint start automatically when
+ * {@link #connect(SocketAddress, IoHandler)} is invoked, and stop when all
+ * connection attempts are finished.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public interface IoConnector extends IoSessionManager
+{
+ /**
+ * Connects to the specified <code>address</code>. If communication starts
+ * successfully, events are fired to the specified
+ * <code>handler</code>. This method blocks.
+ *
+ * @throws IOException if failed to connect
+ */
+ IoSession connect( SocketAddress address, IoHandler handler )
+ throws IOException;
+
+ /**
+ * Connects to the specified <code>address</code>. If communication starts
+ * successfully, events are fired to the specified
+ * <code>handler</code>. This method blocks.
+ *
+ * @param localAddress the local address the channel is bound to
+ * @throws IOException if failed to connect
+ */
+ IoSession connect( SocketAddress address, SocketAddress localAddress,
+ IoHandler handler ) throws IOException;
+
+ /**
+ * Connects to the specified <code>address</code> with timeout. If
+ * communication starts successfully, events are fired to the specified
+ * <code>handler</code>. This method blocks.
+ *
+ * @throws IOException if failed to connect
+ */
+ IoSession connect( SocketAddress address, int timeout, IoHandler handler )
+ throws IOException;
+
+ /**
+ * Connects to the specified <code>address</code> with timeout. If
+ * communication starts successfully, events are fired to the specified
+ * <code>handler</code>. This method blocks.
+ *
+ * @param localAddress the local address the channel is bound to
+ * @throws IOException if failed to connect
+ */
+ IoSession connect( SocketAddress address, SocketAddress localAddress,
+ int timeout, IoHandler handler ) throws IOException;
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/common/IoConnector.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilter.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilter.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilter.java Mon May 9 02:21:50 2005
@@ -0,0 +1,98 @@
+/*
+ * @(#) $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.common;
+
+
+/**
+ * A filter which intercepts {@link IoHandler} events like Servlet
+ * filters. Filters can be used for these purposes:
+ * <ul>
+ * <li>Event logging,</li>
+ * <li>Performance measurement,</li>
+ * <li>Authorization,</li>
+ * <li>Overload control,</li>
+ * <li>Message transformation (e.g. encryption and decryption, ...),</li>
+ * <li>and many more.</li>
+ * </ul>
+ * <p>
+ * <strong>Please NEVER implement your filters to wrap
+ * {@link IoSession}s.</strong> Users can cache the reference to the
+ * session, which might malfunction if any filters are added or removed later.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ *
+ * @see IoFilterAdapter
+ */
+public interface IoFilter
+{
+ /**
+ * Filters {@link IoHandler#sessionOpened(IoSession)} event.
+ */
+ void sessionOpened( NextFilter nextFilter, IoSession session ) throws Exception;
+
+ /**
+ * Filters {@link IoHandler#sessionClosed(IoSession)} event.
+ */
+ void sessionClosed( NextFilter nextFilter, IoSession session ) throws Exception;
+
+ /**
+ * Filters {@link IoHandler#sessionIdle(IoSession,IdleStatus)}
+ * event.
+ */
+ void sessionIdle( NextFilter nextFilter, IoSession session,
+ IdleStatus status ) throws Exception;
+
+ /**
+ * Filters {@link IoHandler#exceptionCaught(IoSession,Throwable)}
+ * event.
+ */
+ void exceptionCaught( NextFilter nextFilter,
+ IoSession session, Throwable cause ) throws Exception;
+
+ /**
+ * Filters {@link IoHandler#messageReceived(IoSession,Object)}
+ * event.
+ */
+ void messageReceived( NextFilter nextFilter,
+ IoSession session, Object message ) throws Exception;
+
+ /**
+ * Filters {@link IoHandler#messageSent(IoSession,Object)}
+ * event.
+ */
+ void messageSent( NextFilter nextFilter, IoSession session,
+ Object message ) throws Exception;
+
+ /**
+ * Filters {@link IoSession#write(Object)} method invocation.
+ */
+ void filterWrite( NextFilter nextFilter, IoSession session, Object message ) throws Exception;
+
+ public interface NextFilter
+ {
+ void sessionOpened( IoSession session );
+ void sessionClosed( IoSession session );
+ void sessionIdle( IoSession session, IdleStatus status );
+ void exceptionCaught( IoSession session, Throwable cause );
+ void messageReceived( IoSession session, Object message );
+ void messageSent( IoSession session, Object message );
+ void filterWrite( IoSession session, Object message );
+ }
+}
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilter.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision
Added: directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilterAdapter.java
URL: http://svn.apache.org/viewcvs/directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilterAdapter.java?rev=169259&view=auto
==============================================================================
--- directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilterAdapter.java (added)
+++ directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilterAdapter.java Mon May 9 02:21:50 2005
@@ -0,0 +1,66 @@
+/*
+ * @(#) $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.common;
+
+
+/**
+ * An abstract adapter class for {@link ProtocolFilter}. You can extend
+ * this class and selectively override required event filter methods only. All
+ * methods forwards events to the next filter by default.
+ *
+ * @author Trustin Lee (trustin@apache.org)
+ * @version $Rev$, $Date$
+ */
+public class IoFilterAdapter implements IoFilter
+{
+ public void sessionOpened( NextFilter nextFilter, IoSession session ) throws Exception
+ {
+ nextFilter.sessionOpened( session );
+ }
+
+ public void sessionClosed( NextFilter nextFilter, IoSession session ) throws Exception
+ {
+ nextFilter.sessionClosed( session );
+ }
+
+ public void sessionIdle( NextFilter nextFilter, IoSession session, IdleStatus status ) throws Exception
+ {
+ nextFilter.sessionIdle( session, status );
+ }
+
+ public void exceptionCaught( NextFilter nextFilter, IoSession session, Throwable cause ) throws Exception
+ {
+ nextFilter.exceptionCaught( session, cause );
+ }
+
+ public void messageReceived( NextFilter nextFilter, IoSession session, Object message ) throws Exception
+ {
+ nextFilter.messageReceived( session, message );
+ }
+
+ public void messageSent( NextFilter nextFilter, IoSession session, Object message ) throws Exception
+ {
+ nextFilter.messageSent( session, message );
+ }
+
+ public void filterWrite( NextFilter nextFilter, IoSession session, Object message ) throws Exception
+ {
+ nextFilter.filterWrite( session, message );
+ }
+}
\ No newline at end of file
Propchange: directory/network/branches/api_integration/src/java/org/apache/mina/common/IoFilterAdapter.java
------------------------------------------------------------------------------
svn:keywords = HeadURL Id LastChangedBy LastChangedDate LastChangedRevision