Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 Jeanfrancois Arcand
   *
   * Licensed under the Apache License, Version 2.0 (the "License"); you may not
   * use this file except in compliance with the License. You may obtain a copy of
   * the License at
   *
   * http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  * License for the specific language governing permissions and limitations under
  * the License.
  */
 package org.atmosphere.wasync;
 
Base class for building Options

Parameters:
<T>
Author(s):
Jeanfrancois Arcand
 
 public abstract class OptionsBuilder<U extends Options, T extends OptionsBuilder<U,T>> {
 
     private Transport transport;
     private boolean reconnect = true;
     private int reconnectInSecond = 0;
     private long waitBeforeUnlocking = 5000;
     private AsyncHttpClient client;
     private boolean runtimeShared = false;
     private int requestTimeout = -1;
     protected final Class<T> derived;
 
     protected OptionsBuilder(Class<T> derived) {
         this. = derived;
     }

    
The time, in seconds, the connection will stay open when waiting for new messages. This can be seen as the idle time.

Returns:
this
 
     public T requestTimeoutInSeconds(int requestTimeout) {
         this. = requestTimeout;
         return .cast(this);
     }

    
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
 
     public T registerTransport(Transport transport) {
         this. = transport;
         return .cast(this);
     }

    
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
 
     public T reconnect(boolean reconnect) {
         this. = reconnect;
         return .cast(this);
     }

    
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
 
     public T pauseBeforeReconnectInSeconds(int reconnectInSecond) {
         this. = reconnectInSecond;
         return .cast(this);
     }

    
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
 
     public T waitBeforeUnlocking(long waitBeforeUnlocking) {
         this. = waitBeforeUnlocking;
         return .cast(this);
     }

    
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;
    public T runtimeShared(boolean runtimeShared) {
        this. = runtimeShared;
        return .cast(this);
    }

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

Parameters:
client
Returns:
this;
    public T runtime(AsyncHttpClient client) {
        return runtime(clienttrue);
    }

    
Allow an application that want to share com.ning.http.client.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;
    public T runtime(AsyncHttpClient clientboolean runtimeShared) {
        this. = client;
        this. = runtimeShared;
        return .cast(this);
    }

    
Build an Options

Returns:
Options
    public abstract U build();

    
The used Transport

Returns:
Transport
    public Transport transport() {
        return ;
    }
    
Reconnect after a network failure or when the server close the connection.

Returns:
reconnect
    public boolean reconnect(){
        return ;
    }
    
The delay, in second, before reconnecting.

Returns:
The delay, in second, before reconnecting.
    public int reconnectInSeconds(){
        return ;
    }
    
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(java.lang.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.
    public long waitBeforeUnlocking() {
        return ;
    }
    
The com.ning.http.client.AsyncHttpClient used to communicate with server.

Returns:
com.ning.http.client.AsyncHttpClient used to communicate with server.
    public AsyncHttpClient runtime(){
        return ;
    }
    
Return true is the com.ning.http.client.AsyncHttpClient is shared between Socket. Default is false. You need to invoke runtime(com.ning.http.client.AsyncHttpClient) to make it shared.

    public boolean runtimeShared(){
        return ;
    }
    
The time, in seconds to wait before closing the connection.

Returns:
The time, in seconds to wait before closing the connection.
    public int requestTimeoutInSeconds() {
        return ;
    }
New to GrepCode? Check out our FAQ X