org.abstracthorizon.danube.service.server
Class SocketChannelConnection

java.lang.Object
  extended by org.abstracthorizon.danube.service.server.SocketChannelConnection
All Implemented Interfaces:
Adaptable, AdapterFactory, Connection

public class SocketChannelConnection
extends Object
implements Connection, AdapterFactory

This is socket connection implementation.

Author:
Daniel Sendula
See Also:
org.abstracthorizon.danube.connection.socket.SocketConnection, Connection

Field Summary
protected static Class<?>[] ADAPTING_CLASSES
          Classes that are available through this object as an AdapterFactory
protected  InputStream cachedInputStream
          Cached input stream
protected  OutputStream cachedOutputStream
          Cached output stream
protected  SocketChannel socketChannel
          Socket
 
Constructor Summary
SocketChannelConnection(AdapterManager adapterManager, SocketChannel socketChannel)
          Constructor.
SocketChannelConnection(SocketChannel socketChannel)
          Constructor.
 
Method Summary
<T> T
adapt(Class<T> cls)
          Returns an object that is instance of asked class
<T> T
adapt(T object, Class<T> cls)
          Adopts given object to the instance of the asked class
 void close()
          Closes the socket channel
<T> Class<T>[]
getAdaptingClasses(T object)
          Returns list of classes to which given object can be adopted to by this adopter factory
 InputStream getInputStream()
          Returns input stream
 OutputStream getOutputStream()
          Returns output stream
 Socket getSocket()
          Returns socket
 SocketChannel getSocketChannel()
          Returns socket channel
 boolean isClosed()
          Checks if socket is closed
 String toString()
          Returns connection as a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

ADAPTING_CLASSES

protected static final Class<?>[] ADAPTING_CLASSES
Classes that are available through this object as an AdapterFactory


socketChannel

protected SocketChannel socketChannel
Socket


cachedInputStream

protected InputStream cachedInputStream
Cached input stream


cachedOutputStream

protected OutputStream cachedOutputStream
Cached output stream

Constructor Detail

SocketChannelConnection

public SocketChannelConnection(SocketChannel socketChannel)
Constructor. It creates buffered input and output streams.

Parameters:
socket -

SocketChannelConnection

public SocketChannelConnection(AdapterManager adapterManager,
                               SocketChannel socketChannel)
Constructor. It creates buffered input and output streams.

Parameters:
socket -
Method Detail

getSocketChannel

public SocketChannel getSocketChannel()
Returns socket channel

Returns:
socket channel

getSocket

public Socket getSocket()
Returns socket

Returns:
socket

getInputStream

public InputStream getInputStream()
Returns input stream

Returns:
input stream

getOutputStream

public OutputStream getOutputStream()
Returns output stream

Returns:
output stream

close

public void close()
Closes the socket channel

Specified by:
close in interface Connection

isClosed

public boolean isClosed()
Checks if socket is closed

Specified by:
isClosed in interface Connection
Returns:
true if socket is closed

toString

public String toString()
Returns connection as a string

Overrides:
toString in class Object
Returns:
connection as a string

adapt

public <T> T adapt(T object,
                   Class<T> cls)
Adopts given object to the instance of the asked class

Specified by:
adapt in interface AdapterFactory
Parameters:
object - object to he adopted
cls - asked class
Returns:
adopted given object to the instance of the asked class

adapt

public <T> T adapt(Class<T> cls)
Description copied from interface: Adaptable
Returns an object that is instance of asked class

Specified by:
adapt in interface Adaptable
Parameters:
cls - class to be adapted to
Returns:
an object that is instance of asked class

getAdaptingClasses

public <T> Class<T>[] getAdaptingClasses(T object)
Returns list of classes to which given object can be adopted to by this adopter factory

Specified by:
getAdaptingClasses in interface AdapterFactory
Returns:
list of classes to which given object can be adopted to


Copyright © 2005-2009 Abstract Horizon. All Rights Reserved.