org.xsocket.connection
Interface IConnection

Package class diagram package IConnection
All Superinterfaces:
Closeable
All Known Subinterfaces:
IBlockingConnection, INonBlockingConnection
All Known Implementing Classes:
BlockingConnection, NonBlockingConnection

public interface IConnection
extends Closeable

A connection (session) between two endpoints. It encapsulates the underlying socket channel.

Author:
grro@xsocket.org

Nested Class Summary
static class IConnection.FlushMode
           
 
Field Summary
static boolean DEFAULT_AUTOFLUSH
           
static long DEFAULT_CONNECTION_TIMEOUT_MILLIS
           
static IConnection.FlushMode DEFAULT_FLUSH_MODE
           
static long DEFAULT_IDLE_TIMEOUT_MILLIS
           
static String INITIAL_DEFAULT_ENCODING
           
static long MAX_TIMEOUT_MILLIS
           
static String SO_KEEPALIVE
           
static String SO_LINGER
           
static String SO_RCVBUF
           
static String SO_REUSEADDR
           
static String SO_SNDBUF
           
static String SO_TIMEOUT
           
static String TCP_NODELAY
           
 
Method Summary
 Object getAttachment()
          Retrieves the current attachment.
 long getConnectionTimeoutMillis()
          gets the connection timeout
 String getId()
          returns the id
 long getIdleTimeoutMillis()
          returns the idle timeout in millis.
 InetAddress getLocalAddress()
          returns the local address
 int getLocalPort()
          returns the local port
 Object getOption(String name)
          returns the value of a option
 Map<String,Class> getOptions()
          Returns an unmodifiable map of the options supported by this end point.
 long getRemainingMillisToConnectionTimeout()
          returns the remaining time before a connection timeout occurs
 long getRemainingMillisToIdleTimeout()
          returns the remaining time before a idle timeout occurs
 InetAddress getRemoteAddress()
          returns the remote address
 int getRemotePort()
          returns the port of the remote end point
 boolean isOpen()
          returns, if the connection is open.
 boolean isServerSide()
          returns true id connection is server side
 void setAttachment(Object obj)
          Attaches the given object to this connection
 void setConnectionTimeoutMillis(long timeoutMillis)
          sets the max time for a connections.
 void setIdleTimeoutMillis(long timeoutInMillis)
          sets the idle timeout in millis
 void setOption(String name, Object value)
          sets the value of a option.
 
Methods inherited from interface java.io.Closeable
close
 

Field Detail

INITIAL_DEFAULT_ENCODING

static final String INITIAL_DEFAULT_ENCODING
See Also:
Constant Field Values

SO_SNDBUF

static final String SO_SNDBUF
See Also:
Constant Field Values

SO_RCVBUF

static final String SO_RCVBUF
See Also:
Constant Field Values

SO_REUSEADDR

static final String SO_REUSEADDR
See Also:
Constant Field Values

SO_KEEPALIVE

static final String SO_KEEPALIVE
See Also:
Constant Field Values

SO_LINGER

static final String SO_LINGER
See Also:
Constant Field Values

TCP_NODELAY

static final String TCP_NODELAY
See Also:
Constant Field Values

SO_TIMEOUT

static final String SO_TIMEOUT
See Also:
Constant Field Values

MAX_TIMEOUT_MILLIS

static final long MAX_TIMEOUT_MILLIS
See Also:
Constant Field Values

DEFAULT_CONNECTION_TIMEOUT_MILLIS

static final long DEFAULT_CONNECTION_TIMEOUT_MILLIS
See Also:
Constant Field Values

DEFAULT_IDLE_TIMEOUT_MILLIS

static final long DEFAULT_IDLE_TIMEOUT_MILLIS
See Also:
Constant Field Values

DEFAULT_FLUSH_MODE

static final IConnection.FlushMode DEFAULT_FLUSH_MODE

DEFAULT_AUTOFLUSH

static final boolean DEFAULT_AUTOFLUSH
See Also:
Constant Field Values
Method Detail

getId

String getId()
returns the id

Returns:
id

isServerSide

boolean isServerSide()
returns true id connection is server side

Returns:
true, if is server side

isOpen

boolean isOpen()
returns, if the connection is open.

Please note, that a connection could be closed, but reading of already received (and internally buffered) data would not fail. See also IDataHandler.onData(INonBlockingConnection)

Returns:
true if the connection is open

getLocalPort

int getLocalPort()
returns the local port

Returns:
the local port

getLocalAddress

InetAddress getLocalAddress()
returns the local address

Returns:
the local IP address or InetAddress.anyLocalAddress() if the socket is not bound yet.

getRemoteAddress

InetAddress getRemoteAddress()
returns the remote address

Returns:
the remote address

getRemotePort

int getRemotePort()
returns the port of the remote end point

Returns:
the remote port

getIdleTimeoutMillis

long getIdleTimeoutMillis()
returns the idle timeout in millis.

Returns:
idle timeout in millis

setIdleTimeoutMillis

void setIdleTimeoutMillis(long timeoutInMillis)
sets the idle timeout in millis

Parameters:
timeoutInSec - idle timeout in millis

getConnectionTimeoutMillis

long getConnectionTimeoutMillis()
gets the connection timeout

Returns:
connection timeout

setConnectionTimeoutMillis

void setConnectionTimeoutMillis(long timeoutMillis)
sets the max time for a connections. By exceeding this time the connection will be terminated

Parameters:
timeoutSec - the connection timeout in millis

getRemainingMillisToIdleTimeout

long getRemainingMillisToIdleTimeout()
returns the remaining time before a idle timeout occurs

Returns:
the remaining time

getRemainingMillisToConnectionTimeout

long getRemainingMillisToConnectionTimeout()
returns the remaining time before a connection timeout occurs

Returns:
the remaining time

setOption

void setOption(String name,
               Object value)
               throws IOException
sets the value of a option.

A good article for tuning can be found here http://www.onlamp.com/lpt/a/6324

Parameters:
name - the name of the option
value - the value of the option
Throws:
IOException - In an I/O error occurs

getOption

Object getOption(String name)
                 throws IOException
returns the value of a option

Parameters:
name - the name of the option
Returns:
the value of the option
Throws:
IOException - In an I/O error occurs

getOptions

Map<String,Class> getOptions()
Returns an unmodifiable map of the options supported by this end point. The key in the returned map is the name of a option, and its value is the type of the option value. The returned map will never contain null keys or values.

Returns:
An unmodifiable map of the options supported by this channel

setAttachment

void setAttachment(Object obj)
Attaches the given object to this connection

Parameters:
obj - The object to be attached; may be null

getAttachment

Object getAttachment()
Retrieves the current attachment.

Returns:
The object currently attached to this key, or null if there is no attachment


Copyright 2010 xSocket.org