Package com.webmethods.jms.protocol
Class ProtocolHandler
- java.lang.Object
-
- com.webmethods.jms.protocol.ProtocolHandler
-
- All Implemented Interfaces:
Protocol
- Direct Known Subclasses:
AsciiProtocolHandler
,BinaryProtocolHandler
public abstract class ProtocolHandler extends java.lang.Object implements Protocol
Abstract class for the physical link to the Broker. Subclasses of this class encapsulate the protocol level implementation.
-
-
Field Summary
Fields Modifier and Type Field Description protected byte[]
_buffer
protected int
_bufferEol
protected int
_bufferPos
protected java.lang.String
_clientGroup
protected java.lang.String
_clientID
protected static java.lang.String
_clientLicenseID
protected boolean
_confirmDelivery
protected WmConnectionImpl
_connection
protected boolean
_isLoggable
protected long
_lastResponseFromBroker
protected Link
_link
protected WmMarshalIn
_marshalIn
protected java.lang.Object
_marshalInUserData
protected WmMarshalOut
_marshalOut
protected java.lang.Object
_marshalOutUserData
protected WmMessageFactory
_messageFactory
protected BrokerURL
_url
static java.lang.String
ADMIN_APPLICATION
static java.lang.String
CLIENT_TYPE_ADMIN
static java.lang.String
CLIENT_TYPE_CONNECTION
static java.lang.String
CLIENT_TYPE_DURABLE_SUBSCRIBER
static java.lang.String
CLIENT_TYPE_PROPERTY
static java.lang.String
CLIENT_TYPE_QUEUE
static java.lang.String
CLIENT_TYPE_SUBSCRIBER
static java.lang.String
CONNECTION_APPLICATION
static java.lang.String
DURABLE_SUBSCRIBER_APPLICATION
static java.lang.String
MESSAGE_TYPE_PROPERTY
static java.lang.String
MESSAGE_TYPE_QUEUE
static java.lang.String
MESSAGE_TYPE_TEMPORARY_QUEUE
static java.lang.String
MESSAGE_TYPE_TEMPORARY_TOPIC
static java.lang.String
MESSAGE_TYPE_TOPIC
protected static int
MIN_BUFFER_SIZE
static java.lang.String
QUEUE_APPLICATION
static java.lang.String
SUBSCRIBER_APPLICATION
-
Constructor Summary
Constructors Modifier Constructor Description protected
ProtocolHandler(WmConnectionImpl connection, SSLInfo sslinfo)
Create a new link to the Broker.protected
ProtocolHandler(SSLInfo sslinfo)
Create a new link to the Broker.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
acquireSendRequestEventsLock()
void
connect(BrokerURL url)
Start the protocol.protected WmMessageImpl
createMessage(byte[] event, int offset, int length, int deliveryCount, long sequenceNumber, int[] subscriptionIDs)
void
disconnect()
Stops the protocol.protected abstract void
dispatch()
Read Broker replies from the link and dispatch.protected void
dispatchReply(Reply reply)
Dispatch a reply.BrokerURL
getBrokerURL()
java.lang.String
getClientID()
Returns the Broker client ID.int
getEncryptionLevel()
Returns the encryption level of the link.protected static java.lang.String
getPosixFromLocale(java.util.Locale locale)
Converts a Java locale to a POSIX locale.protected abstract Reply
getReconnectReply()
java.util.Properties
getServerCertificate()
Returns properties of the server certificate.protected void
handleError(int protocolError)
Default error handler for replies that are errors.boolean
isDisconnected()
Check if the Protocol is already disconnected.boolean
isTransactionCompleted()
void
markForClosure(boolean exceptionOccured)
Marks the connection for closure.protected WmBrokerEventWrapperImpl
marshal(WmMessageImpl message)
protected int
nextRequestID()
Get the next request ID.void
processClientLicense()
protected int
read()
Read data from the link.void
reconnect()
void
releaseSendRequestEventsLock()
protected Notification
sendWithCb(Request request, int requestID, ReplyCb cb)
Send a request to the Broker and process the reply asynchronously.protected void
sendWithNoReply(Request request)
Send a request to the Broker but don't wait for a reply.protected void
sendWithNoReply(Request request, byte[] data)
Send a publish request to the Broker but don't wait for a reply.protected void
sendWithNoReply(Request request, byte[][] data)
Send a publish request to the Broker but don't wait for a reply.protected Reply
sendWithReply(Request request, byte[][] data, int requestID)
Send a publish request to the Broker and wait for a reply.protected Reply
sendWithReply(Request request, byte[] data, int requestID)
Send a publish request to the Broker and wait for a reply.protected Reply
sendWithReply(Request request, int requestID)
Send a request to the Broker and wait for a reply.void
setBrokerInactive(boolean invokeExceptionListener)
void
setBrokerURL(BrokerURL url)
void
setTransactionCompleted(boolean transactionCompleted)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.webmethods.jms.protocol.Protocol
acknowledge, acknowledge, acknowledgeThrough, beginBrowse, browse, cancelReceive, canPublish, canSubscribe, clearQueue, commit, commit, destroy, disconnect, endBrowse, endTransaction, forget, getAccessLabel, getBrokerName, getPublishProcessState, getQueueLength, getTerritory, getUniqueID, initializeConnection, initializeConnection, initializeSession, negativeAcknowledge, negativeAcknowledge, prepare, prepare, publish, publish, publish, publish, receive, recover, rollback, rollback, sendKeepAlive, sendKeepAliveResponse, setBrowseFilter, setFilter, setInfo, setTransactionID, setTransactionTimeout, startTransaction, startTransaction, startTransaction, subscribe, subscriptions, unsubscribe
-
-
-
-
Field Detail
-
CLIENT_TYPE_PROPERTY
public static final java.lang.String CLIENT_TYPE_PROPERTY
- See Also:
- Constant Field Values
-
CLIENT_TYPE_CONNECTION
public static final java.lang.String CLIENT_TYPE_CONNECTION
- See Also:
- Constant Field Values
-
CLIENT_TYPE_SUBSCRIBER
public static final java.lang.String CLIENT_TYPE_SUBSCRIBER
- See Also:
- Constant Field Values
-
CLIENT_TYPE_DURABLE_SUBSCRIBER
public static final java.lang.String CLIENT_TYPE_DURABLE_SUBSCRIBER
- See Also:
- Constant Field Values
-
CLIENT_TYPE_QUEUE
public static final java.lang.String CLIENT_TYPE_QUEUE
- See Also:
- Constant Field Values
-
CLIENT_TYPE_ADMIN
public static final java.lang.String CLIENT_TYPE_ADMIN
- See Also:
- Constant Field Values
-
MESSAGE_TYPE_PROPERTY
public static final java.lang.String MESSAGE_TYPE_PROPERTY
- See Also:
- Constant Field Values
-
MESSAGE_TYPE_QUEUE
public static final java.lang.String MESSAGE_TYPE_QUEUE
- See Also:
- Constant Field Values
-
MESSAGE_TYPE_TOPIC
public static final java.lang.String MESSAGE_TYPE_TOPIC
- See Also:
- Constant Field Values
-
MESSAGE_TYPE_TEMPORARY_QUEUE
public static final java.lang.String MESSAGE_TYPE_TEMPORARY_QUEUE
- See Also:
- Constant Field Values
-
MESSAGE_TYPE_TEMPORARY_TOPIC
public static final java.lang.String MESSAGE_TYPE_TEMPORARY_TOPIC
- See Also:
- Constant Field Values
-
CONNECTION_APPLICATION
public static final java.lang.String CONNECTION_APPLICATION
- See Also:
- Constant Field Values
-
SUBSCRIBER_APPLICATION
public static final java.lang.String SUBSCRIBER_APPLICATION
- See Also:
- Constant Field Values
-
DURABLE_SUBSCRIBER_APPLICATION
public static final java.lang.String DURABLE_SUBSCRIBER_APPLICATION
- See Also:
- Constant Field Values
-
QUEUE_APPLICATION
public static final java.lang.String QUEUE_APPLICATION
- See Also:
- Constant Field Values
-
ADMIN_APPLICATION
public static final java.lang.String ADMIN_APPLICATION
- See Also:
- Constant Field Values
-
MIN_BUFFER_SIZE
protected static final int MIN_BUFFER_SIZE
- See Also:
- Constant Field Values
-
_connection
protected WmConnectionImpl _connection
-
_link
protected Link _link
-
_url
protected BrokerURL _url
-
_clientID
protected java.lang.String _clientID
-
_clientGroup
protected java.lang.String _clientGroup
-
_clientLicenseID
protected static java.lang.String _clientLicenseID
-
_buffer
protected byte[] _buffer
-
_bufferPos
protected int _bufferPos
-
_bufferEol
protected int _bufferEol
-
_marshalOut
protected WmMarshalOut _marshalOut
-
_marshalOutUserData
protected java.lang.Object _marshalOutUserData
-
_marshalIn
protected WmMarshalIn _marshalIn
-
_marshalInUserData
protected java.lang.Object _marshalInUserData
-
_messageFactory
protected WmMessageFactory _messageFactory
-
_isLoggable
protected boolean _isLoggable
-
_confirmDelivery
protected boolean _confirmDelivery
-
_lastResponseFromBroker
protected volatile long _lastResponseFromBroker
-
-
Constructor Detail
-
ProtocolHandler
protected ProtocolHandler(SSLInfo sslinfo) throws javax.jms.JMSException
Create a new link to the Broker.- Throws:
javax.jms.JMSException
-
ProtocolHandler
protected ProtocolHandler(WmConnectionImpl connection, SSLInfo sslinfo) throws javax.jms.JMSException
Create a new link to the Broker.- Parameters:
connection
- the connection to which this link belongs- Throws:
javax.jms.JMSException
-
-
Method Detail
-
connect
public void connect(BrokerURL url) throws javax.jms.JMSException
Start the protocol.- Throws:
javax.jms.JMSException
- if the protocol could not be started
-
setBrokerURL
public void setBrokerURL(BrokerURL url)
-
reconnect
public void reconnect() throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
markForClosure
public void markForClosure(boolean exceptionOccured)
Marks the connection for closure.
-
disconnect
public void disconnect() throws javax.jms.JMSException
Stops the protocol.- Throws:
javax.jms.JMSException
- if the protocol could not be stopped.
-
isDisconnected
public boolean isDisconnected()
Check if the Protocol is already disconnected.- Returns:
- true if the Protocol is disconnected
-
getClientID
public java.lang.String getClientID()
Returns the Broker client ID.- Returns:
- the Broker client ID
-
getBrokerURL
public BrokerURL getBrokerURL()
-
createMessage
protected WmMessageImpl createMessage(byte[] event, int offset, int length, int deliveryCount, long sequenceNumber, int[] subscriptionIDs) throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
getEncryptionLevel
public int getEncryptionLevel() throws javax.jms.JMSException
Returns the encryption level of the link.- Returns:
- the encryption level
- Throws:
javax.jms.JMSException
- if an error occurs getting the encryption level
-
getServerCertificate
public java.util.Properties getServerCertificate() throws javax.jms.JMSException
Returns properties of the server certificate. The included property names are: "subjectDn", "issuerDn", "status" "serialNumber", "beginDate", "endDate".- Returns:
- server certificate properties
- Throws:
javax.jms.JMSException
- if an error occurs getting the server certificate
-
sendWithNoReply
protected void sendWithNoReply(Request request) throws javax.jms.JMSException
Send a request to the Broker but don't wait for a reply.- Parameters:
request
- the request to send to the Broker- Throws:
javax.jms.JMSException
- if unable to send the request to the Broker
-
sendWithReply
protected Reply sendWithReply(Request request, int requestID) throws javax.jms.JMSException
Send a request to the Broker and wait for a reply.- Parameters:
request
- the request to send to the BrokerrequestID
- the request ID- Returns:
- the Broker reply
- Throws:
javax.jms.JMSException
- if unable to send the request or read the reply
-
sendWithCb
protected Notification sendWithCb(Request request, int requestID, ReplyCb cb) throws javax.jms.JMSException
Send a request to the Broker and process the reply asynchronously.- Parameters:
request
- the request to send to the BrokerrequestID
- the request IDcb
- the callback to call when the reply is received- Returns:
- the request notification object
- Throws:
javax.jms.JMSException
- if unable to send the request to the Broker
-
sendWithNoReply
protected void sendWithNoReply(Request request, byte[] data) throws javax.jms.JMSException
Send a publish request to the Broker but don't wait for a reply.- Parameters:
request
- the publish requestdata
- the message to publish- Throws:
javax.jms.JMSException
- if unable to publish the message to the Broker
-
sendWithReply
protected Reply sendWithReply(Request request, byte[] data, int requestID) throws javax.jms.JMSException
Send a publish request to the Broker and wait for a reply.- Parameters:
request
- the publish requestdata
- the message data to publishrequestID
- the request ID- Returns:
- the Broker reply
- Throws:
javax.jms.JMSException
- if unable to publish the message or read the reply
-
sendWithNoReply
protected void sendWithNoReply(Request request, byte[][] data) throws javax.jms.JMSException
Send a publish request to the Broker but don't wait for a reply.- Parameters:
request
- the publish requestdata
- the messages to publish- Throws:
javax.jms.JMSException
- if unable to publish the messages to the Broker
-
sendWithReply
protected Reply sendWithReply(Request request, byte[][] data, int requestID) throws javax.jms.JMSException
Send a publish request to the Broker and wait for a reply.- Parameters:
request
- the publish requestdata
- the messages to publishrequestID
- the request ID- Returns:
- the Broker reply
- Throws:
javax.jms.JMSException
- if unable to publish the messages or read the reply
-
nextRequestID
protected int nextRequestID()
Get the next request ID.- Returns:
- the next request ID
-
read
protected int read() throws java.io.IOException, javax.jms.JMSException
Read data from the link.- Throws:
java.io.IOException
javax.jms.JMSException
-
dispatch
protected abstract void dispatch() throws java.io.IOException, javax.jms.JMSException
Read Broker replies from the link and dispatch.- Throws:
javax.jms.JMSException
- if unable to read the link or parse the replyjava.io.IOException
-
getReconnectReply
protected abstract Reply getReconnectReply()
-
dispatchReply
protected void dispatchReply(Reply reply) throws javax.jms.JMSException
Dispatch a reply.- Parameters:
reply
- the reply to dispatch- Throws:
javax.jms.JMSException
-
getPosixFromLocale
protected static java.lang.String getPosixFromLocale(java.util.Locale locale)
Converts a Java locale to a POSIX locale.- Parameters:
locale
- the Java locale- Returns:
- a POSIX locale
-
handleError
protected void handleError(int protocolError) throws javax.jms.JMSException
Default error handler for replies that are errors.- Parameters:
protocolError
- the protocol error- Throws:
javax.jms.JMSException
- based upon the reply's error number
-
marshal
protected WmBrokerEventWrapperImpl marshal(WmMessageImpl message) throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
acquireSendRequestEventsLock
public boolean acquireSendRequestEventsLock()
-
releaseSendRequestEventsLock
public void releaseSendRequestEventsLock()
-
isTransactionCompleted
public boolean isTransactionCompleted()
-
setTransactionCompleted
public void setTransactionCompleted(boolean transactionCompleted)
-
setBrokerInactive
public void setBrokerInactive(boolean invokeExceptionListener)
-
processClientLicense
public void processClientLicense() throws javax.jms.JMSException
- Throws:
javax.jms.JMSException
-
-