org.atmosphere.wasync.impl
Class DefaultSocket

java.lang.Object
  extended by org.atmosphere.wasync.impl.DefaultSocket
All Implemented Interfaces:
Socket
Direct Known Subclasses:
AtmosphereSocket, SerializedSocket

public class DefaultSocket
extends java.lang.Object
implements Socket

Default implementation of the Socket

Author:
Jeanfrancois Arcand

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.atmosphere.wasync.Socket
Socket.STATUS
 
Field Summary
protected  java.util.List<FunctionWrapper> functions
           
protected  Options options
           
protected  Request request
           
protected  SocketRuntime socketRuntime
           
protected  Transport transportInUse
           
 
Constructor Summary
DefaultSocket(Options options)
           
 
Method Summary
protected  void addFunction(long timeout, java.util.concurrent.TimeUnit tu)
           
 void close()
          Close this Socket, asynchronously.
protected  void closeRuntime(boolean async)
           
protected  Socket connect(com.ning.http.client.RequestBuilder r, java.util.List<Transport> transports, long timeout, java.util.concurrent.TimeUnit tu)
           
 SocketRuntime createRuntime(DefaultFuture future, Options options, java.util.List<FunctionWrapper> functions)
           
 Future fire(java.lang.Object data)
          Send data to the remote Server.
protected  java.util.List<Transport> getTransport(com.ning.http.client.RequestBuilder r, Request request)
           
protected  SocketRuntime internalSocket()
           
 Socket on(Event event, Function<?> function)
          Associate a Function with an Event.
 Socket on(Function<? extends java.lang.Object> function)
          Associate a Function with the Socket.
 Socket on(java.lang.String functionName, Function<? extends java.lang.Object> function)
          Associate a Function with the Socket.
 Socket open(Request request)
          Connect to the remote Server using the Request's information.
 Socket open(Request request, long timeout, java.util.concurrent.TimeUnit tu)
          Connect to the remote Server using the Request's information, will timeout if the connection failed to open within a certain time.
protected  Request request()
           
 Socket.STATUS status()
          Return the Socket.STATUS of this Socket.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

request

protected Request request

socketRuntime

protected SocketRuntime socketRuntime

functions

protected final java.util.List<FunctionWrapper> functions

transportInUse

protected Transport transportInUse

options

protected final Options options
Constructor Detail

DefaultSocket

public DefaultSocket(Options options)
Method Detail

fire

public Future fire(java.lang.Object data)
            throws java.io.IOException
Send data to the remote Server. The object will first be delivered to the set of Encoder, and then send to the server. The server's response will be delivered to the set of defined Function using the opened Transport, e.g for Request.TRANSPORT.WEBSOCKET, the same connection will be re-used and, for others transports, the suspended connection.

Specified by:
fire in interface Socket
Parameters:
data - object to send
Returns:
a Future
Throws:
java.io.IOException

on

public Socket on(Function<? extends java.lang.Object> function)
Associate a Function with the Socket. When a response is received, the library will try to associated the decoded message (decoded by Decoder) to the defined type of the Function

Specified by:
on in interface Socket
Parameters:
function - a Function
Returns:
this

on

public Socket on(java.lang.String functionName,
                 Function<? extends java.lang.Object> function)
Associate a Function with the Socket. When a response is received, the library will try to associated the decoded message (decoded by Decoder) to the defined type of the Function. The default messages are defined by Event but handling of custom message can be done using a FunctionResolver

Specified by:
on in interface Socket
function - a Function
Returns:
this

on

public Socket on(Event event,
                 Function<?> function)
Description copied from interface: Socket
Associate a Function with an Event. When the event happen the library will try to associated the decoded event (decoded by Decoder) to the defined type of the Function. The default event are defined by Event but handling of custom event can be done using a FunctionResolver

Specified by:
on in interface Socket
function - a Function
Returns:
this

open

public Socket open(Request request)
            throws java.io.IOException
Description copied from interface: Socket
Connect to the remote Server using the Request's information.

Specified by:
open in interface Socket
Parameters:
request - a Request
Returns:
this
Throws:
java.io.IOException - in case the connect fails or a network failure occurs.

open

public Socket open(Request request,
                   long timeout,
                   java.util.concurrent.TimeUnit tu)
            throws java.io.IOException
Connect to the remote Server using the Request's information, will timeout if the connection failed to open within a certain time.

Specified by:
open in interface Socket
Parameters:
request - a Request
timeout - the maximum time to wait
tu - the time unit of the timeout argument
Returns:
this
Throws:
java.io.IOException - in case the connect fails or a network failure occurs.

connect

protected Socket connect(com.ning.http.client.RequestBuilder r,
                         java.util.List<Transport> transports,
                         long timeout,
                         java.util.concurrent.TimeUnit tu)
                  throws java.io.IOException
Throws:
java.io.IOException

addFunction

protected void addFunction(long timeout,
                           java.util.concurrent.TimeUnit tu)

close

public void close()
Close this Socket, asynchronously.

Specified by:
close in interface Socket

closeRuntime

protected void closeRuntime(boolean async)

status

public Socket.STATUS status()
Description copied from interface: Socket
Return the Socket.STATUS of this Socket.

Specified by:
status in interface Socket

internalSocket

protected SocketRuntime internalSocket()

getTransport

protected java.util.List<Transport> getTransport(com.ning.http.client.RequestBuilder r,
                                                 Request request)
                                          throws java.io.IOException
Throws:
java.io.IOException

request

protected Request request()

createRuntime

public SocketRuntime createRuntime(DefaultFuture future,
                                   Options options,
                                   java.util.List<FunctionWrapper> functions)


Copyright © 2014. All Rights Reserved.