Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/**
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.camel.component.sjms.producer;
import java.util.Map;
import java.util.TreeMap;
import java.util.UUID;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Exchanger;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
import javax.jms.Session;
import org.apache.camel.AsyncCallback;
import org.apache.camel.CamelException;
import org.apache.camel.Exchange;
import org.apache.camel.component.sjms.MessageConsumerResources;
import org.apache.camel.component.sjms.MessageProducerResources;
import org.apache.camel.component.sjms.SjmsEndpoint;
import org.apache.camel.component.sjms.SjmsExchangeMessageHelper;
import org.apache.camel.component.sjms.SjmsProducer;
import org.apache.camel.component.sjms.jms.JmsObjectFactory;
import org.apache.camel.component.sjms.tx.SessionTransactionSynchronization;
import org.apache.camel.util.ObjectHelper;
import org.apache.commons.pool.BasePoolableObjectFactory;
import org.apache.commons.pool.impl.GenericObjectPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* A Camel Producer that provides the InOut Exchange pattern.
*/
public class InOutProducer extends SjmsProducer {
/**
* We use the {@link ReadWriteLock} to manage the {@link TreeMap} in place
* of a {@link ConcurrentMap} because due to significant performance gains.
*/
private static Map> exchangerMap = new TreeMap>();
private ReadWriteLock lock = new ReentrantReadWriteLock();
/**
* A pool of {@link MessageConsumerResource} objects that are the reply
* consumers.
*/
protected class MessageConsumerResourcesFactory extends BasePoolableObjectFactory {
@Override
public MessageConsumerResources makeObject() throws Exception {
MessageConsumerResources answer = null;
Connection conn = null;
Session session = null;
try {
conn = getConnectionResource().borrowConnection();
if (isEndpointTransacted()) {
session = conn.createSession(true, Session.SESSION_TRANSACTED);
} else {
session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
}
Destination replyToDestination = null;
if (ObjectHelper.isEmpty(getNamedReplyTo())) {
replyToDestination = JmsObjectFactory.createTemporaryDestination(session, isTopic());
} else {
replyToDestination = JmsObjectFactory.createDestination(session, getNamedReplyTo(), isTopic());
}
MessageConsumer messageConsumer = JmsObjectFactory.createMessageConsumer(session, replyToDestination, null, isTopic(), null, true);
messageConsumer.setMessageListener(new MessageListener() {
@Override
public void onMessage(Message message) {
if (log.isDebugEnabled()) {
log.debug("Message Received in the Consumer Pool");
log.debug(" Message : {}", message);
}
try {
Exchanger