de.netseeker.ejoe
Class ConnectionHeader

java.lang.Object
  extended by de.netseeker.ejoe.ConnectionHeader
All Implemented Interfaces:
java.io.Serializable
Direct Known Subclasses:
ServerInfo

public class ConnectionHeader
extends java.lang.Object
implements java.io.Serializable

A simple connection header contining informations about compression and blocking/non-blocking io features. The header bits are structured as follows: |compression|nio|persistent|http|directMode|mixedMode|useAdapter|canHandleServerHandshakeResponse|

Since:
0.3.0
Author:
netseeker
See Also:
Serialized Form

Constructor Summary
ConnectionHeader(boolean isClient)
          Creates a new instance of ConnectionHeader.
ConnectionHeader(java.nio.channels.SocketChannel channel, java.lang.String host, boolean isClient)
          Creates a new instance of ConnectionHeader.
ConnectionHeader(java.nio.channels.SocketChannel channel, java.lang.String host, boolean isClient, byte header)
          Creates a new instance of ConnectionHeader.
ConnectionHeader(java.lang.String host, boolean isClient)
          Creates a new instance of ConnectionHeader.
 
Method Summary
 ConnectionHeader copy()
          Returns a clean copy of the current instance containing all transportable settings of the connection header
 void fromByte(byte header)
          sets the eight most important bits of the connection header based on the bits contained in the given byte
 void fromString(java.lang.String header)
          Extracts the header settings from a formatted header string which follows the mask: header=12345678[&adapter=somepackage.someadapter]
 java.lang.String getAdapterName()
           
 java.lang.Object getAttachementInfo()
           
 java.lang.Object getAttachment()
           
 java.nio.channels.SocketChannel getChannel()
           
 int getCompressionLevel()
           
 java.lang.String getHost()
           
 java.nio.ByteBuffer getWaitingBuffer()
           
 boolean hasAdapter()
           
 boolean hasAttachment()
           
 boolean hasCompression()
           
 boolean hasNonBlockingReadWrite()
           
 boolean hasWaitingBuffer()
           
 boolean isClient()
           
 boolean isConnected()
           
 boolean isDirect()
           
 boolean isHandshakeResponseAware()
           
 boolean isHttp()
           
 boolean isMixed()
           
 boolean isPersistent()
           
 void releaseAttachment()
           
 void releaseWaitingBuffer()
           
 void setAdapterName(java.lang.String name)
           
 void setAttachment(java.lang.Object attachment)
           
 void setAttachment(java.lang.Object attachment, java.lang.Object attachmentInfo)
           
 void setChannel(java.nio.channels.SocketChannel channel)
           
 void setCompression(boolean enable)
           
 void setCompressionLevel(int level)
           
 void setConnected(boolean enable)
           
 void setHost(java.lang.String host)
           
 void setHttp(boolean enable)
           
 void setIsDirect(boolean enable)
           
 void setIsHandshakeResponseAware(boolean enable)
           
 void setIsMixed(boolean enable)
           
 void setNonBlockingReadWrite(boolean enable)
           
 void setPersistent(boolean enable)
           
 void setWaitingBuffer(java.nio.ByteBuffer buf)
           
 byte toByte()
          Returns a byte representation of the eight most important bits of the connection header
 java.nio.ByteBuffer toByteBuffer()
          Returns a ByteBuffer containg all transportable settings of the connection header
 byte[] toBytes()
          Returns the byte array representation of this connection header
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ConnectionHeader

public ConnectionHeader(boolean isClient)
Creates a new instance of ConnectionHeader.


ConnectionHeader

public ConnectionHeader(java.lang.String host,
                        boolean isClient)
Creates a new instance of ConnectionHeader. The host member will be set to the given host.

Parameters:
host - the host string in the form IP address : port, eg. 127.0.0.1:12577

ConnectionHeader

public ConnectionHeader(java.nio.channels.SocketChannel channel,
                        java.lang.String host,
                        boolean isClient)
Creates a new instance of ConnectionHeader. The host member will be set to the given host and the channel member will be set to given channel.

Parameters:
channel - The channel to which this connection header applies.
host - the host string in the form IP address : port, eg. 127.0.0.1:12577

ConnectionHeader

public ConnectionHeader(java.nio.channels.SocketChannel channel,
                        java.lang.String host,
                        boolean isClient,
                        byte header)
Creates a new instance of ConnectionHeader. The host member will be set to the given host and the channel member will be set to given channel.

Parameters:
channel - The channel to which this connection header applies.
host - the host string in the form IP address : port, eg. 127.0.0.1:12577
header - The byte representing the settings used for:
  • has compression
  • has non blocking io
  • is connected
  • use persistent connection
Method Detail

hasCompression

public boolean hasCompression()
Returns:

setCompression

public void setCompression(boolean enable)
Parameters:
enable -

setCompressionLevel

public void setCompressionLevel(int level)
Parameters:
level -

getCompressionLevel

public int getCompressionLevel()
Returns:

hasNonBlockingReadWrite

public boolean hasNonBlockingReadWrite()
Returns:

setNonBlockingReadWrite

public void setNonBlockingReadWrite(boolean enable)
Parameters:
enable -

isPersistent

public boolean isPersistent()
Returns:

setPersistent

public void setPersistent(boolean enable)
Parameters:
enable -

isHttp

public boolean isHttp()
Returns:

setHttp

public void setHttp(boolean enable)
Parameters:
http -

isDirect

public boolean isDirect()
Returns:

setIsDirect

public void setIsDirect(boolean enable)
Parameters:
enable -

isMixed

public boolean isMixed()

setIsMixed

public void setIsMixed(boolean enable)

hasAdapter

public boolean hasAdapter()
Returns:

setAdapterName

public void setAdapterName(java.lang.String name)
Parameters:
name -

isHandshakeResponseAware

public boolean isHandshakeResponseAware()
Returns:

setIsHandshakeResponseAware

public void setIsHandshakeResponseAware(boolean enable)
Parameters:
enable -

getAdapterName

public java.lang.String getAdapterName()
Returns:

isConnected

public boolean isConnected()
Returns:

setConnected

public void setConnected(boolean enable)
Parameters:
enable -

hasWaitingBuffer

public boolean hasWaitingBuffer()
Returns:

getWaitingBuffer

public java.nio.ByteBuffer getWaitingBuffer()
Returns:

setWaitingBuffer

public void setWaitingBuffer(java.nio.ByteBuffer buf)
Parameters:
buf -

releaseWaitingBuffer

public void releaseWaitingBuffer()

hasAttachment

public boolean hasAttachment()
Returns:

setAttachment

public void setAttachment(java.lang.Object attachment)
Parameters:
attachment -

setAttachment

public void setAttachment(java.lang.Object attachment,
                          java.lang.Object attachmentInfo)
Parameters:
attachment -
attachmentInfo -

isClient

public boolean isClient()
Returns:

getAttachment

public java.lang.Object getAttachment()
Returns:

getAttachementInfo

public java.lang.Object getAttachementInfo()
Returns:

releaseAttachment

public void releaseAttachment()

setChannel

public void setChannel(java.nio.channels.SocketChannel channel)
Parameters:
channel -

getChannel

public java.nio.channels.SocketChannel getChannel()
Returns:

getHost

public java.lang.String getHost()
Returns:

setHost

public void setHost(java.lang.String host)
Parameters:
host -

toByte

public byte toByte()
Returns a byte representation of the eight most important bits of the connection header

Returns:
a byte containing the eight most important bits of the connection header

fromByte

public void fromByte(byte header)
sets the eight most important bits of the connection header based on the bits contained in the given byte

Parameters:
header -

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

fromString

public void fromString(java.lang.String header)
                throws java.text.ParseException
Extracts the header settings from a formatted header string which follows the mask:
        header=12345678[&adapter=somepackage.someadapter]
 

Parameters:
header -
Throws:
java.text.ParseException

toByteBuffer

public java.nio.ByteBuffer toByteBuffer()
Returns a ByteBuffer containg all transportable settings of the connection header

Returns:
a ByteBuffer representation of the connection header

toBytes

public byte[] toBytes()
Returns the byte array representation of this connection header

Returns:
an array of bytes containing all transportable settings in the connection header

copy

public ConnectionHeader copy()
Returns a clean copy of the current instance containing all transportable settings of the connection header

Returns:
a clean copy


Copyright © 2005-2007 netseeker. All Rights Reserved.