|
xmlBlaster 2.2.0 client API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface I_XmlBlasterAccess
The Java client side access to xmlBlaster.
This interface hides a remote connection or a native connection to the server.
Method Summary | |
---|---|
ConnectReturnQos |
connect(ConnectQos qos,
I_Callback updateListener)
Login to xmlBlaster. |
SynchronousCache |
createSynchronousCache(int size)
Setup the cache mode. |
boolean |
disconnect(DisconnectQos disconnectQos)
Logout from the server. |
EraseReturnQos[] |
erase(EraseKey eraseKey,
EraseQos eraseQos)
|
MsgUnit[] |
get(GetKey getKey,
GetQos getQos)
Get synchronous messages. |
MsgUnit[] |
getCached(GetKey getKey,
GetQos getQos)
Access synchronously messages. |
I_CallbackServer |
getCbServer()
Access the callback server which is currently used in I_XmlBlasterAccess. |
ConnectQos |
getConnectQos()
Access the current ConnectQos. |
ConnectReturnQos |
getConnectReturnQos()
Access the returned QoS of a connect() call. |
Global |
getGlobal()
Access the environment settings of this connection. |
java.lang.String |
getId()
A unique name for this client, for logging only |
org.xmlBlaster.authentication.plugins.I_ClientPlugin |
getSecurityPlugin()
Access the client side security plugin. |
java.lang.String |
getServerNodeId()
The cluster node id (name) to which we want to connect. |
SessionName |
getSessionName()
The public session ID of this login session. |
java.lang.String |
getStorageIdStr()
|
java.lang.Object |
getUserObject()
Can be freely used by client code to store an object and later retrieve it. |
I_CallbackServer |
initCbServer(java.lang.String loginName,
CallbackAddress callbackAddress)
Create a new instance of the desired protocol driver like CORBA or RMI driver using the plugin loader. |
boolean |
isConnected()
Has the connect() method successfully passed? |
void |
leaveServer(java.util.Map map)
Leaves the connection to the server and cleans up the client side resources without making a server side disconnect. |
void |
ping()
Force a async ping to re-check connection to server. |
PublishReturnQos |
publish(MsgUnit msgUnit)
|
void |
publishOneway(MsgUnit[] msgUnitArr)
Publish messages. |
PublishReturnQos[] |
publishStream(java.io.InputStream is,
MsgKeyData keyData,
MsgQosData qosData,
int maxBufSize,
I_ReplaceContent contentReplacer)
Publishes one message in streaming manner, if the message content is too big to fit in one single chunk, the message is split in several smaller messages (called chunks) and these are published. |
MsgUnit[] |
receive(java.lang.String oid,
int maxEntries,
long timeout,
boolean consumable)
This method synchronously accesses maxEntries messages from any xmlBlaster server side queue. |
void |
refreshSession()
Send an event to xmlBlaster to refresh the login session life time. |
void |
registerConnectionListener(I_ConnectionStateListener connectionListener)
Register a listener to get events about connection status changes. |
I_PostSendListener |
registerPostSendListener(I_PostSendListener postSendListener)
Register a listener to get notifications when a messages is successfully send from the client side tail back queue. |
MsgUnit[] |
request(MsgUnit msgUnit,
long timeout,
int maxEntries)
Implements the blocking request/reply pattern. |
java.lang.String |
sendAdministrativeCommand(java.lang.String command)
Convenience method to send an administrative command to xmlBlaster. |
void |
setCallbackDispatcherActive(boolean activate)
Switch callback dispatcher on/off. |
void |
setClientErrorHandler(I_MsgErrorHandler msgErrorHandler)
Use a specific error handler instead of the default one. |
void |
setServerNodeId(java.lang.String nodeId)
Allows to set the node name for nicer logging. |
void |
setStorageIdStr(java.lang.String prefix)
Allows to set a unique client side queue name (connection queue). |
void |
setUserObject(java.lang.Object userObject)
Can be freely used by client code to store an object and later retrieve it. |
SubscribeReturnQos |
subscribe(java.lang.String xmlKey,
java.lang.String xmlQos,
I_Callback cb)
Subscribe to messages. |
SubscribeReturnQos |
subscribe(SubscribeKey subscribeKey,
SubscribeQos subscribeQos)
Subscribe to messages. |
SubscribeReturnQos |
subscribe(SubscribeKey subscribeKey,
SubscribeQos subscribeQos,
I_Callback cb)
This subscribe variant allows to specify a specialized callback for updated messages. |
java.lang.String |
toXml()
Dump state of this client connection handler into an XML ASCII string. |
UnSubscribeReturnQos[] |
unSubscribe(UnSubscribeKey unSubscribeKey,
UnSubscribeQos unSubscribeQos)
Cancel subscription. |
Methods inherited from interface org.xmlBlaster.client.protocol.I_XmlBlaster |
---|
erase, get, publishArr, subscribe, unSubscribe |
Methods inherited from interface org.xmlBlaster.client.I_ConnectionHandler |
---|
getQueue, getState, isAlive, isDead, isPolling |
Method Detail |
---|
void registerConnectionListener(I_ConnectionStateListener connectionListener)
connectionListener
- null or your listener implementation on connection state changes (ALIVE | POLLING | DEAD)I_PostSendListener registerPostSendListener(I_PostSendListener postSendListener)
postSendListener
- The postSendListener to set, pass null to stop the listener
SynchronousCache createSynchronousCache(int size)
size
- Size of the cache. This number specifies the count of subscriptions the cache
can hold. It specifies NOT the number of messages.
getCached(GetKey, GetQos)
,
client.cache requirementvoid setClientErrorHandler(I_MsgErrorHandler msgErrorHandler)
msgErrorHandler
- Your implementation of the error handler.ClientErrorHandler
ConnectReturnQos connect(ConnectQos qos, I_Callback updateListener) throws XmlBlasterException
Connecting with the default configuration (which checks xmlBlaster.properties and your command line arguments):
import org.xmlBlaster.util.Global; ... I_XmlBlasterAccess xmlBlasterAccess = glob.getXmlBlasterAccess(); xmlBlasterAccess.connect(null, null);
The default behavior is to poll automatically for the server if it is not found. As we have not specified a listener for returned messages from the server there is no callback server created.
This example shows how to configure different behavior:
// Example how to configure fail safe settings ConnectQos connectQos = new ConnectQos(glob); Address address = new Address(glob); address.setDelay(4000L); // retry connecting every 4 sec address.setRetries(-1); // -1 == forever address.setPingInterval(0L); // switched off addr.setType("SOCKET"); // don't use CORBA protocol, but use SOCKET instead connectQos.setAddress(address); CallbackAddress cbAddress = new CallbackAddress(glob); cbAddress.setDelay(4000L); // retry connecting every 4 sec cbAddress.setRetries(-1); // -1 == forever cbAddress.setPingInterval(4000L); // ping every 4 seconds connectQos.addCallbackAddress(cbAddress); xmlBlasterAccess.connect(connectQos, new I_Callback() { public String update(String cbSessionId, UpdateKey updateKey, byte[] content, UpdateQos updateQos) { if (updateKey.isInternal()) { return ""; } if (updateQos.isErased()) { return ""; } log.info(ME, "Receiving asynchronous message '" + updateKey.getOid() + "' state=" + updateQos.getState() + " in default handler"); return ""; } }); // Login to xmlBlaster, default handler for updates;
qos
- Your configuration desireupdateListener
- If not null a callback server will be created and
callback messages will be routed to your updateListener.update() method.
XmlBlasterException
- only if connection state is DEAD, typically thrown on wrong configurations.
You must call connect again with different settings.I_CallbackServer initCbServer(java.lang.String loginName, CallbackAddress callbackAddress) throws XmlBlasterException
Note that the returned instance is of your control only, we don't cache it in any way, this method is only a helper hiding the plugin loading.
loginName
- A nice name for logging purposescallbackAddress
- The callback address configuration, contains for example
type like "IOR" or "RMI" and version of the driver, e.g. "1.0"
XmlBlasterException
void setCallbackDispatcherActive(boolean activate) throws XmlBlasterException
activate
- true: XmlBlaster server delivers callback messages
false: XmlBlaster server keeps messages for this client in the callback queue
XmlBlasterException
java.lang.String sendAdministrativeCommand(java.lang.String command) throws XmlBlasterException
command
- for example "client/joe/?dispatcherActive" (a getter) or "client/joe/?dispatcherActive=false" (a setter).
The "__cmd:" is added by us
To enforce a getter or setter you can write "get client/joe/?dispatcherActive" or
"set client/joe/?dispatcherActive=false"
XmlBlasterException
- on problemsorg.xmlBlaster.authentication.plugins.I_ClientPlugin getSecurityPlugin()
boolean disconnect(DisconnectQos disconnectQos)
leaveServer(null)
and throw the xmlBlasterAccess instance away.
This is often the case if the client disappears and at a later point wants
to reconnect. On server side the queue for this session remains alive and
collects messages.
If '-dispatch/connection/doSendConnect false' was set call disconnect() nevertheless
to cleanup client side resources.
disconnectQos
- Describe the desired behavior on disconnect
void leaveServer(java.util.Map map)
As the login session on server side stays alive, all subscriptions stay valid and callback messages are queued by the server. If you connect at a later time the server sends us all queued messages.
Once you have called this method the I_XmlBlasterAccess becomes invalid and any further invocation results in an XmlBlasterException to be thrown.
map
- The properties to pass while leaving server.
Currently this argument has no effect. You can
pass null as a parameter.boolean isConnected()
Note that this contains no information about the current connection state of the protocol layer.
I_ConnectionHandler.isAlive()
,
I_ConnectionHandler.isPolling()
,
I_ConnectionHandler.isDead()
void refreshSession() throws XmlBlasterException
XmlBlasterException
- like ErrorCode.USER_NOT_CONNECTED and othersConnectReturnQos getConnectReturnQos()
ConnectQos getConnectQos()
I_CallbackServer getCbServer()
connect(ConnectQos, I_Callback)
java.lang.String getId()
SessionName getSessionName()
java.lang.String getStorageIdStr()
void setStorageIdStr(java.lang.String prefix)
prefix
- For example "toserver1"+sessionName.getRelativeName()void setServerNodeId(java.lang.String nodeId)
nodeId
- For example "/xmlBlaster/node/heron"java.lang.String getServerNodeId()
SubscribeReturnQos subscribe(SubscribeKey subscribeKey, SubscribeQos subscribeQos) throws XmlBlasterException
The messages are delivered asynchronous with the update() method.
subscribeKey
- Which message topics to retrievesubscribeQos
- Control the behavior and further filter messages with mime based filter plugins
XmlBlasterException
- like ErrorCode.USER_NOT_CONNECTED and othersI_Callback.update(String, org.xmlBlaster.client.key.UpdateKey, byte[], org.xmlBlaster.client.qos.UpdateQos)
,
interface.subscribe requirementSubscribeReturnQos subscribe(SubscribeKey subscribeKey, SubscribeQos subscribeQos, I_Callback cb) throws XmlBlasterException
XmlBlasterAccess con = ... // login etc. ... SubscribeKey key = new SubscribeKey(glob, "//stock", "XPATH"); SubscribeQos qos = new SubscribeQos(glob); try { con.subscribe(key, qos, new I_Callback() { public String update(String name, UpdateKey updateKey, byte[] content, UpdateQos updateQos) { System.out.println("Receiving message for '//stock' subscription ..."); return ""; } }); } catch(XmlBlasterException e) { System.out.println(e.getMessage()); }NOTE: You need to pass a callback handle on login as well (even if you never use it). It allows to setup the callback server and is the default callback deliver channel for PtP messages. NOTE: On logout we automatically unSubscribe() this subscription if not done before.
cb
- Your callback handling implementation
XmlBlasterException
- like ErrorCode.USER_NOT_CONNECTED and othersSubscribeReturnQos subscribe(java.lang.String xmlKey, java.lang.String xmlQos, I_Callback cb) throws XmlBlasterException
xmlKey
- Which message topics to retrievexmlQos
- Control the behavior and further filter messages with mime based filter plugins
XmlBlasterException
- like ErrorCode.USER_NOT_CONNECTED and otherssubscribe(SubscribeKey, SubscribeQos, I_Callback)
MsgUnit[] getCached(GetKey getKey, GetQos getQos) throws XmlBlasterException
A typical use case is a servlet which receives many HTML requests and usually the message has not changed. This way we avoid asking xmlBlaster every time for the information but take it directly from the cache.
The cache is always up to date as it has subscribed on this topic
You need to call createSynchronousCache() before using getCached().
NOTE: Passing two similar getKey but with different getQos filters is currently not supported.
NOTE: GetKey requests with EXACT oid are automatically removed from cache when the topic with this oid is erased. XPATH queries are removed from cache when the last topic oid which matched the XPATH disappears.
getKey
- Which message topics to retrievegetQos
- Control the behavior and further filter messages with mime based filter plugins
XmlBlasterException
- if createSynchronousCache() was not used to establish a cache first
XmlBlasterException
- like ErrorCode.USER_NOT_CONNECTED and otherscreateSynchronousCache(int)
,
client.cache requirementMsgUnit[] get(GetKey getKey, GetQos getQos) throws XmlBlasterException
getKey
- Which message topics to retrievegetQos
- Control the behavior and further filter messages with mime based filter plugins
XmlBlasterException
- like ErrorCode.USER_NOT_CONNECTED and othersMsgUnit[] receive(java.lang.String oid, int maxEntries, long timeout, boolean consumable) throws XmlBlasterException
This is a convenience method which uses get() with a specific Qos.
Important note:
Currently you shouldn't use unlimited timeout==-1 as this could
lead to a server side thread leak on client disconnect.
As a workaround please use a loop and a timeout of for example 60000
and just ignore returned arrays of length 0.
oid
- The identifier like
"topic/hello" to access a history queue,
"client/joe" to access a subject queue or
"client/joe/session/1"
to access a callback queue.
The string must follow the formatting rule of ContextNode.javamaxEntries
- The maximum number of entries to retrievetimeout
- The time to wait until return.
If you choose a negative value it will block until the maxEntries
has been reached.
If the value is '0' (i.e. zero) it will not wait and will correspond to a non-blocking get.
If the value is positive it will block until the specified amount in milliseconds
has elapsed or when the maxEntries has been reached (whichever comes first).consumable
- Expressed with 'true' or 'false'.
If true the entries returned are deleted from the queue
XmlBlasterException
ContextNode
,
engine.qos.queryspec.QueueQuery requirement,
MessageConsumer.receive()
UnSubscribeReturnQos[] unSubscribe(UnSubscribeKey unSubscribeKey, UnSubscribeQos unSubscribeQos) throws XmlBlasterException
unSubscribeKey
- Which messages to cancelunSubscribeQos
- Control the behavior
XmlBlasterException
- like ErrorCode.USER_NOT_CONNECTED and othersPublishReturnQos publish(MsgUnit msgUnit) throws XmlBlasterException
publish
in interface I_XmlBlaster
XmlBlasterException
void publishOneway(MsgUnit[] msgUnitArr) throws XmlBlasterException
publishOneway
in interface I_XmlBlaster
msgUnitArr
- The messages to send to the server
XmlBlasterException
- like ErrorCode.USER_NOT_CONNECTED and othersPublishReturnQos[] publishStream(java.io.InputStream is, MsgKeyData keyData, MsgQosData qosData, int maxBufSize, I_ReplaceContent contentReplacer) throws XmlBlasterException
is
- The input stream from which to read the input data.keyData
- The key for the message (same for all chunks)qosData
- The qos for all messages (same for all chunks besides internal stuff added in this method)maxBufSize
- The maximum content size of each chunk.contentReplacer
- an optional content replacer (i.e. a modifier of the content) can be null.
XmlBlasterException
MsgUnit[] request(MsgUnit msgUnit, long timeout, int maxEntries) throws XmlBlasterException
The msgUnit should contain a PublishQos which routes the request
to the desired client, for example sending it to client joe
and its login session 1
or sending it to a topic which was subscribed
by the destination client:
import org.xmlBlaster.util.qos.address.Destination; import org.xmlBlaster.client.qos.PublishQos; ... Global glob = ...; ... PublishQos pq = new PublishQos(glob); Destination dest = new Destination(glob, new SessionName(glob, "joe/1")); dest.forceQueuing(true); pq.addDestination(dest);
This receiver needs to send the response to the topic oid as passed with the client property "__jms:JMSReplyTo":
String tempTopicOid = updateQos.getClientProperty(Constants.JMS_REPLY_TO, ""); // Send reply back ... PublishKey pk = new PublishKey(glob, tempTopicOid); ...
This approach is similar to the JMS approach for request/reply (TopicRequestor.java) but we have the choice to send the msgUnit directly to another client or to a topic (as JMS), and we can handle multiple replies for one request.
The feature is implemented on client side with a temporary response topic and a receive()
call.
The temporary response topic is erased after the response has arrived.
You can optionally add a clientProperty "__responseTopicIdPrefix", this topicId is
used as a prefix for the temporary response topicId. the given prefix must be unique
between clients. This is thread safe.
A use case could be to simplify detecting the topic for an authorizer plugin.
You can optionally add a clientProperty "__responseTopicId" with a unique topicId
to avoid the creation of temporary response topics, note that this feature
is NOT thread safe, the client may only send one request() at a time.
The response topic will live for one day after last usage.
A reason to do so could be the better performance (avoid short living temporary response topics).
Please note the timeout limitation as described at
receive(String, int, long, boolean)
)
msgUnit
- The request to send. The topicId may be any you wish for the receiver to recognize.
If the receiver has not subsribed on this topicId you need to send it PtP (add the Destination client).timeout
- The milliseconds to block, 0 is none blocking, -1 blocks forevermaxEntries
- The maximum number of entries to deliver or return with less after timeout
XmlBlasterException
EraseReturnQos[] erase(EraseKey eraseKey, EraseQos eraseQos) throws XmlBlasterException
eraseKey
- The topics to eraseeraseQos
- Control the erase behavior
XmlBlasterException
- like ErrorCode.USER_NOT_CONNECTED and othersvoid ping()
Global getGlobal()
Enforced by interface I_ConnectionHandler
java.lang.String toXml()
java.lang.Object getUserObject()
void setUserObject(java.lang.Object userObject)
userObject
- any user object
|
xmlBlaster 2.2.0 client API | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |