org.norther.tammi.spray.connector
Class DefaultChannelConnector

java.lang.Object
  extended by org.norther.tammi.core.base.Adaptee
      extended by org.norther.tammi.spray.connector.DefaultConnector
          extended by org.norther.tammi.spray.connector.DefaultExecutableConnector
              extended by org.norther.tammi.spray.connector.DefaultTCPConnector
                  extended by org.norther.tammi.spray.connector.DefaultChannelConnector
All Implemented Interfaces:
Serializable, Runnable, NotificationBroadcaster, NotificationEmitter, Manageable, MBeanDelegate, Startable, Executable, ChannelConnector, Connector, ExecutableConnector, TCPConnector

public class DefaultChannelConnector
extends DefaultTCPConnector
implements ChannelConnector

A default implementation of ChannelConnector.

Version:
$Id: DefaultChannelConnector.java,v 1.14 2009/10/29 21:39:55 cvsimp Exp $
Author:
Ilkka Priha
See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.norther.tammi.spray.connector.DefaultConnector
LOCALHOST
 
Fields inherited from class org.norther.tammi.core.base.Adaptee
ADAPTEE_NOTIF_DESCRIPTION, ADAPTEE_NOTIFICATIONS
 
Constructor Summary
DefaultChannelConnector()
          Constructs a new connector.
DefaultChannelConnector(InetAddress addr)
          Constructs a connector with a host address.
 
Method Summary
 int getChannelTimeout()
          Gets the timeout to wait for an asynchronous I/O operation from a channel.
 int getConnectionCount()
          Gets a snapshot of the number of active and idle connections.
 int getSelectorCount()
          Gets the number of selectors to apply.
 int getSelectorTimeout()
          Gets the timeout to wait for selected channels to be ready for I/O.
 boolean keepConnection(Connection con)
          Keeps the specified connection alive on idle after processing the corresponding request if applicable.
 void postmanaged()
          This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.
 void run()
           
 void setAddress(String addr)
          Sets the address of the server of the connection.
 void setChannelTimeout(int timeout)
          Sets the timeout to wait for an asynchronous I/O operation.
 void setSelectorCount(int count)
          Sets the number of selectors to apply.
 void setSelectorTimeout(int timeout)
          Sets the timeout to wait for selected channels to be ready for I/O.
 void start()
          Starts the MBean.
 void stop()
          Stops the MBean.
 void unmanaged()
          This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.
 
Methods inherited from class org.norther.tammi.spray.connector.DefaultTCPConnector
getReceiveBufferSize, getSendBufferSize, getServerBufferSize, getSoLinger, getSoTimeout, isTcpNoDelay, setReceiveBufferSize, setSendBufferSize, setServerBufferSize, setSoLinger, setSoTimeout, setTcpNoDelay
 
Methods inherited from class org.norther.tammi.spray.connector.DefaultExecutableConnector
execute, getExecutorMBean, getExecutorName, getRequestExecutorName, isStarted, premanaged, setExecutorName, setRequestExecutorName
 
Methods inherited from class org.norther.tammi.spray.connector.DefaultConnector
getAddress, getConnectionTimeout, getFilterMBean, getFilterName, getInetAddress, getKeyAlias, getLoggerMBean, getLoggerName, getMaxIdleConnections, getName, getPort, getProvider, getRedirectPort, getRequestTimeout, getTimeoutMBean, isKeepConnection, isLoggingDisabled, isSecure, setConnectionTimeout, setFilterName, setInetAddress, setKeyAlias, setKeyPassword, setLoggerName, setLoggingDisabled, setMaxIdleConnections, setPort, setProvider, setRedirectPort, setRequestTimeout, setSecure
 
Methods inherited from class org.norther.tammi.core.base.Adaptee
addAdaptee, addNotificationListener, getAttributeSupport, getBroker, getCanonicalName, getDomain, getFactory, getLoader, getLog, getLog, getMBean, getMBeanServer, getNotificationInfo, getObjectName, getRegistrationTime, getSequenceNumber, hasListeners, isRegistered, removeNotificationListener, removeNotificationListener, sendNotification, sendNotification, sendNotification, sendNotification, unregister
 
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.TCPConnector
getReceiveBufferSize, getSendBufferSize, getServerBufferSize, getSoLinger, getSoTimeout, isTcpNoDelay, setReceiveBufferSize, setSendBufferSize, setServerBufferSize, setSoLinger, setSoTimeout, setTcpNoDelay
 
Methods inherited from interface org.norther.tammi.spray.connector.ExecutableConnector
getRequestExecutorName, setRequestExecutorName
 
Methods inherited from interface org.norther.tammi.spray.connector.Connector
getAddress, getConnectionTimeout, getFilterName, getKeyAlias, getLoggerName, getMaxIdleConnections, getName, getPort, getProvider, getRedirectPort, getRequestTimeout, isKeepConnection, isLoggingDisabled, isSecure, setConnectionTimeout, setFilterName, setKeyAlias, setKeyPassword, setLoggerName, setLoggingDisabled, setMaxIdleConnections, setPort, setProvider, setRedirectPort, setRequestTimeout, setSecure
 
Methods inherited from interface org.norther.tammi.core.thread.Executable
getExecutorName, setExecutorName
 
Methods inherited from interface org.norther.tammi.core.base.Startable
isStarted
 

Constructor Detail

DefaultChannelConnector

public DefaultChannelConnector()
Constructs a new connector.


DefaultChannelConnector

public DefaultChannelConnector(InetAddress addr)
Constructs a connector with a host address.

Parameters:
addr - the host address.
Method Detail

postmanaged

public void postmanaged()
Description copied from interface: Manageable
This method is called when the implementing adaptee has been managed either during post-registration of the corresponding adapter MBean or just after it is explicitly added to the adapter MBean during run-time.

Specified by:
postmanaged in interface Manageable
Overrides:
postmanaged in class DefaultConnector

unmanaged

public void unmanaged()
               throws Exception
Description copied from interface: Manageable
This method is called when the implementing adaptee is unmanaged either during pre-deregistration of the corresponding adapter MBean or just before it is explicitly removed from the adapter MBean during run-time.

Specified by:
unmanaged in interface Manageable
Overrides:
unmanaged in class DefaultExecutableConnector
Throws:
Exception - if the adaptee refused to be unmanaged.

getConnectionCount

public int getConnectionCount()
Description copied from interface: Connector
Gets a snapshot of the number of active and idle connections.

Note that the count is implementation dependent and its accuracy may vary.

Specified by:
getConnectionCount in interface Connector
Specified by:
getConnectionCount in interface ExecutableConnector
Overrides:
getConnectionCount in class DefaultExecutableConnector
Returns:
the number of connections.

setAddress

public void setAddress(String addr)
                throws UnknownHostException
Description copied from class: DefaultConnector
Sets the address of the server of the connection.

Specified by:
setAddress in interface ChannelConnector
Overrides:
setAddress in class DefaultConnector
Parameters:
addr - the address of the server.
Throws:
UnknownHostException - if not found.

getChannelTimeout

public int getChannelTimeout()
Description copied from interface: ChannelConnector
Gets the timeout to wait for an asynchronous I/O operation from a channel.

Specified by:
getChannelTimeout in interface ChannelConnector
Returns:
the timeout for channels in msecs.

setChannelTimeout

public void setChannelTimeout(int timeout)
Description copied from interface: ChannelConnector
Sets the timeout to wait for an asynchronous I/O operation. -1 waits until notified, 0 reads/writes immediately, other values wait the specified number of msecs.

Specified by:
setChannelTimeout in interface ChannelConnector
Parameters:
timeout - the timeout for channels in msecs.

getSelectorTimeout

public int getSelectorTimeout()
Description copied from interface: ChannelConnector
Gets the timeout to wait for selected channels to be ready for I/O.

Specified by:
getSelectorTimeout in interface ChannelConnector
Returns:
the timeout for selectors in msecs.

setSelectorTimeout

public void setSelectorTimeout(int timeout)
Description copied from interface: ChannelConnector
Sets the timeout to wait for selected channels to be ready for I/O. -1 waits for an OS-specific poll to finish, 0 selects immediately, other values wait the specified number of msecs.

Note that selector threads in Linux seem to suspend for exactly 100 seconds during longer intervals without selections if the selector timeout is not specified.

Specified by:
setSelectorTimeout in interface ChannelConnector
Parameters:
timeout - the timeout for channels in msecs.

getSelectorCount

public int getSelectorCount()
Description copied from interface: ChannelConnector
Gets the number of selectors to apply.

Specified by:
getSelectorCount in interface ChannelConnector
Returns:
the number of idle selectors.

setSelectorCount

public void setSelectorCount(int count)
Description copied from interface: ChannelConnector
Sets the number of selectors to apply. 0 indicates a per-thread connection model without selectors for idle connections, 1 applies the same selector to accept new connections and to keep alive idle connections, greater values reserve one selector for accepting new connections and the rest for idle connections.

Note that the per-thread model doesn't work for SSL connections.

Note that this value cannot be changed while the connector is running.

Specified by:
setSelectorCount in interface ChannelConnector
Parameters:
count - the number of idle selectors.

keepConnection

public boolean keepConnection(Connection con)
Description copied from interface: Connector
Keeps the specified connection alive on idle after processing the corresponding request if applicable.

Specified by:
keepConnection in interface Connector
Overrides:
keepConnection in class DefaultConnector
Parameters:
con - the connection.
Returns:
true if kept, false otherwise.

start

public void start()
           throws Exception
Description copied from interface: Startable
Starts the MBean.

Specified by:
start in interface Startable
Overrides:
start in class DefaultExecutableConnector
Throws:
Exception - if start fails.

stop

public void stop()
Description copied from interface: Startable
Stops the MBean.

Specified by:
stop in interface Startable
Overrides:
stop in class DefaultExecutableConnector

run

public void run()
Specified by:
run in interface Runnable
Overrides:
run in class DefaultExecutableConnector


Copyright © 2004 The Norther Organization. All rights reserved.