Example usage for javax.jms Destination equals

List of usage examples for javax.jms Destination equals

Introduction

In this page you can find the example usage for javax.jms Destination equals.

Prototype

public boolean equals(Object obj) 

Source Link

Document

Indicates whether some other object is "equal to" this one.

Usage

From source file:de.marcelsauer.jmsloadtester.handler.DestinationHandlerImplTest.java

@Test
public void testCaching() throws NamingException {
    expect(mockJndiTemplate.lookup("dummy1")).andReturn(mockDestination1).times(1);
    expect(mockJndiTemplate.lookup("dummy2")).andReturn(mockDestination2).times(1);
    replay();//from  w w  w  . ja v a  2  s . c om
    final Destination dest1 = handler.getDestination("dummy1");
    final Destination dest2 = handler.getDestination("dummy2");
    assertTrue(dest1 != null);
    assertTrue(dest2 != null);
    assertTrue(dest1 != dest2);
    assertFalse(dest1.equals(dest2));
    for (int i = 0; i < 100; i++) {
        Destination cachedDest = handler.getDestination("dummy1");
        assertTrue(dest1 == cachedDest);
        assertTrue(dest1.equals(cachedDest));
    }
    verify();
}

From source file:org.apache.servicemix.jms.endpoints.JmsProviderEndpoint.java

/**
 * Process an InOnly or RobustInOnly exchange inside a JMS session.
 * This method delegates the JMS message creation to the marshaler and uses
 * the JMS template to send it.  If the JMS destination that was used to send
 * the message is not the default one, it synchronously wait for the message
 * to come back using a JMS selector.  Else, it just returns and the response
 * message will come back from the listener container.
 *
 * @param exchange/*from w  ww  .j a va  2  s .  co  m*/
 * @param in
 * @param session
 * @throws Exception
 */
protected void processInOutInSession(final MessageExchange exchange, final NormalizedMessage in,
        final Session session) throws Exception {
    // Create destinations
    final Destination dest = getDestination(exchange, in, session);
    final Destination replyDest = getReplyDestination(exchange, in, session);
    // Create message and send it
    final Message sendJmsMsg = marshaler.createMessage(exchange, in, session);
    sendJmsMsg.setJMSReplyTo(replyDest);
    // handle correlation ID
    String correlationId = sendJmsMsg.getJMSMessageID() != null ? sendJmsMsg.getJMSMessageID()
            : exchange.getExchangeId();
    sendJmsMsg.setJMSCorrelationID(correlationId);

    boolean asynchronous = replyDest.equals(replyDestination);

    if (asynchronous) {
        store.store(correlationId, exchange);
    }

    try {
        template.send(dest, new MessageCreator() {
            public Message createMessage(Session session) throws JMSException {
                return sendJmsMsg;
            }
        });
    } catch (Exception e) {
        if (asynchronous) {
            store.load(exchange.getExchangeId());
        }
        throw e;
    }

    if (!asynchronous) {
        // Create selector
        String jmsId = sendJmsMsg.getJMSMessageID();
        String selector = MSG_SELECTOR_START + jmsId + MSG_SELECTOR_END;
        // Receiving JMS Message, Creating and Returning NormalizedMessage out
        Message receiveJmsMsg = template.receiveSelected(replyDest, selector);
        if (receiveJmsMsg == null) {
            throw new IllegalStateException("Unable to receive response");
        }

        NormalizedMessage out = exchange.getMessage("out");
        if (out == null) {
            out = exchange.createMessage();
            exchange.setMessage(out, "out");
        }
        marshaler.populateMessage(receiveJmsMsg, exchange, out);
        boolean txSync = exchange.isTransacted()
                && Boolean.TRUE.equals(exchange.getProperty(JbiConstants.SEND_SYNC));
        if (txSync) {
            sendSync(exchange);
        } else {
            send(exchange);
        }
    }
}