com.sun.sgs.impl.io
Class SocketConnector

java.lang.Object
  extended by com.sun.sgs.impl.io.SocketConnector
All Implemented Interfaces:
Connector<SocketAddress>

 class SocketConnector
extends Object
implements Connector<SocketAddress>

This is a socket-based implementation of an Connector using the Apache MINA framework for the underlying transport. It uses an IoConnector to initiate connections on remote hosts.

Its constructor is package-private, so use Endpoint.createConnector() to create an instance. This implementation is thread-safe.


Nested Class Summary
(package private) static class SocketConnector.ConnectorConnListner
          Internal adaptor class to handle events from the connector itself.
 
Constructor Summary
SocketConnector(SocketEndpoint endpoint, org.apache.mina.common.IoConnector connector)
          Constructs a SocketConnector using the given IoConnector for the underlying transport.
 
Method Summary
 void connect(ConnectionListener listener)
          Actively initiates a connection to the associated Endpoint.
 SocketEndpoint getEndpoint()
          Returns the Endpoint for this Connector.
 boolean isConnected()
          Returns true if this connector is connected, otherwise returns false.
 void shutdown()
          Shuts down this Connector.
 boolean waitForConnect(long timeout)
          Waits for the connect attempt, initiated by invoking the connect method, to complete with the given timeout (specified in milliseconds), and returns true if the connect attempt completed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SocketConnector

SocketConnector(SocketEndpoint endpoint,
                org.apache.mina.common.IoConnector connector)
Constructs a SocketConnector using the given IoConnector for the underlying transport. This constructor is only visible to the package, so use one of the ConnectorFactory.createConnector methods to create a new instance.

Parameters:
endpoint - the remote address to which to connect
connector - the MINA IoConnector to use for establishing the connection
Method Detail

connect

public void connect(ConnectionListener listener)
Actively initiates a connection to the associated Endpoint. This call is non-blocking. connected will be called asynchronously on the given listener upon successful connection, or disconnected if it fails.

This implementation ensures that only complete messages are delivered on the connection that it connects.

Specified by:
connect in interface Connector<SocketAddress>
Parameters:
listener - the listener for all IO events on the connection, including the result of the connection attempt

isConnected

public boolean isConnected()
Returns true if this connector is connected, otherwise returns false.

Specified by:
isConnected in interface Connector<SocketAddress>
Returns:
true if this connector is connected

waitForConnect

public boolean waitForConnect(long timeout)
                       throws IOException,
                              InterruptedException
Waits for the connect attempt, initiated by invoking the connect method, to complete with the given timeout (specified in milliseconds), and returns true if the connect attempt completed.

Use the isConnected method on this instance to determine if the connect attempt was successful.

Specified by:
waitForConnect in interface Connector<SocketAddress>
Parameters:
timeout - the wait timeout
Returns:
true if the connect attempt completed
Throws:
IOException - if the implementation determines that the connect attempt failed with an IOException
InterruptedException - if the waiting thread is interrupted

shutdown

public void shutdown()
Shuts down this Connector. The pending connection attempt will be cancelled.

Specified by:
shutdown in interface Connector<SocketAddress>

getEndpoint

public SocketEndpoint getEndpoint()
Returns the Endpoint for this Connector.

Specified by:
getEndpoint in interface Connector<SocketAddress>
Returns:
the Endpoint for this Connector

Project Darkstar, Version 0.9.10.1
2013-07-29 21:03:34

Copyright © 2007-2013 Sun Microsystems, Inc. All rights reserved