com.sun.sgs.io
Interface Connector<T>

Type Parameters:
T - the address family encapsulated by this Connector's associated Endpoint
All Known Implementing Classes:
SocketConnector

public interface Connector<T>

Actively initiates a single connection to an Endpoint and asynchronously notifies the associated ConnectionListener when the connection completes.

A connection attempt may be terminated by a call to shutdown(), unless the connection has already finished connecting. Once a Connector has connected or shut down, it may not be reused.


Method Summary
 void connect(ConnectionListener listener)
          Actively initiates a connection to the associated Endpoint.
 Endpoint<T> 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.
 

Method Detail

connect

void connect(ConnectionListener listener)
             throws IOException
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.

Parameters:
listener - the listener for all IO events on the connection, including the result of the connection attempt
Throws:
IOException - if there was a problem initiating the connection
IllegalStateException - if the Connector has been shut down or has already attempted a connection

waitForConnect

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.

Parameters:
timeout - the wait timeout
Returns:
true if the connect attempt completed
Throws:
IllegalStateException - if no connect attempt is in progress
InterruptedException - if the waiting thread is interrupted
IOException - if the implementation determines that the connect attempt failed with an IOException

isConnected

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

Returns:
true if this connector is connected

getEndpoint

Endpoint<T> getEndpoint()
Returns the Endpoint for this Connector.

Returns:
the Endpoint for this Connector

shutdown

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

Throws:
IllegalStateException - if there is no connection attempt in progress

Project Darkstar, Version 0.9.9
2013-07-29 20:40:00

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