org.atmosphere.gwt.client
Class AtmosphereClient

java.lang.Object
  extended by org.atmosphere.gwt.client.AtmosphereClient
All Implemented Interfaces:
UserInterface

public class AtmosphereClient
extends Object
implements UserInterface

This class is the client interface. It will connect to the given url and notify the given AtmosphereListener of events. To receive GWT serialized objects supply a AtmosphereGWTSerializer class with the appropriate annotations.

The sequence of events are as follows: The application calls start(). AtmosphereListener.onConnected(int,int) gets called when the connection is established. AtmosphereListener.onMessage(List) gets called when messages are received from the server. AtmosphereListener.onDisconnected() gets called when the connection is disconnected AtmosphereListener.onError(Throwable, boolean) gets called if there is an error with the connection. For more details about the possible events see AtmosphereListener.

The client will attempt to maintain a connection when disconnections occur until the application calls stop().

The server sends heart beat messages to ensure the connection is maintained and that disconnections can be detected in all cases.

Author:
Richard Zschech, Pierre Havelaar

Constructor Summary
AtmosphereClient(String url, AtmosphereGWTSerializer serializer, AtmosphereListener listener)
           
AtmosphereClient(String url, AtmosphereGWTSerializer serializer, AtmosphereListener listener, boolean webSocketsEnabled)
           
AtmosphereClient(String url, AtmosphereListener listener)
           
 
Method Summary
 void broadcast(List<?> messages)
          Send a message back to the server on this connection and use our broadcaster to send this message to other clients connected to the same broadcaster.
 void broadcast(Object message)
          Send a message back to the server on this connection and use our broadcaster to send this message to other clients connected to the same broadcaster.
 int getConnectionID()
          The unique connection ID
 int getConnectionTimeout()
           
 AtmosphereListener getListener()
           
 int getReconnectionCount()
           
 int getReconnectionTimeout()
           
 AtmosphereGWTSerializer getSerializer()
           
 String getUrl()
           
 boolean isRunning()
          This is true between start() and stop() If the connection is failing and the reconnectionCount has been reached then stop is also called.
 boolean isWebSocketsEnabled()
           
 void post(List<?> messages)
          push messages back to the server on this connection.
 void post(List<?> messages, com.google.gwt.user.client.rpc.AsyncCallback<Void> callback)
          push messages back to the server on this connection.
 void post(Object message)
          push message back to the server on this connection.
 void post(Object message, com.google.gwt.user.client.rpc.AsyncCallback<Void> callback)
          push message back to the server on this connection.
 void setConnectionTimeout(int connectionTimeout)
          This is the amount of time the client waits until a connection is established.
 void setReconnectionCount(int reconnectionCount)
          The amount of times to try to reconnect if a connection has failed.
 void setReconnectionTimeout(int reconnectionTimeout)
          This establishes the wait time before a new connection is started.
 void setUrl(String url)
           
 void setWebSocketsEnabled(boolean webSocketsEnabled)
           
static com.google.gwt.core.client.JsArrayString split(String string, String separator)
           
 void start()
          This will startup the connection to the server and the client will try to maintain the connection until is called.
 void stop()
          End the connection.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AtmosphereClient

public AtmosphereClient(String url,
                        AtmosphereListener listener)

AtmosphereClient

public AtmosphereClient(String url,
                        AtmosphereGWTSerializer serializer,
                        AtmosphereListener listener)

AtmosphereClient

public AtmosphereClient(String url,
                        AtmosphereGWTSerializer serializer,
                        AtmosphereListener listener,
                        boolean webSocketsEnabled)
Method Detail

isWebSocketsEnabled

public boolean isWebSocketsEnabled()

setWebSocketsEnabled

public void setWebSocketsEnabled(boolean webSocketsEnabled)

getUrl

public String getUrl()

setUrl

public void setUrl(String url)

getSerializer

public AtmosphereGWTSerializer getSerializer()

getListener

public AtmosphereListener getListener()

setConnectionTimeout

public void setConnectionTimeout(int connectionTimeout)
This is the amount of time the client waits until a connection is established. If the connection is not established within this time the connection is assumed to be dead.

Parameters:
connectionTimeout - the timeout in milliseconds defaults to 10000

getConnectionTimeout

public int getConnectionTimeout()

setReconnectionTimeout

public void setReconnectionTimeout(int reconnectionTimeout)
This establishes the wait time before a new connection is started. When a connection has dropped this timeout is used to setup a wait time before a new connection is started. The algorithm will start with the given reconnectionTimeout and will multiply the timeout with the number of failed attempts to reconnect. This will prevent for instance a server that is rebooted from being flooded with connections.

Parameters:
reconnectionTimeout -
See Also:
setReconnectionCount(int)

getReconnectionTimeout

public int getReconnectionTimeout()

getReconnectionCount

public int getReconnectionCount()

setReconnectionCount

public void setReconnectionCount(int reconnectionCount)
The amount of times to try to reconnect if a connection has failed. If the count has been reached then client is stopped stop() and isRunning() will return false.

Parameters:
reconnectionCount - Set to -1 to keep trying (default -1)

isRunning

public boolean isRunning()
This is true between start() and stop() If the connection is failing and the reconnectionCount has been reached then stop is also called.

Returns:

getConnectionID

public int getConnectionID()
The unique connection ID

Returns:

post

public void post(Object message)
push message back to the server on this connection. On the serverside the message can be received by the AtmosphereGwtHandler#doPost

Specified by:
post in interface UserInterface

post

public void post(Object message,
                 com.google.gwt.user.client.rpc.AsyncCallback<Void> callback)
push message back to the server on this connection. On the serverside the message can be received by the AtmosphereGwtHandler#doPost

Specified by:
post in interface UserInterface

post

public void post(List<?> messages)
push messages back to the server on this connection. On the serverside the message can be received by the AtmosphereGwtHandler#doPost

Specified by:
post in interface UserInterface

post

public void post(List<?> messages,
                 com.google.gwt.user.client.rpc.AsyncCallback<Void> callback)
push messages back to the server on this connection. On the serverside the message can be received by the AtmosphereGwtHandler#doPost

Specified by:
post in interface UserInterface

broadcast

public void broadcast(Object message)
Send a message back to the server on this connection and use our broadcaster to send this message to other clients connected to the same broadcaster.

Specified by:
broadcast in interface UserInterface

broadcast

public void broadcast(List<?> messages)
Send a message back to the server on this connection and use our broadcaster to send this message to other clients connected to the same broadcaster.

Specified by:
broadcast in interface UserInterface

start

public void start()
This will startup the connection to the server and the client will try to maintain the connection until is called.

Specified by:
start in interface UserInterface

stop

public void stop()
End the connection.

Specified by:
stop in interface UserInterface

split

public static com.google.gwt.core.client.JsArrayString split(String string,
                                                             String separator)


Copyright © 2012. All Rights Reserved.