http://git-wip-us.apache.org/repos/asf/activemq-6/blob/034adfbf/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAManagedConnection.java ---------------------------------------------------------------------- diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAManagedConnection.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAManagedConnection.java new file mode 100644 index 0000000..7ec8379 --- /dev/null +++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAManagedConnection.java @@ -0,0 +1,921 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.apache.activemq.ra; + +import javax.jms.ExceptionListener; +import javax.jms.JMSException; +import javax.jms.ResourceAllocationException; +import javax.jms.Session; +import javax.jms.XASession; +import javax.resource.ResourceException; +import javax.resource.spi.ConnectionEvent; +import javax.resource.spi.ConnectionEventListener; +import javax.resource.spi.ConnectionRequestInfo; +import javax.resource.spi.IllegalStateException; +import javax.resource.spi.LocalTransaction; +import javax.resource.spi.ManagedConnection; +import javax.resource.spi.ManagedConnectionMetaData; +import javax.resource.spi.SecurityException; +import javax.security.auth.Subject; +import javax.transaction.Status; +import javax.transaction.SystemException; +import javax.transaction.Transaction; +import javax.transaction.TransactionManager; +import javax.transaction.xa.XAResource; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.locks.ReentrantLock; + +import org.apache.activemq.core.client.impl.ClientSessionInternal; +import org.apache.activemq.jms.client.ActiveMQConnection; +import org.apache.activemq.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.jms.client.ActiveMQXAConnection; + +/** + * The managed connection + * + * @author <a href="mailto:adr...@jboss.com">Adrian Brock</a> + * @author <a href="mailto:jesper.peder...@jboss.org">Jesper Pedersen</a> + * @author <a href="mailto:mtay...@redhat.com">Martyn Taylor</a> + */ +public final class ActiveMQRAManagedConnection implements ManagedConnection, ExceptionListener +{ + /** + * Trace enabled + */ + private static boolean trace = ActiveMQRALogger.LOGGER.isTraceEnabled(); + + /** + * The managed connection factory + */ + private final ActiveMQRAManagedConnectionFactory mcf; + + /** + * The connection request information + */ + private final ActiveMQRAConnectionRequestInfo cri; + + /** + * The resource adapter + */ + private final ActiveMQResourceAdapter ra; + + /** + * The user name + */ + private final String userName; + + /** + * The password + */ + private final String password; + + /** + * Has the connection been destroyed + */ + private final AtomicBoolean isDestroyed = new AtomicBoolean(false); + + /** + * Event listeners + */ + private final List<ConnectionEventListener> eventListeners; + + /** + * Handles + */ + private final Set<ActiveMQRASession> handles; + + /** + * Lock + */ + private ReentrantLock lock = new ReentrantLock(); + + // Physical connection stuff + private ActiveMQConnectionFactory connectionFactory; + + private ActiveMQXAConnection connection; + + // The ManagedConnection will play with a XA and a NonXASession to couple with + // cases where a commit is called on a non-XAed (or non-enlisted) case. + private Session nonXAsession; + + private XASession xaSession; + + private XAResource xaResource; + + private final TransactionManager tm; + + private boolean inManagedTx; + + /** + * Constructor + * + * @param mcf The managed connection factory + * @param cri The connection request information + * @param userName The user name + * @param password The password + */ + public ActiveMQRAManagedConnection(final ActiveMQRAManagedConnectionFactory mcf, + final ActiveMQRAConnectionRequestInfo cri, + final ActiveMQResourceAdapter ra, + final String userName, + final String password) throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("constructor(" + mcf + ", " + cri + ", " + userName + ", ****)"); + } + + this.mcf = mcf; + this.cri = cri; + this.tm = ra.getTM(); + this.ra = ra; + this.userName = userName; + this.password = password; + eventListeners = Collections.synchronizedList(new ArrayList<ConnectionEventListener>()); + handles = Collections.synchronizedSet(new HashSet<ActiveMQRASession>()); + + connection = null; + nonXAsession = null; + xaSession = null; + xaResource = null; + + try + { + setup(); + } + catch (ResourceException e) + { + try + { + destroy(); + } + catch (Throwable ignored) + { + } + + throw e; + } + catch (Throwable t) + { + try + { + destroy(); + } + catch (Throwable ignored) + { + } + throw new ResourceException("Error during setup", t); + } + } + + /** + * Get a connection + * + * @param subject The security subject + * @param cxRequestInfo The request info + * @return The connection + * @throws ResourceException Thrown if an error occurs + */ + public synchronized Object getConnection(final Subject subject, final ConnectionRequestInfo cxRequestInfo) throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getConnection(" + subject + ", " + cxRequestInfo + ")"); + } + + // Check user first + ActiveMQRACredential credential = ActiveMQRACredential.getCredential(mcf, subject, cxRequestInfo); + + // Null users are allowed! + if (userName != null && !userName.equals(credential.getUserName())) + { + throw new SecurityException("Password credentials not the same, reauthentication not allowed"); + } + + if (userName == null && credential.getUserName() != null) + { + throw new SecurityException("Password credentials not the same, reauthentication not allowed"); + } + + if (isDestroyed.get()) + { + throw new IllegalStateException("The managed connection is already destroyed"); + } + + ActiveMQRASession session = new ActiveMQRASession(this, (ActiveMQRAConnectionRequestInfo) cxRequestInfo); + handles.add(session); + return session; + } + + /** + * Destroy all handles. + * + * @throws ResourceException Failed to close one or more handles. + */ + private void destroyHandles() throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("destroyHandles()"); + } + + try + { + + if (connection != null) + { + connection.stop(); + } + } + catch (Throwable t) + { + ActiveMQRALogger.LOGGER.trace("Ignored error stopping connection", t); + } + + for (ActiveMQRASession session : handles) + { + session.destroy(); + } + + handles.clear(); + } + + /** + * Destroy the physical connection. + * + * @throws ResourceException Could not property close the session and connection. + */ + public void destroy() throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("destroy()"); + } + + if (isDestroyed.get() || connection == null) + { + return; + } + + isDestroyed.set(true); + + try + { + connection.setExceptionListener(null); + } + catch (JMSException e) + { + ActiveMQRALogger.LOGGER.debug("Error unsetting the exception listener " + this, e); + } + if (connection != null) + { + connection.signalStopToAllSessions(); + } + + destroyHandles(); + + try + { + /** + * (xa|nonXA)Session.close() may NOT be called BEFORE connection.close() + * <p> + * If the ClientSessionFactory is trying to fail-over or reconnect with -1 attempts, and + * one calls session.close() it may effectively dead-lock. + * <p> + * connection close will close the ClientSessionFactory which will close all sessions. + */ + if (connection != null) + { + connection.close(); + } + + // The following calls should not be necessary, as the connection should close the + // ClientSessionFactory, which will close the sessions. + try + { + if (nonXAsession != null) + { + nonXAsession.close(); + } + + if (xaSession != null) + { + xaSession.close(); + } + } + catch (JMSException e) + { + ActiveMQRALogger.LOGGER.debug("Error closing session " + this, e); + } + + // we must close the ActiveMQConnectionFactory because it contains a ServerLocator + if (connectionFactory != null) + { + connectionFactory.close(); + } + } + catch (Throwable e) + { + throw new ResourceException("Could not properly close the session and connection", e); + } + } + + /** + * Cleanup + * + * @throws ResourceException Thrown if an error occurs + */ + public void cleanup() throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("cleanup()"); + } + + if (isDestroyed.get()) + { + throw new IllegalStateException("ManagedConnection already destroyed"); + } + + destroyHandles(); + + inManagedTx = false; + + inManagedTx = false; + + // I'm recreating the lock object when we return to the pool + // because it looks too nasty to expect the connection handle + // to unlock properly in certain race conditions + // where the dissociation of the managed connection is "random". + lock = new ReentrantLock(); + } + + /** + * Move a handler from one mc to this one. + * + * @param obj An object of type ActiveMQSession. + * @throws ResourceException Failed to associate connection. + * @throws IllegalStateException ManagedConnection in an illegal state. + */ + public void associateConnection(final Object obj) throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("associateConnection(" + obj + ")"); + } + + if (!isDestroyed.get() && obj instanceof ActiveMQRASession) + { + ActiveMQRASession h = (ActiveMQRASession) obj; + h.setManagedConnection(this); + handles.add(h); + } + else + { + throw new IllegalStateException("ManagedConnection in an illegal state"); + } + } + + public void checkTransactionActive() throws JMSException + { + // don't bother looking at the transaction if there's an active XID + if (!inManagedTx && tm != null) + { + try + { + Transaction tx = tm.getTransaction(); + if (tx != null) + { + int status = tx.getStatus(); + // Only allow states that will actually succeed + if (status != Status.STATUS_ACTIVE && status != Status.STATUS_PREPARING && + status != Status.STATUS_PREPARED && + status != Status.STATUS_COMMITTING) + { + throw new javax.jms.IllegalStateException("Transaction " + tx + " not active"); + } + } + } + catch (SystemException e) + { + JMSException jmsE = new javax.jms.IllegalStateException("Unexpected exception on the Transaction ManagerTransaction"); + jmsE.initCause(e); + throw jmsE; + } + } + } + + + /** + * Aqquire a lock on the managed connection + */ + protected void lock() + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("lock()"); + } + + lock.lock(); + } + + /** + * Aqquire a lock on the managed connection within the specified period + * + * @throws JMSException Thrown if an error occurs + */ + protected void tryLock() throws JMSException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("tryLock()"); + } + + Integer tryLock = mcf.getUseTryLock(); + if (tryLock == null || tryLock.intValue() <= 0) + { + lock(); + return; + } + try + { + if (lock.tryLock(tryLock.intValue(), TimeUnit.SECONDS) == false) + { + throw new ResourceAllocationException("Unable to obtain lock in " + tryLock + " seconds: " + this); + } + } + catch (InterruptedException e) + { + throw new ResourceAllocationException("Interrupted attempting lock: " + this); + } + } + + /** + * Unlock the managed connection + */ + protected void unlock() + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("unlock()"); + } + + lock.unlock(); + } + + /** + * Add a connection event listener. + * + * @param l The connection event listener to be added. + */ + public void addConnectionEventListener(final ConnectionEventListener l) + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("addConnectionEventListener(" + l + ")"); + } + + eventListeners.add(l); + } + + /** + * Remove a connection event listener. + * + * @param l The connection event listener to be removed. + */ + public void removeConnectionEventListener(final ConnectionEventListener l) + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("removeConnectionEventListener(" + l + ")"); + } + + eventListeners.remove(l); + } + + /** + * Get the XAResource for the connection. + * + * @return The XAResource for the connection. + * @throws ResourceException XA transaction not supported + */ + public XAResource getXAResource() throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getXAResource()"); + } + + // + // Spec says a mc must always return the same XA resource, + // so we cache it. + // + if (xaResource == null) + { + ClientSessionInternal csi = (ClientSessionInternal) xaSession.getXAResource(); + ActiveMQRAXAResource activeMQRAXAResource = new ActiveMQRAXAResource(this, xaSession.getXAResource()); + xaResource = new ActiveMQXAResourceWrapper(activeMQRAXAResource, ra.getJndiName(), csi.getNodeId()); + } + + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("XAResource=" + xaResource); + } + + return xaResource; + } + + /** + * Get the location transaction for the connection. + * + * @return The local transaction for the connection. + * @throws ResourceException Thrown if operation fails. + */ + public LocalTransaction getLocalTransaction() throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getLocalTransaction()"); + } + + LocalTransaction tx = new ActiveMQRALocalTransaction(this); + + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("LocalTransaction=" + tx); + } + + return tx; + } + + /** + * Get the meta data for the connection. + * + * @return The meta data for the connection. + * @throws ResourceException Thrown if the operation fails. + * @throws IllegalStateException Thrown if the managed connection already is destroyed. + */ + public ManagedConnectionMetaData getMetaData() throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getMetaData()"); + } + + if (isDestroyed.get()) + { + throw new IllegalStateException("The managed connection is already destroyed"); + } + + return new ActiveMQRAMetaData(this); + } + + /** + * Set the log writer -- NOT SUPPORTED + * + * @param out The log writer + * @throws ResourceException If operation fails + */ + public void setLogWriter(final PrintWriter out) throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("setLogWriter(" + out + ")"); + } + } + + /** + * Get the log writer -- NOT SUPPORTED + * + * @return Always null + * @throws ResourceException If operation fails + */ + public PrintWriter getLogWriter() throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getLogWriter()"); + } + + return null; + } + + /** + * Notifies user of a JMS exception. + * + * @param exception The JMS exception + */ + public void onException(final JMSException exception) + { + if (ActiveMQConnection.EXCEPTION_FAILOVER.equals(exception.getErrorCode())) + { + return; + } + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("onException(" + exception + ")"); + } + + if (isDestroyed.get()) + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("Ignoring error on already destroyed connection " + this, exception); + } + return; + } + + ActiveMQRALogger.LOGGER.handlingJMSFailure(exception); + + try + { + connection.setExceptionListener(null); + } + catch (JMSException e) + { + ActiveMQRALogger.LOGGER.debug("Unable to unset exception listener", e); + } + + ConnectionEvent event = new ConnectionEvent(this, ConnectionEvent.CONNECTION_ERROR_OCCURRED, exception); + sendEvent(event); + } + + /** + * Get the session for this connection. + * + * @return The session + * @throws JMSException + */ + protected Session getSession() throws JMSException + { + if (xaResource != null && inManagedTx) + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getSession() -> XA session " + xaSession.getSession()); + } + + return xaSession.getSession(); + } + else + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getSession() -> non XA session " + nonXAsession); + } + + return nonXAsession; + } + } + + /** + * Send an event. + * + * @param event The event to send. + */ + protected void sendEvent(final ConnectionEvent event) + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("sendEvent(" + event + ")"); + } + + int type = event.getId(); + + // convert to an array to avoid concurrent modification exceptions + ConnectionEventListener[] list = eventListeners.toArray(new ConnectionEventListener[eventListeners.size()]); + + for (ConnectionEventListener l : list) + { + switch (type) + { + case ConnectionEvent.CONNECTION_CLOSED: + l.connectionClosed(event); + break; + + case ConnectionEvent.LOCAL_TRANSACTION_STARTED: + l.localTransactionStarted(event); + break; + + case ConnectionEvent.LOCAL_TRANSACTION_COMMITTED: + l.localTransactionCommitted(event); + break; + + case ConnectionEvent.LOCAL_TRANSACTION_ROLLEDBACK: + l.localTransactionRolledback(event); + break; + + case ConnectionEvent.CONNECTION_ERROR_OCCURRED: + l.connectionErrorOccurred(event); + break; + + default: + throw new IllegalArgumentException("Illegal eventType: " + type); + } + } + } + + /** + * Remove a handle from the handle map. + * + * @param handle The handle to remove. + */ + protected void removeHandle(final ActiveMQRASession handle) + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("removeHandle(" + handle + ")"); + } + + handles.remove(handle); + } + + /** + * Get the request info for this connection. + * + * @return The connection request info for this connection. + */ + protected ActiveMQRAConnectionRequestInfo getCRI() + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getCRI()"); + } + + return cri; + } + + /** + * Get the connection factory for this connection. + * + * @return The connection factory for this connection. + */ + protected ActiveMQRAManagedConnectionFactory getManagedConnectionFactory() + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getManagedConnectionFactory()"); + } + + return mcf; + } + + /** + * Start the connection + * + * @throws JMSException Thrown if the connection can't be started + */ + void start() throws JMSException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("start()"); + } + + if (connection != null) + { + connection.start(); + } + } + + /** + * Stop the connection + * + * @throws JMSException Thrown if the connection can't be stopped + */ + void stop() throws JMSException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("stop()"); + } + + if (connection != null) + { + connection.stop(); + } + } + + /** + * Get the user name + * + * @return The user name + */ + protected String getUserName() + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("getUserName()"); + } + + return userName; + } + + /** + * Setup the connection. + * + * @throws ResourceException Thrown if a connection couldn't be created + */ + private void setup() throws ResourceException + { + if (ActiveMQRAManagedConnection.trace) + { + ActiveMQRALogger.LOGGER.trace("setup()"); + } + + try + { + + createCF(); + + boolean transacted = cri.isTransacted(); + int acknowledgeMode = Session.AUTO_ACKNOWLEDGE; + if (cri.getType() == ActiveMQRAConnectionFactory.TOPIC_CONNECTION) + { + if (userName != null && password != null) + { + connection = (ActiveMQXAConnection) connectionFactory.createXATopicConnection(userName, password); + } + else + { + connection = (ActiveMQXAConnection) connectionFactory.createXATopicConnection(); + } + + connection.setExceptionListener(this); + + xaSession = connection.createXATopicSession(); + nonXAsession = connection.createNonXATopicSession(transacted, acknowledgeMode); + + } + else if (cri.getType() == ActiveMQRAConnectionFactory.QUEUE_CONNECTION) + { + if (userName != null && password != null) + { + connection = (ActiveMQXAConnection) connectionFactory.createXAQueueConnection(userName, password); + } + else + { + connection = (ActiveMQXAConnection) connectionFactory.createXAQueueConnection(); + } + + connection.setExceptionListener(this); + + xaSession = connection.createXAQueueSession(); + nonXAsession = connection.createNonXAQueueSession(transacted, acknowledgeMode); + + } + else + { + if (userName != null && password != null) + { + connection = (ActiveMQXAConnection) connectionFactory.createXAConnection(userName, password); + } + else + { + connection = (ActiveMQXAConnection) connectionFactory.createXAConnection(); + } + + connection.setExceptionListener(this); + + xaSession = connection.createXASession(); + nonXAsession = connection.createNonXASession(transacted, acknowledgeMode); + } + + } + catch (JMSException je) + { + throw new ResourceException(je.getMessage(), je); + } + } + + private void createCF() + { + if (connectionFactory == null) + { + connectionFactory = ra.createActiveMQConnectionFactory(mcf.getProperties()); + } + } + + protected void setInManagedTx(boolean inManagedTx) + { + this.inManagedTx = inManagedTx; + } + +}
http://git-wip-us.apache.org/repos/asf/activemq-6/blob/034adfbf/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAManagedConnectionFactory.java ---------------------------------------------------------------------- diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAManagedConnectionFactory.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAManagedConnectionFactory.java new file mode 100644 index 0000000..8c40ab9 --- /dev/null +++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAManagedConnectionFactory.java @@ -0,0 +1,805 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.apache.activemq.ra; + +import javax.jms.ConnectionMetaData; +import javax.resource.ResourceException; +import javax.resource.spi.ConnectionManager; +import javax.resource.spi.ConnectionRequestInfo; +import javax.resource.spi.ManagedConnection; +import javax.resource.spi.ManagedConnectionFactory; +import javax.resource.spi.ResourceAdapter; +import javax.resource.spi.ResourceAdapterAssociation; +import javax.security.auth.Subject; +import java.io.PrintWriter; +import java.util.Iterator; +import java.util.Set; + +import org.apache.activemq.jms.client.ActiveMQConnectionFactory; +import org.apache.activemq.jms.server.recovery.XARecoveryConfig; + +/** + * ActiveMQ ManagedConnectionFactory + * + * @author <a href="mailto:adr...@jboss.com">Adrian Brock</a> + * @author <a href="mailto:jesper.peder...@jboss.org">Jesper Pedersen</a>. + * @author <a href="mailto:andy.tay...@jboss.org">Andy Taylor</a> + */ +public final class ActiveMQRAManagedConnectionFactory implements ManagedConnectionFactory, ResourceAdapterAssociation +{ + /** + * Serial version UID + */ + static final long serialVersionUID = -1452379518562456741L; + /** + * Trace enabled + */ + private static boolean trace = ActiveMQRALogger.LOGGER.isTraceEnabled(); + + /** + * The resource adapter + */ + private ActiveMQResourceAdapter ra; + + /** + * Connection manager + */ + private ConnectionManager cm; + + /** + * The managed connection factory properties + */ + private final ActiveMQRAMCFProperties mcfProperties; + + /** + * Connection Factory used if properties are set + */ + private ActiveMQConnectionFactory recoveryConnectionFactory; + + /* + * The resource recovery if there is one + * */ + private XARecoveryConfig resourceRecovery; + + /** + * Constructor + */ + public ActiveMQRAManagedConnectionFactory() + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("constructor()"); + } + + ra = null; + cm = null; + mcfProperties = new ActiveMQRAMCFProperties(); + } + + /** + * Creates a Connection Factory instance + * + * @return javax.resource.cci.ConnectionFactory instance + * @throws ResourceException Thrown if a connection factory can't be created + */ + public Object createConnectionFactory() throws ResourceException + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.debug("createConnectionFactory()"); + } + + return createConnectionFactory(new ActiveMQRAConnectionManager()); + } + + /** + * Creates a Connection Factory instance + * + * @param cxManager The connection manager + * @return javax.resource.cci.ConnectionFactory instance + * @throws ResourceException Thrown if a connection factory can't be created + */ + public Object createConnectionFactory(final ConnectionManager cxManager) throws ResourceException + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("createConnectionFactory(" + cxManager + ")"); + } + + cm = cxManager; + + ActiveMQRAConnectionFactory cf = new ActiveMQRAConnectionFactoryImpl(this, cm); + + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("Created connection factory: " + cf + + ", using connection manager: " + + cm); + } + return cf; + } + + /** + * Creates a new physical connection to the underlying EIS resource manager. + * + * @param subject Caller's security information + * @param cxRequestInfo Additional resource adapter specific connection request information + * @return The managed connection + * @throws ResourceException Thrown if a managed connection can't be created + */ + public ManagedConnection createManagedConnection(final Subject subject, final ConnectionRequestInfo cxRequestInfo) throws ResourceException + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("createManagedConnection(" + subject + ", " + cxRequestInfo + ")"); + } + + ActiveMQRAConnectionRequestInfo cri = getCRI((ActiveMQRAConnectionRequestInfo) cxRequestInfo); + + ActiveMQRACredential credential = ActiveMQRACredential.getCredential(this, subject, cri); + + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("jms credential: " + credential); + } + + ActiveMQRAManagedConnection mc = new ActiveMQRAManagedConnection(this, + cri, + ra, + credential.getUserName(), + credential.getPassword()); + + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("created new managed connection: " + mc); + } + + registerRecovery(); + + return mc; + } + + private synchronized void registerRecovery() + { + if (recoveryConnectionFactory == null) + { + recoveryConnectionFactory = ra.createRecoveryActiveMQConnectionFactory(mcfProperties); + resourceRecovery = ra.getRecoveryManager().register(recoveryConnectionFactory, null, null); + } + } + + public XARecoveryConfig getResourceRecovery() + { + return resourceRecovery; + } + + /** + * Returns a matched connection from the candidate set of connections. + * + * @param connectionSet The candidate connection set + * @param subject Caller's security information + * @param cxRequestInfo Additional resource adapter specific connection request information + * @return The managed connection + * @throws ResourceException Thrown if the managed connection can not be found + */ + public ManagedConnection matchManagedConnections(@SuppressWarnings("rawtypes") final Set connectionSet, final Subject subject, final ConnectionRequestInfo cxRequestInfo) throws ResourceException + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("matchManagedConnections(" + connectionSet + + ", " + + subject + + ", " + + cxRequestInfo + + ")"); + } + + ActiveMQRAConnectionRequestInfo cri = getCRI((ActiveMQRAConnectionRequestInfo) cxRequestInfo); + ActiveMQRACredential credential = ActiveMQRACredential.getCredential(this, subject, cri); + + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("Looking for connection matching credentials: " + credential); + } + + Iterator<?> connections = connectionSet.iterator(); + + while (connections.hasNext()) + { + Object obj = connections.next(); + + if (obj instanceof ActiveMQRAManagedConnection) + { + ActiveMQRAManagedConnection mc = (ActiveMQRAManagedConnection) obj; + ManagedConnectionFactory mcf = mc.getManagedConnectionFactory(); + + if ((mc.getUserName() == null || mc.getUserName() != null && mc.getUserName() + .equals(credential.getUserName())) && mcf.equals(this)) + { + if (cri.equals(mc.getCRI())) + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("Found matching connection: " + mc); + } + + return mc; + } + } + } + } + + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("No matching connection was found"); + } + + return null; + } + + /** + * Set the log writer -- NOT SUPPORTED + * + * @param out The writer + * @throws ResourceException Thrown if the writer can't be set + */ + public void setLogWriter(final PrintWriter out) throws ResourceException + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("setLogWriter(" + out + ")"); + } + } + + /** + * Get the log writer -- NOT SUPPORTED + * + * @return The writer + * @throws ResourceException Thrown if the writer can't be retrieved + */ + public PrintWriter getLogWriter() throws ResourceException + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("getLogWriter()"); + } + + return null; + } + + /** + * Get the resource adapter + * + * @return The resource adapter + */ + public ResourceAdapter getResourceAdapter() + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("getResourceAdapter()"); + } + + return ra; + } + + /** + * Set the resource adapter + * <p/> + * This should ensure that when the RA is stopped, this MCF will be stopped as well. + * + * @param ra The resource adapter + * @throws ResourceException Thrown if incorrect resource adapter + */ + public void setResourceAdapter(final ResourceAdapter ra) throws ResourceException + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("setResourceAdapter(" + ra + ")"); + } + + if (ra == null || !(ra instanceof ActiveMQResourceAdapter)) + { + throw new ResourceException("Resource adapter is " + ra); + } + + this.ra = (ActiveMQResourceAdapter) ra; + this.ra.setManagedConnectionFactory(this); + } + + /** + * Indicates whether some other object is "equal to" this one. + * + * @param obj Object with which to compare + * @return True if this object is the same as the obj argument; false otherwise. + */ + @Override + public boolean equals(final Object obj) + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("equals(" + obj + ")"); + } + + if (obj == null) + { + return false; + } + + if (obj instanceof ActiveMQRAManagedConnectionFactory) + { + ActiveMQRAManagedConnectionFactory other = (ActiveMQRAManagedConnectionFactory) obj; + + return mcfProperties.equals(other.getProperties()) && ra.equals(other.getResourceAdapter()); + } + else + { + return false; + } + } + + /** + * Return the hash code for the object + * + * @return The hash code + */ + @Override + public int hashCode() + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("hashCode()"); + } + + int hash = mcfProperties.hashCode(); + hash += 31 * ra.hashCode(); + + return hash; + } + + /** + * Get the default session type + * + * @return The value + */ + public String getSessionDefaultType() + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("getSessionDefaultType()"); + } + + return mcfProperties.getSessionDefaultType(); + } + + /** + * Set the default session type + * + * @param type either javax.jms.Topic or javax.jms.Queue + */ + public void setSessionDefaultType(final String type) + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("setSessionDefaultType(" + type + ")"); + } + + mcfProperties.setSessionDefaultType(type); + } + + /** + * @return the connectionParameters + */ + public String getConnectionParameters() + { + return mcfProperties.getStrConnectionParameters(); + } + + public void setConnectionParameters(final String configuration) + { + mcfProperties.setConnectionParameters(configuration); + } + + /** + * @return the transportType + */ + public String getConnectorClassName() + { + return mcfProperties.getConnectorClassName(); + } + + public void setConnectorClassName(final String value) + { + mcfProperties.setConnectorClassName(value); + } + + public String getConnectionLoadBalancingPolicyClassName() + { + return mcfProperties.getConnectionLoadBalancingPolicyClassName(); + } + + public void setConnectionLoadBalancingPolicyClassName(final String connectionLoadBalancingPolicyClassName) + { + mcfProperties.setConnectionLoadBalancingPolicyClassName(connectionLoadBalancingPolicyClassName); + } + + public String getDiscoveryAddress() + { + return mcfProperties.getDiscoveryAddress(); + } + + public void setDiscoveryAddress(final String discoveryAddress) + { + mcfProperties.setDiscoveryAddress(discoveryAddress); + } + + public Integer getDiscoveryPort() + { + return mcfProperties.getDiscoveryPort(); + } + + public void setDiscoveryPort(final Integer discoveryPort) + { + mcfProperties.setDiscoveryPort(discoveryPort); + } + + public Long getDiscoveryRefreshTimeout() + { + return mcfProperties.getDiscoveryRefreshTimeout(); + } + + public void setDiscoveryRefreshTimeout(final Long discoveryRefreshTimeout) + { + mcfProperties.setDiscoveryRefreshTimeout(discoveryRefreshTimeout); + } + + public Long getDiscoveryInitialWaitTimeout() + { + return mcfProperties.getDiscoveryInitialWaitTimeout(); + } + + public void setDiscoveryInitialWaitTimeout(final Long discoveryInitialWaitTimeout) + { + mcfProperties.setDiscoveryInitialWaitTimeout(discoveryInitialWaitTimeout); + } + + public String getClientID() + { + return mcfProperties.getClientID(); + } + + public void setClientID(final String clientID) + { + mcfProperties.setClientID(clientID); + } + + public Integer getDupsOKBatchSize() + { + return mcfProperties.getDupsOKBatchSize(); + } + + public void setDupsOKBatchSize(final Integer dupsOKBatchSize) + { + mcfProperties.setDupsOKBatchSize(dupsOKBatchSize); + } + + public Integer getTransactionBatchSize() + { + return mcfProperties.getTransactionBatchSize(); + } + + public void setTransactionBatchSize(final Integer transactionBatchSize) + { + mcfProperties.setTransactionBatchSize(transactionBatchSize); + } + + public Long getClientFailureCheckPeriod() + { + return mcfProperties.getClientFailureCheckPeriod(); + } + + public void setClientFailureCheckPeriod(final Long clientFailureCheckPeriod) + { + mcfProperties.setClientFailureCheckPeriod(clientFailureCheckPeriod); + } + + public Long getConnectionTTL() + { + return mcfProperties.getConnectionTTL(); + } + + public void setConnectionTTL(final Long connectionTTL) + { + mcfProperties.setConnectionTTL(connectionTTL); + } + + public Long getCallTimeout() + { + return mcfProperties.getCallTimeout(); + } + + public void setCallTimeout(final Long callTimeout) + { + mcfProperties.setCallTimeout(callTimeout); + } + + public Integer getConsumerWindowSize() + { + return mcfProperties.getConsumerWindowSize(); + } + + public void setConsumerWindowSize(final Integer consumerWindowSize) + { + mcfProperties.setConsumerWindowSize(consumerWindowSize); + } + + public Integer getConsumerMaxRate() + { + return mcfProperties.getConsumerMaxRate(); + } + + public void setConsumerMaxRate(final Integer consumerMaxRate) + { + mcfProperties.setConsumerMaxRate(consumerMaxRate); + } + + public Integer getConfirmationWindowSize() + { + return mcfProperties.getConfirmationWindowSize(); + } + + public void setConfirmationWindowSize(final Integer confirmationWindowSize) + { + mcfProperties.setConfirmationWindowSize(confirmationWindowSize); + } + + public Integer getProducerMaxRate() + { + return mcfProperties.getProducerMaxRate(); + } + + public void setProducerMaxRate(final Integer producerMaxRate) + { + mcfProperties.setProducerMaxRate(producerMaxRate); + } + + public Integer getMinLargeMessageSize() + { + return mcfProperties.getMinLargeMessageSize(); + } + + public void setMinLargeMessageSize(final Integer minLargeMessageSize) + { + mcfProperties.setMinLargeMessageSize(minLargeMessageSize); + } + + public Boolean isBlockOnAcknowledge() + { + return mcfProperties.isBlockOnAcknowledge(); + } + + public void setBlockOnAcknowledge(final Boolean blockOnAcknowledge) + { + mcfProperties.setBlockOnAcknowledge(blockOnAcknowledge); + } + + public Boolean isBlockOnNonDurableSend() + { + return mcfProperties.isBlockOnNonDurableSend(); + } + + public void setBlockOnNonDurableSend(final Boolean blockOnNonDurableSend) + { + mcfProperties.setBlockOnNonDurableSend(blockOnNonDurableSend); + } + + public Boolean isBlockOnDurableSend() + { + return mcfProperties.isBlockOnDurableSend(); + } + + public void setBlockOnDurableSend(final Boolean blockOnDurableSend) + { + mcfProperties.setBlockOnDurableSend(blockOnDurableSend); + } + + public Boolean isAutoGroup() + { + return mcfProperties.isAutoGroup(); + } + + public void setAutoGroup(final Boolean autoGroup) + { + mcfProperties.setAutoGroup(autoGroup); + } + + public Boolean isPreAcknowledge() + { + return mcfProperties.isPreAcknowledge(); + } + + public void setPreAcknowledge(final Boolean preAcknowledge) + { + mcfProperties.setPreAcknowledge(preAcknowledge); + } + + public Long getRetryInterval() + { + return mcfProperties.getRetryInterval(); + } + + public void setRetryInterval(final Long retryInterval) + { + mcfProperties.setRetryInterval(retryInterval); + } + + public Double getRetryIntervalMultiplier() + { + return mcfProperties.getRetryIntervalMultiplier(); + } + + public void setRetryIntervalMultiplier(final Double retryIntervalMultiplier) + { + mcfProperties.setRetryIntervalMultiplier(retryIntervalMultiplier); + } + + public Integer getReconnectAttempts() + { + return mcfProperties.getReconnectAttempts(); + } + + public void setReconnectAttempts(final Integer reconnectAttempts) + { + mcfProperties.setReconnectAttempts(reconnectAttempts); + } + + public Boolean isUseGlobalPools() + { + return mcfProperties.isUseGlobalPools(); + } + + public void setUseGlobalPools(final Boolean useGlobalPools) + { + mcfProperties.setUseGlobalPools(useGlobalPools); + } + + public Integer getScheduledThreadPoolMaxSize() + { + return mcfProperties.getScheduledThreadPoolMaxSize(); + } + + public void setScheduledThreadPoolMaxSize(final Integer scheduledThreadPoolMaxSize) + { + mcfProperties.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize); + } + + public Integer getThreadPoolMaxSize() + { + return mcfProperties.getThreadPoolMaxSize(); + } + + public void setThreadPoolMaxSize(final Integer threadPoolMaxSize) + { + mcfProperties.setThreadPoolMaxSize(threadPoolMaxSize); + } + + public Boolean isHA() + { + return mcfProperties.isHA(); + } + + public void setHA(Boolean ha) + { + mcfProperties.setHA(ha); + } + + /** + * Get the useTryLock. + * + * @return the useTryLock. + */ + public Integer getUseTryLock() + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("getUseTryLock()"); + } + + return mcfProperties.getUseTryLock(); + } + + /** + * Set the useTryLock. + * + * @param useTryLock the useTryLock. + */ + public void setUseTryLock(final Integer useTryLock) + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("setUseTryLock(" + useTryLock + ")"); + } + + mcfProperties.setUseTryLock(useTryLock); + } + + /** + * Get the connection metadata + * + * @return The metadata + */ + public ConnectionMetaData getMetaData() + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("getMetadata()"); + } + + return new ActiveMQRAConnectionMetaData(); + } + + /** + * Get the managed connection factory properties + * + * @return The properties + */ + protected ActiveMQRAMCFProperties getProperties() + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("getProperties()"); + } + + return mcfProperties; + } + + /** + * Get a connection request info instance + * + * @param info The instance that should be updated; may be <code>null</code> + * @return The instance + */ + private ActiveMQRAConnectionRequestInfo getCRI(final ActiveMQRAConnectionRequestInfo info) + { + if (ActiveMQRAManagedConnectionFactory.trace) + { + ActiveMQRALogger.LOGGER.trace("getCRI(" + info + ")"); + } + + if (info == null) + { + // Create a default one + return new ActiveMQRAConnectionRequestInfo(ra.getProperties(), mcfProperties.getType()); + } + else + { + // Fill the one with any defaults + info.setDefaults(ra.getProperties()); + return info; + } + } + + // this should be called when ActiveMQResourceAdapter.stop() is called since this MCF is registered with it + public void stop() + { + if (resourceRecovery != null) + { + ra.getRecoveryManager().unRegister(resourceRecovery); + } + + if (recoveryConnectionFactory != null) + { + recoveryConnectionFactory.close(); + recoveryConnectionFactory = null; + } + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/034adfbf/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAMapMessage.java ---------------------------------------------------------------------- diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAMapMessage.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAMapMessage.java new file mode 100644 index 0000000..8affe60 --- /dev/null +++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAMapMessage.java @@ -0,0 +1,452 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.apache.activemq.ra; + +import java.util.Arrays; +import java.util.Enumeration; + +import javax.jms.JMSException; +import javax.jms.MapMessage; + + +/** + * A wrapper for a message + * + * @author <a href="mailto:adr...@jboss.com">Adrian Brock</a> + * @author <a href="mailto:jesper.peder...@jboss.org">Jesper Pedersen</a> + * @version $Revision: 71554 $ + */ +public class ActiveMQRAMapMessage extends ActiveMQRAMessage implements MapMessage +{ + /** Whether trace is enabled */ + private static boolean trace = ActiveMQRALogger.LOGGER.isTraceEnabled(); + + /** + * Create a new wrapper + * + * @param message the message + * @param session the session + */ + public ActiveMQRAMapMessage(final MapMessage message, final ActiveMQRASession session) + { + super(message, session); + + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("constructor(" + message + ", " + session + ")"); + } + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public boolean getBoolean(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getBoolean(" + name + ")"); + } + + return ((MapMessage)message).getBoolean(name); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public byte getByte(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getByte(" + name + ")"); + } + + return ((MapMessage)message).getByte(name); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public byte[] getBytes(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getBytes(" + name + ")"); + } + + return ((MapMessage)message).getBytes(name); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public char getChar(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getChar(" + name + ")"); + } + + return ((MapMessage)message).getChar(name); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public double getDouble(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getDouble(" + name + ")"); + } + + return ((MapMessage)message).getDouble(name); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public float getFloat(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getFloat(" + name + ")"); + } + + return ((MapMessage)message).getFloat(name); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public int getInt(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getInt(" + name + ")"); + } + + return ((MapMessage)message).getInt(name); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public long getLong(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getLong(" + name + ")"); + } + + return ((MapMessage)message).getLong(name); + } + + /** + * Get the map names + * @return The values + * @exception JMSException Thrown if an error occurs + */ + @SuppressWarnings("rawtypes") + public Enumeration getMapNames() throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getMapNames()"); + } + + return ((MapMessage)message).getMapNames(); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public Object getObject(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getObject(" + name + ")"); + } + + return ((MapMessage)message).getObject(name); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public short getShort(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getShort(" + name + ")"); + } + + return ((MapMessage)message).getShort(name); + } + + /** + * Get + * @param name The name + * @return The value + * @exception JMSException Thrown if an error occurs + */ + public String getString(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getString(" + name + ")"); + } + + return ((MapMessage)message).getString(name); + } + + /** + * Does the item exist + * @param name The name + * @return True / false + * @exception JMSException Thrown if an error occurs + */ + public boolean itemExists(final String name) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("itemExists(" + name + ")"); + } + + return ((MapMessage)message).itemExists(name); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setBoolean(final String name, final boolean value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setBoolean(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setBoolean(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setByte(final String name, final byte value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setByte(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setByte(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @param offset The offset + * @param length The length + * @exception JMSException Thrown if an error occurs + */ + public void setBytes(final String name, final byte[] value, final int offset, final int length) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setBytes(" + name + ", " + Arrays.toString(value) + ", " + offset + ", " + + length + ")"); + } + + ((MapMessage)message).setBytes(name, value, offset, length); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setBytes(final String name, final byte[] value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setBytes(" + name + ", " + Arrays.toString(value) + ")"); + } + + ((MapMessage)message).setBytes(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setChar(final String name, final char value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setChar(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setChar(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setDouble(final String name, final double value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setDouble(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setDouble(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setFloat(final String name, final float value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setFloat(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setFloat(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setInt(final String name, final int value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setInt(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setInt(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setLong(final String name, final long value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setLong(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setLong(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setObject(final String name, final Object value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setObject(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setObject(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setShort(final String name, final short value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setShort(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setShort(name, value); + } + + /** + * Set + * @param name The name + * @param value The value + * @exception JMSException Thrown if an error occurs + */ + public void setString(final String name, final String value) throws JMSException + { + if (ActiveMQRAMapMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setString(" + name + ", " + value + ")"); + } + + ((MapMessage)message).setString(name, value); + } +} http://git-wip-us.apache.org/repos/asf/activemq-6/blob/034adfbf/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAMessage.java ---------------------------------------------------------------------- diff --git a/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAMessage.java b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAMessage.java new file mode 100644 index 0000000..565ab15 --- /dev/null +++ b/activemq-ra/src/main/java/org/apache/activemq/ra/ActiveMQRAMessage.java @@ -0,0 +1,897 @@ +/* + * Copyright 2005-2014 Red Hat, Inc. + * Red Hat licenses this file to you under the Apache License, version + * 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + * implied. See the License for the specific language governing + * permissions and limitations under the License. + */ +package org.apache.activemq.ra; + +import javax.jms.Destination; +import javax.jms.JMSException; +import javax.jms.Message; +import java.util.Arrays; +import java.util.Enumeration; + + +/** + * A wrapper for a message + * + * @author <a href="mailto:adr...@jboss.com">Adrian Brock</a> + * @author <a href="mailto:jesper.peder...@jboss.org">Jesper Pedersen</a> + */ +public class ActiveMQRAMessage implements Message +{ + /** + * Whether trace is enabled + */ + private static boolean trace = ActiveMQRALogger.LOGGER.isTraceEnabled(); + + /** + * The message + */ + protected Message message; + + /** + * The session + */ + protected ActiveMQRASession session; + + /** + * Create a new wrapper + * + * @param message the message + * @param session the session + */ + public ActiveMQRAMessage(final Message message, final ActiveMQRASession session) + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("constructor(" + message + ", " + session + ")"); + } + + this.message = message; + this.session = session; + } + + /** + * Acknowledge + * + * @throws JMSException Thrown if an error occurs + */ + public void acknowledge() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("acknowledge()"); + } + + session.getSession(); // Check for closed + message.acknowledge(); + } + + /** + * Clear body + * + * @throws JMSException Thrown if an error occurs + */ + public void clearBody() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("clearBody()"); + } + + message.clearBody(); + } + + /** + * Clear properties + * + * @throws JMSException Thrown if an error occurs + */ + public void clearProperties() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("clearProperties()"); + } + + message.clearProperties(); + } + + /** + * Get property + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public boolean getBooleanProperty(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getBooleanProperty(" + name + ")"); + } + + return message.getBooleanProperty(name); + } + + /** + * Get property + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public byte getByteProperty(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getByteProperty(" + name + ")"); + } + + return message.getByteProperty(name); + } + + /** + * Get property + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public double getDoubleProperty(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getDoubleProperty(" + name + ")"); + } + + return message.getDoubleProperty(name); + } + + /** + * Get property + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public float getFloatProperty(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getFloatProperty(" + name + ")"); + } + + return message.getFloatProperty(name); + } + + /** + * Get property + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public int getIntProperty(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getIntProperty(" + name + ")"); + } + + return message.getIntProperty(name); + } + + /** + * Get correlation id + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public String getJMSCorrelationID() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSCorrelationID()"); + } + + return message.getJMSCorrelationID(); + } + + /** + * Get correlation id + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public byte[] getJMSCorrelationIDAsBytes() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSCorrelationIDAsBytes()"); + } + + return message.getJMSCorrelationIDAsBytes(); + } + + /** + * Get delivery mode + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public int getJMSDeliveryMode() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSDeliveryMode()"); + } + + return message.getJMSDeliveryMode(); + } + + /** + * Get destination + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public Destination getJMSDestination() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSDestination()"); + } + + return message.getJMSDestination(); + } + + /** + * Get expiration + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public long getJMSExpiration() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSExpiration()"); + } + + return message.getJMSExpiration(); + } + + /** + * Get message id + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public String getJMSMessageID() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSMessageID()"); + } + + return message.getJMSMessageID(); + } + + /** + * Get priority + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public int getJMSPriority() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSPriority()"); + } + + return message.getJMSPriority(); + } + + /** + * Get redelivered status + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public boolean getJMSRedelivered() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSRedelivered()"); + } + + return message.getJMSRedelivered(); + } + + /** + * Get reply to destination + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public Destination getJMSReplyTo() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSReplyTo()"); + } + + return message.getJMSReplyTo(); + } + + /** + * Get timestamp + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public long getJMSTimestamp() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSTimestamp()"); + } + + return message.getJMSTimestamp(); + } + + /** + * Get type + * + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public String getJMSType() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSType()"); + } + + return message.getJMSType(); + } + + /** + * Get property + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public long getLongProperty(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getLongProperty(" + name + ")"); + } + + return message.getLongProperty(name); + } + + /** + * Get property + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public Object getObjectProperty(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getObjectProperty(" + name + ")"); + } + + return message.getObjectProperty(name); + } + + /** + * Get property names + * + * @return The values + * @throws JMSException Thrown if an error occurs + */ + @SuppressWarnings("rawtypes") + public Enumeration getPropertyNames() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getPropertyNames()"); + } + + return message.getPropertyNames(); + } + + /** + * Get property + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public short getShortProperty(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getShortProperty(" + name + ")"); + } + + return message.getShortProperty(name); + } + + /** + * Get property + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public String getStringProperty(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getStringProperty(" + name + ")"); + } + + return message.getStringProperty(name); + } + + /** + * Do property exist + * + * @param name The name + * @return The value + * @throws JMSException Thrown if an error occurs + */ + public boolean propertyExists(final String name) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("propertyExists(" + name + ")"); + } + + return message.propertyExists(name); + } + + /** + * Set property + * + * @param name The name + * @param value The value + * @throws JMSException Thrown if an error occurs + */ + public void setBooleanProperty(final String name, final boolean value) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setBooleanProperty(" + name + ", " + value + ")"); + } + + message.setBooleanProperty(name, value); + } + + /** + * Set property + * + * @param name The name + * @param value The value + * @throws JMSException Thrown if an error occurs + */ + public void setByteProperty(final String name, final byte value) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setByteProperty(" + name + ", " + value + ")"); + } + + message.setByteProperty(name, value); + } + + /** + * Set property + * + * @param name The name + * @param value The value + * @throws JMSException Thrown if an error occurs + */ + public void setDoubleProperty(final String name, final double value) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setDoubleProperty(" + name + ", " + value + ")"); + } + + message.setDoubleProperty(name, value); + } + + /** + * Set property + * + * @param name The name + * @param value The value + * @throws JMSException Thrown if an error occurs + */ + public void setFloatProperty(final String name, final float value) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setFloatProperty(" + name + ", " + value + ")"); + } + + message.setFloatProperty(name, value); + } + + /** + * Set property + * + * @param name The name + * @param value The value + * @throws JMSException Thrown if an error occurs + */ + public void setIntProperty(final String name, final int value) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setIntProperty(" + name + ", " + value + ")"); + } + + message.setIntProperty(name, value); + } + + /** + * Set correlation id + * + * @param correlationID The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSCorrelationID(final String correlationID) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSCorrelationID(" + correlationID + ")"); + } + + message.setJMSCorrelationID(correlationID); + } + + /** + * Set correlation id + * + * @param correlationID The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSCorrelationIDAsBytes(final byte[] correlationID) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSCorrelationIDAsBytes(" + Arrays.toString(correlationID) + ")"); + } + + message.setJMSCorrelationIDAsBytes(correlationID); + } + + /** + * Set delivery mode + * + * @param deliveryMode The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSDeliveryMode(final int deliveryMode) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSDeliveryMode(" + deliveryMode + ")"); + } + + message.setJMSDeliveryMode(deliveryMode); + } + + /** + * Set destination + * + * @param destination The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSDestination(final Destination destination) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSDestination(" + destination + ")"); + } + + message.setJMSDestination(destination); + } + + /** + * Set expiration + * + * @param expiration The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSExpiration(final long expiration) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSExpiration(" + expiration + ")"); + } + + message.setJMSExpiration(expiration); + } + + /** + * Set message id + * + * @param id The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSMessageID(final String id) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSMessageID(" + id + ")"); + } + + message.setJMSMessageID(id); + } + + /** + * Set priority + * + * @param priority The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSPriority(final int priority) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSPriority(" + priority + ")"); + } + + message.setJMSPriority(priority); + } + + /** + * Set redelivered status + * + * @param redelivered The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSRedelivered(final boolean redelivered) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSRedelivered(" + redelivered + ")"); + } + + message.setJMSRedelivered(redelivered); + } + + /** + * Set reply to + * + * @param replyTo The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSReplyTo(final Destination replyTo) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSReplyTo(" + replyTo + ")"); + } + + message.setJMSReplyTo(replyTo); + } + + /** + * Set timestamp + * + * @param timestamp The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSTimestamp(final long timestamp) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSTimestamp(" + timestamp + ")"); + } + + message.setJMSTimestamp(timestamp); + } + + /** + * Set type + * + * @param type The value + * @throws JMSException Thrown if an error occurs + */ + public void setJMSType(final String type) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSType(" + type + ")"); + } + + message.setJMSType(type); + } + + /** + * Set property + * + * @param name The name + * @param value The value + * @throws JMSException Thrown if an error occurs + */ + public void setLongProperty(final String name, final long value) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setLongProperty(" + name + ", " + value + ")"); + } + + message.setLongProperty(name, value); + } + + /** + * Set property + * + * @param name The name + * @param value The value + * @throws JMSException Thrown if an error occurs + */ + public void setObjectProperty(final String name, final Object value) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setObjectProperty(" + name + ", " + value + ")"); + } + + message.setObjectProperty(name, value); + } + + /** + * Set property + * + * @param name The name + * @param value The value + * @throws JMSException Thrown if an error occurs + */ + public void setShortProperty(final String name, final short value) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setShortProperty(" + name + ", " + value + ")"); + } + + message.setShortProperty(name, value); + } + + /** + * Set property + * + * @param name The name + * @param value The value + * @throws JMSException Thrown if an error occurs + */ + public void setStringProperty(final String name, final String value) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setStringProperty(" + name + ", " + value + ")"); + } + + message.setStringProperty(name, value); + } + + @Override + public long getJMSDeliveryTime() throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getJMSDeliveryTime()"); + } + return message.getJMSDeliveryTime(); + } + + @Override + public void setJMSDeliveryTime(long deliveryTime) throws JMSException + { + + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("setJMSDeliveryTime(" + deliveryTime + ")"); + } + message.setJMSDeliveryTime(deliveryTime); + } + + @Override + public <T> T getBody(Class<T> c) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("getBody(" + c + ")"); + } + return message.getBody(c); + } + + @Override + public boolean isBodyAssignableTo(@SuppressWarnings("rawtypes") + Class c) throws JMSException + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("isBodyAssignableTo(" + c + ")"); + } + return message.isBodyAssignableTo(c); + } + + /** + * Return the hash code + * + * @return The hash code + */ + @Override + public int hashCode() + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("hashCode()"); + } + + return message.hashCode(); + } + + /** + * Check for equality + * + * @param object The other object + * @return True / false + */ + @Override + public boolean equals(final Object object) + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("equals(" + object + ")"); + } + + if (object != null && object instanceof ActiveMQRAMessage) + { + return message.equals(((ActiveMQRAMessage)object).message); + } + else + { + return message.equals(object); + } + } + + /** + * Return string representation + * + * @return The string + */ + @Override + public String toString() + { + if (ActiveMQRAMessage.trace) + { + ActiveMQRALogger.LOGGER.trace("toString()"); + } + + return message.toString(); + } +}