|
BEA Systems, Inc. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.connecterra.ale.reader.ChannelManager
public class ChannelManager
This class manages a set of channels used to communicate with a
device. It separates the responsibilities of channel maintenance
and device state maintenance, so channel implementations can be
reused and device drivers do not need to concern themselves with
initialization and retry semantics. A state machine ensures that
all channels are active and the device is initialized before
attempting to execute any operations on the device. The
ChannelManager delegates channel-specific operations to classes
which extend DeviceChannel
and delegates device-specific
operations to an object which implements the ChannelManager.Proxy
interface.
In general, a ChannelManager is used as follows:
DeviceChannels
are created and added to the manager.
Note that neither creating or registering a channel will actually
attempt to activate or use the channel, although it may attempt to
resolve some configuration information, such as loading classes or
resolving hostnames.
Operations
are executed on the manager.
Before executing any operation, the manager will DeviceChannel.activate()
each channel, then ChannelManager.Proxy.initialize()
the Proxy. If activation, initialization, or execution has a
communication problem and throws an IOException, then the manager
will retry once before giving up.
The manager uses the proxy's logger to issue log messages when state transitions occur.
The manager is not reentrant. The caller is responsible for ensuring that access to the ChannelManager and to the I/O methods in the DeviceChannels are properly synchronized to avoid simultaneous calls. Exceptions to this are noted in method documentation.
In addition to the above reentrancy rules, channels may need to
execute invoke callbacks when input is received asynchronously from
devices by listeners. Such callbacks are invoked from within a
Runnable passed to the ChannelManager.Proxy.listenerExecute(java.lang.Runnable)
method.
Because these callbacks may use I/O methods on DeviceChannels, the
implementation must therefore ensure that the Runnable is not
executed at the same time as any methods on ChannelManager or
DeviceChannel. For maximum performance, some sort of work queue is
recommended.
Nested Class Summary | |
---|---|
static interface |
ChannelManager.Operation
This interface is implemented by classes which represent work to be performed after activation and initialization. |
static interface |
ChannelManager.Proxy
This class is implemented by consumers of the ChannelManager mechanism. |
static class |
ChannelManager.State
The manager implements a state machine which has these states. |
Constructor Summary | |
---|---|
ChannelManager(ChannelManager.Proxy p)
Creates a new ChannelManager instance with the
specified ChannelManager.Proxy . |
Method Summary | |
---|---|
void |
addChannel(DeviceChannel c)
Adds a DeviceChannel to the manager. |
void |
execute(ChannelManager.Operation op)
This method is called to do some work which communicates with the device. |
long |
getLastUsedTime()
|
ChannelManager.State |
getState()
|
void |
reactivateChannels()
Deactivates each channel, activates each channel, then initializes the proxy. |
void |
removeAllChannels()
Removes all DeviceChannels from the manager. |
void |
removeChannel(DeviceChannel c)
Removes a DeviceChannel from the manager. |
void |
setProxy(ChannelManager.Proxy p)
Sets the manager's proxy instance. |
void |
terminate()
Makes a best-effort attempt to close all the channels. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ChannelManager(ChannelManager.Proxy p)
ChannelManager
instance with the
specified ChannelManager.Proxy
.
p
- the Proxy
instanceMethod Detail |
---|
public void setProxy(ChannelManager.Proxy p)
p
- a Proxy
valuepublic void addChannel(DeviceChannel c)
INACTIVE
state.
c
- a DeviceChannel
value
IllegalStateException
- if called when the state is not
INACTIVE.public void removeChannel(DeviceChannel c)
INACTIVE
state.
c
- a DeviceChannel
value
IllegalStateException
- if called when the state is not
INACTIVE.public void removeAllChannels()
INACTIVE
state.
IllegalStateException
- if called when the state is not
INACTIVE.public void execute(ChannelManager.Operation op)
If the method is called in the INACTIVE or OFFLINE state,
then the manager will activate each channel in turn, then call
the ChannelManager.Proxy.initialize()
method.
The* op
's {#link Operation#execute} method is run.
If any of the prior steps throws an IOException, all of the channels are deactivated, and the process restarts as if from the INACTIVE state one more time.
op
- an Operation
valuepublic void reactivateChannels()
public void terminate()
public ChannelManager.State getState()
State
value representing the current
statepublic long getLastUsedTime()
System.currentTimeMillis()
.
|
Documentation is available at ${DOCSWEBROOT} Copyright 2007 BEA Systems Inc. |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |