public class Client
extends java.lang.Object
implements java.lang.AutoCloseable
The Client object creates and manages background threads. The object provides both a synchronous interface for processing messages on the calling thread and an asynchronous interface suitable for populating a queue to be processed by worker threads.
The Client provides named convenience methods for many AMPS commands.
These methods provide control over commonly used parameters and support
most programs. For full control over AMPS, you build a
Command
object and use
execute(com.crankuptheamps.client.Command)
or executeAsync(com.crankuptheamps.client.Command, com.crankuptheamps.client.MessageHandler)
to run the command.
AMPS uses the client name to detect duplicate messages, so the name of each instance of the client application should be unique.
An example of a simple Java program publishing the JSON message
{ "message" : "Hello, World!"}
is listed below.
public static void main(String[] args) {
Client client = new Client("ConsolePublisher");
try
{
client.connect("tcp://127.0.0.1:9007/amps");
System.out.println("connected..");
client.logon();
client.publish("messages", "{\"message\" : \"Hello, World!\"}");
System.exit(0);
}
catch (AMPSException e)
{
System.err.println(e.getLocalizedMessage());
e.printStackTrace(System.err);
}
}
Modifier and Type | Class and Description |
---|---|
static class |
Client.Bookmarks
Provides constants for special bookmark values.
|
protected class |
Client.ClientHandler |
static class |
Client.GlobalCommandTypeHandlers
Specifies a type of message that is always sent to an associated
handler when one is set.
|
static class |
Client.Version
Class that holds supported versions of AMPS, those are: AMPS version 3, AMPS
version 4 and AMPS version 5.
|
Modifier and Type | Field and Description |
---|---|
protected int |
_lastFailedConnectionVersion |
protected java.beans.ExceptionListener |
exceptionListener |
protected java.util.concurrent.locks.Lock |
lock |
static int |
MIN_MULTI_BOOKMARK_VERSION |
static int |
MIN_PERSISTED_BOOKMARK_VERSION |
Constructor and Description |
---|
Client()
Default constructor that creates a client without a name.
|
Client(java.lang.String name)
Creates a client.
|
Client(java.lang.String name,
int version)
Creates a client.
|
Client(java.lang.String name,
Transport transport)
Creates a client with a transport.
|
Client(java.lang.String name,
Transport transport,
int version)
Creates a client with a transport
|
Modifier and Type | Method and Description |
---|---|
protected void |
_ack(byte[] topic,
int topicPos,
int topicLen,
byte[] bookmark,
int bookmarkPos,
int bookmarkLen,
byte[] options,
int optionsPos,
int optionsLen) |
protected void |
_ack(Field topic,
Field bookmark)
Used internally for autoacking and by Message.
|
protected void |
_ack(Field topic,
Field bookmark,
Field options)
Used internally for autoacking and by Message.
|
void |
ack(byte[] topic,
int topicPos,
int topicLen,
byte[] bookmark,
int bookmarkPos,
int bookmarkLen)
ACKs a message from a message queue with a byte-array topic and bookmark
|
void |
ack(byte[] topic,
int topicPos,
int topicLen,
byte[] bookmark,
int bookmarkPos,
int bookmarkLen,
byte[] options,
int optionsPos,
int optionsLen)
ACKs a message from a message queue with a byte-array topic and bookmark
|
void |
ack(Field topic,
Field bookmark)
ACKs a message queue message using
Field objects from a message. |
void |
ack(Field topic,
Field bookmark,
Field options)
ACKs a message queue message using
Field objects from a message. |
void |
ack(java.lang.String topic,
java.lang.String bookmark)
ACKs a message queue message.
|
void |
ack(java.lang.String topic,
java.lang.String bookmark,
java.lang.String options)
ACKs a message queue message.
|
void |
addConnectionStateListener(ConnectionStateListener listener_)
Adds a
ConnectionStateListener instance that will be invoked when
this client connects or disconnects. |
void |
addHttpPreflightHeader(java.lang.String header)
Add a new header to the list of HTTP preflight headers.
|
void |
addHttpPreflightHeader(java.lang.String key,
java.lang.String value)
Add a new key/value pair to the list of HTTP preflight headers.
|
void |
addMessageHandler(CommandId commandId_,
MessageHandler messageHandler_,
int requestedAcks_,
boolean isSubscribe_)
Adds a MessageHandler for a given CommandId to self.
|
Message |
allocateMessage()
Creates a new
Message appropriate for this client. |
CommandId |
bookmarkSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
CommandId subId,
java.lang.String bookmark,
java.lang.String options,
long timeout)
Places a bookmark subscription with AMPS.
|
protected void |
broadcastConnectionStateChanged(int newState_)
This method is responsible for broadcasting changes in the connection state to all registered
ConnectionStateListener objects.
|
void |
clearHttpPreflightHeaders()
Clear the list of HTTP preflight headers.
|
void |
close()
Disconnect from the AMPS server.
|
void |
connect(java.lang.String uri)
Connects to the AMPS instance through the provided URI.
|
long |
deltaPublish(byte[] topic,
int topicOffset,
int topicLength,
byte[] data,
int dataOffset,
int dataLength)
Delta publish a message to an AMPS topic.
|
long |
deltaPublish(byte[] topic,
int topicOffset,
int topicLength,
byte[] data,
int dataOffset,
int dataLength,
int expiration)
Delta publish a message to an AMPS topic.
|
long |
deltaPublish(java.lang.String topic,
java.lang.String data)
Delta publish a message to an AMPS topic.
|
long |
deltaPublish(java.lang.String topic,
java.lang.String data,
int expiration)
Delta publish a message to an AMPS topic.
|
CommandId |
deltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
long timeout)
Places a delta subscription with AMPS.
|
CommandId |
deltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
long timeout)
Places a delta subscription with AMPS.
|
CommandId |
deltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
java.lang.String options,
long timeout)
Places a delta subscription with AMPS.
|
CommandId |
deltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
java.lang.String options,
long timeout,
java.lang.String subId)
Places a delta subscription with AMPS.
|
void |
disconnect()
Disconnect from the AMPS server.
|
MessageStream |
execute(Command command)
Execute the provided command and return messages received in response
in a
MessageStream . |
CommandId |
executeAsync(Command command,
MessageHandler handler)
Execute the provided command and process responses on
the client receive thread using the provided handler.
|
long |
flush()
Deprecated.
As of 5.3.0.0. Use (@link #publishFlush) instead.
Clear the queued messages which may be waiting in the transport.
This is a no-op.
|
long |
flush(long timeout)
Deprecated.
As of 5.3.0.0. Use (@link #publishFlush) instead.
Clear the queued messages which may be waiting in the transport.
This is a no-op.
|
void |
flushAcks()
Send the current set of queue acknowledgements ("sow_delete" with the message
bookmark) to the AMPS server.
|
int |
getAckBatchSize()
Returns the current ACK batch size.
|
long |
getAckTimeout()
Returns the current queue ack timeout in milliseconds.
|
boolean |
getAutoAck()
Returns the current setting of auto-acking.
|
BookmarkStore |
getBookmarkStore()
Returns the underlying bookmark store for this client.
|
ConnectionInfo |
getConnectionInfo()
Assembles a new ConnectionInfo with the state of this client and
associated classes at the point in time this is called.
|
int |
getDefaultMaxDepth()
Gets the currently set default value for the max depth of
MessageStream instances created by this client. |
ClientDisconnectHandler |
getDisconnectHandler()
Returns the current
ClientDisconnectHandler set on self. |
MessageHandler |
getDuplicateMessageHandler()
Returns the
MessageHandler instance used for duplicate messages. |
java.beans.ExceptionListener |
getExceptionListener()
Returns the
ExceptionListener instance used for
communicating absorbed exceptions. |
FailedWriteHandler |
getFailedWriteHandler()
Returns the
FailedWriteHandler instance used to report on failed
messages that have been written. |
int |
getHeartbeatInterval()
Returns the heartbeat interval used by the Client.
|
java.util.List<java.lang.String> |
getHttpPreflightHeaders()
Return the list of HTTP preflight headers.
|
java.lang.String |
getLogonCorrelationData()
Gets the uninterpreted logon correlation information currently set.
|
java.lang.String |
getName()
Return the name of the Client.
|
java.lang.String |
getNameHash()
Return the name hash of the Client as returned by the server at logon.
|
Store |
getPublishStore()
Returns the underlying publish store for this client.
|
int |
getReadTimeout()
Returns the time (in seconds) to allow silence on the connection before
assuming it is dead.
|
boolean |
getRetryOnDisconnect()
Return whether or not messages being sent to the server will retry if the
client is disconnected.
|
int |
getServerVersion()
Return the server version retrieved during logon.
|
VersionInfo |
getServerVersionInfo()
Return the server version retrieved during logon.
|
SubscriptionManager |
getSubscriptionManager()
Returns the
SubscriptionManager instance used for recording active
subscriptions. |
ThreadCreatedHandler |
getThreadCreatedHandler()
Get the handler that is invoked immediately by any thread created by
the transport.
|
Transport |
getTransport()
Return the underlying transport.
|
protected TransportDisconnectHandler |
getTransportDisconnectHandler() |
TransportFilter |
getTransportFilter()
Get the filter that is used by the Client's transport for all incoming
and outgoing messages.
|
protected MessageHandler |
getTransportMessageHandler() |
java.net.URI |
getURI()
Return the URI the Client is connected to.
|
static java.lang.String |
getVersion()
Return the build number for the client that is stored in the Manifest.mf of
the jar file.
|
static int |
getVersionAsInt(java.lang.String version)
Deprecated.
|
CommandId |
logon()
Logs into AMPS with the parameters provided in the connect method.
|
CommandId |
logon(long timeout)
Logs into AMPS with the parameters provided in the connect method and the
logon correlation id, if any, that is set.
|
CommandId |
logon(long timeout,
Authenticator authenticator)
Logs into AMPS with the parameters provided in the connect method and the
logon correlation id, if any, that is set.
|
CommandId |
logon(long timeout,
Authenticator authenticator,
java.lang.String options)
Logs into AMPS with the parameters provided in the connect method and the
logon correlation id, if any, that is set.
|
CommandId |
logon(long timeout,
java.lang.String options)
Logs into AMPS with the parameters provided in the connect method and the
logon correlation id, if any, that is set.
|
CommandId |
logon(java.lang.String options)
Logs into AMPS with the parameters provided in the connect method and the
logon correlation id, if any, that is set.
|
long |
publish(byte[] topic,
int topicOffset,
int topicLength,
byte[] data,
int dataOffset,
int dataLength)
Publish a message to an AMPS topic.
|
long |
publish(byte[] topic,
int topicOffset,
int topicLength,
byte[] data,
int dataOffset,
int dataLength,
int expiration)
Publish a message to an AMPS topic.
|
long |
publish(java.lang.String topic,
java.lang.String data)
Publish a message to an AMPS topic.
|
long |
publish(java.lang.String topic,
java.lang.String data,
int expiration)
Publish a message to an AMPS topic.
|
void |
publishFlush()
Ensures that AMPS messages are sent and have been processed by the
AMPS server.
|
void |
publishFlush(long timeout)
Ensures that AMPS messages are sent and have been processed by the
AMPS server.
|
void |
publishFlush(java.lang.String ackType)
Ensures that AMPS messages are sent and have been processed by the
AMPS server.
|
void |
publishFlush(java.lang.String ackType,
long timeout)
Ensures that AMPS messages are sent and have been processed by the
AMPS server.
|
void |
removeConnectionStateListener(ConnectionStateListener listener_)
Removes a
ConnectionStateListener from being invoked when this client
connects or disconnects. |
boolean |
removeMessageHandler(CommandId commandId_)
Remove a MessageHandler for a given CommandId from self.
|
void |
send(Message message)
|
CommandId |
send(MessageHandler messageHandler,
Message message,
long timeout)
Send a
Message to AMPS and register the messageHandler for any
messages resulting from the command execution. |
void |
setAckBatchSize(int batchSize)
Sets the current ACK batch size.
|
void |
setAckTimeout(long ackTimeout)
Sets the ack timeout -- the maximum time to let a success ack be cached
before sending.
|
void |
setAutoAck(boolean isAutoAckEnabled)
Enables or disables auto-acking.
|
void |
setBookmarkStore(BookmarkStore val)
Sets the underlying bookmark store, which is used to track which
messages the client has received and which messages have been
processed by the program.
|
void |
setDefaultMaxDepth(int md)
Sets the default value used for the max depth of
MessageStream
instances created by this client. |
void |
setDisconnectHandler(ClientDisconnectHandler disconnectHandler_)
Sets the
ClientDisconnectHandler . |
void |
setDuplicateMessageHandler(MessageHandler messageHandler)
Sets the
MessageHandler instance used for duplicate messages. |
void |
setExceptionListener(java.beans.ExceptionListener exceptionListener)
Sets the
ExceptionListener instance used for communicating
absorbed exceptions. |
void |
setFailedWriteHandler(FailedWriteHandler handler_)
Sets the
FailedWriteHandler instance used to report on failed
messages that have been written. |
void |
setFailedWriteHandler(FailedWriteHandlerV4 handler_)
Sets the
FailedWriteHandler instance used to report on failed
messages that have been written. |
void |
setGlobalCommandTypeMessageHandler(Client.GlobalCommandTypeHandlers command,
MessageHandler messageHandler)
Sets the
MessageHandler instance used for all messages of the
given command type. |
void |
setGlobalCommandTypeMessageHandler(int command,
MessageHandler messageHandler)
Sets the
MessageHandler instance used for all messages of the
given command type. |
void |
setGlobalCommandTypeMessageHandler(java.lang.String command,
MessageHandler messageHandler)
Sets the
MessageHandler instance used for all messages of the
given command type. |
void |
setHeartbeat(int intervalSeconds_)
Requests a server heartbeat, and configures the client to close the
connection
if a heartbeat (or other activity) is not seen on the connection after two
heartbeat intervals.
|
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 |
setHttpPreflightHeaders(java.util.List<java.lang.String> headers)
Set the list of HTTP preflight headers replacing any previously set.
|
void |
setLastChanceMessageHandler(MessageHandler messageHandler)
Sets the
MessageHandler instance used when no other handler matches. |
void |
setLogonCorrelationData(java.lang.String correlationData)
Sets the uninterpreted logon correlation information a client sends
at logon to aid in searching server log files for specific clients.
|
void |
setName(java.lang.String name)
This method MUST be called to assign a unique client name before
connecting to an AMPS server when the client was constructed using
the default constructor.
|
void |
setPublishStore(Store store)
Sets the underlying publish store, which is used to store
published messages until the AMPS instance has acknowledged
those messages.
|
void |
setRetryOnDisconnect(boolean isRetryOnDisconnect)
Set whether or not messages being sent to the server should retry if the
client is disconnected.
|
void |
setSubscriptionManager(SubscriptionManager subscriptionManager)
Sets the
SubscriptionManager instance used for recording active
subscriptions. |
void |
setThreadCreatedHandler(ThreadCreatedHandler handler_)
Set a handler that is invoked immediately by any thread created by
the transport.
|
void |
setTransportFilter(TransportFilter filter_)
Set a filter that is used by the Client's transport for all incoming
and outgoing messages.
|
void |
setUnhandledMessageHandler(MessageHandler messageHandler)
Deprecated.
|
CommandId |
sow(MessageHandler messageHandler,
java.lang.String topic,
int batchSize,
long timeout)
Executes a SOW query.
|
CommandId |
sow(MessageHandler messageHandler,
java.lang.String topic,
long timeout)
Executes a SOW query.
|
CommandId |
sow(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
int batchSize,
long timeout)
Executes a SOW query.
|
CommandId |
sow(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
int batchSize,
java.lang.String options,
long timeout)
Executes a SOW query.
|
CommandId |
sow(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
java.lang.String orderBy,
java.lang.String bookmark,
int batchSize,
int topN,
java.lang.String options,
long timeout)
Executes a SOW query.
|
MessageStream |
sow(java.lang.String topic)
Synchronously execute a SOW query.
|
MessageStream |
sow(java.lang.String topic,
java.lang.String filter)
Synchronously execute a SOW query.
|
CommandId |
sowAndDeltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
int batchSize,
long timeout)
Executes a SOW query and places a delta subscription.
|
CommandId |
sowAndDeltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
long timeout)
Executes a SOW query and places a delta subscription.
|
CommandId |
sowAndDeltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
int batchSize,
boolean oofEnabled,
boolean sendEmpties,
long timeout)
Executes a SOW query and places a delta subscription.
|
CommandId |
sowAndDeltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
int batchSize,
boolean oofEnabled,
boolean sendEmpties,
java.lang.String options,
long timeout)
Executes a SOW query and places a delta subscription.
|
CommandId |
sowAndDeltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
int batchSize,
long timeout)
Executes a SOW query and places a delta subscription.
|
CommandId |
sowAndDeltaSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
java.lang.String orderBy,
int batchSize,
int topN,
java.lang.String options,
long timeout)
Executes a SOW query and places a delta subscription.
|
CommandId |
sowAndSubscribe(MessageHandler messageHandler,
java.lang.String topic,
int batchSize,
long timeout)
Executes a SOW query and places a subscription.
|
CommandId |
sowAndSubscribe(MessageHandler messageHandler,
java.lang.String topic,
long timeout)
Executes a SOW query and places a subscription.
|
CommandId |
sowAndSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
int batchSize,
boolean oofEnabled,
long timeout)
Executes a SOW query and places a subscription.
|
CommandId |
sowAndSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
int batchSize,
long timeout)
Executes a SOW query and places a subscription.
|
CommandId |
sowAndSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
int batchSize,
java.lang.String options,
long timeout)
Executes a SOW query and places a subscription.
|
CommandId |
sowAndSubscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
java.lang.String orderBy,
java.lang.String bookmark,
int batchSize,
int topN,
java.lang.String options,
long timeout)
Executes a SOW query and places a subscription.
|
MessageStream |
sowAndSubscribe(java.lang.String topic)
Executes a SOW query and places a subscription.
|
MessageStream |
sowAndSubscribe(java.lang.String topic,
java.lang.String filter)
Executes a SOW query and places a subscription.
|
CommandId |
sowDelete(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
long timeout)
Executes a SOW delete with filter.
|
CommandId |
sowDelete(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
java.lang.String options,
long timeout)
Executes a SOW delete with filter.
|
Message |
sowDelete(java.lang.String topic,
java.lang.String filter,
long timeout)
Executes a SOW delete with filter.
|
CommandId |
sowDeleteByData(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String data,
long timeout)
Executes a SOW delete by data.
|
CommandId |
sowDeleteByKeys(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String keys,
long timeout)
Executes a SOW delete using the SowKey assigned by AMPS to specify
the messages to delete.
|
void |
startTimer()
Deprecated.
No longer supported by the AMPS server.
Sends a start timer command to AMPS, which can be later stopped
with a stop timer command.
|
CommandId |
stopTimer(MessageHandler handler_)
Deprecated.
No longer supported by the AMPS server.
Sends a stop timer command to AMPS
|
CommandId |
subscribe(MessageHandler messageHandler,
java.lang.String topic,
long timeout)
Places a subscription with AMPS.
|
CommandId |
subscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
long timeout)
Places a subscription with AMPS.
|
CommandId |
subscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
java.lang.String options,
long timeout)
Places a subscription with AMPS.
|
CommandId |
subscribe(MessageHandler messageHandler,
java.lang.String topic,
java.lang.String filter,
java.lang.String options,
long timeout,
java.lang.String subId)
Places a subscription with AMPS.
|
MessageStream |
subscribe(java.lang.String topic)
Places a subscription with AMPS.
|
MessageStream |
subscribe(java.lang.String topic,
java.lang.String filter)
Places a subscription with AMPS.
|
void |
unsubscribe()
Remove all of the client's subscriptions from AMPS.
|
void |
unsubscribe(CommandId subscriptionId)
Remove a subscription from AMPS.
|
protected volatile java.beans.ExceptionListener exceptionListener
protected final java.util.concurrent.locks.Lock lock
protected volatile int _lastFailedConnectionVersion
public static final int MIN_PERSISTED_BOOKMARK_VERSION
public static final int MIN_MULTI_BOOKMARK_VERSION
public Client()
setName(String)
before connecting.Client(String)
,
setName(String)
public Client(java.lang.String name)
name
- Name for the client. This name is used for duplicate
message detection and should be unique. AMPS does not enforce
specific restrictions on the character set used, however some
protocols (for example, XML) may not allow specific characters.
60East recommends that the client name be meaningful, short,
human
readable, and avoids using control characters, newline
characters,
or square brackets.public Client(java.lang.String name, int version)
name
- Name for the client. This name is used for duplicate
message detection and should be unique.AMPS does not enforce
specific restrictions on the character set used, however some
protocols (for example, XML) may not allow specific
characters.
60East recommends that the client name be meaningful, short,
human
readable, and avoids using control characters, newline
characters,
or square brackets.version
- Server version connecting topublic Client(java.lang.String name, Transport transport)
name
- Name for the client. This name is used for duplicate
message detection and should be unique.transport
- Transport to use for this clientpublic Client(java.lang.String name, Transport transport, int version)
name
- Name for the client. This name is used for duplicate
message detection and should be unique.transport
- Transport to use with the clientversion
- Server version connecting to. Only AMPS_3 and greater are
supported.public void setName(java.lang.String name)
IllegalStateException
. This method and the default constructor
exist to better support frameworks that require managed objects to
have a default constructor.name
- The client name, passed to the server to uniquely identify
this client across sessions. AMPS does not enforce
specific restrictions on the character set used, however some
protocols (for example, XML) may not allow specific characters.
60East recommends that the client name be meaningful, short, human
readable, and avoids using control characters, newline characters,
or square brackets.java.lang.IllegalStateException
- If this is called when the client
already has a non-empty name.Client()
,
Client(String)
public java.lang.String getName()
public java.lang.String getNameHash()
public java.net.URI getURI()
public int getServerVersion()
public VersionInfo getServerVersionInfo()
@Deprecated public static int getVersionAsInt(java.lang.String version) throws CommandException
VersionInfo.getVersion()
Return the numeric value for the given version string with the pattern:
Major.Minor.Maintenance.Hotfix
The version uses 2 digits each for major minor maintenance and hotfix
i.e., 3.8.1.5 will return 3080105
Version strings passed in can be shortened to not include all levels
so 3.8 will return 3080000.
Version parts with more than 2 digits will be set to 99. This function will
be deprecated in a future version of the client.version
- The version string to convert.CommandException
- The string doesn't represent a valid version.public Transport getTransport()
public void setBookmarkStore(BookmarkStore val) throws AlreadyConnectedException
val
- The new bookmark store.AlreadyConnectedException
- The store cannot be set while the client is
connected.public BookmarkStore getBookmarkStore()
public void setPublishStore(Store store) throws AlreadyConnectedException
store
- The new publish store.AlreadyConnectedException
- The store cannot be set while the client is
connected.public Store getPublishStore()
public void connect(java.lang.String uri) throws ConnectionException
The URI is a String
with the format:
transport://user:password@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.
Authentication is optional if the system is using the default authentication provided with AMPS. This default authentication allows all users to authenticate, regardless of the user or password provided. If your AMPS installation uses custom authentication, use the Authenticator appropriate for that authentication mechanism.
uri
- The URI string to connect toConnectionRefusedException
- The connection could not be establishedAlreadyConnectedException
- The connection is already connectedInvalidURIException
- The specified URI is invalidProtocolException
- The protocol is invalidTransportTypeException
- The transport type is invalidConnectionException
public void setDisconnectHandler(ClientDisconnectHandler disconnectHandler_)
ClientDisconnectHandler
. In the event that the Client is
unintentionally disconnected from AMPS, the invoke
method
from the ClientDisconnectHandler will be invoked.disconnectHandler_
- The disconnect handlerpublic ClientDisconnectHandler getDisconnectHandler()
ClientDisconnectHandler
set on self.@Deprecated public void setUnhandledMessageHandler(MessageHandler messageHandler)
setLastChanceMessageHandler(com.crankuptheamps.client.MessageHandler)
instead.MessageHandler
instance used when no other handler matches.messageHandler
- The message handler used when no other handler matches.public void setLastChanceMessageHandler(MessageHandler messageHandler)
MessageHandler
instance used when no other handler matches.messageHandler
- The message handler used when no other handler matches.public void setExceptionListener(java.beans.ExceptionListener exceptionListener)
ExceptionListener
instance used for communicating
absorbed exceptions.exceptionListener
- The exception listener instance to invoke for
exceptions.public java.beans.ExceptionListener getExceptionListener()
ExceptionListener
instance used for
communicating absorbed exceptions.public void setSubscriptionManager(SubscriptionManager subscriptionManager)
SubscriptionManager
instance used for recording active
subscriptions.subscriptionManager
- The subscription manager invoked when the
subscriptions change.public SubscriptionManager getSubscriptionManager()
SubscriptionManager
instance used for recording active
subscriptions.public void setGlobalCommandTypeMessageHandler(java.lang.String command, MessageHandler messageHandler) throws CommandException
MessageHandler
instance used for all messages of the
given command type.command
- The type of command to send to this handlermessageHandler
- The message handler to invoke for duplicate messagesCommandException
- If the command is not a supported command.public void setGlobalCommandTypeMessageHandler(int command, MessageHandler messageHandler) throws CommandException
MessageHandler
instance used for all messages of the
given command type.command
- The Message.Command value of the desired command to
send to this handler.messageHandler
- The message handler to invoke for duplicate messagesCommandException
- If the command is not a supported command.public void setGlobalCommandTypeMessageHandler(Client.GlobalCommandTypeHandlers command, MessageHandler messageHandler) throws CommandException
MessageHandler
instance used for all messages of the
given command type.command
- The GlobalCommandTypeHandlers value of the desired
command to send to this handler.messageHandler
- The message handler to invoke for duplicate messagesCommandException
- If the command is not a supported command.public void setDuplicateMessageHandler(MessageHandler messageHandler)
MessageHandler
instance used for duplicate messages.messageHandler
- The message handler to invoke for duplicate messagespublic MessageHandler getDuplicateMessageHandler()
MessageHandler
instance used for duplicate messages.public void setFailedWriteHandler(FailedWriteHandlerV4 handler_)
FailedWriteHandler
instance used to report on failed
messages that have been written.handler_
- The handler to invoke for published duplicates.public void setFailedWriteHandler(FailedWriteHandler handler_)
FailedWriteHandler
instance used to report on failed
messages that have been written.handler_
- The handler to invoke for published duplicates.public FailedWriteHandler getFailedWriteHandler()
FailedWriteHandler
instance used to report on failed
messages that have been written.public void addConnectionStateListener(ConnectionStateListener listener_)
ConnectionStateListener
instance that will be invoked when
this client connects or disconnects.listener_
- The instance to invoke.public void removeConnectionStateListener(ConnectionStateListener listener_)
ConnectionStateListener
from being invoked when this client
connects or disconnects.listener_
- The instance to remove.protected void broadcastConnectionStateChanged(int newState_)
newState_
- An integer representing the new connection state. This value is provided to
listeners through the connectionStateChanged method of the ConnectionStateListener
interface.public void disconnect()
public void close()
close
in interface java.lang.AutoCloseable
public Message allocateMessage() throws DisconnectedException
Message
appropriate for this client. This function
should be
called rarely, since it does allocate a handful of small objects. Users
sensitive
to garbage collection delays should cache the message object for later usage.Message
instanceDisconnectedException
- When the client has been closed or has never
been connected.public void send(Message message) throws DisconnectedException
Message
to AMPS via the Transport
used in the Client.
This method is provided for special cases. In general, you can get the
same results with additional error checking by using a Command
object with the execute or executeAsync methods.message
- The message to sendDisconnectedException
- The connection was disconnected at time of sendpublic void addMessageHandler(CommandId commandId_, MessageHandler messageHandler_, int requestedAcks_, boolean isSubscribe_)
commandId_
- The command, query, or subid used to invoke the
handler.messageHandler_
- The message handler to route torequestedAcks_
- The acks requested to be sent to the handlerisSubscribe_
- True if this route is for an ongoing subscriptionpublic boolean removeMessageHandler(CommandId commandId_)
commandId_
- The commandId for the handler to removepublic void setRetryOnDisconnect(boolean isRetryOnDisconnect)
isRetryOnDisconnect
- False to disable default behavior of automatic
retry.public boolean getRetryOnDisconnect()
public void setDefaultMaxDepth(int md)
Sets the default value used for the max depth of MessageStream
instances created by this client. This value defaults to
Integer.MAX_VALUE
. Note: changing this value will not affect
any message stream instances that have already been created by this
client; instead use MessageStream.maxDepth(int)
.
WARNING: Before setting this, be sure to read important limitations
and restrictions of this feature discussed here:
MessageStream.maxDepth(int)
md
- The default max depth of all message stream instances created
by this client instance.MessageStream.maxDepth(int)
public int getDefaultMaxDepth()
MessageStream
instances created by this client.setDefaultMaxDepth(int)
public CommandId send(MessageHandler messageHandler, Message message, long timeout) throws AMPSException
Message
to AMPS and register the messageHandler for any
messages resulting from the command execution.
This method is provided for special cases. In general, you can get the
same results with additional error checking by using a Command
object with the execute or executeAsync methods.messageHandler
- The message handler that'll receive messages for this
commandmessage
- The message to sendtimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyAMPSException
- An exception occurred while sending or waiting for a
response to this Message.public MessageStream execute(Command command) throws AMPSException
MessageStream
.
This method creates a message based on the provided Command
,
sends the message to AMPS, and receives the results. AMPS sends the
message and receives the results on a background thread. That thread
populates the MessageStream returned by this method.command
- The Command object containing the command to send to AMPSAMPSException
- Thrown when the command fails.public CommandId executeAsync(Command command, MessageHandler handler) throws AMPSException
Command
,
sends the message to AMPS, and invokes the provided
MessageHandler
to process messages returned in response
to the command. Rather than providing messages on the calling thread,
AMPS runs the MessageHandler directly on the client receive thread.
When the provided MessageHandler is not null, this method blocks
until AMPS acknowledges that the command has been processed. The results
of the command after that acknowledgement are provided to the
MessageHandler.command
- The Command object containing the command to send to AMPShandler
- The MessageHandler to invoke to process messages receivedAMPSException
- Thrown when the command fails.public void setHeartbeat(int intervalSeconds_, int timeoutSeconds_) throws DisconnectedException
intervalSeconds_
- The time (seconds) between beats from the server.timeoutSeconds_
- The time (seconds) to allow silence on the connection
before assuming it is dead.DisconnectedException
- The client became disconnected while attempting
to send the heartbeat request.public void setHeartbeat(int intervalSeconds_) throws DisconnectedException
intervalSeconds_
- The time (seconds) between beats from the server.DisconnectedException
- The client became disconnected while attempting
to send the heartbeat request.public int getHeartbeatInterval()
public int getReadTimeout()
public long publish(byte[] topic, int topicOffset, int topicLength, byte[] data, int dataOffset, int dataLength) throws AMPSException
topic
- the topic to publish totopicOffset
- the offset in topic where the topic beginstopicLength
- the length of the topic in the topic arraydata
- the data to publishdataOffset
- the offset in data where data beginsdataLength
- the length of the dataDisconnectedException
- the client is not connected; the program needs
to call connect()StoreException
- An error occurred writing to the local HA
store.AMPSException
public long publish(java.lang.String topic, java.lang.String data) throws AMPSException
topic
- the topic to publish the data todata
- the data to publish to the topicDisconnectedException
- the client is not connected; the program needs
to call connect()StoreException
- An error occurred writing to the local HA
store.AMPSException
public long publish(byte[] topic, int topicOffset, int topicLength, byte[] data, int dataOffset, int dataLength, int expiration) throws AMPSException
topic
- the topic to publish totopicOffset
- the offset in topic where the topic beginstopicLength
- the length of the topic in the topic arraydata
- the data to publishdataOffset
- the offset in data where data beginsdataLength
- the length of the dataexpiration
- the number of seconds until the message expiresDisconnectedException
- the client is not connected; the program needs
to call connect()StoreException
- An error occurred writing to the local HA
store.AMPSException
public long publish(java.lang.String topic, java.lang.String data, int expiration) throws AMPSException
topic
- Topic to publish the data todata
- Data to publish to the topicexpiration
- The number of seconds until the message expiresDisconnectedException
- The client is not connected; the program needs
to call connect()StoreException
- An error occurred writing to the local HA
store.AMPSException
public long deltaPublish(byte[] topic, int topicOffset, int topicLength, byte[] data, int dataOffset, int dataLength) throws AMPSException
topic
- Topic to publish the data totopicOffset
- offset into topic array where the topic name beginstopicLength
- length of topic arraydata
- Data to publish to the topicdataOffset
- offset into data array where the data beginsdataLength
- length of data arrayDisconnectedException
- The client was disconnected at time of publishStoreException
- An error occurred writing to the local HA
store.AMPSException
public long deltaPublish(java.lang.String topic, java.lang.String data) throws AMPSException
topic
- Topic to publish the data todata
- Data to publish to the topicDisconnectedException
- The client was disconnected at time of publishStoreException
- An error occurred writing to the local HA
store.AMPSException
public long deltaPublish(byte[] topic, int topicOffset, int topicLength, byte[] data, int dataOffset, int dataLength, int expiration) throws AMPSException
topic
- Topic to publish the data totopicOffset
- offset into topic array where the topic name beginstopicLength
- length of topic arraydata
- Data to publish to the topicdataOffset
- offset into data array where the data beginsdataLength
- length of data arrayexpiration
- the number of seconds until the message expiresDisconnectedException
- The client was disconnected at time of publishStoreException
- An error occurred writing to the local HA
store.AMPSException
public long deltaPublish(java.lang.String topic, java.lang.String data, int expiration) throws AMPSException
topic
- Topic to publish the data todata
- Data to publish to the topicexpiration
- the number of seconds until the message expiresDisconnectedException
- The client was disconnected at time of publishStoreException
- An error occurred writing to the local HA
store.AMPSException
@Deprecated public void startTimer() throws AMPSException
ConnectionException
- A connection error occurred while sending.AMPSException
@Deprecated public CommandId stopTimer(MessageHandler handler_) throws AMPSException
handler_
- A MessageHandler to process the acknowledgement returned by
AMPS.ConnectionException
- A connection error occurred while sending.AMPSException
public void setLogonCorrelationData(java.lang.String correlationData)
correlationData
- The base64 data to be used for logon correlation.public java.lang.String getLogonCorrelationData()
public CommandId logon(long timeout) throws ConnectionException
timeout
- The number of milliseconds to wait for the client to receive
and consume a processed ack for this command, where 0
indicates to wait indefinitelyConnectionException
- A connection error occurred while logging on.public CommandId logon(long timeout, java.lang.String options) throws ConnectionException
timeout
- The number of milliseconds to wait for the client to receive
and consume a processed ack for this command, where 0
indicates to wait indefinitelyoptions
- The options string to pass with the logon commandConnectionException
- A connection error occurred while logging on.public CommandId logon(java.lang.String options) throws ConnectionException
options
- The options string to pass with the logon commandConnectionException
- A connection error occurred while logging on.public CommandId logon(long timeout, Authenticator authenticator) throws ConnectionException
timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyauthenticator
- The custom authenticator object to authenticate againstConnectionException
- A connection error occurred while logging on.public CommandId logon(long timeout, Authenticator authenticator, java.lang.String options) throws ConnectionException
timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyauthenticator
- The custom authenticator object to authenticate againstoptions
- The options string to pass with the logon commandConnectionException
- A connection error occurred while logging on.public CommandId logon() throws ConnectionException
ConnectionException
- A connection error occurred while logging on.public CommandId bookmarkSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, CommandId subId, java.lang.String bookmark, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filtersubId
- The subscription ID. You may optionally provide a
subscription ID
to ease recovery scenarios, instead of having the
system automatically
generate one for you. When used with the 'replace'
option, this
is the subscription to be replaced. With a bookmark
store,
this is the subscription ID used for recovery. So, when
using a persistent bookmark store, provide an explicit
subscription ID that is consistent across application
restarts.bookmark
- The timestamp or bookmark location at which to start
the subscription. This parameter can be the bookmark
assigned by AMPS to a message, one of the special
values in Client.Bookmarks
, or a string of the
format YYYYmmddTHHMMSS, as described in the AMPS User's
guide.options
- A Message.Options
value indicating desired
options for this
subscription. Use Message.Options.None if no options
are desired.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId subscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filtertimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId subscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filteroptions
- A value from Message.Options indicating additional
processing options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId subscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, java.lang.String options, long timeout, java.lang.String subId) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filteroptions
- A value from Message.Options indicating additional
processing options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelysubId
- The subscription id to use for the subscription.SubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public MessageStream subscribe(java.lang.String topic) throws AMPSException
topic
- The topic to subscribe toBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public MessageStream subscribe(java.lang.String topic, java.lang.String filter) throws AMPSException
topic
- The topic to subscribe tofilter
- The filterBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public CommandId subscribe(MessageHandler messageHandler, java.lang.String topic, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe totimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId deltaSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filteroptions
- A value from Message.Options indicating additional
processing options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId deltaSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, java.lang.String options, long timeout, java.lang.String subId) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filteroptions
- A value from Message.Options indicating additional
processing options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelysubId
- The subscription id to use for the subscription.SubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId deltaSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filtertimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId deltaSubscribe(MessageHandler messageHandler, java.lang.String topic, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe totimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public void unsubscribe(CommandId subscriptionId) throws DisconnectedException
subscriptionId
- The subscription identifier to removeDisconnectedException
- The client was disconnected at the time of
execution. This can still be considered a
success because the
subscription was still removed from the
client's subscription
manager (if any) and since the client is
disconnected,
it is unsubscribed on the server-side.public void unsubscribe() throws DisconnectedException
DisconnectedException
- The client was disconnected at the time of
execution. This can still be considered a
success because any subscriptions were
still removed from the client's subscription
manager (if any) and since the client is
disconnected, it is unsubscribed on the
server-side.public MessageStream sow(java.lang.String topic, java.lang.String filter) throws AMPSException
topic
- The topic to queryfilter
- The filterBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public MessageStream sow(java.lang.String topic) throws AMPSException
topic
- The topic to queryBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public CommandId sow(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, java.lang.String orderBy, java.lang.String bookmark, int batchSize, int topN, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterorderBy
- The ordering propertybookmark
- The timestamp or bookmark location for a historical
query. This parameter can be the bookmark assigned by
AMPS to a message, one of the special values in
Client.Bookmarks
, or a string of the format
YYYYmmddTHHMMSS, as described in the AMPS User's guide.batchSize
- The batching parameter to use for the resultstopN
- The maximum number of records the server will return
(default is all that match)options
- The options string for the command, or an empty string
for no options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public CommandId sow(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, int batchSize, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterbatchSize
- The batching parameter to use for the resultsoptions
- The options string for the command, or an empty string
for no options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public CommandId sow(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, int batchSize, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterbatchSize
- The batching parameter to use for the resultstimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public CommandId sow(MessageHandler messageHandler, java.lang.String topic, int batchSize, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tobatchSize
- The batching parameter to use for the resultstimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public CommandId sow(MessageHandler messageHandler, java.lang.String topic, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe totimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public MessageStream sowAndSubscribe(java.lang.String topic, java.lang.String filter) throws AMPSException
topic
- The topic to subscribe tofilter
- The filterSubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public MessageStream sowAndSubscribe(java.lang.String topic) throws AMPSException
topic
- The topic to subscribe toSubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, java.lang.String orderBy, java.lang.String bookmark, int batchSize, int topN, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterorderBy
- The ordering propertybookmark
- The timestamp or bookmark location for a historical
query. This parameter can be the bookmark assigned by
AMPS to a message, one of the special values in
Client.Bookmarks
, or a string of the format
YYYYmmddTHHMMSS, as described in the AMPS User's guide.batchSize
- The batching parameter to use for the SOW query resultstopN
- The maximum number of records the server will return
(default is all that match)options
- A value from Message.Options indicating additional
processing options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, int batchSize, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterbatchSize
- The batching parameter to use for the SOW query resultsoptions
- A value from Message.Options indicating additional
processing options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, int batchSize, boolean oofEnabled, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterbatchSize
- The batching parameter to use for the SOW query resultsoofEnabled
- Specifies whether or not Out-of-Focus processing is
enabledtimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, int batchSize, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterbatchSize
- The batching parameter to use for the SOW query resultstimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndSubscribe(MessageHandler messageHandler, java.lang.String topic, int batchSize, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tobatchSize
- The batching parameter to use for the SOW query resultstimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndSubscribe(MessageHandler messageHandler, java.lang.String topic, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe totimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndDeltaSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, java.lang.String orderBy, int batchSize, int topN, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterorderBy
- The ordering propertybatchSize
- The batching parameter to use for the SOW query resultstopN
- The maximum number of records the server will return
(default is all that match)options
- A value from Message.Options indicating additional
processing optionstimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndDeltaSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, int batchSize, boolean oofEnabled, boolean sendEmpties, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterbatchSize
- The batching parameter to use for the SOW query resultsoofEnabled
- Specifies whether or not Out-of-Focus processing is
enabledsendEmpties
- Specifies whether or not unchanged records are received
on the delta subscriptionoptions
- A value from Message.Options indicating additional
processing options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndDeltaSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, int batchSize, boolean oofEnabled, boolean sendEmpties, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterbatchSize
- The batching parameter to use for the SOW query resultsoofEnabled
- Specifies whether or not Out-of-Focus processing is
enabledsendEmpties
- Specifies whether or not unchanged records are received
on the delta subscriptiontimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndDeltaSubscribe(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, int batchSize, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tofilter
- The filterbatchSize
- The batching parameter to use for the SOW query resultstimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndDeltaSubscribe(MessageHandler messageHandler, java.lang.String topic, int batchSize, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe tobatchSize
- The batching parameter to use for the SOW query resultstimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowAndDeltaSubscribe(MessageHandler messageHandler, java.lang.String topic, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with matching messagestopic
- The topic to subscribe totimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelySubscriptionAlreadyExistsException
- A subscription with this
identifier is already registeredBadRegexTopicException
- The topic specified was an invalid
regular expressionTimedOutException
- The operation took longer than the
timeout to executeDisconnectedException
- The client wasn't connected when
the operation was executedAMPSException
public CommandId sowDelete(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, java.lang.String options, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with stats and completed
acknowledgementstopic
- The topic to subscribe tofilter
- The filter. To delete all records, set a filter that is
always true ('1=1')options
- A value from Message.Options indicating additional
processing options.timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public CommandId sowDelete(MessageHandler messageHandler, java.lang.String topic, java.lang.String filter, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with stats and completed
acknowledgementstopic
- The topic to subscribe tofilter
- The filter. To delete all records, set a filter that is
always true ('1=1')timeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public Message sowDelete(java.lang.String topic, java.lang.String filter, long timeout) throws AMPSException
topic
- The topic to subscribe tofilter
- The filter. To delete all records, set a filter that is always
true ('1=1')timeout
- The number of milliseconds to wait for the client to receive
and consume a processed ack for this command, where 0
indicates to wait indefinitelyBadFilterException
- The provided filter is invalidBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public CommandId sowDeleteByKeys(MessageHandler messageHandler, java.lang.String topic, java.lang.String keys, long timeout) throws AMPSException
// DeleteMessageHandler receives a message containing
// the results of the delete.
DeleteMessageHandler dmh = new DeleteMessageHandler();
client.sowDeleteByKeys(dmh, message.getTopic(), message.getSowKey(), 1000);
messageHandler
- The message handler to invoke with stats and completed
acknowledgementstopic
- The topic to execute the SOW delete againstkeys
- A comma separated list of SOW keys to be deletedtimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyBadRegexTopicException
- The topic specified was an invalid regular
expressionTimedOutException
- The operation took longer than the timeout to
executeDisconnectedException
- The client wasn't connected when the operation
was executedAMPSException
public CommandId sowDeleteByData(MessageHandler messageHandler, java.lang.String topic, java.lang.String data, long timeout) throws AMPSException
messageHandler
- The message handler to invoke with stats and completed
acknowledgementstopic
- The topic to execute the SOW delete againstdata
- The message to match and delete in the SOW cachetimeout
- The number of milliseconds to wait for the client to
receive and consume a processed ack for this command,
where 0 indicates to wait indefinitelyAMPSException
- An error occurred while waiting for this command to be
processed.public void publishFlush() throws DisconnectedException, TimedOutException
DisconnectedException
- Thrown if the client is shut down or has never
been connectedTimedOutException
- Not thrown from this overload: the method
blocks until the operation completes.public void publishFlush(java.lang.String ackType) throws CommandException, DisconnectedException, TimedOutException
ackType
- The acknowledgement type that the flush command should wait to
receive, see Message.AckType
. `processed` matches the
no arguments version of this function. `persisted` ensures all
previous messages have been persisted.CommandException
- Thrown if an invalid ack type is requested.DisconnectedException
- Thrown if the client is shut down or has never
been connectedTimedOutException
- Not thrown from this overload: the method
blocks until the operation completes.public void publishFlush(long timeout) throws DisconnectedException, TimedOutException
timeout
- Number of milliseconds to wait for flush, where 0 indicates to
wait indefinitelyDisconnectedException
- Thrown if the client is shut down or has never
been connectedTimedOutException
- Thrown if the timeout period expires before the
method returnspublic void publishFlush(java.lang.String ackType, long timeout) throws CommandException, DisconnectedException, TimedOutException
ackType
- The acknowledgement type that the flush command should wait to
receive, see Message.AckType
. `processed` matches the
timeout only version of this function. `persisted` ensures all
previous messages have been persisted.timeout
- Number of milliseconds to wait for flush, where 0 indicates to
wait indefinitelyCommandException
- Thrown if an invalid ack type is requested.DisconnectedException
- Thrown if the client is shut down or has never
been connectedTimedOutException
- Not thrown from this overload: the method
blocks until the operation completes.@Deprecated public long flush() throws DisconnectedException
DisconnectedException
- Thrown if the client is shut down or has never
been connected@Deprecated public long flush(long timeout) throws DisconnectedException
timeout
- Number of milliseconds to wait for flush, where 0 indicates to
wait indefinitelyDisconnectedException
- Thrown if the client is shut down or has never
been connectedpublic static java.lang.String getVersion()
public ThreadCreatedHandler getThreadCreatedHandler()
public void setThreadCreatedHandler(ThreadCreatedHandler handler_)
handler_
- A ThreadCreatedHandler to be invoked by new
transport threads.public TransportFilter getTransportFilter()
public void setTransportFilter(TransportFilter filter_)
filter_
- A TransportFilter to be invoked by the transport.public ConnectionInfo getConnectionInfo()
public void ack(byte[] topic, int topicPos, int topicLen, byte[] bookmark, int bookmarkPos, int bookmarkLen) throws AMPSException
topic
- The bytes of the topic to acktopicPos
- The starting position in topictopicLen
- The length of the topic in bytesbookmark
- The bytes of the bookmark to ackbookmarkPos
- The starting position in bookmarkbookmarkLen
- The length of the bookmarkAMPSException
- An exception occurred while sending a sow_delete
message.public void ack(Field topic, Field bookmark) throws AMPSException
Field
objects from a message.topic
- The topic to ackbookmark
- The bookmark to ackAMPSException
- An error occurred while sending a sow_delete message.public void ack(java.lang.String topic, java.lang.String bookmark) throws AMPSException
topic
- The topic to ackbookmark
- The bookmark or comma-delimited bookmark list to ack.AMPSException
- An error occurred while sending a sow_delete message.public void ack(byte[] topic, int topicPos, int topicLen, byte[] bookmark, int bookmarkPos, int bookmarkLen, byte[] options, int optionsPos, int optionsLen) throws AMPSException
topic
- The bytes of the topic to acktopicPos
- The starting position in topictopicLen
- The length of the topic in bytesbookmark
- The bytes of the bookmark to ackbookmarkPos
- The starting position in bookmarkbookmarkLen
- The length of the bookmarkoptions
- The bytes of the options for the ackoptionsPos
- The starting position in optionsoptionsLen
- The length of the optionsAMPSException
- An exception occurred while sending a sow_delete
message.protected void _ack(byte[] topic, int topicPos, int topicLen, byte[] bookmark, int bookmarkPos, int bookmarkLen, byte[] options, int optionsPos, int optionsLen) throws AMPSException
AMPSException
public void ack(Field topic, Field bookmark, Field options) throws AMPSException
Field
objects from a message.topic
- The topic to ackbookmark
- The bookmark to ackoptions
- The options for the ackAMPSException
- An error occurred while sending a sow_delete message.public void ack(java.lang.String topic, java.lang.String bookmark, java.lang.String options) throws AMPSException
topic
- The topic to ackbookmark
- The bookmark or comma-delimited bookmark list to ack.options
- The options for the ackAMPSException
- An error occurred while sending a sow_delete message.protected void _ack(Field topic, Field bookmark) throws AMPSException
topic
- The topic to ackbookmark
- The bookmark to ackAMPSException
- An error occurred while sending a sow_delete message.protected void _ack(Field topic, Field bookmark, Field options) throws AMPSException
topic
- The topic to ackbookmark
- The bookmark to ackoptions
- The options for the ackAMPSException
- An error occurred while sending a sow_delete message.public void setAutoAck(boolean isAutoAckEnabled)
isAutoAckEnabled
- true to enable auto-acking; false to disable.
(default: disabled).public boolean getAutoAck()
public void setAckBatchSize(int batchSize)
batchSize
- The batch size to use (default: 1)public int getAckBatchSize()
setAckBatchSize(int)
for more information on this setting.public void setAckTimeout(long ackTimeout)
ackTimeout
- The maximum time in milliseconds to wait to acknowledge
messages, which must be greater than 0 if the ack
batch size is greater than 1.public long getAckTimeout()
public void flushAcks() throws AMPSException
AMPSException
- Thrown when the client is unable to flush
acknowledgements.public java.util.List<java.lang.String> getHttpPreflightHeaders()
public void addHttpPreflightHeader(java.lang.String header)
header
- The header string, e.g. Cookie: a=1; b=2public void addHttpPreflightHeader(java.lang.String key, java.lang.String value)
key
- The key to add to the list of key/value headers used int he HTTP connect request.value
- The value to add to the list of key/value headers used int he HTTP connect request.public void setHttpPreflightHeaders(java.util.List<java.lang.String> headers)
headers
- The new list of key/value headers for HTTP connect request.public void clearHttpPreflightHeaders()
protected MessageHandler getTransportMessageHandler()
protected TransportDisconnectHandler getTransportDisconnectHandler()