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.
/**
* Copyright (C) 2012 Ness Computing, Inc.
*
* Licensed 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 com.nesscomputing.jms;
import java.lang.annotation.Annotation;
import javax.annotation.Nullable;
import javax.jms.ConnectionFactory;
import javax.jms.Message;
import com.google.common.base.Preconditions;
import com.google.inject.Inject;
import com.google.inject.Injector;
import com.google.inject.Key;
import com.google.inject.Singleton;
/**
* Factory to create new Runnables to access topics and queues.
*/
@Singleton
public class JmsRunnableFactory
{
private final Annotation annotation;
private ConnectionFactory connectionFactory;
private JmsConfig jmsConfig;
private JsonProducerCallback producerCallback;
JmsRunnableFactory(@Nullable final Annotation annotation)
{
this.annotation = annotation;
}
@Inject
void inject(final Injector injector, final JsonProducerCallback jsonProducerCallback)
{
if (annotation == null) {
this.connectionFactory = injector.getInstance(Key.get(ConnectionFactory.class));
this.jmsConfig = injector.getInstance(Key.get(JmsConfig.class));
}
else {
this.connectionFactory = injector.getInstance(Key.get(ConnectionFactory.class, annotation));
this.jmsConfig = injector.getInstance(Key.get(JmsConfig.class, annotation));
}
this.producerCallback = jsonProducerCallback;
}
/**
* Creates a new {@link TopicProducer}. The callback is called to convert an object that is sent into the TopicProducer
* into a JMS message type.
*/
public TopicProducer createTopicProducer(final String topic, final ProducerCallback messageCallback)
{
Preconditions.checkState(connectionFactory != null, "connection factory was never injected!");
return new TopicProducer(connectionFactory, jmsConfig, topic, messageCallback);
}
/**
* Creates a new {@link QueueProducer}. The callback is called to convert an object that is sent into the QueueProducer
* into a JMS message type.
*/
public QueueProducer createQueueProducer(final String topic, final ProducerCallback messageCallback)
{
Preconditions.checkState(connectionFactory != null, "connection factory was never injected!");
return new QueueProducer(connectionFactory, jmsConfig, topic, messageCallback);
}
/**
* Creates a new {@link TopicProducer}. The producer accepts arbitrary objects and uses the Jackson object mapper to convert them into
* JSON and sends them as a text message.
*/
public TopicProducer