org.activeio.adapter
Class SyncToAsyncChannel

java.lang.Object
  extended byorg.activeio.adapter.SyncToAsyncChannel
All Implemented Interfaces:
AsyncChannel, Channel, Disposable, InputAsyncChannel, OutputChannel, Runnable, Service
Direct Known Subclasses:
SynchToAsynchChannelAdapter

public class SyncToAsyncChannel
extends Object
implements AsyncChannel, Runnable

Adapts a org.activeio.SynchChannel so that it provides an AsyncChannel interface. When this channel is started, a background thread is used to poll the org.activeio.SynchChannel for packets comming up the channel which are then delivered to the org.activeio.ChannelConsumer.

Version:
$Revision$

Field Summary
 
Fields inherited from interface org.activeio.Service
NO_WAIT_TIMEOUT, WAIT_FOREVER_TIMEOUT
 
Constructor Summary
SyncToAsyncChannel(SyncChannel syncChannel)
          Deprecated. #adapt(SynchChannel)
SyncToAsyncChannel(SyncChannel syncChannel, Executor executor)
          Deprecated. #adapt(SynchChannel, Executor)
 
Method Summary
static AsyncChannel adapt(Channel channel)
           
static AsyncChannel adapt(Channel channel, Executor executor)
           
 void dispose()
          This method should not throw any exceptions.
 void flush()
          Some channels may buffer data which may be sent down if flush() is called.
 AsyncChannelListener getAsyncChannelListener()
           
 SyncChannel getSynchChannel()
           
 Object narrow(Class target)
          Since a Channel may be composed from a chain of other Channel obejcts, this method allows you to query the chain for the specified interface.
 void run()
          reads packets from a Socket
 void setAsyncChannelListener(AsyncChannelListener channelListener)
          Registers the ChannelConsumer that the protcol will use to deliver packets coming 'up' the channel.
 void start()
          Starts the channel.
 void stop(long timeout)
          Stops the channel.
 String toString()
           
 void write(Packet packet)
          Sends a packet down the channel towards the media.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SyncToAsyncChannel

public SyncToAsyncChannel(SyncChannel syncChannel)
Deprecated. #adapt(SynchChannel)


SyncToAsyncChannel

public SyncToAsyncChannel(SyncChannel syncChannel,
                          Executor executor)
Deprecated. #adapt(SynchChannel, Executor)

Method Detail

adapt

public static AsyncChannel adapt(Channel channel)

adapt

public static AsyncChannel adapt(Channel channel,
                                 Executor executor)

start

public void start()
           throws IOException
Description copied from interface: Service
Starts the channel. Once started, the channel is in the running state.

Specified by:
start in interface Service
Throws:
IOException

stop

public void stop(long timeout)
          throws IOException
Description copied from interface: Service
Stops the channel. Once stopped, the channel is in the stopped state.

Specified by:
stop in interface Service
Parameters:
timeout - The amount of time the channel is allowed to take to gracefully stop. If the timeout is exceeded, the channel should do a forcefull stop.
Throws:
IOException

run

public void run()
reads packets from a Socket

Specified by:
run in interface Runnable

setAsyncChannelListener

public void setAsyncChannelListener(AsyncChannelListener channelListener)
Description copied from interface: InputAsyncChannel
Registers the ChannelConsumer that the protcol will use to deliver packets coming 'up' the channel.

Specified by:
setAsyncChannelListener in interface InputAsyncChannel
See Also:
org.activeio.AsyncChannel#setAsyncChannelListener(org.activeio.UpPacketListener)

write

public void write(Packet packet)
           throws IOException
Description copied from interface: OutputChannel
Sends a packet down the channel towards the media.

Specified by:
write in interface OutputChannel
Parameters:
packet -
Throws:
IOException
See Also:
org.activeio.Channel#write(org.activeio.Packet)

flush

public void flush()
           throws IOException
Description copied from interface: OutputChannel
Some channels may buffer data which may be sent down if flush() is called.

Specified by:
flush in interface OutputChannel
Throws:
IOException
See Also:
org.activeio.Channel#flush()

dispose

public void dispose()
Description copied from interface: Disposable
This method should not throw any exceptions. Cleaning up a Disposable object should be easy of an end user therefore do not make him have to handle an Exception.

Specified by:
dispose in interface Disposable
See Also:
Disposable.dispose()

getAsyncChannelListener

public AsyncChannelListener getAsyncChannelListener()
Specified by:
getAsyncChannelListener in interface InputAsyncChannel
Returns:
the registered Packet consumer

narrow

public Object narrow(Class target)
Description copied from interface: Channel
Since a Channel may be composed from a chain of other Channel obejcts, this method allows you to query the chain for the specified interface. The first Channel in the chain the implments the requested interface will be return an implementing object. If no Channel in the chain implements the requested class, then null is returned.

Specified by:
narrow in interface Channel

getSynchChannel

public SyncChannel getSynchChannel()

toString

public String toString()


Copyright © -2007 The ActiveIO Project. All Rights Reserved.