org.abstracthorizon.danube.service.server
Class SocketConnection

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

public class SocketConnection
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  Socket socket
          Socket
 
Constructor Summary
SocketConnection(AdapterManager adapterManager, Socket socket)
          Constructor.
SocketConnection(Socket socket)
          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 connection - closes the underlaying socket.
<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
 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


socket

protected Socket socket
Socket


cachedInputStream

protected InputStream cachedInputStream
Cached input stream


cachedOutputStream

protected OutputStream cachedOutputStream
Cached output stream

Constructor Detail

SocketConnection

public SocketConnection(Socket socket)
Constructor. It creates buffered input and output streams.

Parameters:
socket - socket

SocketConnection

public SocketConnection(AdapterManager adapterManager,
                        Socket socket)
Constructor. It creates buffered input and output streams.

Parameters:
socket - socket
Method Detail

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 connection - closes the underlaying socket.

Specified by:
close in interface Connection

isClosed

public boolean isClosed()
Checks if socket is closed

Specified by:
isClosed in interface Connection
Returns:
true when 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.