org.jppf.server.nio
Class AbstractChannelWrapper<S>

java.lang.Object
  extended by org.jppf.utils.ThreadSynchronization
      extended by org.jppf.server.nio.AbstractChannelWrapper<S>
Type Parameters:
S - the type of wrapped channel.
All Implemented Interfaces:
ChannelWrapper<S>
Direct Known Subclasses:
AbstractLocalChannelWrapper, SelectionKeyWrapper

public abstract class AbstractChannelWrapper<S>
extends ThreadSynchronization
implements ChannelWrapper<S>

Wraps a communication channel, no matter what the channel is.

Author:
Laurent Cohen

Field Summary
protected  S channel
          The channel to wrap.
protected  long id
          Id of this instance.
protected  ChannelSelector selector
          The selctor for this channel.
 
Fields inherited from class org.jppf.utils.ThreadSynchronization
stopped
 
Constructor Summary
AbstractChannelWrapper(S channel)
          Initialize this channel wrapper with the specified channel.
 
Method Summary
 void close()
          Close the channel.
 boolean equals(Object obj)
          Determine whether an other object is equal to this one.
 S getChannel()
          Get the channel to wrap.
abstract  NioContext getContext()
          Get the AbstractNioContext attached to the channel.
 String getId()
          Get a string uniquely identifying this channel.
 int getKeyOps()
          Get the operations enabled for this channel.
abstract  int getReadyOps()
          Get the operations available for this channel.
 ChannelSelector getSelector()
          Default implementation of this method returns null.
 int hashCode()
          
 boolean isAcceptable()
          Determine whether the channel can accept connections.
 boolean isConnectable()
          Determine whether the channel can be connected.
 boolean isOpen()
          Determine whether the channel is opened.
 boolean isReadable()
          Determine whether the channel can be read from.
 boolean isWritable()
          Determine whether the channel can be written to.
 void setKeyOps(int keyOps)
          Get the operations enabled for this channel.
 void setSelector(ChannelSelector selector)
          By default, this method does nothing.
 String toString()
          
 
Methods inherited from class org.jppf.utils.ThreadSynchronization
goToSleep, goToSleep, goToSleep, isStopped, setStopped, wakeUp
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

id

protected final long id
Id of this instance.


channel

protected S channel
The channel to wrap.


selector

protected ChannelSelector selector
The selctor for this channel.

Constructor Detail

AbstractChannelWrapper

public AbstractChannelWrapper(S channel)
Initialize this channel wrapper with the specified channel.

Parameters:
channel - the channel to wrap.
Method Detail

getChannel

public S getChannel()
Get the channel to wrap.

Specified by:
getChannel in interface ChannelWrapper<S>
Returns:
the wrapped channel.

close

public void close()
           throws Exception
Close the channel.

Specified by:
close in interface ChannelWrapper<S>
Throws:
Exception - if any error occurs while closing the channel.
See Also:
ChannelWrapper.close()

getContext

public abstract NioContext getContext()
Get the AbstractNioContext attached to the channel.

Specified by:
getContext in interface ChannelWrapper<S>
Returns:
a AbstractNioContext instance.

isOpen

public boolean isOpen()
Determine whether the channel is opened.

Specified by:
isOpen in interface ChannelWrapper<S>
Returns:
true if the channel is opened, false otherwise.

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Determine whether an other object is equal to this one.

Overrides:
equals in class Object
Parameters:
obj - the object to compare with.
Returns:
true if this object is equal to the other one, false otherwise.
See Also:
Object.equals(java.lang.Object)

toString

public String toString()

Overrides:
toString in class Object

getKeyOps

public int getKeyOps()
Get the operations enabled for this channel.

Specified by:
getKeyOps in interface ChannelWrapper<S>
Returns:
the operations as an int value.
See Also:
ChannelWrapper.getKeyOps()

setKeyOps

public void setKeyOps(int keyOps)
Get the operations enabled for this channel.

Specified by:
setKeyOps in interface ChannelWrapper<S>
Parameters:
keyOps - the operations as an int value.
See Also:
ChannelWrapper.setKeyOps(int)

getReadyOps

public abstract int getReadyOps()
Get the operations available for this channel.

Specified by:
getReadyOps in interface ChannelWrapper<S>
Returns:
the operations as an int value.

isReadable

public boolean isReadable()
Determine whether the channel can be read from.

Specified by:
isReadable in interface ChannelWrapper<S>
Returns:
true if the channel can be read, false otherwise.
See Also:
ChannelWrapper.isReadable()

isWritable

public boolean isWritable()
Determine whether the channel can be written to.

Specified by:
isWritable in interface ChannelWrapper<S>
Returns:
true if the channel can be written to, false otherwise.
See Also:
ChannelWrapper.isWritable()

isAcceptable

public boolean isAcceptable()
Determine whether the channel can accept connections.

Specified by:
isAcceptable in interface ChannelWrapper<S>
Returns:
true if the channel can accept connections, false otherwise.
See Also:
ChannelWrapper.isAcceptable()

isConnectable

public boolean isConnectable()
Determine whether the channel can be connected.

Specified by:
isConnectable in interface ChannelWrapper<S>
Returns:
true if the channel can be connected, false otherwise.
See Also:
ChannelWrapper.isConnectable()

getSelector

public ChannelSelector getSelector()
Default implementation of this method returns null.

Specified by:
getSelector in interface ChannelWrapper<S>
Returns:
by default this method returns null.
See Also:
ChannelWrapper.getSelector()

setSelector

public void setSelector(ChannelSelector selector)
By default, this method does nothing. Subclasses should override it ot implement their own selection mechanism.

Specified by:
setSelector in interface ChannelWrapper<S>
Parameters:
selector - the selector associated with this mechanism.
See Also:
ChannelWrapper.setSelector(org.jppf.server.nio.ChannelSelector)

getId

public String getId()
Get a string uniquely identifying this channel.

Returns:
a unique id as a string.


Copyright © 2005-2010 JPPF Team.