xmlBlaster 2.2.0 client API

org.xmlBlaster.util.dispatch
Class DispatchConnection

java.lang.Object
  extended by org.xmlBlaster.util.dispatch.DispatchConnection
All Implemented Interfaces:
I_Timeout
Direct Known Subclasses:
ClientDispatchConnection

public abstract class DispatchConnection
extends java.lang.Object
implements I_Timeout

Holding all necessary infos to establish a remote connection and check this connection.

    State chart of a single connection:

          +<--toAlive()----+
          |                |
    #########            ##########         ##########
   #         #          #          #       #          #
   #  ALIVE  #          # POLLING  #       #   DEAD   #
   #         #          #          #       #          #
    #########            ##########         ##########
      |   |                |    |             |    |
      |   +--toPolling()-->+    +--toDead()-->+    |
      |                                            |
      +-------------toDead()---------------------->+

 

Note that DispatchConnection can't recover from DEAD state you need to create a new instance if desired

Author:
xmlBlaster@marcelruff.info, michele@laghi.eu

Field Summary
protected  AddressBase address
           
protected  DispatchConnectionsHandler connectionsHandler
           
protected  Global glob
           
 java.lang.String ME
           
protected  java.lang.String myId
          For logging only
protected  boolean physicalConnectionOk
           
static java.lang.String PING_THREAD_NAME
           
protected  long previousBytesRead
           
protected  long previousBytesWritten
           
protected  int retryCounter
           
protected  boolean serverAcceptsRequests
          Flag if the remote server is reachable but is not willing to process our requests (standby mode).
protected  ConnectionStateEnum state
           
 
Constructor Summary
DispatchConnection(Global glob, DispatchConnectionsHandler connectionsHandler, AddressBase address)
          Our loadPlugin() and initialize() needs to be called next.
 
Method Summary
abstract  void connectLowlevel()
          Connect on protocol layer and try an initial low level ping.
abstract  java.lang.String doPing(java.lang.String data)
          Does the real ping to the remote server instance.
abstract  void doSend(MsgQueueEntry[] msgArr_, boolean isAsyncMode)
          Send the messages.
 void finalize()
           
protected abstract  boolean forcePingFailure()
           
 AddressBase getAddress()
           
abstract  java.lang.String getDriverName()
          A human readable name of the protocol plugin
abstract  java.lang.String getName()
           
 ConnectionStateEnum getState()
           
 void handleTransition(boolean byDispatchConnectionsHandler, java.lang.Throwable throwable)
           
 void initialize()
          Connects on protocol level to the server and tries a ping.
 boolean isAlive()
           
 boolean isConnectionWasDown()
           
 boolean isDead()
           
 boolean isPolling()
           
 boolean isUndef()
           
abstract  void loadPlugin()
          The derived class should create an instance of the protocol driver.
 java.lang.String ping(java.lang.String data)
          Ping the remote server instance (callback of the client or xmlBlaster itself)
protected  java.lang.String ping(java.lang.String data, boolean byDispatchConnectionsHandler)
          Ping the xmlBlaster server or callback server of the client.
protected abstract  void reconnect()
          On reconnect polling try to establish the connection
abstract  I_ProgressListener registerProgressListener(I_ProgressListener listener)
          Should be overwritten by extending classes.
abstract  void resetConnection()
          Called on COMMUNICATION errors, reset protocol driver for reconnect polling
 void send(MsgQueueEntry[] msgArr, boolean isAsyncMode)
          Send the messages back to the client.
 void setAddress(AddressBase address)
           
 void setConnectionWasDown(boolean connectionWasDown)
           
 void shutdown(boolean delayed)
          Stop all remote connections.
protected  void spanPingTimer(long timeout, boolean isPing)
           
 void timeout(java.lang.Object userData)
          We are notified to do the next ping or reconnect polling.
abstract  java.lang.String toXml(java.lang.String extraOffset)
          Dump state of this object into a XML ASCII string.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ME

public final java.lang.String ME

glob

protected final Global glob

PING_THREAD_NAME

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

connectionsHandler

protected DispatchConnectionsHandler connectionsHandler

myId

protected final java.lang.String myId
For logging only


address

protected AddressBase address

state

protected ConnectionStateEnum state

retryCounter

protected int retryCounter

serverAcceptsRequests

protected boolean serverAcceptsRequests
Flag if the remote server is reachable but is not willing to process our requests (standby mode). This flag is only evaluated in POLLING state


physicalConnectionOk

protected boolean physicalConnectionOk

previousBytesWritten

protected long previousBytesWritten

previousBytesRead

protected long previousBytesRead
Constructor Detail

DispatchConnection

public DispatchConnection(Global glob,
                          DispatchConnectionsHandler connectionsHandler,
                          AddressBase address)
Our loadPlugin() and initialize() needs to be called next.

Parameters:
connectionsHandler - The DevliveryConnectionsHandler witch i belong to
address - The address i shall connect to
Method Detail

setAddress

public void setAddress(AddressBase address)
                throws XmlBlasterException
Throws:
XmlBlasterException

getName

public abstract java.lang.String getName()
Returns:
A nice name for logging

initialize

public final void initialize()
                      throws XmlBlasterException
Connects on protocol level to the server and tries a ping. Needs to be called after construction

Calls connectLowLevel() which needs to be implemented by derived classes loadPlugin() needs to be called before.

Called by ClientDispatchConnectionsHandler or CbDispatchConnectionsHandler

Throws:
XmlBlasterException

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

getAddress

public final AddressBase getAddress()

resetConnection

public abstract void resetConnection()
Called on COMMUNICATION errors, reset protocol driver for reconnect polling


loadPlugin

public abstract void loadPlugin()
                         throws XmlBlasterException
The derived class should create an instance of the protocol driver.

Throws:
XmlBlasterException

connectLowlevel

public abstract void connectLowlevel()
                              throws XmlBlasterException
Connect on protocol layer and try an initial low level ping.

Throws:
XmlBlasterException - with ErrorCode.COMMUNICATION* if server is not reachable or other exceptions on other errors

getDriverName

public abstract java.lang.String getDriverName()
A human readable name of the protocol plugin


doSend

public abstract void doSend(MsgQueueEntry[] msgArr_,
                            boolean isAsyncMode)
                     throws XmlBlasterException
Send the messages.

Parameters:
msgArr - Should be a copy of the original, since we export it which changes/encrypts the content. msgArr[i].getReturnObj() transports the returned string array from the client which is decrypted if necessary, for oneway updates it is null
isAsyncMode - true if coming from queue
Throws:
XmlBlasterException

registerProgressListener

public abstract I_ProgressListener registerProgressListener(I_ProgressListener listener)
Should be overwritten by extending classes.


send

public void send(MsgQueueEntry[] msgArr,
                 boolean isAsyncMode)
          throws XmlBlasterException
Send the messages back to the client.

Parameters:
msgArr - Should be a copy of the original, since we export it which changes/encrypts the content
isAsyncMode - true if coming from queue
Throws:
XmlBlasterException

doPing

public abstract java.lang.String doPing(java.lang.String data)
                                 throws XmlBlasterException
Does the real ping to the remote server instance.

Parameters:
data - QoS, never null
Returns:
ping return QoS, never null
Throws:
XmlBlasterException
See Also:
org.xmlBlaster.protocol.I_XmlBlaster#ping(String)

ping

public final java.lang.String ping(java.lang.String data)
                            throws XmlBlasterException
Ping the remote server instance (callback of the client or xmlBlaster itself)

Throws:
XmlBlasterException

ping

protected final java.lang.String ping(java.lang.String data,
                                      boolean byDispatchConnectionsHandler)
                               throws XmlBlasterException
Ping the xmlBlaster server or callback server of the client. Sets serverAcceptsRequests to false if the protocol reaches the remote server but this is in standby mode.

Parameters:
byDispatchConnectionsHandler - true if invoked by DispatchConnectionsHandler we can throw exceptions back. false: If invoked by our timer/ping thread, we need to notify the situation
Throws:
XmlBlasterException

isConnectionWasDown

public boolean isConnectionWasDown()

setConnectionWasDown

public void setConnectionWasDown(boolean connectionWasDown)

reconnect

protected abstract void reconnect()
                           throws XmlBlasterException
On reconnect polling try to establish the connection

Throws:
XmlBlasterException

timeout

public final void timeout(java.lang.Object userData)
We are notified to do the next ping or reconnect polling.

When connected, we ping
When connection is lost, we do reconnect polling

Specified by:
timeout in interface I_Timeout
Parameters:
userData - You get bounced back your userData which you passed with Timeout.addTimeoutListener() here it is "poll" or null

spanPingTimer

protected void spanPingTimer(long timeout,
                             boolean isPing)
                      throws XmlBlasterException
Throws:
XmlBlasterException

handleTransition

public final void handleTransition(boolean byDispatchConnectionsHandler,
                                   java.lang.Throwable throwable)
                            throws XmlBlasterException
Parameters:
toReconnected - If true if the connection is OK (it is a transition to reconnected)
byDispatchConnectionsHandler - true if invoked by DispatchConnectionsHandler, false if invoked by our timer/ping
The - problem, is expected to be not null for toReconnected==false
Throws:
XmlBlasterException - If delivery failed

shutdown

public void shutdown(boolean delayed)
              throws XmlBlasterException
Stop all remote connections.

Throws:
XmlBlasterException

getState

public final ConnectionStateEnum getState()

isUndef

public final boolean isUndef()

isAlive

public final boolean isAlive()

isPolling

public final boolean isPolling()

isDead

public final boolean isDead()

toXml

public abstract java.lang.String toXml(java.lang.String extraOffset)
Dump state of this object into a XML ASCII string.

Parameters:
extraOffset - indenting of tags for nice output
Returns:
internal state as an XML ASCII string

forcePingFailure

protected abstract boolean forcePingFailure()
Returns:
true if the implementation has to throw an exception in case the ping is invoked when there is an ongoing write or read operation on the same connection. Normally it shall give false on the callback and true on the client side. The client side shall give true because otherwise if such a situation arizes it will never go in polling and no reconnect will be triggered.

xmlBlaster 2.2.0 client API

Copyright © 1999-2014 The xmlBlaster.org contributers.