com.appenginefan.toolkit.common
Class WebConnectionClient

java.lang.Object
  extended by com.appenginefan.toolkit.common.WebConnectionClient

public class WebConnectionClient
extends Object

A client than can connect to a WebConnection. WebConnection objects can be used in App Engine applications to replace socket-based services. This class can be used as basis of communicating with such an end point on the web.


Nested Class Summary
static interface WebConnectionClient.Environment
          Abstraction of everything that depends on the runtime environment, like system clock, threading, or network.
static interface WebConnectionClient.Receiver
          Represents the receiving end of the communication
 
Constructor Summary
WebConnectionClient(URL url, int silencePeriodInMillis, int maxMessages)
          Constructor.
WebConnectionClient(WebConnectionClient.Environment env, int silencePeriodInMillis, int maxMessages)
          Constructor
 
Method Summary
 void close()
          Signals a running executing thread to cease its work.
 void open(WebConnectionClient.Receiver receiver)
          Starts a thread (through the executor) that connects to the server on a regular base
 void send(String message)
          Enqueues an object for transmission.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebConnectionClient

public WebConnectionClient(URL url,
                           int silencePeriodInMillis,
                           int maxMessages)
Constructor. Uses a simple environment implementation that opens the socket in a new thread and uses URL.openStream() to connect to the WebSocket

Parameters:
url - the URL to connect to
silencePeriodInMillis - the time the thread should wait between each http call
maxMessages - the maximum amount of messages that should be transported in one http request

WebConnectionClient

public WebConnectionClient(WebConnectionClient.Environment env,
                           int silencePeriodInMillis,
                           int maxMessages)
Constructor

Parameters:
env - the Environment that this client runs in
silencePeriodInMillis - the time the thread should wait between each http call
maxMessages - the maximum amount of messages that should be transported in one http request
Method Detail

close

public void close()
Signals a running executing thread to cease its work.


open

public void open(WebConnectionClient.Receiver receiver)
Starts a thread (through the executor) that connects to the server on a regular base


send

public void send(String message)
Enqueues an object for transmission.