org.atmosphere.wasync
Class OptionsBuilder<U extends Options,T extends OptionsBuilder<U,T>>

java.lang.Object
  extended by org.atmosphere.wasync.OptionsBuilder<U,T>
Type Parameters:
T -
Direct Known Subclasses:
DefaultOptionsBuilder, SerializedOptionsBuilder

public abstract class OptionsBuilder<U extends Options,T extends OptionsBuilder<U,T>>
extends java.lang.Object

Base class for building Options

Author:
Jeanfrancois Arcand

Field Summary
protected  java.lang.Class<T> derived
           
 
Constructor Summary
protected OptionsBuilder(java.lang.Class<T> derived)
           
 
Method Summary
 boolean binary()
          Return true is server's response binary is supported.
 T binary(boolean binary)
          Set to true in order to received byte data from the server.
abstract  U build()
          Build an Options
 T pauseBeforeReconnectInSeconds(int reconnectInSecond)
          The time in second, before the reconnection occurs.
 boolean reconnect()
          Reconnect after a network failure or when the server close the connection.
 T reconnect(boolean reconnect)
          Automatically reconnect in case the connection get closed.
 int reconnectAttempts()
          Maximum reconnection attempts that will be executed if the connection is lost.
 T reconnectAttempts(int reconnectAttempts)
          Maximum reconnection attempts that will be executed if the connection is lost.
 int reconnectInSeconds()
          The delay, in second, before reconnecting.
 T registerTransport(Transport transport)
          Register a new Transport implementation.
 int requestTimeoutInSeconds()
          The time, in seconds to wait before closing the connection.
 T requestTimeoutInSeconds(int requestTimeout)
          The time, in seconds, the connection will stay open when waiting for new messages.
 com.ning.http.client.AsyncHttpClient runtime()
          The AsyncHttpClient used to communicate with server.
 T runtime(com.ning.http.client.AsyncHttpClient client)
          Allow an application that want to share AsyncHttpClient or configure it before it gets used by the library.
 T runtime(com.ning.http.client.AsyncHttpClient client, boolean runtimeShared)
          Allow an application that want to share AsyncHttpClient or configure it before it gets used by the library.
 boolean runtimeShared()
          Return true is the AsyncHttpClient is shared between Socket.
 T runtimeShared(boolean runtimeShared)
          Set to true if your AsyncHttpClient is shared between clients.
 Transport transport()
          The used Transport
 long waitBeforeUnlocking()
          The delay before considering the http connection has been fully processed by the server.
 T waitBeforeUnlocking(long waitBeforeUnlocking)
          For streaming and long-polling, the server may not send the headers so the client never knows if the connection succeeded or not.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

derived

protected final java.lang.Class<T extends OptionsBuilder<U,T>> derived
Constructor Detail

OptionsBuilder

protected OptionsBuilder(java.lang.Class<T> derived)
Method Detail

requestTimeoutInSeconds

public T requestTimeoutInSeconds(int requestTimeout)
The time, in seconds, the connection will stay open when waiting for new messages. This can be seen as the idle time.

Returns:
this

registerTransport

public T registerTransport(Transport transport)
Register a new Transport implementation. Register a transport only if you are planning to use a different transport than the supported one.

Parameters:
transport - Transport
Returns:
this

reconnect

public T reconnect(boolean reconnect)
Automatically reconnect in case the connection get closed. Default is true

Parameters:
reconnect - reconnect in case the connection get closed. Default is true
Returns:
this

pauseBeforeReconnectInSeconds

public T pauseBeforeReconnectInSeconds(int reconnectInSecond)
The time in second, before the reconnection occurs. Default is 1 second

Parameters:
reconnectInSecond - time in second, before the reconnection occurs. Default is 1 second
Returns:
this

reconnectAttempts

public T reconnectAttempts(int reconnectAttempts)
Maximum reconnection attempts that will be executed if the connection is lost. Must be used in conjunction with reconnectInSeconds()


waitBeforeUnlocking

public T waitBeforeUnlocking(long waitBeforeUnlocking)
For streaming and long-polling, the server may not send the headers so the client never knows if the connection succeeded or not. By default the library will wait for 2500 milliseconds before considering the connection established.

Parameters:
waitBeforeUnlocking - the time in millisecond
Returns:
this

runtimeShared

public T runtimeShared(boolean runtimeShared)
Set to true if your AsyncHttpClient is shared between clients. by the library.

Parameters:
runtimeShared - true if your AsyncHttpClient is shared between clients.
Returns:
this;

runtime

public T runtime(com.ning.http.client.AsyncHttpClient client)
Allow an application that want to share AsyncHttpClient or configure it before it gets used by the library. Application must call AsyncHttpClient.close() at the end of their execution as the library won't close it since shared.

Parameters:
client -
Returns:
this;

runtime

public T runtime(com.ning.http.client.AsyncHttpClient client,
                 boolean runtimeShared)
Allow an application that want to share AsyncHttpClient or configure it before it gets used by the library.

Parameters:
client -
runtimeShared - to true if the runtime is shared between clients. If shared, the asyncHttpClient.close() must be invoked by the application itself.
Returns:
this;

build

public abstract U build()
Build an Options

Returns:
Options

transport

public Transport transport()
The used Transport

Returns:
Transport

reconnect

public boolean reconnect()
Reconnect after a network failure or when the server close the connection.

Returns:
reconnect

reconnectInSeconds

public int reconnectInSeconds()
The delay, in second, before reconnecting.

Returns:
The delay, in second, before reconnecting.

reconnectAttempts

public int reconnectAttempts()
Maximum reconnection attempts that will be executed if the connection is lost. Must be used in conjunction with reconnectInSeconds()

Returns:
the number of maximum reconnection attempts

waitBeforeUnlocking

public long waitBeforeUnlocking()
The delay before considering the http connection has been fully processed by the server. By default, the library will wait 2 seconds before allowing the Socket.fire(Object) to send message. Server side framework that aren't sending any data when suspending a connection may not be ready to fullfil request, hence some data may be lost. Framework like Atmosphere, Socket.io, Cometd do send some "handshake data" allow the fire operation to be available fast without loosing ant data.


runtime

public com.ning.http.client.AsyncHttpClient runtime()
The AsyncHttpClient used to communicate with server.

Returns:
AsyncHttpClient used to communicate with server.

runtimeShared

public boolean runtimeShared()
Return true is the AsyncHttpClient is shared between Socket. Default is false. You need to invoke runtime(com.ning.http.client.AsyncHttpClient) to make it shared.

Returns:
true is the AsyncHttpClient

requestTimeoutInSeconds

public int requestTimeoutInSeconds()
The time, in seconds to wait before closing the connection.

Returns:
The time, in seconds to wait before closing the connection.

binary

public T binary(boolean binary)
Set to true in order to received byte data from the server. By default, binary aren't supported and response's server are considered as String.

Parameters:
binary - true to enabled
Returns:
this;

binary

public boolean binary()
Return true is server's response binary is supported. Default is false

Returns:
true is server's response binary is supported. Default is false


Copyright © 2014. All Rights Reserved.