org.activeio.adapter
Class SyncToAsyncChannelServer

java.lang.Object
  extended by org.activeio.adapter.SyncToAsyncChannelServer
All Implemented Interfaces:
Runnable, AsyncChannelServer, Channel, ChannelServer, Disposable, Service

public final class SyncToAsyncChannelServer
extends Object
implements AsyncChannelServer, Runnable

Adapts a org.activeio,SynchChannelServer so that it provides an AsyncChannelServer interface. When this channel is started, a background thread is used to poll the (@see org.activeio.SynchChannelServer} for accepted channel connections which are then delivered to the org.activeio.AcceptConsumer.

Version:
$Revision$

Field Summary
 
Fields inherited from interface org.activeio.Service
NO_WAIT_TIMEOUT, WAIT_FOREVER_TIMEOUT
 
Constructor Summary
SyncToAsyncChannelServer(SyncChannelServer syncServer)
           
SyncToAsyncChannelServer(SyncChannelServer syncServer, Executor executor)
           
 
Method Summary
static AsyncChannelServer adapt(ChannelServer channel)
           
static AsyncChannelServer adapt(ChannelServer channel, Executor executor)
           
 void dispose()
          This method should not throw any exceptions.
 URI getBindURI()
          The URI that was used when the channel was bound.
 URI getConnectURI()
          Once bound, the channel may be able to construct a URI that is more sutible for when a client needs to connect to the server.
 SyncChannelServer getSynchChannelServer()
           
 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()
           
 void setAcceptListener(AcceptListener acceptListener)
          Registers an AcceptListener which is notified of accepted channels.
 void start()
          Starts the channel.
 void stop(long timeout)
          Stops the channel.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SyncToAsyncChannelServer

public SyncToAsyncChannelServer(SyncChannelServer syncServer)

SyncToAsyncChannelServer

public SyncToAsyncChannelServer(SyncChannelServer syncServer,
                                Executor executor)
Method Detail

adapt

public static AsyncChannelServer adapt(ChannelServer channel)

adapt

public static AsyncChannelServer adapt(ChannelServer 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()
Specified by:
run in interface Runnable

setAcceptListener

public void setAcceptListener(AcceptListener acceptListener)
Description copied from interface: AsyncChannelServer
Registers an AcceptListener which is notified of accepted channels.

Specified by:
setAcceptListener in interface AsyncChannelServer
See Also:
AsyncChannelServer.setAcceptListener(org.activeio.AcceptListener)

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()

getBindURI

public URI getBindURI()
Description copied from interface: ChannelServer
The URI that was used when the channel was bound. This could be different than what is used by a client to connect to the ChannelServer. For example, the bind URI might be tcp://localhost:0 which means the channel should bind to an anonymous port.

Specified by:
getBindURI in interface ChannelServer
Returns:
The URI that was used when the channel was bound

getConnectURI

public URI getConnectURI()
Description copied from interface: ChannelServer
Once bound, the channel may be able to construct a URI that is more sutible for when a client needs to connect to the server. For examle the port of the URI may be updated to reflect the actual local port that the channel server is listening on.

Specified by:
getConnectURI in interface ChannelServer
Returns:
a URI that a client can use to connect to the server or null if the channel cannot construct the URI.

getSynchChannelServer

public SyncChannelServer getSynchChannelServer()

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

toString

public String toString()
Overrides:
toString in class Object


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