org.glassfish.tyrus.platform
Class RemoteEndpointWrapper<T>

java.lang.Object
  extended by org.glassfish.tyrus.platform.RemoteEndpointWrapper<T>
All Implemented Interfaces:
RemoteEndpoint<T>

public final class RemoteEndpointWrapper<T>
extends Object
implements RemoteEndpoint<T>

Wrapps the RemoteEndpoint and represents the other side of the websocket connection.

Author:
Danny Coward, Martin Matula (martin.matula at oracle.com), Stepan Kopriva (stepan.kopriva at oracle.com)

Method Summary
 void close(CloseReason cr)
           
 String getAddress()
          URI to which the remote originally connected.
static RemoteEndpointWrapper getRemoteWrapper(org.glassfish.tyrus.spi.SPIRemoteEndpoint socket, WebSocketEndpointImpl application, boolean serverEndpoint)
          Get the RemoteEndpoint wrapper.
 OutputStream getSendStream()
           
 Writer getSendWriter()
           
 Session getSession()
           
 boolean isConnected()
          The endpoint is connected.
 void sendBytes(byte[] data)
          Send a binary message, returning when all of the message has been transmitted.
 Future<SendResult> sendBytes(byte[] data, SendHandler completion)
          Initiates the asynchronous transmission of a binary message.
 void sendObject(T o)
          Sends a custom developer object, blocking until it has been transmitted.
 Future<SendResult> sendObject(T o, SendHandler handler)
          Initiates the transmission of a custom developer object.
 void sendPartialBytes(byte[] partialByte, boolean isLast)
          Send a binary message, blocking until all of the message has been transmitted.
 void sendPartialString(String fragment, boolean isLast)
           
 void sendPing(byte[] applicationData)
          Send a Ping message containing the given application data to the remote endpoint.
 void sendPong(byte[] applicationData)
          Allows the developer to send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session.
 void sendString(String data)
          Send a text message, blocking until all of the message has been transmitted.
 Future<SendResult> sendString(String text, SendHandler completion)
          Initiates the asynchronous transmission of a text message.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getRemoteWrapper

public static RemoteEndpointWrapper getRemoteWrapper(org.glassfish.tyrus.spi.SPIRemoteEndpoint socket,
                                                     WebSocketEndpointImpl application,
                                                     boolean serverEndpoint)
Get the RemoteEndpoint wrapper.

Parameters:
socket - socket corresponding to the required wrapper
application - web socket endpoint for which the wrapper represents the other side of the connection
serverEndpoint - server / client endpoint
Returns:
wrapper corresponding to socket

getAddress

public String getAddress()
URI to which the remote originally connected.

Returns:
URI

isConnected

public boolean isConnected()
The endpoint is connected.

Returns:
true iff the endpoint is connected, false otherwise.

sendString

public void sendString(String data)
                throws IOException
Description copied from interface: RemoteEndpoint
Send a text message, blocking until all of the message has been transmitted.

Specified by:
sendString in interface RemoteEndpoint<T>
Throws:
IOException

sendBytes

public void sendBytes(byte[] data)
               throws IOException
Description copied from interface: RemoteEndpoint
Send a binary message, returning when all of the message has been transmitted.

Specified by:
sendBytes in interface RemoteEndpoint<T>
Throws:
IOException

sendPartialString

public void sendPartialString(String fragment,
                              boolean isLast)
                       throws IOException
Specified by:
sendPartialString in interface RemoteEndpoint<T>
Throws:
IOException

sendPartialBytes

public void sendPartialBytes(byte[] partialByte,
                             boolean isLast)
                      throws IOException
Description copied from interface: RemoteEndpoint
Send a binary message, blocking until all of the message has been transmitted. The container reads the message from the caller of the API through the Iterable parameter until all the message has been sent.

Specified by:
sendPartialBytes in interface RemoteEndpoint<T>
Throws:
IOException

getSendStream

public OutputStream getSendStream()
                           throws IOException
Specified by:
getSendStream in interface RemoteEndpoint<T>
Throws:
IOException

getSendWriter

public Writer getSendWriter()
                     throws IOException
Specified by:
getSendWriter in interface RemoteEndpoint<T>
Throws:
IOException

sendObject

public void sendObject(T o)
                throws IOException,
                       EncodeException
Description copied from interface: RemoteEndpoint
Sends a custom developer object, blocking until it has been transmitted. Containers will by default be able to encode java primitive types, their object equivalents, and arrays or collections thereof. The developer will have provided an encoder for this object type in the endpoint configuration.

Specified by:
sendObject in interface RemoteEndpoint<T>
Throws:
IOException
EncodeException

sendString

public Future<SendResult> sendString(String text,
                                     SendHandler completion)
Description copied from interface: RemoteEndpoint
Initiates the asynchronous transmission of a text message. This method returns before the message is transmitted. Developers may provide a callback to be notified when the message has been transmitted, or may use the returned Future object to track progress of the transmission. Errors in transmission are given to the developer in the SendResult object in either case.

Specified by:
sendString in interface RemoteEndpoint<T>
Returns:

sendBytes

public Future<SendResult> sendBytes(byte[] data,
                                    SendHandler completion)
Description copied from interface: RemoteEndpoint
Initiates the asynchronous transmission of a binary message. This method returns before the message is transmitted. Developers may provide a callback to be notified when the message has been transmitted, or may use the returned Future object to track progress of the transmission. Errors in transmission are given to the developer in the SendResult object in either case.

Specified by:
sendBytes in interface RemoteEndpoint<T>
Returns:

sendObject

public Future<SendResult> sendObject(T o,
                                     SendHandler handler)
Description copied from interface: RemoteEndpoint
Initiates the transmission of a custom developer object. The developer will have provided an encoder for this object type in the endpoint configuration. Containers will by default be able to encode java primitive types, their object equivalents, and arrays or collections thereof. Progress can be tracked using the Future object, or the developer can wait for a provided callback object to be notified when transmission is complete.

Specified by:
sendObject in interface RemoteEndpoint<T>
Returns:

sendPing

public void sendPing(byte[] applicationData)
Description copied from interface: RemoteEndpoint
Send a Ping message containing the given application data to the remote endpoint. The corresponding Pong message may be picked up using the MessageHandler.Pong handler.

Specified by:
sendPing in interface RemoteEndpoint<T>

sendPong

public void sendPong(byte[] applicationData)
Description copied from interface: RemoteEndpoint
Allows the developer to send an unsolicited Pong message containing the given application data in order to serve as a unidirectional heartbeat for the session.

Specified by:
sendPong in interface RemoteEndpoint<T>

toString

public String toString()
Overrides:
toString in class Object

close

public void close(CloseReason cr)
           throws IOException
Throws:
IOException

getSession

public Session getSession()


Copyright © 2012. All Rights Reserved.