public class ConnectionImpl extends Object implements Connection
| Modifier and Type | Field and Description |
|---|---|
static String |
_CRLF_ |
static String |
_EMPTY_ |
static String |
_ERR_OP_ |
static String |
_INFO_OP_ |
static String |
_MSG_OP_ |
static String |
_OK_OP_ |
static String |
_PING_OP_ |
static String |
_PONG_OP_ |
static String |
_PUB_P_ |
static String |
_SPC_ |
static String |
CONN_PROTO |
static String |
OK_PROTO |
static String |
PING_PROTO |
static String |
PONG_PROTO |
static String |
PUB_PROTO |
Constants.ConnState |
status |
static String |
SUB_PROTO |
static String |
UNSUB_PROTO |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes the connection, also closing all subscriptions on this connection.
|
void |
flush()
Flushes the current connection, waiting up to 60 seconds for completion.
|
void |
flush(int timeout)
Flushes the current connection, waiting up to
timeout for successful completion. |
ClosedCallback |
getClosedCallback()
Returns the connection closed callback.
|
String |
getConnectedServerId()
Returns the unique server ID string of the connected server.
|
io.nats.client.ServerInfo |
getConnectedServerInfo()
Returns the details from the INFO protocol message received.
|
String |
getConnectedUrl()
Returns the URL string of the currently connected NATS server.
|
DisconnectedCallback |
getDisconnectedCallback()
Returns the connection disconnected callback.
|
ExceptionHandler |
getExceptionHandler()
Returns the connection's asynchronous exception callback.
|
Exception |
getLastException()
Returns the last exception registered on the connection.
|
long |
getMaxPayload()
Gets the maximum payload size this connection will accept.
|
int |
getPendingByteCount()
Returns the number of valid bytes in the pending output buffer.
|
ReconnectedCallback |
getReconnectedCallback()
Returns the connection reconnected callback.
|
Constants.ConnState |
getState()
Returns the current connection state.
|
Statistics |
getStats()
Retrieves the connection statistics.
|
boolean |
isClosed()
Indicates whether the connection has been closed.
|
boolean |
isConnected()
Indicates whether the connection is currently reconnecting.
|
boolean |
isReconnecting()
Indicates whether the connection is currently reconnecting.
|
String |
newInbox()
Creates a new, uniquely named inbox with the prefix '_INBOX.'
|
void |
publish(Message msg)
Publishes a message to a subject.
|
void |
publish(String subject,
byte[] data)
Publishes the payload specified by
data to the subject specified by subject. |
void |
publish(String subject,
String reply,
byte[] data)
Publishes the payload specified by
data to the subject specified by subject,
with an optional reply subject. |
Message |
request(String subject,
byte[] data)
Publishes a request message to the specified subject, waiting for a response until one is
available.
|
Message |
request(String subject,
byte[] data,
long timeout)
Publishes a request message to the specified subject, waiting up to
timeout msec for
a response. |
Message |
request(String subject,
byte[] data,
long timeout,
TimeUnit unit) |
void |
resetStats()
Resets the gathered statistics for this connection.
|
void |
setClosedCallback(ClosedCallback cb)
Sets the connection closed callback.
|
void |
setDisconnectedCallback(DisconnectedCallback cb)
Sets the connection disconnected callback.
|
void |
setExceptionHandler(ExceptionHandler exceptionHandler)
Sets the connection's asynchronous exception callback.
|
void |
setReconnectedCallback(ReconnectedCallback cb)
Sets the connection reconnected callback.
|
SyncSubscription |
subscribe(String subject)
Creates a
SyncSubscription with interest in a given subject. |
AsyncSubscription |
subscribe(String subject,
MessageHandler cb)
Creates a
AsyncSubscription with interest in a given subject, assign the callback,
and immediately start receiving messages |
SyncSubscription |
subscribe(String subject,
String queue)
Creates a
SyncSubscription with interest in a given subject. |
AsyncSubscription |
subscribe(String subj,
String queue,
MessageHandler cb)
Creates an asynchronous queue subscriber on a given subject of interest.
|
AsyncSubscription |
subscribeAsync(String subj,
MessageHandler cb)
Deprecated.
|
AsyncSubscription |
subscribeAsync(String subject,
String queue,
MessageHandler cb)
Deprecated.
|
SyncSubscription |
subscribeSync(String subject)
Creates a
SyncSubscription with interest in a given subject. |
SyncSubscription |
subscribeSync(String subject,
String queue)
Creates a synchronous queue subscriber on a given subject of interest.
|
public Constants.ConnState status
public static final String _CRLF_
public static final String _EMPTY_
public static final String _SPC_
public static final String _PUB_P_
public static final String _OK_OP_
public static final String _ERR_OP_
public static final String _MSG_OP_
public static final String _PING_OP_
public static final String _PONG_OP_
public static final String _INFO_OP_
public static final String CONN_PROTO
public static final String PING_PROTO
public static final String PONG_PROTO
public static final String PUB_PROTO
public static final String SUB_PROTO
public static final String UNSUB_PROTO
public static final String OK_PROTO
public void close()
When close() is called, the following things happen, in order:
AutoCloseable.close()public boolean isReconnecting()
public boolean isConnected()
public boolean isClosed()
public void flush(int timeout)
throws Exception
timeout for successful completion.timeout - - the connection timeout in milliseconds.IOException - if a connection-related error prevents the flush from completingTimeoutException - if the connection does not complete within the specified intervalException - if some other error occurspublic void flush()
throws Exception
IOException - if a connection-related issue prevented the flush from completing
successfullyException - if some other error is encounteredflush(int)public SyncSubscription subscribe(String subject)
SyncSubscription with interest in a given subject. In order to receive
messages, call one of the available SyncSubscription.nextMessage().subject - the subject of interestSyncSubscriptionpublic SyncSubscription subscribe(String subject, String queue)
SyncSubscription with interest in a given subject. All subscribers with the
same queue name will form the queue group and only one member of the group will be selected
to receive any given message.subject - the subject of interestqueue - the queue groupSyncSubscriptionpublic AsyncSubscription subscribe(String subject, MessageHandler cb)
AsyncSubscription with interest in a given subject, assign the callback,
and immediately start receiving messagessubject - the subject of interestcb - a MessageHandler object used to process messages received by the
AsyncSubscriptionAsyncSubscriptionpublic AsyncSubscription subscribe(String subj, String queue, MessageHandler cb)
subj - the subject of interestqueue - the name of the queue groupcb - a MessageHandler object used to process messages received by the
SubscriptionSubscription@Deprecated public AsyncSubscription subscribeAsync(String subject, String queue, MessageHandler cb)
AsyncSubscription with interest in a given subject, assign the message
callback, and immediately start receiving messages.subject - the subject of interestqueue - the name of the queue groupcb - a message callback for this subscriptionAsyncSubscription@Deprecated public AsyncSubscription subscribeAsync(String subj, MessageHandler cb)
AsyncSubscription with interest in a given subject, assign the callback,
and immediately start receiving messagessubj - the subject of interestcb - a MessageHandler object used to process messages received by the
AsyncSubscriptionAsyncSubscriptionpublic SyncSubscription subscribeSync(String subject, String queue)
MessageHandler must be registered, and
AsyncSubscription.start() must be called.subject - the subject of interestqueue - the queue groupSyncSubscriptionpublic SyncSubscription subscribeSync(String subject)
SyncSubscription with interest in a given subject. In order to receive
messages, call one of the available SyncSubscription.nextMessage().subject - the subject of interestSyncSubscriptionpublic void publish(String subject, String reply, byte[] data) throws IOException
Connectiondata to the subject specified by subject,
with an optional reply subject. If reply is null, the behavior is identical
to Connection.publish(String, byte[])publish in interface Connectionsubject - the subject to publish the message toreply - the subject to which subscribers should send responsesdata - the message payloadIOException - if an I/O error is encounteredpublic void publish(String subject, byte[] data) throws IOException
Connectiondata to the subject specified by subject.publish in interface Connectionsubject - the subject to publish the message todata - the message payloadIOException - if an I/O error is encounteredpublic void publish(Message msg) throws IOException
ConnectionMessage.setSubject(String)
or the Message.Message(String, String, byte[]) constructor.publish in interface Connectionmsg - the Message to publishIOException - if an I/O error is encounteredpublic Message request(String subject, byte[] data, long timeout, TimeUnit unit) throws TimeoutException, IOException
request in interface ConnectionTimeoutExceptionIOExceptionpublic Message request(String subject, byte[] data, long timeout) throws TimeoutException, IOException
Connectiontimeout msec for
a response.request in interface Connectionsubject - the subject to publish the request message todata - the request message payloadtimeout - how long to wait for a response message (in msec)TimeoutException - if timeout elapses before a message is returnedIOException - if a connection-related error occurspublic Message request(String subject, byte[] data) throws IOException, TimeoutException
Connectionrequest in interface Connectionsubject - the subject to publish the request message todata - the message payloadIOException - if a connection-related error occursTimeoutException - if timeout elapses before a message is returnedpublic String newInbox()
public Statistics getStats()
Statisticspublic void resetStats()
Statisticspublic long getMaxPayload()
public ClosedCallback getClosedCallback()
ClosedCallbackpublic void setClosedCallback(ClosedCallback cb)
cb - the connection closed callback to setpublic DisconnectedCallback getDisconnectedCallback()
public void setDisconnectedCallback(DisconnectedCallback cb)
cb - the disconnected callback to setpublic ReconnectedCallback getReconnectedCallback()
public void setReconnectedCallback(ReconnectedCallback cb)
cb - the reconnect callback to set for this connectionpublic ExceptionHandler getExceptionHandler()
ExceptionHandlerpublic void setExceptionHandler(ExceptionHandler exceptionHandler)
exceptionHandler - the asynchronous exception handler to set for this connectionExceptionHandlerpublic String getConnectedUrl()
public String getConnectedServerId()
public Constants.ConnState getState()
Constants.ConnStatepublic io.nats.client.ServerInfo getConnectedServerInfo()
ServerInfopublic Exception getLastException()
public int getPendingByteCount()
Copyright © 2015-2016 Apcera, Inc.. All Rights Reserved.