xmlBlaster 2.1.0 API

org.xmlBlaster.client
Class StreamingCallback

java.lang.Object
  extended by org.xmlBlaster.client.StreamingCallback
All Implemented Interfaces:
I_Callback, I_ConnectionStateListener, I_Timeout

public class StreamingCallback
extends java.lang.Object
implements I_Callback, I_Timeout, I_ConnectionStateListener

StreamingCallback

Author:
Michele Laghi

Nested Class Summary
(package private)  class StreamingCallback.ExecutionThread
           
(package private)  class StreamingCallback.Writer
          Writer needed since the out stream must be written from a thread which does not die before the thread which reads the in counterpart.
 
Field Summary
private  I_StreamingCallback callback
           
private  java.lang.String cbSessionId
           
static java.lang.String ENTRY_CB_SESSION_ID
           
private  XmlBlasterException ex
           
private  Global global
           
private  java.io.PipedInputStream in
           
private  boolean initialized
           
private  boolean lastMessageCompleted
           
private static java.util.logging.Logger log
           
private  java.util.concurrent.locks.ReentrantLock mutex
           
private  java.io.PipedOutputStream out
           
private  I_Queue queue
           
private  java.lang.String ret
           
private  Timeout timer
           
private  Timestamp timestamp
           
private  boolean useQueue
           
private  long waitForChunksTimeout
          The time to wait in ms until returning when waiting (if zero or negative inifinite)
private  StreamingCallback.Writer writer
           
 
Constructor Summary
StreamingCallback(Global global, I_StreamingCallback callback)
           
StreamingCallback(Global global, I_StreamingCallback callback, long waitForChunksTimeout, long waitForClientReturnTimeout, boolean useQueue)
           
 
Method Summary
private  void clearQueue()
           
private  void consumeExceptionIfNotNull()
          returns the exception (if any) and resets it.
private  ClientProperty getProp(java.lang.String key, UpdateQos qos)
           
private  boolean isFirstChunk(UpdateQos qos)
           
private  boolean isLastChunk(UpdateQos qos)
           
 void reachedAlive(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
          This is the callback method invoked from XmlBlasterAccess notifying the client that a connection has been established and that its status is now ALIVE.
 void reachedAliveSync(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
          Invoked when the dispatcher goes to synch again after having delivered entries which where in the queue when the state changed to ALIVE.
 void reachedDead(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
          This is the callback method invoked from XmlBlasterAccess informing the client that the connection was lost (i.e.
 void reachedPolling(ConnectionStateEnum oldState, I_XmlBlasterAccess connection)
          This is the callback method invoked from XmlBlasterAccess informing the client that the connection state has changed to POLLING.
private  void reset()
           
 int sendInitialQueueEntries()
           
private  void setException(java.lang.Throwable ex)
          Always makes a USER_UPDATE_HOLDBACK Exception out of it, no matter what the original exception was.
private  void storeEntry(java.lang.String cbSessId, UpdateKey key, byte[] cont, UpdateQos qos)
           
 void timeout(java.lang.Object userData)
          It is used here to inform the user update method that a timeout occured, it will throw an IOException when reading the in stream of the update method.
 java.lang.String update(java.lang.String cbSessId, UpdateKey updKey, byte[] cont, UpdateQos updQos)
          This is the callback method invoked from I_XmlBlasterAccess informing the client in an asynchronous mode about a new message.
private  java.lang.String updateInternal(java.lang.String cbSessId, UpdateKey updKey, byte[] cont, UpdateQos updQos, boolean isExternal)
           
 java.lang.String updateNewMessage(java.lang.String cbSessId, UpdateKey updKey, byte[] cont, UpdateQos updQos)
           
 java.lang.String updateStraight(java.lang.String cbSessId, UpdateKey updKey, byte[] cont, UpdateQos updQos)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

private static java.util.logging.Logger log

ENTRY_CB_SESSION_ID

public static final java.lang.String ENTRY_CB_SESSION_ID
See Also:
Constant Field Values

callback

private I_StreamingCallback callback

global

private Global global

out

private java.io.PipedOutputStream out

in

private java.io.PipedInputStream in

ex

private XmlBlasterException ex

ret

private java.lang.String ret

cbSessionId

private java.lang.String cbSessionId

writer

private StreamingCallback.Writer writer

waitForChunksTimeout

private long waitForChunksTimeout
The time to wait in ms until returning when waiting (if zero or negative inifinite)


timer

private Timeout timer

timestamp

private Timestamp timestamp

queue

private I_Queue queue

useQueue

private boolean useQueue

initialized

private boolean initialized

lastMessageCompleted

private boolean lastMessageCompleted

mutex

private final java.util.concurrent.locks.ReentrantLock mutex
Constructor Detail

StreamingCallback

public StreamingCallback(Global global,
                         I_StreamingCallback callback)
                  throws XmlBlasterException
Throws:
XmlBlasterException

StreamingCallback

public StreamingCallback(Global global,
                         I_StreamingCallback callback,
                         long waitForChunksTimeout,
                         long waitForClientReturnTimeout,
                         boolean useQueue)
                  throws XmlBlasterException
Parameters:
callback -
Throws:
XmlBlasterException
Method Detail

reset

private void reset()
            throws XmlBlasterException
Throws:
XmlBlasterException

sendInitialQueueEntries

public final int sendInitialQueueEntries()
                                  throws XmlBlasterException
Returns:
the number of delivered entries from local client update queue.
Throws:
XmlBlasterException

storeEntry

private final void storeEntry(java.lang.String cbSessId,
                              UpdateKey key,
                              byte[] cont,
                              UpdateQos qos)
                       throws XmlBlasterException
Throws:
XmlBlasterException

updateStraight

public java.lang.String updateStraight(java.lang.String cbSessId,
                                       UpdateKey updKey,
                                       byte[] cont,
                                       UpdateQos updQos)
                                throws XmlBlasterException,
                                       java.io.IOException
Throws:
XmlBlasterException
java.io.IOException
See Also:
I_Callback.update(java.lang.String, org.xmlBlaster.client.key.UpdateKey, byte[], org.xmlBlaster.client.qos.UpdateQos)

updateNewMessage

public java.lang.String updateNewMessage(java.lang.String cbSessId,
                                         UpdateKey updKey,
                                         byte[] cont,
                                         UpdateQos updQos)
                                  throws XmlBlasterException,
                                         java.io.IOException
Throws:
XmlBlasterException
java.io.IOException
See Also:
I_Callback.update(java.lang.String, org.xmlBlaster.client.key.UpdateKey, byte[], org.xmlBlaster.client.qos.UpdateQos)

isFirstChunk

private final boolean isFirstChunk(UpdateQos qos)

isLastChunk

private final boolean isLastChunk(UpdateQos qos)

getProp

private final ClientProperty getProp(java.lang.String key,
                                     UpdateQos qos)

update

public java.lang.String update(java.lang.String cbSessId,
                               UpdateKey updKey,
                               byte[] cont,
                               UpdateQos updQos)
                        throws XmlBlasterException
Description copied from interface: I_Callback
This is the callback method invoked from I_XmlBlasterAccess informing the client in an asynchronous mode about a new message.

So you should implement in your client code the I_Callback interface - suppling the update() method where you can do with the message whatever you want.

The raw protocol driver specific update() method (e.g. CORBA-BlasterCallback.update()) is unpacked and for each arrived message this update is called.

Specified by:
update in interface I_Callback
Parameters:
cbSessId - The session ID specified by the client which registered the callback. You can specify a cbSessionId during connection (with ConnectQos) and this is bounced back here so you can authenticate the message.
updKey - The arrived key containing the topic name
cont - The arrived message content. This is your payload.
Throws:
XmlBlasterException
See Also:
I_Callback.update(java.lang.String, org.xmlBlaster.client.key.UpdateKey, byte[], org.xmlBlaster.client.qos.UpdateQos)

updateInternal

private final java.lang.String updateInternal(java.lang.String cbSessId,
                                              UpdateKey updKey,
                                              byte[] cont,
                                              UpdateQos updQos,
                                              boolean isExternal)
                                       throws XmlBlasterException
Throws:
XmlBlasterException
See Also:
I_Callback.update(java.lang.String, org.xmlBlaster.client.key.UpdateKey, byte[], org.xmlBlaster.client.qos.UpdateQos)

timeout

public void timeout(java.lang.Object userData)
It is used here to inform the user update method that a timeout occured, it will throw an IOException when reading the in stream of the update method.

Specified by:
timeout in interface I_Timeout
Parameters:
userData - You get bounced back your userData which you passed with Timeout.addTimeoutListener()
See Also:
I_Timeout.timeout(java.lang.Object)

clearQueue

private final void clearQueue()

setException

private void setException(java.lang.Throwable ex)
Always makes a USER_UPDATE_HOLDBACK Exception out of it, no matter what the original exception was.

Parameters:
ex -

consumeExceptionIfNotNull

private void consumeExceptionIfNotNull()
                                throws XmlBlasterException
returns the exception (if any) and resets it.

Throws:
XmlBlasterException

reachedAlive

public void reachedAlive(ConnectionStateEnum oldState,
                         I_XmlBlasterAccess connection)
Description copied from interface: I_ConnectionStateListener
This is the callback method invoked from XmlBlasterAccess notifying the client that a connection has been established and that its status is now ALIVE.

Note that this method is invoked also when the connection has been established the first time. In this case the connection is fully operational but your connect() call has not yet returned. You can access the returned connect QoS in this case with connect.getConnectReturnQos().

You can erase all entries of the queue manually or add others before you return and in this way control the behavior. During you have control in reachedAlive() the client side queue is blocked and does not accept publish or request messages from other threads. So you can do peacefully your work (your thread is allowed to modify the queue exclusively).

If you send messages during this method invocation they are queued only and are sent as soon as this method returns.

This method is invoked by the login polling thread from I_XmlBlasterAccess in which case it is a physical Alive, and by the connect method on successful login in which case it is a logical Alive.

Specified by:
reachedAlive in interface I_ConnectionStateListener
Parameters:
oldState - The previous state of the connection.
See Also:
I_ConnectionStateListener.reachedAlive(org.xmlBlaster.util.dispatch.ConnectionStateEnum, org.xmlBlaster.client.I_XmlBlasterAccess)

reachedAliveSync

public void reachedAliveSync(ConnectionStateEnum oldState,
                             I_XmlBlasterAccess connection)
Description copied from interface: I_ConnectionStateListener
Invoked when the dispatcher goes to synch again after having delivered entries which where in the queue when the state changed to ALIVE. Note that this could take some time or in the worst case it could never been invoked if the queue is never completely processed.

Specified by:
reachedAliveSync in interface I_ConnectionStateListener
Parameters:
oldState - is always ALIVE.
See Also:
I_ConnectionStateListener.reachedAlive(org.xmlBlaster.util.dispatch.ConnectionStateEnum, org.xmlBlaster.client.I_XmlBlasterAccess)

reachedDead

public void reachedDead(ConnectionStateEnum oldState,
                        I_XmlBlasterAccess connection)
Description copied from interface: I_ConnectionStateListener
This is the callback method invoked from XmlBlasterAccess informing the client that the connection was lost (i.e. when the state of the connection has gone to DEAD).

Specified by:
reachedDead in interface I_ConnectionStateListener
Parameters:
oldState - The previous state of the connection.

reachedPolling

public void reachedPolling(ConnectionStateEnum oldState,
                           I_XmlBlasterAccess connection)
Description copied from interface: I_ConnectionStateListener
This is the callback method invoked from XmlBlasterAccess informing the client that the connection state has changed to POLLING.

Specified by:
reachedPolling in interface I_ConnectionStateListener
Parameters:
oldState - The previous state of the connection.

xmlBlaster 2.1.0 API

Copyright © 1999-2011 The xmlBlaster.org contributers.