|
xmlBlaster 1.6.2 API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
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 |
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()
|
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. |
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). |
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 |
public void registerConnectionListener(I_ConnectionStateListener connectionListener)
connectionListener - null or your listener implementation on connection state changes (ALIVE | POLLING | DEAD)public I_PostSendListener registerPostSendListener(I_PostSendListener postSendListener)
postSendListener - The postSendListener to set, pass null to stop the listener
public 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 requirementpublic void setClientErrorHandler(I_MsgErrorHandler msgErrorHandler)
msgErrorHandler - Your implementation of the error handler.ClientErrorHandler
public 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.
public 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
public 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
public 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 problemspublic I_ClientPlugin getSecurityPlugin()
public 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
public 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.public 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()
public void refreshSession()
throws XmlBlasterException
XmlBlasterException - like ErrorCode.USER_NOT_CONNECTED and otherspublic ConnectReturnQos getConnectReturnQos()
public ConnectQos getConnectQos()
public I_CallbackServer getCbServer()
connect(ConnectQos, I_Callback)public java.lang.String getId()
public SessionName getSessionName()
public java.lang.String getStorageIdStr()
public void setStorageIdStr(java.lang.String prefix)
prefix - For example "toserver1"+sessionName.getRelativeName()public void setServerNodeId(java.lang.String nodeId)
nodeId - For example "/xmlBlaster/node/heron"public java.lang.String getServerNodeId()
public 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 requirement
public SubscribeReturnQos 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 others
public SubscribeReturnQos 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)
public 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 requirement
public MsgUnit[] 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 others
public MsgUnit[] 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
XmlBlasterExceptionContextNode,
engine.qos.queryspec.QueueQuery requirement,
MessageConsumer.receive()
public UnSubscribeReturnQos[] unSubscribe(UnSubscribeKey unSubscribeKey,
UnSubscribeQos unSubscribeQos)
throws XmlBlasterException
unSubscribeKey - Which messages to cancelunSubscribeQos - Control the behavior
XmlBlasterException - like ErrorCode.USER_NOT_CONNECTED and others
public PublishReturnQos publish(MsgUnit msgUnit)
throws XmlBlasterException
publish in interface I_XmlBlasterXmlBlasterException
public void publishOneway(MsgUnit[] msgUnitArr)
throws XmlBlasterException
publishOneway in interface I_XmlBlastermsgUnitArr - The messages to send to the server
XmlBlasterException - like ErrorCode.USER_NOT_CONNECTED and others
public PublishReturnQos[] 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
public 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:
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.
Please note the timeout limitation as described at
receive(String, int, long, boolean))
msgUnit - The request to sendtimeout - 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
public EraseReturnQos[] erase(EraseKey eraseKey,
EraseQos eraseQos)
throws XmlBlasterException
eraseKey - The topics to eraseeraseQos - Control the erase behavior
XmlBlasterException - like ErrorCode.USER_NOT_CONNECTED and otherspublic Global getGlobal()
Enforced by interface I_ConnectionHandler
public java.lang.String toXml()
|
xmlBlaster 1.6.2 API | ||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||