com.crankuptheamps.client
Class HAClient

java.lang.Object
  extended by com.crankuptheamps.client.Client
      extended by com.crankuptheamps.client.HAClient
All Implemented Interfaces:
Closeable

public class HAClient
extends Client

A highly-available AMPS Client object that automatically reconnects and re-subscribes to AMPS instances upon disconnect.


Nested Class Summary
static class HAClient.HADisconnectHandler
           
 
Nested classes/interfaces inherited from class com.crankuptheamps.client.Client
Client.Bookmarks, Client.Version
 
Field Summary
 
Fields inherited from class com.crankuptheamps.client.Client
exceptionListener, MIN_MULTI_BOOKMARK_VERSION, MIN_PERSISTED_BOOKMARK_VERSION
 
Constructor Summary
HAClient(String name)
          Constructs a new HAClient.
 
Method Summary
 void connect(String uri)
          Connects to the AMPS instance through the provided URI.
 void connectAndLogon()
          Connects to the next server chosen for us by our ServerChooser.
static HAClient createFileBacked(String name, String publishLog, int initialPublishCapacity, String subscribeLog)
          Creates a new highly available client backed by disk.
static HAClient createFileBacked(String name, String publishLog, String subscribeLog)
          Creates a new highly available client backed by disk.
static HAClient createMemoryBacked(String name)
          Creates a new memory-backed highly-available client.
 void disconnect()
          Disconnect from the AMPS server.
 ConnectionInfo getConnectionInfo()
          Assembles a new ConnectionInfo with the state of this client and associated classes.
 int getReconnectDelay()
          Returns the time delay between reconnect events.
 ServerChooser getServerChooser()
          Returns the current ServerChooser.
 int getTimeout()
          Returns the timeout used for logging on and resubscribing, once a connection is re-established.
 void setHeartbeat(int intervalSeconds_, int timeoutSeconds_)
          Requests a server heartbeat, and configures the client to close the connection if a heartbeat (or other activity) is not seen on the connection.
 void setReconnectDelay(int reconnectInterval)
          Sets the time delay between reconnect events.
 void setServerChooser(ServerChooser serverChooser_)
          Sets a ServerChooser for self.
 void setTimeout(int timeout_)
          Sets the timeout used for logging on and resubscribing, once a connection is re-established.
 
Methods inherited from class com.crankuptheamps.client.Client
addConnectionStateListener, allocateMessage, bookmarkDeltaSubscribe, bookmarkSubscribe, broadcastConnectionStateChanged, close, deltaPublish, deltaPublish, deltaPublish, deltaPublish, deltaSubscribe, deltaSubscribe, deltaSubscribe, deltaSubscribe, execute, executeAsync, flush, flush, getBookmarkStore, getDisconnectHandler, getName, getPublishStore, getServerVersion, getSubscriptionManager, getTransport, getURI, getVersion, getVersionAsInt, logon, logon, logon, publish, publish, publish, publish, publishFlush, publishFlush, removeConnectionStateListener, send, send, setBookmarkStore, setDisconnectHandler, setDuplicateMessageHandler, setExceptionListener, setFailedWriteHandler, setHeartbeat, setLastChanceMessageHandler, setPublishStore, setSubscriptionManager, setUnhandledMessageHandler, sow, sow, sow, sow, sow, sow, sow, sowAndDeltaSubscribe, sowAndDeltaSubscribe, sowAndDeltaSubscribe, sowAndDeltaSubscribe, sowAndDeltaSubscribe, sowAndDeltaSubscribe, sowAndSubscribe, sowAndSubscribe, sowAndSubscribe, sowAndSubscribe, sowAndSubscribe, sowAndSubscribe, sowAndSubscribe, sowAndSubscribe, sowDelete, sowDelete, sowDelete, sowDeleteByData, sowDeleteByKeys, startTimer, stopTimer, subscribe, subscribe, subscribe, subscribe, subscribe, subscribe, unsubscribe, unsubscribe
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HAClient

public HAClient(String name)
Constructs a new HAClient.

Parameters:
name - The client name, passed to the server to uniquely identify this client across sessions.
Method Detail

getReconnectDelay

public int getReconnectDelay()
Returns the time delay between reconnect events.

Returns:
The time waited between reconnect events, in milliseconds.

setReconnectDelay

public void setReconnectDelay(int reconnectInterval)
Sets the time delay between reconnect events.

Parameters:
reconnectInterval - The time waited between reconnect events, in milliseconds.

setTimeout

public void setTimeout(int timeout_)
Sets the timeout used for logging on and resubscribing, once a connection is re-established.

Parameters:
timeout_ - The timeout value, in milliseconds.

getTimeout

public int getTimeout()
Returns the timeout used for logging on and resubscribing, once a connection is re-established.

Returns:
The timeout value in millseconds.

setHeartbeat

public void setHeartbeat(int intervalSeconds_,
                         int timeoutSeconds_)
                  throws DisconnectedException
Description copied from class: Client
Requests a server heartbeat, and configures the client to close the connection if a heartbeat (or other activity) is not seen on the connection.

Overrides:
setHeartbeat in class Client
Parameters:
intervalSeconds_ - The time (seconds) between beats from the server.
timeoutSeconds_ - The time (seconds) to allow silence on the connection before assuming it is dead.
Throws:
DisconnectedException - The client became disconnected while attempting to send the heartbeat request.

getServerChooser

public ServerChooser getServerChooser()
Returns the current ServerChooser.

Returns:
The current ServerChooser.

setServerChooser

public void setServerChooser(ServerChooser serverChooser_)
Sets a ServerChooser for self.

Parameters:
serverChooser_ - The ServerChooser that will be used by self to reconnect.

createMemoryBacked

public static HAClient createMemoryBacked(String name)
                                   throws StoreException
Creates a new memory-backed highly-available client. This client will automatically reconnect and re-subscribe, and uses memory to ensure messages are not lost and duplicates are processed appropriately.

Parameters:
name - The client name, passed to the server to uniquely identify this client across sessions.
Returns:
A new memory-backed HAClient instance.
Throws:
StoreException

createFileBacked

public static HAClient createFileBacked(String name,
                                        String publishLog,
                                        int initialPublishCapacity,
                                        String subscribeLog)
                                 throws IOException,
                                        StoreException
Creates a new highly available client backed by disk. This client will automatically reconnect and re-subscribe, and uses disk to ensure messages are not lost and duplicates are processed appropriately.

Parameters:
name - The client name, passed to the server to uniquely identify this client across sessions.
publishLog - The path to a file used to store outgoing messages. This file will be created if it does not exist.
initialPublishCapacity - The initial size (in 2k blocks) of the publish store. Choosing an optimal value of initialPublishCapacity can prevent costly resizes, when servers or networks slow down.
subscribeLog - The path to a file used to log incoming message bookmarks. This file will be created if it does not exist.
Returns:
A new HAClient instance.
Throws:
IOException
StoreException

createFileBacked

public static HAClient createFileBacked(String name,
                                        String publishLog,
                                        String subscribeLog)
                                 throws IOException,
                                        StoreException
Creates a new highly available client backed by disk. This client will automatically reconnect and re-subscribe, and uses disk to ensure messages are not lost and duplicates are processed appropriately.

Parameters:
name - The client name, passed to the server to uniquely identify this client across sessions.
publishLog - The path to a file used to store outgoing messages. This file will be created if it does not exist.
subscribeLog - The path to a file used to log incoming message bookmarks. This file will be created if it does not exist.
Returns:
A new HAClient instance.
Throws:
IOException
StoreException

connectAndLogon

public void connectAndLogon()
                     throws ConnectionException
Connects to the next server chosen for us by our ServerChooser. Will continue attempting to connect and logon to each successive server returned by the ServerChooser until the connection suceeds or the ServerChooser returns an empty URI.

Throws:
ConnectionException - An exception indicating no AMPS instance could be connected to.

connect

public void connect(String uri)
             throws ConnectionException
Description copied from class: Client
Connects to the AMPS instance through the provided URI. The URI is a String with the format: transport://host:port/protocol Notice that the protocol can be independent of the message type. 60East recommends using the amps protocol, although some installations use one of the legacy protocols such as fix, nvfix or xml. Contact your server administrator for the correct URI for the instance.

Overrides:
connect in class Client
Parameters:
uri - The URI string to connect to
Throws:
ConnectionRefusedException - The connection could not be established
AlreadyConnectedException - The connection is already connected
InvalidURIException - The specified URI is invalid
ProtocolException - The protocol is invalid
TransportTypeException - The transport type is invalid
ConnectionException

disconnect

public void disconnect()
Description copied from class: Client
Disconnect from the AMPS server.

Overrides:
disconnect in class Client

getConnectionInfo

public ConnectionInfo getConnectionInfo()
Assembles a new ConnectionInfo with the state of this client and associated classes.

Overrides:
getConnectionInfo in class Client
Returns:
A new ConnectionInfo object.