| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||

java.lang.Objectorg.xsocket.connection.ConnectionUtils
public final class ConnectionUtils
utility class
| Field Summary | |
|---|---|
| static String | DEFAULT_DOMAIN | 
| static String | SERVER_TRHREAD_PREFIX | 
| Method Summary | ||
|---|---|---|
| static ByteBuffer[] | copy(ByteBuffer[] buffers)(deep) copy of the byte buffer array | |
| static String | getImplementationDate()get the implementation date | |
| static String | getImplementationVersion()get the implementation version | |
| static boolean | isDispatcherThread()returns if current thread is dispatcher thread | |
| static boolean | matchVersion(String currentVersion,
             String requiredVersion)checks if the current version matchs with the required version by using the maven version style | |
| static
 | newMapCache(int maxSize)creates a thread-safe new bound cache | |
| static ObjectName | registerMBean(IConnectionPool pool)creates and registers a mbean for the given connection pool on the platform MBeanServer | |
| static ObjectName | registerMBean(IConnectionPool pool,
              String domain)creates and registers a mbean for the given connection pool on the platform MBeanServer under the given domain name | |
| static ObjectName | registerMBean(IConnectionPool pool,
              String domain,
              MBeanServer mbeanServer)creates and registers a mbean for the given pool on the given MBeanServer under the given domain name | |
| static ObjectName | registerMBean(IServer server)creates and registers a mbean for the given server on the platform MBeanServer | |
| static ObjectName | registerMBean(IServer server,
              String domain)creates and registers a mbean for the given server on the platform MBeanServer under the given domain name | |
| static ObjectName | registerMBean(IServer server,
              String domain,
              MBeanServer mbeanServer)creates and registers a mbean for the given server on the given MBeanServer under the given domain name | |
| static void | start(IServer server)starts the given server within a dedicated thread. | |
| static void | start(IServer server,
      int timeoutSec)starts the given server within a dedicated thread. | |
| static IBlockingConnection | synchronizedConnection(IBlockingConnection con)Returns a synchronized (thread-safe) connection backed by the specified connection. | |
| static INonBlockingConnection | synchronizedConnection(INonBlockingConnection con)Returns a synchronized (thread-safe) connection backed by the specified connection. | |
| static int | validateSufficientDatasizeByIntLengthField(INonBlockingConnection connection)validate, based on a leading int length field. | |
| static int | validateSufficientDatasizeByIntLengthField(INonBlockingConnection connection,
                                           boolean removeLengthField)validate, based on a leading int length field, that enough data (getNumberOfAvailableBytes() >= length) is available. | |
| Methods inherited from class java.lang.Object | 
|---|
| clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | 
| Field Detail | 
|---|
public static final String DEFAULT_DOMAIN
public static final String SERVER_TRHREAD_PREFIX
| Method Detail | 
|---|
public static int validateSufficientDatasizeByIntLengthField(INonBlockingConnection connection)
                                                      throws IOException,
                                                             BufferUnderflowException
connection - the connection
IOException - if an exception occurs
BufferUnderflowException - if not enough data is available
public static int validateSufficientDatasizeByIntLengthField(INonBlockingConnection connection,
                                                             boolean removeLengthField)
                                                      throws IOException,
                                                             BufferUnderflowException
 //client
 connection.setAutoflush(false);  // avoid immediate write
 ...
 connection.markWritePosition();  // mark current position
 connection.write((int) 0);       // write "emtpy" length field
  
 // write and count written size
 int written = connection.write(CMD_PUT);
 written += ...
  
 connection.resetToWriteMark();  // return to length field position
 connection.write(written);      // and update it
 connection.flush(); // flush (marker will be removed implicit)
 ...
 
 
 // server
 class MyHandler implements IDataHandler {
    ...
    public boolean onData(INonBlockingConnection connection) throws IOException, BufferUnderflowException {
       int length = ConnectionUtils.validateSufficientDatasizeByIntLengthField(connection);
       
       // enough data (BufferUnderflowException hasn`t been thrown)
       byte cmd = connection.readByte();
       ...
    }
  }      
 
connection - the connectionremoveLengthField - true, if length field should be removed
IOException - if an exception occurs
BufferUnderflowException - if not enough data is available
public static void start(IServer server)
                  throws SocketTimeoutException
server - the server to start
SocketTimeoutException - is the timeout has been reached
public static void start(IServer server,
                         int timeoutSec)
                  throws SocketTimeoutException
server - the server to starttimeoutSec - the maximum time to wait
SocketTimeoutException - is the timeout has been reachedpublic static ByteBuffer[] copy(ByteBuffer[] buffers)
buffers - the byte buffer array
public static INonBlockingConnection synchronizedConnection(INonBlockingConnection con)
con - the connection to be "wrapped" in a synchronized connection
public static IBlockingConnection synchronizedConnection(IBlockingConnection con)
con - the connection to be "wrapped" in a synchronized connection
public static ObjectName registerMBean(IServer server)
                                throws JMException
server - the server to register
JMException - if an jmx exception occurs
public static ObjectName registerMBean(IServer server,
                                       String domain)
                                throws JMException
server - the server to registerdomain - the domain name to use
JMException - if an jmx exception occurs
public static ObjectName registerMBean(IServer server,
                                       String domain,
                                       MBeanServer mbeanServer)
mbeanServer - the mbean server to useserver - the server to registerdomain - the domain name to use
JMException - if an jmx exception occurs
public static ObjectName registerMBean(IConnectionPool pool)
                                throws JMException
pool - the pool to register
JMException - if an jmx exception occurs
public static ObjectName registerMBean(IConnectionPool pool,
                                       String domain)
                                throws JMException
pool - the pool to registerdomain - the domain name to use
JMException - if an jmx exception occurs
public static ObjectName registerMBean(IConnectionPool pool,
                                       String domain,
                                       MBeanServer mbeanServer)
                                throws JMException
mbeanServer - the mbean server to usepool - the pool to registerdomain - the domain name to use
JMException - if an jmx exception occurs
public static boolean matchVersion(String currentVersion,
                                   String requiredVersion)
currentVersion - the current versionrequiredVersion - the required version
public static String getImplementationVersion()
public static String getImplementationDate()
public static <T> Map<Class,T> newMapCache(int maxSize)
T - the map value typemaxSize - the max size of the cache
public static boolean isDispatcherThread()
| 
 | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||