com.sun.grizzly
Class UDPConnectorHandler

java.lang.Object
  extended by com.sun.grizzly.AbstractConnectorHandler<UDPSelectorHandler,CallbackHandler>
      extended by com.sun.grizzly.UDPConnectorHandler
All Implemented Interfaces:
AsyncQueueReadable, AsyncQueueWritable, ConnectorHandler<UDPSelectorHandler,CallbackHandler>, Handler, Closeable

public class UDPConnectorHandler
extends AbstractConnectorHandler<UDPSelectorHandler,CallbackHandler>

Client side interface used to implement non blocking client operation. Implementation of this class must make sure the following methods are invoked in that order:


 (1) connect()
 (2) read() or write().
 

Author:
Jeanfrancois Arcand

Field Summary
protected  CountDownLatch isConnectedLatch
          IsConnected Latch related
 
Fields inherited from class com.sun.grizzly.AbstractConnectorHandler
callbackHandler, controller, inputStream, isConnected, protocol, selectorHandler, underlyingChannel
 
Constructor Summary
UDPConnectorHandler()
           
 
Method Summary
 void close()
          Close the underlying connection.
 void connect(SocketAddress remoteAddress, SocketAddress localAddress)
          Connect to hostname:port.
 void connect(SocketAddress remoteAddress, SocketAddress localAddress, CallbackHandler callbackHandler, UDPSelectorHandler selectorHandler)
          Connect to hostname:port.
 void finishConnect(SelectionKey key)
          Finish handling the OP_CONNECT interest ops.
 Controller.Protocol protocol()
          A token decribing the protocol supported by an implementation of this interface
 long read(ByteBuffer byteBuffer, boolean blocking)
          Read bytes.
 SocketAddress receive(ByteBuffer byteBuffer)
          Receive bytes.
 long send(ByteBuffer byteBuffer, SocketAddress socketAddress)
          Receive bytes.
 
Methods inherited from class com.sun.grizzly.AbstractConnectorHandler
connect, connect, connect, connect, getCallbackHandler, getController, getSelectorHandler, getUnderlyingChannel, isConnected, protocol, readFromAsyncQueue, readFromAsyncQueue, readFromAsyncQueue, setCallbackHandler, setController, setSelectorHandler, setUnderlyingChannel, write, writeToAsyncQueue, writeToAsyncQueue, writeToAsyncQueue, writeToAsyncQueue, writeToAsyncQueue, writeToAsyncQueue, writeToAsyncQueue, writeToAsyncQueue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isConnectedLatch

protected volatile CountDownLatch isConnectedLatch
IsConnected Latch related

Constructor Detail

UDPConnectorHandler

public UDPConnectorHandler()
Method Detail

connect

public void connect(SocketAddress remoteAddress,
                    SocketAddress localAddress,
                    CallbackHandler callbackHandler,
                    UDPSelectorHandler selectorHandler)
             throws IOException
Connect to hostname:port. When an aysnchronous event happens (e.g OP_READ or OP_WRITE), the Controller will invoke the CallBackHandler.

Parameters:
remoteAddress - remote address to connect
localAddress - local address to bin
callbackHandler - the handler invoked by its associated SelectorHandler when a non blocking operation is ready to be handled. When null, all read and write operation will be delegated to the default ProtocolChain and its list of ProtocolFilter . When null, this ConnectorHandler will create an instance of DefaultCallbackHandler.
selectorHandler - an instance of SelectorHandler.
Throws:
IOException

connect

public void connect(SocketAddress remoteAddress,
                    SocketAddress localAddress)
             throws IOException
Connect to hostname:port. Internally an instance of Controller and its default SelectorHandler will be created everytime this method is called. This method should be used only and only if no external Controller has been initialized.

Parameters:
remoteAddress - remote address to connect
localAddress - local address to bin
Throws:
IOException

read

public long read(ByteBuffer byteBuffer,
                 boolean blocking)
          throws IOException
Read bytes. If blocking is set to true, a pool of temporary Selector will be used to read bytes.

Specified by:
read in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>
Overrides:
read in class AbstractConnectorHandler<UDPSelectorHandler,CallbackHandler>
Parameters:
byteBuffer - The byteBuffer to store bytes.
blocking - true if a a pool of temporary Selector is required to handle a blocking read.
Returns:
number of bytes read
Throws:
IOException

send

public long send(ByteBuffer byteBuffer,
                 SocketAddress socketAddress)
          throws IOException
Receive bytes.

Parameters:
byteBuffer - The byteBuffer to store bytes.
socketAddress -
Returns:
number bytes sent
Throws:
IOException

receive

public SocketAddress receive(ByteBuffer byteBuffer)
                      throws IOException
Receive bytes.

Parameters:
byteBuffer - The byteBuffer to store bytes.
Returns:
SocketAddress
Throws:
IOException

close

public void close()
           throws IOException
Close the underlying connection.

Throws:
IOException

finishConnect

public void finishConnect(SelectionKey key)
                   throws IOException
Finish handling the OP_CONNECT interest ops.

Parameters:
key - SelectionKey
Throws:
IOException

protocol

public Controller.Protocol protocol()
A token decribing the protocol supported by an implementation of this interface

Specified by:
protocol in interface ConnectorHandler<UDPSelectorHandler,CallbackHandler>
Overrides:
protocol in class AbstractConnectorHandler<UDPSelectorHandler,CallbackHandler>
Returns:
the ConnectorHandler Controller.Protocol.


Copyright © 2012 Oracle Corporation. All Rights Reserved.