/** * Returns a new {@link HazelcastMQInstance} using the given configuration. If * the configuration is null, a default configuration will be used. * * @param config * the configuration for the instance * @return the new HazelcastMQ instance */ public static HazelcastMQInstance newHazelcastMQInstance( HazelcastMQConfig config) { if (config == null) { config = new HazelcastMQConfig(); } return new DefaultHazelcastMQInstance(config); } }
@Override public HazelcastMQContext createContext() { return createContext(false); }
/** * Constructs the context. The context is a child of the given HazelcastMQ * instance. * * @param transacted true to create a transacted context, false otherwise * @param hazelcastMQInstance the parent MQ instance */ public DefaultHazelcastMQContext( DefaultHazelcastMQInstance hazelcastMQInstance) { this.hazelcastMQInstance = hazelcastMQInstance; this.config = this.hazelcastMQInstance.getConfig(); this.consumerMap = new HashMap<>(); this.temporaryQueues = new HashSet<>(); this.temporaryTopics = new HashSet<>(); this.id = "hzmqcontext-" + UUID.randomUUID().toString(); this.contextLock = new ReentrantLock(); this.receiveReadyCondition = this.contextLock.newCondition(); switch (config.getContextDispatchStrategy()) { case DEDICATED_THREAD: messageDispatcher = new DedicatedThreadDispatcher(); break; case REACTOR: messageDispatcher = new ReactorThreadDispatcher(); break; default: throw new IllegalArgumentException(format( "Unknown context dispatch strategy [%s]", config. getContextDispatchStrategy())); } }
/** * Constructs the producer. * * @param destination the destination to use for send operations that don't * specify a destination * @param hazelcastMQContext the context that this producer belongs to */ public DefaultHazelcastMQProducer(String destination, DefaultHazelcastMQContext hazelcastMQContext) { this.destination = destination; this.hazelcastMQContext = hazelcastMQContext; this.config = hazelcastMQContext.getHazelcastMQInstance().getConfig(); this.idGenerator = config.getHazelcastInstance().getIdGenerator( "hazelcastmqproducer"); }
this.closed = false; this.hazelcastMQContext = hazelcastMQContext; this.config = hazelcastMQContext.getHazelcastMQInstance().getConfig(); this.contextLock = hazelcastMQContext.getContextLock(); this.id = "hzmqconsumer-" + UUID.randomUUID().toString();
/** * Constructs the relayer which will immediately create a context and begin * listening for messages. */ public TopicMessageRelayer() { context = createContext(); consumer = context.createConsumer(TXN_TOPIC_QUEUE_DESTINATION); consumer.setMessageListener(this); }