|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.avis.client.Elvin
public final class Elvin
The core class in the Avis client library which manages a client's connection to an Elvin router. Typically a client creates a connection and then subscribes to notifications and/or sends them.
Example:
Elvin elvin = new Elvin ("elvin://elvinhostname"); // subscribe to some notifications elvin.subscribe ("Foo == 42 || begins-with (Bar, 'baz')"); // add a handler for notifications elvin.addSubscriptionListener (new GeneralSubscriptionListener () { public void notificationReceived (GeneralNotificationEvent e) { System.out.println ("Got a notification:\n" + e.notification); } }); // send a notification that we will get back from the router Notification notification = new Notification (); notification.set ("Foo", 42); notification.set ("Bar", "bar"); notification.set ("Data", new byte []{0x00, 0xff}); elvin.send (notification); elvin.close ();
ExecutorService
.
Constructor Summary | |
---|---|
Elvin(ElvinURI routerUri)
Create a new connection to an Elvin router. |
|
Elvin(ElvinURI routerUri,
ConnectionOptions options)
Create a new connection to an Elvin router. |
|
Elvin(ElvinURI routerUri,
ConnectionOptions options,
Keys notificationKeys,
Keys subscriptionKeys)
Create a new connection to an Elvin router. |
|
Elvin(ElvinURI routerUri,
ElvinOptions options)
Create a new connection to an Elvin router. |
|
Elvin(ElvinURI routerUri,
Keys notificationKeys,
Keys subscriptionKeys)
Create a new connection to an Elvin router. |
|
Elvin(String elvinUri)
Create a new connection to an Elvin router. |
|
Elvin(String elvinUri,
ConnectionOptions options)
Create a new connection to an Elvin router. |
|
Elvin(String routerUri,
ElvinOptions options)
Create a new connection to an Elvin router. |
Method Summary | |
---|---|
void |
addCloseListener(CloseListener listener)
Add listener to the close event sent when the client's connection to the router is disconnected. |
void |
addLogListener(ElvinLogListener listener)
Add a listener for log events emitted by the client. |
void |
addNotificationListener(GeneralNotificationListener listener)
Add a listener to all notifications received by all subscriptions of this connection. |
void |
close()
Close the connection to the router. |
void |
closeOnExit()
Signal that this connection should be automatically closed when the VM exits. |
ConnectionOptions |
connectionOptions()
The connection options established with the router. |
boolean |
hasSubscription(Subscription subscription)
Test if a given subscription is part of this connection. |
boolean |
isOpen()
Test if this connection is open i.e. |
long |
livenessTimeout()
|
Object |
mutex()
Return the mutex used to synchronize access to this connection. |
Keys |
notificationKeys()
|
ElvinOptions |
options()
Return the current options for the connection. |
long |
receiveTimeout()
|
void |
removeCloseListener(CloseListener listener)
Remove a previously added close listener. |
void |
removeLogListener(ElvinLogListener listener)
Remove a previously added log listener. |
void |
removeNotificationListener(GeneralNotificationListener listener)
Remove a listener to all notifications received by all subscriptions of this connection. |
ElvinURI |
routerUri()
The router's URI. |
void |
send(Notification notification)
Send a notification. |
void |
send(Notification notification,
Keys keys)
Send a notification with a set of keys but with no requirement for secure delivery: use send (notification,
REQUIRE_SECURE_DELIVERY, keys) if you want only
subscriptions with matching keys to receive a notification. |
void |
send(Notification notification,
Keys keys,
SecureMode secureMode)
Send a notification. |
void |
send(Notification notification,
SecureMode secureMode)
Send a notification with a specified security mode. |
void |
setKeys(Keys newNotificationKeys,
Keys newSubscriptionKeys)
Change the connection-wide keys used to secure the receipt and delivery of notifications. |
void |
setLivenessTimeout(long livenessTimeout)
Set the liveness timeout period (default is 60 seconds). |
void |
setNotificationKeys(Keys newNotificationKeys)
Set the connection-wide notification keys used to secure delivery of notifications. |
void |
setReceiveTimeout(long receiveTimeout)
Set the amount of time that must pass before the router is assumed not to be responding to a request message (default is 10 seconds). |
void |
setSubscriptionKeys(Keys newSubscriptionKeys)
Set the connection-wide subscription keys used to secure receipt of notifications. |
Subscription |
subscribe(String subscriptionExpr)
Create a new subscription. |
Subscription |
subscribe(String subscriptionExpr,
Keys keys)
Create a new subscription with a given set of security keys to enable secure delivery, but also allowing insecure notifications. |
Subscription |
subscribe(String subscriptionExpr,
Keys keys,
SecureMode secureMode)
Create a new subscription. |
Subscription |
subscribe(String subscriptionExpr,
SecureMode secureMode)
Create a new subscription with a given security mode but with an empty key set. |
Keys |
subscriptionKeys()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public Elvin(String elvinUri) throws InvalidURIException, IllegalArgumentException, ConnectException, IOException
elvinUri
- A URI for the Elvin router.
InvalidURIException
- if elvinUri is invalid.
IllegalArgumentException
- if one of the arguments is not
valid.
ConnectException
- if the socket to the router could not be
opened, e.g. connection refused.
IOException
- if a general network error occurs.Elvin(ElvinURI, ConnectionOptions, Keys, Keys)
public Elvin(String elvinUri, ConnectionOptions options) throws InvalidURIException, IllegalArgumentException, ConnectException, IOException
elvinUri
- A URI for the Elvin router.options
- The connection options.
InvalidURIException
- if elvinUri is invalid.
IllegalArgumentException
- if one of the arguments is not
valid.
ConnectException
- if the socket to the router could not be
opened, e.g. connection refused.
IOException
- if a general network error occurs.Elvin(ElvinURI, ConnectionOptions, Keys, Keys)
public Elvin(ElvinURI routerUri) throws IllegalArgumentException, ConnectException, IOException
routerUri
- A URI for the Elvin router.
IllegalArgumentException
- if one of the arguments is not
valid.
ConnectException
- if the socket to the router could not be
opened, e.g. connection refused.
IOException
- if a general network error occurs.Elvin(ElvinURI, ConnectionOptions, Keys, Keys)
public Elvin(ElvinURI routerUri, ConnectionOptions options) throws IllegalArgumentException, ConnectException, IOException, ConnectionOptionsException
routerUri
- A URI for the Elvin router.options
- The connection options.
IllegalArgumentException
- if one of the arguments is not
valid.
ConnectException
- if the socket to the router could not be
opened, e.g. connection refused.
IOException
- if a general network error occurs.
ConnectionOptionsException
- if the router rejects a
connection option.Elvin(ElvinURI, ConnectionOptions, Keys, Keys)
public Elvin(ElvinURI routerUri, Keys notificationKeys, Keys subscriptionKeys) throws IllegalArgumentException, ConnectException, IOException, ConnectionOptionsException
routerUri
- The URI of the router to connect to.notificationKeys
- These keys automatically apply to all
notifications, exactly as if they were added to the keys
in the
send
call.subscriptionKeys
- These keys automatically apply to all
subscriptions, exactly as if they were added to the keys
in the
subscription
call.
IllegalArgumentException
- if one of the arguments is not
valid.
ConnectException
- if a socket to the router could not be
opened, e.g. connection refused.
ConnectionOptionsException
- if the router rejected the
connection options. The client may elect to change the
options and try to create a new connection.
IOException
- if some other IO error occurs.Elvin(ElvinURI, ConnectionOptions, Keys, Keys)
public Elvin(ElvinURI routerUri, ConnectionOptions options, Keys notificationKeys, Keys subscriptionKeys) throws IllegalArgumentException, ConnectException, IOException, ConnectionOptionsException
routerUri
- The URI of the router to connect to.options
- The connection options.notificationKeys
- These keys automatically apply to all
notifications, exactly as if they were added to the keys
in the
send
call.subscriptionKeys
- These keys automatically apply to all
subscriptions, exactly as if they were added to the keys
in the
subscription
call.
IllegalArgumentException
- if one of the arguments is not
valid.
ConnectException
- if a socket to the router could not be
opened, e.g. connection refused.
ConnectionOptionsException
- if the router rejected the
connection options. The client may elect to change the
options and try to create a new connection.
IOException
- if some other IO error occurs.subscribe(String, Keys, SecureMode)
,
send(Notification, Keys, SecureMode)
,
setKeys(Keys, Keys)
public Elvin(String routerUri, ElvinOptions options) throws IllegalArgumentException, ConnectException, IOException, ConnectionOptionsException
routerUri
- The URI of the router to connect to.options
- The Elvin client options. Modifying these after
they have been passed into this constructor has no
effect.
IllegalArgumentException
- if one of the arguments is not
valid.
ConnectException
- if a socket to the router could not be
opened, e.g. connection refused.
ConnectionOptionsException
- if the router rejected the
connection options. The client may elect to
change the options and try to create a new
connection.
IOException
- if some other IO error occurs.subscribe(String, Keys, SecureMode)
,
send(Notification, Keys, SecureMode)
,
setKeys(Keys, Keys)
public Elvin(ElvinURI routerUri, ElvinOptions options) throws IllegalArgumentException, ConnectException, IOException, ConnectionOptionsException
routerUri
- The URI of the router to connect to.options
- The Elvin client options. Modifying these after
they have been passed into this constructor has no
effect.
IllegalArgumentException
- if one of the arguments is not
valid.
ConnectException
- if a socket to the router could not be
opened, e.g. connection refused.
ConnectionOptionsException
- if the router rejected the
connection options. The client may elect to
change the options and try to create a new
connection.
IOException
- if some other IO error occurs.subscribe(String, Keys, SecureMode)
,
send(Notification, Keys, SecureMode)
,
setKeys(Keys, Keys)
Method Detail |
---|
public void close()
close
in interface Closeable
addCloseListener(CloseListener)
public void closeOnExit()
This method is most suitable for small applications that want to create a connection, do something with it, and then cleanly shut down without having to worry about whether the VM exits normally, on Ctrl+C, System.exit (), etc.
public boolean isOpen()
close()
public ElvinURI routerUri()
public ElvinOptions options()
setReceiveTimeout(long)
, setNotificationKeys(Keys)
, etc.
public ConnectionOptions connectionOptions()
options()
,
Elvin(ElvinURI, ConnectionOptions, Keys, Keys)
public long receiveTimeout()
setReceiveTimeout(long)
,
options()
public void setReceiveTimeout(long receiveTimeout)
ElvinOptions.receiveTimeout
.
receiveTimeout
- The new receive timeout in milliseconds.setLivenessTimeout(long)
public long livenessTimeout()
setLivenessTimeout(long)
,
options()
public void setLivenessTimeout(long livenessTimeout)
ElvinOptions.livenessTimeout
.
livenessTimeout
- The new liveness timeout in milliseconds.
Cannot be less than 1000.setReceiveTimeout(long)
public void addCloseListener(CloseListener listener)
close()
, disconnections caused by the remote router
shutting down, and abnormal disconnections caused by
communications errors.
public void removeCloseListener(CloseListener listener)
public void addLogListener(ElvinLogListener listener)
public void removeLogListener(ElvinLogListener listener)
public Object mutex()
subscribe(String, Keys, SecureMode)
.
NB: while this mutex is held, all callbacks (e.g. notification delivery) will be blocked.
public Subscription subscribe(String subscriptionExpr) throws IOException, InvalidSubscriptionException
subscribe(String, Keys, SecureMode)
for details.
subscriptionExpr
- The subscription expression.
IOException
- if an IO error occurs.
InvalidSubscriptionException
- if the subscription expression
is invalid.public Subscription subscribe(String subscriptionExpr, Keys keys) throws IOException, InvalidSubscriptionException
subscribe(String, Keys, SecureMode)
for details.
subscriptionExpr
- The subscription expression.keys
- The keys to add to the subscription.
IOException
- if an IO error occurs.
InvalidSubscriptionException
- if the subscription expression
is invalid.public Subscription subscribe(String subscriptionExpr, SecureMode secureMode) throws IOException, InvalidSubscriptionException
setKeys(Keys, Keys)
or Subscription.setKeys(Keys)
, the subscription will
never be able to receive notifications.
See subscribe(String, Keys, SecureMode)
for more details.
subscriptionExpr
- The subscription expression.secureMode
- The security mode: specifying
REQUIRE_SECURE_DELIVERY means the subscription will only
receive notifications that are sent by clients with keys
matching the set supplied here or the global
subscription key set.
IOException
- if an IO error occurs.
InvalidSubscriptionException
- if the subscription expression
is invalid.public Subscription subscribe(String subscriptionExpr, Keys keys, SecureMode secureMode) throws IOException, InvalidSubscriptionException
See the Elvin Subscription Language page for information on how subscription expressions work.
There exists the possibility that, between creating a subscription and adding a listener to it, the client could miss a notification. If needed, the client may ensure this will not happen by acquiring the connection's mutex before subscribing. e.g.
Elvin elvin = ...; synchronized (elvin.mutex ()) { Subscription sub = elvin.subscribe (...); sub.addNotificationListener (...); }
subscriptionExpr
- The subscription expression to match
notifications.keys
- The keys that must match notificiation keys for
secure delivery.secureMode
- The security mode: specifying
REQUIRE_SECURE_DELIVERY means the subscription will only
receive notifications that are sent by clients with keys
matching the set supplied here or the global
subscription key set.
IOException
- if a network error occurs.
InvalidSubscriptionException
- if the subscription expression
is invalid.send(Notification, Keys, SecureMode)
,
addNotificationListener(GeneralNotificationListener)
,
Subscription
,
Subscription.escapeField(String)
,
Subscription.escapeString(String)
,
SecureMode
,
Keys
public boolean hasSubscription(Subscription subscription)
Subscription.isActive()
public void addNotificationListener(GeneralNotificationListener listener)
removeNotificationListener(GeneralNotificationListener)
,
Subscription.addListener(NotificationListener)
public void removeNotificationListener(GeneralNotificationListener listener)
addNotificationListener(GeneralNotificationListener)
public void send(Notification notification) throws IOException
send(Notification, Keys, SecureMode)
for details.
IOException
public void send(Notification notification, Keys keys) throws IOException
send (notification,
REQUIRE_SECURE_DELIVERY, keys)
if you want only
subscriptions with matching keys to receive a notification.
See send(Notification, Keys, SecureMode)
for more details.
notification
- The notification to send.keys
- The keys to attach to the notification.
IOException
- if an IO error occurs during sending.public void send(Notification notification, SecureMode secureMode) throws IOException
setKeys(Keys, Keys)
or
setNotificationKeys(Keys)
, the notification will never
be able to to be delivered.
See send(Notification, Keys, SecureMode)
for more details.
notification
- The notification to send.secureMode
- The security requirement.
IOException
- if an IO error occurs during sending.public void send(Notification notification, Keys keys, SecureMode secureMode) throws IOException
notification
- The notification to send.keys
- The keys that must match for secure delivery.secureMode
- The security requirement.
REQUIRE_SECURE_DELIVERY means the notification can only
be received by subscriptions with keys matching the set
supplied here (or the connections'
global notification keys).
IOException
- if an IO error occurs.subscribe(String, Keys, SecureMode)
,
Notification
,
SecureMode
,
Keys
public Keys notificationKeys()
setNotificationKeys(Keys)
public void setNotificationKeys(Keys newNotificationKeys) throws IOException
newNotificationKeys
- The new notification keys. These
automatically apply to all notifications, exactly as if
they were added to the keys in the
send
call.
IOException
- if an IO error occurs.setSubscriptionKeys(Keys)
,
setKeys(Keys, Keys)
public Keys subscriptionKeys()
setSubscriptionKeys(Keys)
public void setSubscriptionKeys(Keys newSubscriptionKeys) throws IOException
newSubscriptionKeys
- The new subscription keys. These
automatically apply to all subscriptions, exactly as if
they were added to the keys in the
subscription,
call. This includes currently existing subscriptions.
IOException
- if an IO error occurs.setNotificationKeys(Keys)
,
setKeys(Keys, Keys)
public void setKeys(Keys newNotificationKeys, Keys newSubscriptionKeys) throws IOException
newNotificationKeys
- The new notification keys. These
automatically apply to all notifications, exactly as if
they were added to the keys in the
send
call.newSubscriptionKeys
- The new subscription keys. These
automatically apply to all subscriptions, exactly as if
they were added to the keys in the
subscription,
call. This applies to all existing and future
subscriptions.
IOException
- if an IO error occurs.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |