Top Description Inners Fields Constructors Methods
org.mortbay.io.nio

public abstract Class SelectorManager

extends AbstractLifeCycle
Class Inheritance
Imports
java.io.IOException, java.nio.channels.CancelledKeyException, .SelectionKey, .Selector, .ServerSocketChannel, .SocketChannel, java.util.ArrayList, .Iterator, .List, org.mortbay.component.AbstractLifeCycle, org.mortbay.io.Connection, .EndPoint, org.mortbay.log.Log, org.mortbay.thread.Timeout

The Selector Manager manages and number of SelectSets to allow NIO scheduling to scale to large numbers of connections.
Author
gregw

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class

Field Summary

Modifier and TypeField and Description
private long
private long
private long
private transient SelectorManager.SelectSet[]
private int
private volatile int
Inherited from org.mortbay.component.AbstractLifeCycle:
_listeners

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected abstract SocketChannel
protected void
public abstract boolean
public void
doSelect(int acceptorID)

protected void
protected void
protected abstract void
protected abstract void
public long

Returns:

the lowResourcesConnections
getLowResourcesConnections
()

public long

Returns:

the lowResourcesMaxIdleTime
getLowResourcesMaxIdleTime
()

public long
public int
protected abstract Connection
protected abstract SelectChannelEndPoint
public void
register(SocketChannel channel, Object
Attached Object
att
)

Register a channel

public void
register(ServerSocketChannel acceptChannel)

Register a serverchannel

public void
setLowResourcesConnections(long
the number of connections
lowResourcesConnections
)

Set the number of connections, which if exceeded places this manager in low resources state.

public void
setLowResourcesMaxIdleTime(long
the period in ms that a connection is allowed to be idle when this SelectSet has more connections than getLowResourcesConnections()
lowResourcesMaxIdleTime
)

public void
setMaxIdleTime(long
The maximum period in milli seconds that a connection may be idle before it is closed.
maxIdleTime
)

public void
setSelectSets(int selectSets)

Inherited from org.mortbay.component.AbstractLifeCycle:
addLifeCycleListenerisFailedisRunningisStartedisStartingisStoppedisStoppingremoveLifeCycleListenerstartstop

Field Detail

_lowResourcesConnectionsback to summary
private long _lowResourcesConnections
_lowResourcesMaxIdleTimeback to summary
private long _lowResourcesMaxIdleTime
_maxIdleTimeback to summary
private long _maxIdleTime
_selectSetback to summary
private transient SelectorManager.SelectSet[] _selectSet
_selectSetsback to summary
private int _selectSets
_setback to summary
private volatile int _set

Constructor Detail

SelectorManagerback to summary
public SelectorManager()

Method Detail

acceptChannelback to summary
protected abstract SocketChannel acceptChannel(SelectionKey key) throws IOException
connectionFailedback to summary
protected void connectionFailed(SocketChannel channel, Throwable ex, Object attachment)
dispatchback to summary
public abstract boolean dispatch(Runnable task)
doSelectback to summary
public void doSelect(int acceptorID) throws IOException
doStartback to summary
protected void doStart() throws Exception

Overrides org.mortbay.component.AbstractLifeCycle.doStart.

doStopback to summary
protected void doStop() throws Exception

Overrides org.mortbay.component.AbstractLifeCycle.doStop.

endPointClosedback to summary
protected abstract void endPointClosed(SelectChannelEndPoint endpoint)
endPointOpenedback to summary
protected abstract void endPointOpened(SelectChannelEndPoint endpoint)
getLowResourcesConnectionsback to summary
public long getLowResourcesConnections()
Returns:long

the lowResourcesConnections

getLowResourcesMaxIdleTimeback to summary
public long getLowResourcesMaxIdleTime()
Returns:long

the lowResourcesMaxIdleTime

getMaxIdleTimeback to summary
public long getMaxIdleTime()
getSelectSetsback to summary
public int getSelectSets()
newConnectionback to summary
protected abstract Connection newConnection(SocketChannel channel, SelectChannelEndPoint endpoint)
newEndPointback to summary
protected abstract SelectChannelEndPoint newEndPoint(SocketChannel channel, SelectorManager.SelectSet selectSet, SelectionKey sKey) throws IOException
registerback to summary
public void register(SocketChannel channel, Object att) throws IOException

Register a channel

Parameters
att:Object

Attached Object

registerback to summary
public void register(ServerSocketChannel acceptChannel) throws IOException

Register a serverchannel

setLowResourcesConnectionsback to summary
public void setLowResourcesConnections(long lowResourcesConnections)

Set the number of connections, which if exceeded places this manager in low resources state. This is not an exact measure as the connection count is averaged over the select sets.

Parameters
lowResourcesConnections:long

the number of connections

See Also
setLowResourcesMaxIdleTime(long)
setLowResourcesMaxIdleTimeback to summary
public void setLowResourcesMaxIdleTime(long lowResourcesMaxIdleTime)
Parameters
lowResourcesMaxIdleTime:long

the period in ms that a connection is allowed to be idle when this SelectSet has more connections than getLowResourcesConnections()

See Also
setMaxIdleTime(long)
setMaxIdleTimeback to summary
public void setMaxIdleTime(long maxIdleTime)
Parameters
maxIdleTime:long

The maximum period in milli seconds that a connection may be idle before it is closed.

See Also
setLowResourcesMaxIdleTime(long)
setSelectSetsback to summary
public void setSelectSets(int selectSets)
org.mortbay.io.nio back to summary

public Class SelectorManager.SelectSet

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private transient int
private transient List<Object>[]
private transient Timeout
private transient int
private transient int
private transient boolean
private transient Selector
private transient int
private transient Timeout

Constructor Summary

AccessConstructor and Description
pack-priv
SelectSet(int acceptorID)

Method Summary

Modifier and TypeMethod and Description
public void
public void
public void
public void
public void
doSelect()

Select and dispatch tasks found from changes and the selector.

public SelectorManager
public long
pack-priv Selector
public void
public void
scheduleTimeout(Timeout.Task task, long timeoutMs)

pack-priv void
stop()

public void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_changeback to summary
private transient int _change
_changesback to summary
private transient List<Object>[] _changes
_idleTimeoutback to summary
private transient Timeout _idleTimeout
_jvmBugback to summary
private transient int _jvmBug
_nextSetback to summary
private transient int _nextSet
_selectingback to summary
private transient boolean _selecting
_selectorback to summary
private transient Selector _selector
_setIDback to summary
private transient int _setID
_timeoutback to summary
private transient Timeout _timeout

Constructor Detail

SelectSetback to summary
pack-priv SelectSet(int acceptorID) throws Exception

Method Detail

addChangeback to summary
public void addChange(Object point)
addChangeback to summary
public void addChange(SocketChannel channel, Object att)
cancelIdleback to summary
public void cancelIdle(Timeout.Task task)
cancelTimeoutback to summary
public void cancelTimeout(Timeout.Task task)
doSelectback to summary
public void doSelect() throws IOException

Select and dispatch tasks found from changes and the selector.

getManagerback to summary
public SelectorManager getManager()
getNowback to summary
public long getNow()
getSelectorback to summary
pack-priv Selector getSelector()
scheduleIdleback to summary
public void scheduleIdle(Timeout.Task task)
scheduleTimeoutback to summary
public void scheduleTimeout(Timeout.Task task, long timeoutMs)
stopback to summary
pack-priv void stop() throws Exception
wakeupback to summary
public void wakeup()