xmlBlaster 2.2.0 API

org.xmlBlaster.util.protocol
Class RequestReplyExecutor

java.lang.Object
  extended by org.xmlBlaster.util.protocol.RequestReplyExecutor
All Implemented Interfaces:
I_AdminPlugin, I_AdminUsage, RequestReplyExecutorMBean
Direct Known Subclasses:
EmailExecutor, SocketExecutor

public abstract class RequestReplyExecutor
extends java.lang.Object
implements RequestReplyExecutorMBean

Request/reply simulates a local method invocation.

A common base class for socket or email based messaging. Allows to block during a request and deliver the return message to the waiting thread.

Author:
Marcel Ruff.
See Also:
xmlBlaster SOCKET access protocol, xmlBlaster EMAIL access protocol

Nested Class Summary
private  class RequestReplyExecutor.LatchHolder
           
 
Field Summary
protected  AddressBase addressConfig
           
protected  AddressServer addressServer
           
protected  I_CallbackExtended cbClient
          This is the client side
protected  boolean compressZlib
           
protected  boolean compressZlibStream
           
protected  ContextNode contextNode
           
protected  Global glob
           
private  java.util.Set latchSet
          A set containing LatchHolder instances
private static java.util.logging.Logger log
           
protected  java.lang.Object mbeanHandle
          My JMX registration, can be done optionally by implementing classes
private  java.lang.String ME
           
protected  int minSizeForCompression
           
static boolean ONEWAY
          Used for execute()
protected  long pingResponseTimeout
          How long to block on remote call waiting on ping responses
protected  java.lang.String prefix
          The prefix to create a unique requestId namspace (is set to the loginName)
protected  I_ProgressListener progressListener
          A listener may register to receive send/receive progress informations
protected  java.util.Map responseListenerMap
          For listeners who want to be informed about return messages or exceptions, the invocation is blocking during this period.
private  boolean responseListenerMapWasCleared
           
protected  long responseTimeout
          How long to block on remote call waiting on response
protected  long updateResponseTimeout
          How long to block on remote call waiting on update responses
protected  boolean useEmailExpiryTimestamp
           
static boolean WAIT_ON_RESPONSE
          Used for execute()
private  I_XmlBlaster xmlBlasterImpl
          The singleton handle for this xmlBlaster server (the server side)
 
Constructor Summary
RequestReplyExecutor()
           
 
Method Summary
private  RequestReplyExecutor.LatchHolder addLatch(java.util.concurrent.CountDownLatch latch)
           
 void addResponseListener(java.lang.String requestId, I_ResponseListener l)
          Adds the listener to receive response/exception events.
 void clearResponseListenerMap()
           
protected  void executeException(MsgInfo receiver, XmlBlasterException e, boolean udp)
          Send a one way exception back to the other side
protected  void executeResponse(MsgInfo receiver, java.lang.Object response, boolean udp)
          Send a one way response message back to the other side
 void freePendingThreads()
          If we detect somewhere that the socket is down use this method to free blocking threads which wait on responses
 AddressServer getAddressServer()
           
 I_CallbackExtended getCbClient()
           
 long getDefaultPingResponseTimeout()
          How long to block on remote call waiting on a ping response.
 long getDefaultResponseTimeout()
          How long to block on remote call waiting on response.
 long getDefaultUpdateResponseTimeout()
          How long to block on remote call waiting on a update() response.
 java.sql.Timestamp getExpiryTimestamp(MethodName methodName)
          Return the time in future when the email can be deleted.
private  RequestReplyExecutor.LatchHolder[] getLatches()
           
 int getMinSizeForCompression()
          Compressing too small messages won't reduce the size
 java.lang.String getPendingRequestList()
          For logging only
 long getPingResponseTimeout()
          The invocation timeout for "ping" method calls.
 I_ProgressListener getProgressListener()
           
 I_ResponseListener getResponseListener(java.lang.String requestId)
          Get the response listener object
 long getResponseTimeout()
          The invocation timeout for all remaining method calls like "publish", "connect", "subscribe" but NOT for "ping" and "update"
 long getResponseTimeout(MethodName methodName)
           
 long getResponseTimeout(java.lang.String methodName)
          Access the timeout for method invocation.
 java.lang.String getResponseTimeoutPropertyName(MethodName methodName)
          For logging.
abstract  java.lang.String getType()
          The protocol type, used for logging
 long getUpdateResponseTimeout()
           
 I_XmlBlaster getXmlBlasterCore()
           
protected  boolean hasConnection()
           
protected  void initialize(Global glob, AddressBase addressConfig)
          Used by SocketCallbackImpl on client side, uses I_CallbackExtended to invoke client classes

Used by HandleClient on server side, uses I_XmlBlaster to invoke xmlBlaster core

This executor has mixed client and server specific code for two reasons:
- Possibly we can use the same socket between two xmlBlaster server (load balance)
- Everything is together

protected  void initializeCb(AddressBase addressConfig)
           
 int interruptInvocation()
          Interrupts a blocking request with a not returning reply.
 boolean isCompressZlib()
           
 boolean isCompressZlibStream()
           
 boolean isShutdown()
          Check status
 boolean isShutdownCompletly()
           
 boolean isUseEmailExpiryTimestamp()
           
 boolean receiveReply(MsgInfo receiver, boolean udp)
          Handle common messages
 I_ProgressListener registerProgressListener(I_ProgressListener listener)
           
private  void removeLatch(RequestReplyExecutor.LatchHolder latchHolder)
           
 void removeResponseListener(java.lang.String requestId)
          Removes the specified listener.
 java.lang.Object requestAndBlockForReply(MsgInfo msgInfo, boolean expectingResponse, boolean udp)
          Send a message and block until the response arrives.
protected abstract  void sendMessage(MsgInfo msgInfo, java.lang.String requestId, MethodName methodName, boolean udp)
          Flush the data to the protocol layer (socket, email, ...).
 void setCbClient(I_CallbackExtended cbClient)
           
 void setCompressZlib(boolean compress)
           
 void setCompressZlibStream(boolean compress)
           
protected  void setLoginName(java.lang.String loginName)
          Sets the loginName and automatically the requestId as well
 void setMinSizeForCompression(int minSizeForCompression)
           
 void setPingResponseTimeout(long millis)
          Set the given millis to protect against blocking client for ping invocations.
 void setResponseTimeout(long millis)
          Set the given millis to protect against blocking client.
 void setUpdateResponseTimeout(long millis)
          Set the given millis to protect against blocking client for update() invocations.
 void setUseEmailExpiryTimestamp(boolean useEmailExpiryTimestamp)
           
 void setXmlBlasterCore(I_XmlBlaster xmlBlaster)
           
 void shutdown()
          Shutdown the plugin, free resources.
 java.lang.String usage()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.xmlBlaster.util.admin.I_AdminPlugin
getVersion
 
Methods inherited from interface org.xmlBlaster.util.admin.I_AdminUsage
getUsageUrl, setUsageUrl
 

Field Detail

ME

private java.lang.String ME

glob

protected Global glob

log

private static java.util.logging.Logger log

prefix

protected java.lang.String prefix
The prefix to create a unique requestId namspace (is set to the loginName)


responseTimeout

protected long responseTimeout
How long to block on remote call waiting on response


pingResponseTimeout

protected long pingResponseTimeout
How long to block on remote call waiting on ping responses


updateResponseTimeout

protected long updateResponseTimeout
How long to block on remote call waiting on update responses


cbClient

protected I_CallbackExtended cbClient
This is the client side


xmlBlasterImpl

private I_XmlBlaster xmlBlasterImpl
The singleton handle for this xmlBlaster server (the server side)


latchSet

private final java.util.Set latchSet
A set containing LatchHolder instances


addressConfig

protected AddressBase addressConfig

addressServer

protected AddressServer addressServer

progressListener

protected I_ProgressListener progressListener
A listener may register to receive send/receive progress informations


minSizeForCompression

protected int minSizeForCompression

compressZlib

protected boolean compressZlib

compressZlibStream

protected boolean compressZlibStream

useEmailExpiryTimestamp

protected boolean useEmailExpiryTimestamp

responseListenerMap

protected final java.util.Map responseListenerMap
For listeners who want to be informed about return messages or exceptions, the invocation is blocking during this period.

The key is the String requestId, the value the listener thread I_ResponseListener


responseListenerMapWasCleared

private boolean responseListenerMapWasCleared

ONEWAY

public static final boolean ONEWAY
Used for execute()

See Also:
Constant Field Values

WAIT_ON_RESPONSE

public static final boolean WAIT_ON_RESPONSE
Used for execute()

See Also:
Constant Field Values

mbeanHandle

protected java.lang.Object mbeanHandle
My JMX registration, can be done optionally by implementing classes


contextNode

protected ContextNode contextNode
Constructor Detail

RequestReplyExecutor

public RequestReplyExecutor()
Method Detail

initialize

protected void initialize(Global glob,
                          AddressBase addressConfig)
Used by SocketCallbackImpl on client side, uses I_CallbackExtended to invoke client classes

Used by HandleClient on server side, uses I_XmlBlaster to invoke xmlBlaster core

This executor has mixed client and server specific code for two reasons:
- Possibly we can use the same socket between two xmlBlaster server (load balance)
- Everything is together

Parameters:
addressConfig - The configuration to use

initializeCb

protected void initializeCb(AddressBase addressConfig)

getAddressServer

public AddressServer getAddressServer()

getType

public abstract java.lang.String getType()
The protocol type, used for logging

Specified by:
getType in interface I_AdminPlugin
Returns:
"SOCKET" or "EMAIL", never null

registerProgressListener

public I_ProgressListener registerProgressListener(I_ProgressListener listener)

getProgressListener

public final I_ProgressListener getProgressListener()

getDefaultResponseTimeout

public long getDefaultResponseTimeout()
How long to block on remote call waiting on response. The default is to block forever (Integer.MAX_VALUE) Changed after xmlBlaster release 1.0.7 (before it was one minute: Constants.MINUTE_IN_MILLIS) Can be overwritten by implementations like EMAIL


getDefaultPingResponseTimeout

public long getDefaultPingResponseTimeout()
How long to block on remote call waiting on a ping response. The default is to block for one minute This method can be overwritten by implementations like EMAIL


getDefaultUpdateResponseTimeout

public long getDefaultUpdateResponseTimeout()
How long to block on remote call waiting on a update() response. The default is to block forever This method can be overwritten by implementations like EMAIL


setResponseTimeout

public final void setResponseTimeout(long millis)
Set the given millis to protect against blocking client.

Specified by:
setResponseTimeout in interface RequestReplyExecutorMBean
Parameters:
millis - If <= 0 it is set to the default (forever). An argument less than or equal to zero means not to wait at all and is not supported

setPingResponseTimeout

public final void setPingResponseTimeout(long millis)
Set the given millis to protect against blocking client for ping invocations.

Specified by:
setPingResponseTimeout in interface RequestReplyExecutorMBean
Parameters:
millis - If <= 0 it is set to the default (one minute). An argument less than or equal to zero means not to wait at all and is not supported

setUpdateResponseTimeout

public final void setUpdateResponseTimeout(long millis)
Set the given millis to protect against blocking client for update() invocations.

Specified by:
setUpdateResponseTimeout in interface RequestReplyExecutorMBean
Parameters:
millis - If <= 0 it is set to the default (one minute). An argument less than or equal to zero means not to wait at all and is not supported

getResponseTimeout

public long getResponseTimeout(MethodName methodName)
Returns:
Returns the responseTimeout.

getResponseTimeout

public long getResponseTimeout(java.lang.String methodName)
Access the timeout for method invocation.

Specified by:
getResponseTimeout in interface RequestReplyExecutorMBean
Parameters:
methodName - e.g. "PING", "UPDATE", "SUBSCRIBE", "PUBLISH", ...
Returns:
Returns the responseTimeout for JMX in milli seconds

getExpiryTimestamp

public java.sql.Timestamp getExpiryTimestamp(MethodName methodName)
Return the time in future when the email can be deleted.

Returns:
Returns the expiry timestamp, is null if message never expires

getResponseTimeoutPropertyName

public java.lang.String getResponseTimeoutPropertyName(MethodName methodName)
For logging.

Parameters:
methodName -
Returns:

setCbClient

public final void setCbClient(I_CallbackExtended cbClient)

setXmlBlasterCore

public final void setXmlBlasterCore(I_XmlBlaster xmlBlaster)

getXmlBlasterCore

public final I_XmlBlaster getXmlBlasterCore()

getCbClient

public final I_CallbackExtended getCbClient()

setLoginName

protected void setLoginName(java.lang.String loginName)
Sets the loginName and automatically the requestId as well


addResponseListener

public final void addResponseListener(java.lang.String requestId,
                                      I_ResponseListener l)
Adds the listener to receive response/exception events.


removeResponseListener

public final void removeResponseListener(java.lang.String requestId)
Removes the specified listener.


getResponseListener

public final I_ResponseListener getResponseListener(java.lang.String requestId)
Get the response listener object


getPendingRequestList

public final java.lang.String getPendingRequestList()
For logging only

Returns:
null if none found

clearResponseListenerMap

public void clearResponseListenerMap()

receiveReply

public boolean receiveReply(MsgInfo receiver,
                            boolean udp)
                     throws XmlBlasterException,
                            java.io.IOException
Handle common messages

Returns:
false: for connect() and disconnect() which must be handled by the base class
Throws:
XmlBlasterException
java.io.IOException

hasConnection

protected boolean hasConnection()

requestAndBlockForReply

public java.lang.Object requestAndBlockForReply(MsgInfo msgInfo,
                                                boolean expectingResponse,
                                                boolean udp)
                                         throws XmlBlasterException,
                                                java.io.IOException
Send a message and block until the response arrives.

We simulate RPC (remote procedure call) here. This should be thread save and may be invoked by many client threads in parallel (though i have not tested it).

Parameters:
expectingResponse - WAIT_ON_RESPONSE=true or ONEWAY=false
udp - Some user info which is passed through
Returns:
the response object of the request, of type String(QoS), MsgUnitRaw[] or XmlBlasterException
Throws:
XmlBlasterException
java.io.IOException

shutdown

public void shutdown()
Description copied from interface: I_AdminPlugin
Shutdown the plugin, free resources.

Specified by:
shutdown in interface I_AdminPlugin

interruptInvocation

public int interruptInvocation()
Interrupts a blocking request with a not returning reply. The pending message is handled as not delivered and will be queued

Specified by:
interruptInvocation in interface RequestReplyExecutorMBean
Returns:
Number of interrupted invocations, typically 0 or 1

addLatch

private RequestReplyExecutor.LatchHolder addLatch(java.util.concurrent.CountDownLatch latch)

removeLatch

private void removeLatch(RequestReplyExecutor.LatchHolder latchHolder)

getLatches

private RequestReplyExecutor.LatchHolder[] getLatches()

freePendingThreads

public final void freePendingThreads()
If we detect somewhere that the socket is down use this method to free blocking threads which wait on responses


executeResponse

protected final void executeResponse(MsgInfo receiver,
                                     java.lang.Object response,
                                     boolean udp)
                              throws XmlBlasterException,
                                     java.io.IOException
Send a one way response message back to the other side

Throws:
XmlBlasterException
java.io.IOException

executeException

protected final void executeException(MsgInfo receiver,
                                      XmlBlasterException e,
                                      boolean udp)
                               throws XmlBlasterException,
                                      java.io.IOException
Send a one way exception back to the other side

Throws:
XmlBlasterException
java.io.IOException

sendMessage

protected abstract void sendMessage(MsgInfo msgInfo,
                                    java.lang.String requestId,
                                    MethodName methodName,
                                    boolean udp)
                             throws XmlBlasterException,
                                    java.io.IOException
Flush the data to the protocol layer (socket, email, ...). Overwrite this in your derived class to send using your specific protocol

Throws:
XmlBlasterException
java.io.IOException

isCompressZlib

public boolean isCompressZlib()
Specified by:
isCompressZlib in interface RequestReplyExecutorMBean

setCompressZlib

public void setCompressZlib(boolean compress)
Specified by:
setCompressZlib in interface RequestReplyExecutorMBean

getMinSizeForCompression

public int getMinSizeForCompression()
Compressing too small messages won't reduce the size

Specified by:
getMinSizeForCompression in interface RequestReplyExecutorMBean
Returns:
The number of bytes, only compress if bigger

isCompressZlibStream

public boolean isCompressZlibStream()
Specified by:
isCompressZlibStream in interface RequestReplyExecutorMBean

setCompressZlibStream

public void setCompressZlibStream(boolean compress)
Specified by:
setCompressZlibStream in interface RequestReplyExecutorMBean

getUpdateResponseTimeout

public final long getUpdateResponseTimeout()
Specified by:
getUpdateResponseTimeout in interface RequestReplyExecutorMBean
Returns:
Returns the updateResponseTimeout.

isUseEmailExpiryTimestamp

public boolean isUseEmailExpiryTimestamp()
Specified by:
isUseEmailExpiryTimestamp in interface RequestReplyExecutorMBean
Returns:
Returns the useEmailExpiryTimestamp.

setUseEmailExpiryTimestamp

public void setUseEmailExpiryTimestamp(boolean useEmailExpiryTimestamp)
Specified by:
setUseEmailExpiryTimestamp in interface RequestReplyExecutorMBean
Parameters:
useEmailExpiryTimestamp - The useEmailExpiryTimestamp to set.

usage

public java.lang.String usage()
Specified by:
usage in interface I_AdminUsage
Returns:
a human readable usage help string

isShutdownCompletly

public boolean isShutdownCompletly()

isShutdown

public boolean isShutdown()
Description copied from interface: I_AdminPlugin
Check status

Specified by:
isShutdown in interface I_AdminPlugin
Returns:
true if down

getPingResponseTimeout

public final long getPingResponseTimeout()
The invocation timeout for "ping" method calls.

Specified by:
getPingResponseTimeout in interface RequestReplyExecutorMBean
Returns:
Returns the pingResponseTimeout.

getResponseTimeout

public final long getResponseTimeout()
The invocation timeout for all remaining method calls like "publish", "connect", "subscribe" but NOT for "ping" and "update"

Specified by:
getResponseTimeout in interface RequestReplyExecutorMBean
Returns:
Returns the responseTimeout.

setMinSizeForCompression

public void setMinSizeForCompression(int minSizeForCompression)
Specified by:
setMinSizeForCompression in interface RequestReplyExecutorMBean
Parameters:
minSizeForCompression - The minSizeForCompression to set.

xmlBlaster 2.2.0 API

Copyright © 1999-2014 The xmlBlaster.org contributers.