org.norther.tammi.spray.connector.chain
Class AbstractConnection

java.lang.Object
  extended by org.norther.tammi.core.pool.RecyclableSupport
      extended by org.norther.tammi.core.pool.PoolableSupport
          extended by org.norther.tammi.spray.connector.chain.AbstractConnection
All Implemented Interfaces:
Closeable, Serializable, Runnable, Poolable, Recyclable, Connection
Direct Known Subclasses:
ChannelConnection, InterConnection, SocketConnection

public abstract class AbstractConnection
extends PoolableSupport
implements Connection

An abstact connection avoiding synchronized methods for performance reasons but trusts on atomic fields. So it can return stale values but that has been considered acceptable when the number of allowed connections is large.

Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.norther.tammi.spray.connector.chain.Connection
BUSY, DONE, IDLE, IN_QUEUE, INITIAL
 
Constructor Summary
AbstractConnection(MBeanReference connector, MBeanReference filter, MBeanReference logger, MBeanReference timeout, Thread thread)
          Constructs a new client connection.
 
Method Summary
 void close()
          Closes this connection and stops execution.
 void connected()
          Sets the status of this connection to busy after idle.
 void dispose()
          Disposes the object by setting its disposed flag.
 void disposed()
          A call back indicating that this instance is not needed any more and can be disposed.
 int getConnectionStatus()
          Gets the connection status of this connection.
 long getConnectionTime()
          Gets the connection time of this connection.
 int getConnectionTimeout()
          Gets the connection timeout of this connection.
 Connector getConnector()
          Gets the connector of this connection.
 Filter getFilter()
          Gets the filter of this connection.
 Logger getLogger()
          Gets the logger of this connection.
 MBeanServer getMBeanServer()
          Gets the MBean server of this connection.
 int getReadyOps()
          Gets the ready operations set of this connection.
 int getRequestTimeout()
          Gets the request timeout of this connection.
 Timeout getTimeout()
          Gets the timer of this connection.
 boolean isContextThread()
          Checks whether this connection executes in a connector context thread.
 boolean isKeepConnection()
          Checks whether to keep this connection alive in idle after request processing.
 boolean keepConnection()
          Keeps this connection alive in idle after processing request processing if applicable.
 void log()
          Logs the request of this connection, if applicable
 void recycle(MBeanReference connector, MBeanReference filter, MBeanReference logger, MBeanReference timeout, Thread thread)
          Recycles a client connection.
 void run()
           
 void setReadyOps(int ops)
          Sets the ready operations set of this connection.
 boolean waitUntilDone(int msecs)
          Waits until this the execution of connection is done.
 
Methods inherited from class org.norther.tammi.core.pool.PoolableSupport
recycled
 
Methods inherited from class org.norther.tammi.core.pool.RecyclableSupport
isDisposed, recycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.norther.tammi.spray.connector.chain.Connection
filter, getByteCount, getPeerCertificates, getRemoteAddr, getRemotePort, getRequest, getResponse
 
Methods inherited from interface org.norther.tammi.core.pool.Recyclable
isDisposed, recycle
 

Constructor Detail

AbstractConnection

public AbstractConnection(MBeanReference connector,
                          MBeanReference filter,
                          MBeanReference logger,
                          MBeanReference timeout,
                          Thread thread)
Constructs a new client connection.

Parameters:
connector - the connector.
filter - the filter.
logger - the logger.
timeout - the timeout.
thread - the connector thread.
Method Detail

recycle

public void recycle(MBeanReference connector,
                    MBeanReference filter,
                    MBeanReference logger,
                    MBeanReference timeout,
                    Thread thread)
Recycles a client connection.

Parameters:
connector - the connector.
filter - the filter.
logger - the logger.
timeout - the timeout.
thread - the connector thread.

dispose

public void dispose()
Description copied from class: RecyclableSupport
Disposes the object by setting its disposed flag.

Specified by:
dispose in interface Recyclable
Overrides:
dispose in class RecyclableSupport

disposed

public void disposed()
Description copied from interface: Poolable
A call back indicating that this instance is not needed any more and can be disposed.

Specified by:
disposed in interface Poolable
Overrides:
disposed in class PoolableSupport

run

public final void run()
Specified by:
run in interface Runnable

getConnector

public Connector getConnector()
Description copied from interface: Connection
Gets the connector of this connection.

Specified by:
getConnector in interface Connection
Returns:
the connector.

getFilter

public Filter getFilter()
Description copied from interface: Connection
Gets the filter of this connection.

Specified by:
getFilter in interface Connection
Returns:
the filter.

getLogger

public Logger getLogger()
Description copied from interface: Connection
Gets the logger of this connection.

Specified by:
getLogger in interface Connection
Returns:
the logger.

getTimeout

public Timeout getTimeout()
Description copied from interface: Connection
Gets the timer of this connection.

Specified by:
getTimeout in interface Connection
Returns:
the timer.

getMBeanServer

public MBeanServer getMBeanServer()
Description copied from interface: Connection
Gets the MBean server of this connection.

Specified by:
getMBeanServer in interface Connection
Returns:
the server.

isContextThread

public boolean isContextThread()
Description copied from interface: Connection
Checks whether this connection executes in a connector context thread.

Specified by:
isContextThread in interface Connection
Returns:
true if a context thread, false otherwise.

getConnectionStatus

public int getConnectionStatus()
Description copied from interface: Connection
Gets the connection status of this connection.

Specified by:
getConnectionStatus in interface Connection
Returns:
the status.

getConnectionTime

public long getConnectionTime()
Description copied from interface: Connection
Gets the connection time of this connection.

Specified by:
getConnectionTime in interface Connection
Returns:
the connection time in msecs.

connected

public void connected()
Description copied from interface: Connection
Sets the status of this connection to busy after idle.

Specified by:
connected in interface Connection

getRequestTimeout

public int getRequestTimeout()
Description copied from interface: Connection
Gets the request timeout of this connection.

Specified by:
getRequestTimeout in interface Connection
Returns:
the request timeout in msecs.

getConnectionTimeout

public int getConnectionTimeout()
Description copied from interface: Connection
Gets the connection timeout of this connection.

Specified by:
getConnectionTimeout in interface Connection
Returns:
the connection timeout in msecs.

getReadyOps

public int getReadyOps()
Description copied from interface: Connection
Gets the ready operations set of this connection.

Specified by:
getReadyOps in interface Connection
Returns:
the operations set as a bit mask.

setReadyOps

public void setReadyOps(int ops)
Description copied from interface: Connection
Sets the ready operations set of this connection.

Note that this method must be thread safe and not causing deadlocks as it may be called by several threads during channel selections.

Specified by:
setReadyOps in interface Connection
Parameters:
ops - the operations set as a bit mask.

isKeepConnection

public boolean isKeepConnection()
Description copied from interface: Connection
Checks whether to keep this connection alive in idle after request processing.

Specified by:
isKeepConnection in interface Connection
Returns:
true to keep, false otherwise.

keepConnection

public boolean keepConnection()
Description copied from interface: Connection
Keeps this connection alive in idle after processing request processing if applicable.

Specified by:
keepConnection in interface Connection
Returns:
true if kept, false otherwise.

waitUntilDone

public boolean waitUntilDone(int msecs)
Description copied from interface: Connection
Waits until this the execution of connection is done.

Specified by:
waitUntilDone in interface Connection
Parameters:
msecs - a timeout to wait in msecs.
Returns:
true if done, otherwise false.

close

public void close()
Description copied from interface: Connection
Closes this connection and stops execution.

Note that this method must be thread safe and not causing deadlocks as it may be called by several threads during timeouts.

Specified by:
close in interface Closeable
Specified by:
close in interface Connection

log

public void log()
Description copied from interface: Connection
Logs the request of this connection, if applicable

Specified by:
log in interface Connection


Copyright © 2004 The Norther Organization. All rights reserved.