org.xsocket.stream.io.impl
Class IoProvider

Package class diagram package IoProvider
java.lang.Object
  extended by org.xsocket.stream.io.impl.IoProvider
All Implemented Interfaces:
IClientIoProvider, IHandlerIoProvider, IServerIoProvider

public final class IoProvider
extends java.lang.Object
implements IClientIoProvider, IServerIoProvider

Server and Client IoProvider

This class is a default implementation of the org.xsocket.stream.io.spi and shouldn`t be used outside this context.
The readbuffer preallocation size and direct/non-direct mode should be set by System.properties. Please note that current vm implementations (Juli/2007) could have problems by managing direct buffers. In this case non-direct buffer should be used.

 ...
 System.setProperty("org.xsocket.stream.ReadBufferPreallocationsizeServer", "32768");

 IMultithreadedServer server = new MultithreadedServer(new Handler());
 StreamUtils.start(server);


 ...
 System.setProperty("org.xsocket.stream.ReadBufferPreallocationsizeClient", "4096");

 IBlockingConnection connection = new BlockingConnection(server.getLocalAddress(), server.getLocalPort());
 connection.write(...);
 


Field Summary
static int DEFAULT_READ_BUFFER_PREALLOCATION_SIZE
           
static boolean DEFAULT_USE_DIRECT_BUFFER
           
static java.lang.String READ_BUFFER_PREALLOCATIONSIZE_CLIENT_KEY
           
static java.lang.String READ_BUFFER_PREALLOCATIONSIZE_SERVER_KEY
           
static java.lang.String USE_DIRECT_READ_BUFFER_CLIENT_KEY
           
static java.lang.String USE_DIRECT_READ_BUFFER_SERVER_KEY
           
 
Fields inherited from interface org.xsocket.stream.io.spi.IClientIoProvider
PROVIDER_CLASSNAME_KEY, SO_KEEPALIVE, SO_LINGER, SO_RCVBUF, SO_REUSEADDR, SO_SNDBUF, TCP_NODELAY
 
Fields inherited from interface org.xsocket.stream.io.spi.IServerIoProvider
PROVIDER_CLASSNAME_KEY
 
Fields inherited from interface org.xsocket.stream.io.spi.IHandlerIoProvider
UNLIMITED
 
Constructor Summary
IoProvider()
           
 
Method Summary
 IAcceptor create(IAcceptorCallback callback, IIoHandlerContext handlerContext, java.net.InetSocketAddress address, int backlog, java.util.Map<java.lang.String,java.lang.Object> options, javax.net.ssl.SSLContext sslContext, boolean sslOn)
          
 IAcceptor createAcceptor(IAcceptorCallback callback, IIoHandlerContext handlerContext, java.net.InetSocketAddress address, int backlog, java.util.Map<java.lang.String,java.lang.Object> options)
          create acceptor
 IIoHandler createClientIoHandler(IIoHandlerContext ctx, java.net.InetSocketAddress remoteAddress, java.util.Map<java.lang.String,java.lang.Object> options)
          creates a client-site IIoHandler
 IIoHandler createSSLClientIoHandler(IIoHandlerContext ctx, java.net.InetSocketAddress remoteAddress, java.util.Map<java.lang.String,java.lang.Object> options, javax.net.ssl.SSLContext sslContext, boolean sslOn)
          
 boolean preStartSecuredMode(IIoHandler ioHandler)
           
 IIoHandler setWriteTransferRate(IIoHandler ioHandler, int bytesPerSecond)
          update the write transfer rate for the given handler
 void startSecuredMode(IIoHandler ioHandler, java.util.LinkedList<java.nio.ByteBuffer> buffers)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_READ_BUFFER_PREALLOCATION_SIZE

public static final int DEFAULT_READ_BUFFER_PREALLOCATION_SIZE
See Also:
Constant Field Values

DEFAULT_USE_DIRECT_BUFFER

public static final boolean DEFAULT_USE_DIRECT_BUFFER
See Also:
Constant Field Values

USE_DIRECT_READ_BUFFER_CLIENT_KEY

public static final java.lang.String USE_DIRECT_READ_BUFFER_CLIENT_KEY
See Also:
Constant Field Values

READ_BUFFER_PREALLOCATIONSIZE_CLIENT_KEY

public static final java.lang.String READ_BUFFER_PREALLOCATIONSIZE_CLIENT_KEY
See Also:
Constant Field Values

USE_DIRECT_READ_BUFFER_SERVER_KEY

public static final java.lang.String USE_DIRECT_READ_BUFFER_SERVER_KEY
See Also:
Constant Field Values

READ_BUFFER_PREALLOCATIONSIZE_SERVER_KEY

public static final java.lang.String READ_BUFFER_PREALLOCATIONSIZE_SERVER_KEY
See Also:
Constant Field Values
Constructor Detail

IoProvider

public IoProvider()
Method Detail

createAcceptor

public IAcceptor createAcceptor(IAcceptorCallback callback,
                                IIoHandlerContext handlerContext,
                                java.net.InetSocketAddress address,
                                int backlog,
                                java.util.Map<java.lang.String,java.lang.Object> options)
                         throws java.io.IOException
create acceptor

Specified by:
createAcceptor in interface IServerIoProvider
Parameters:
callback - the acceptor callback
handlerContext - the handler context
address - the listen address
backlog - the backlog
options - the acceptor socket options
Returns:
the acceptor
Throws:
java.io.IOException - If some other I/O error occurs

create

public IAcceptor create(IAcceptorCallback callback,
                        IIoHandlerContext handlerContext,
                        java.net.InetSocketAddress address,
                        int backlog,
                        java.util.Map<java.lang.String,java.lang.Object> options,
                        javax.net.ssl.SSLContext sslContext,
                        boolean sslOn)
                 throws java.io.IOException

Throws:
java.io.IOException

createClientIoHandler

public IIoHandler createClientIoHandler(IIoHandlerContext ctx,
                                        java.net.InetSocketAddress remoteAddress,
                                        java.util.Map<java.lang.String,java.lang.Object> options)
                                 throws java.io.IOException
creates a client-site IIoHandler

Specified by:
createClientIoHandler in interface IClientIoProvider
Parameters:
ctx - the handler context
remoteAddress - the remote address
options - the socket options
Returns:
the new IoHandler-instance
Throws:
java.io.IOException - If some other I/O error occurs

createSSLClientIoHandler

public IIoHandler createSSLClientIoHandler(IIoHandlerContext ctx,
                                           java.net.InetSocketAddress remoteAddress,
                                           java.util.Map<java.lang.String,java.lang.Object> options,
                                           javax.net.ssl.SSLContext sslContext,
                                           boolean sslOn)
                                    throws java.io.IOException

Throws:
java.io.IOException

setWriteTransferRate

public IIoHandler setWriteTransferRate(IIoHandler ioHandler,
                                       int bytesPerSecond)
                                throws java.io.IOException
update the write transfer rate for the given handler

Specified by:
setWriteTransferRate in interface IHandlerIoProvider
Parameters:
ioHandler - the io handler
bytesPerSecond - the transfer rate (bytes/sec)
Returns:
the upated handler
Throws:
java.io.IOException - if an exception occurs

preStartSecuredMode

public boolean preStartSecuredMode(IIoHandler ioHandler)
                            throws java.io.IOException
Throws:
java.io.IOException

startSecuredMode

public void startSecuredMode(IIoHandler ioHandler,
                             java.util.LinkedList<java.nio.ByteBuffer> buffers)
                      throws java.io.IOException
Throws:
java.io.IOException