Class DefaultReqRespManager
- java.lang.Object
-
- org.certificateservices.messages.csmessages.manager.DefaultReqRespManager
-
- All Implemented Interfaces:
MessageResponseCallback,ReqRespManager
- Direct Known Subclasses:
AutoRevokeReqRespManager
public class DefaultReqRespManager extends java.lang.Object implements ReqRespManager, MessageResponseCallback
Default request response manager sending a request on one queue and waiting for a response on a response queue.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classDefaultReqRespManager.RequestEntryA request entry is used the the request map after a send message call i waiting for a response, contains a response PKI Message data.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCALLBACK_ALIASprotected MessageHandlermessageHandlerprotected java.lang.StringmessageListenerNameprotected java.lang.StringmessageSenderNameprotected java.util.Map<java.lang.String,DefaultReqRespManager.RequestEntry>responseMapprotected static longSLEEP_INTERVAL_MILLISprotected longtimeOut
-
Constructor Summary
Constructors Constructor Description DefaultReqRespManager(long timeOut, MessageHandler messageHandler, java.lang.String messageSenderName, java.lang.String messageListenerName)Default constructor of a DefaultReqRespManager
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcancelWaitForResponse(java.lang.String requestId)Method signaling that the waiting thread have stopped listening for a response to this request.protected CSMessagecheckIfResponseIsReady(java.lang.String requestId)Method to check if a response have been sent to a request with the given id.protected java.lang.StringfindRequestId(CSMessage responseMessage)Method that extracts the requestId from the responseMessage.protected CSResponsefindResponsePayload(CSMessage responseMessage)protected booleanpopulateResponseMapIfStillExist(java.lang.String requestId, CSMessage responseMessage)Method that is called by the responseRecieved method that it received a message to this listener and should populate the response map.protected voidregisterWaitForRequestId(java.lang.String requestId)Signals that the current manager is listening for this message.voidresponseReceived(byte[] requestData, CSMessage responseMessage, java.util.Map<java.lang.String,java.lang.String> messageAttributes)Method signaling that a response was received.CSMessagesendRequest(java.lang.String requestId, byte[] request)Main method signaling sending a request with given id and waits for a response for a given time before a time-out IO exception is thrown.CSMessagesendRequest(java.lang.String requestId, byte[] request, java.util.Map<java.lang.String,java.lang.String> requestAttributes)Main method signaling sending a request with given id and waits for a response for a given time before a time-out IO exception is thrown.
-
-
-
Field Detail
-
responseMap
protected java.util.Map<java.lang.String,DefaultReqRespManager.RequestEntry> responseMap
-
timeOut
protected long timeOut
-
messageHandler
protected MessageHandler messageHandler
-
messageListenerName
protected java.lang.String messageListenerName
-
messageSenderName
protected java.lang.String messageSenderName
-
SLEEP_INTERVAL_MILLIS
protected static long SLEEP_INTERVAL_MILLIS
-
CALLBACK_ALIAS
public static final java.lang.String CALLBACK_ALIAS
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DefaultReqRespManager
public DefaultReqRespManager(long timeOut, MessageHandler messageHandler, java.lang.String messageSenderName, java.lang.String messageListenerName) throws MessageProcessingExceptionDefault constructor of a DefaultReqRespManager- Parameters:
timeOut- time in milliseconds to wait for response.messageHandler- , the related message handler.messageListenerName- the name of the message listener to use, never null and must be registered in the message handler.messageSenderName- the name of the message sender to use, never null and must be registered in the message handler.- Throws:
MessageProcessingException- if internal problems occurred setting up the request response manager.
-
-
Method Detail
-
sendRequest
public CSMessage sendRequest(java.lang.String requestId, byte[] request) throws java.lang.IllegalArgumentException, java.io.IOException, MessageProcessingException
Description copied from interface:ReqRespManagerMain method signaling sending a request with given id and waits for a response for a given time before a time-out IO exception is thrown.- Specified by:
sendRequestin interfaceReqRespManager- Throws:
java.lang.IllegalArgumentExceptionjava.io.IOExceptionMessageProcessingException- See Also:
ReqRespManager.sendRequest(java.lang.String, byte[])
-
sendRequest
public CSMessage sendRequest(java.lang.String requestId, byte[] request, java.util.Map<java.lang.String,java.lang.String> requestAttributes) throws java.lang.IllegalArgumentException, java.io.IOException, MessageProcessingException
Description copied from interface:ReqRespManagerMain method signaling sending a request with given id and waits for a response for a given time before a time-out IO exception is thrown. This methods provides optional requestAttributes containing meta-data about the message.- Specified by:
sendRequestin interfaceReqRespManager- Throws:
java.lang.IllegalArgumentExceptionjava.io.IOExceptionMessageProcessingException- See Also:
ReqRespManager.sendRequest(java.lang.String, byte[], Map)
-
responseReceived
public void responseReceived(byte[] requestData, CSMessage responseMessage, java.util.Map<java.lang.String,java.lang.String> messageAttributes)Description copied from interface:MessageResponseCallbackMethod signaling that a response was received.Important only messages with a destination matching this source id should be sent through this callback.
- Specified by:
responseReceivedin interfaceMessageResponseCallback- Parameters:
requestData- the original request dataresponseMessage- the response message that was received.messageAttributes- meta data related to the message such as reply-to queues or correlation id etc if underlying implementation supports it.- See Also:
MessageResponseCallback.responseReceived(byte[], CSMessage, Map)
-
registerWaitForRequestId
protected void registerWaitForRequestId(java.lang.String requestId)
Signals that the current manager is listening for this message.- Parameters:
requestId- the id of the message to register
-
checkIfResponseIsReady
protected CSMessage checkIfResponseIsReady(java.lang.String requestId)
Method to check if a response have been sent to a request with the given id.- Parameters:
requestId- the id to check for- Returns:
- the PKIMessage response or null if no response have been recieved yet.
-
cancelWaitForResponse
protected void cancelWaitForResponse(java.lang.String requestId)
Method signaling that the waiting thread have stopped listening for a response to this request.
-
populateResponseMapIfStillExist
protected boolean populateResponseMapIfStillExist(java.lang.String requestId, CSMessage responseMessage)Method that is called by the responseRecieved method that it received a message to this listener and should populate the response map.
-
findRequestId
protected java.lang.String findRequestId(CSMessage responseMessage)
Method that extracts the requestId from the responseMessage. Where IssueTokenCredentialsResponse and GetCredentialResponse and FailureResponse is supported.- Parameters:
responseMessage- the message to parse request id from- Returns:
- the request id or null if no valid request id was found in the response
-
findResponsePayload
protected CSResponse findResponsePayload(CSMessage responseMessage)
-
-