public void restart() { if (hazelcast != null) { shutdown(); } // Hazelcast Instance hazelcast = Hazelcast.newHazelcastInstance(config); // HazelcastMQ Instance HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); mqInstance = HazelcastMQ.newHazelcastMQInstance(mqConfig); }
@Override public void signalDispatchReady() { config.getExecutor().execute(this); }
/** * 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())); } }
HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hz); mqConfig.setExecutor(Executors.newSingleThreadExecutor()); mqConfig.setContextDispatchStrategy( HazelcastMQConfig.ContextDispatchStrategy.REACTOR); mqConfig.getExecutor().shutdown();
/** * 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); } }
/** * Refreshes the transaction context by obtaining a new one from the * {@link HazelcastInstance}. Refreshing the context is required because * Hazelcast only supports a single transaction per TransactionContext * instance so after a commit or rollback a new context must be fetched. */ private void refreshTransactionContext() { HazelcastInstance hazelcast = DefaultXaHazelcastMQContext.this.config.getHazelcastInstance(); txnContext = hazelcast.newTransactionContext(); }
/** * Constructs the configuration with the following defaults: * <ul> * <li>messageConverter: {@link NoOpMessageConverter}</li> * <li>topicMaxMessageCount: 1000</li> * <li>executor: {@link Executors#newCachedThreadPool()} (lazy * initialized)</li> * <li>contextDispatchStrategy: * {@link ContextDispatchStrategy#DEDICATED_THREAD}</li> * </ul> * * @param hzInstance the Hazelcast instances to use for all queues and topic * operations */ public HazelcastMQConfig(HazelcastInstance hzInstance) { setHazelcastInstance(hzInstance); }
Object msgData = queue.poll(); if (msgData != null) { msg = config.getMessageConverter().toMessage(msgData);
/** * Constructs the topic listener which will listen on the given topic. * * @param topic the topic to listen to */ public HzTopicListener(ITopic<Object> topic) { this.queue = QueueTopicProxyFactory .createQueueProxy(new ArrayBlockingQueue<>(config .getTopicMaxMessageCount())); this.msgTopic = topic; registrationId = topic.addMessageListener(this); }
HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hz); mqConfig.setExecutor(executor); mqConfig.setContextDispatchStrategy( HazelcastMQConfig.ContextDispatchStrategy.REACTOR);
@Bean(destroyMethod = "shutdown") public HazelcastMQInstance hazelcastMQ() { HazelcastMQConfig mqConfig = new HazelcastMQConfig(hazelcast()); return HazelcastMQ.newHazelcastMQInstance(mqConfig); }
@Override public String createTemporaryTopic() { IdGenerator idGenerator = config.getHazelcastInstance().getIdGenerator( "hzmqcontext-temporary-destination"); long tempDestId = idGenerator.newId(); String destination = Headers.DESTINATION_TEMPORARY_TOPIC_PREFIX + tempDestId; temporaryTopics.add(destination); return destination; }
Object msgData = config.getMessageConverter().fromMessage(msg);
public void restart() { if (hazelcast != null) { shutdown(); } // Hazelcast Instance hazelcast = Hazelcast.newHazelcastInstance(config); // HazelcastMQ Instance HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); mqInstance = HazelcastMQ.newHazelcastMQInstance(mqConfig); }
@Bean(destroyMethod = "shutdown") public HazelcastMQInstance hazelcastMQ() { HazelcastMQConfig mqConfig = new HazelcastMQConfig(hazelcast()); return HazelcastMQ.newHazelcastMQInstance(mqConfig); }
@Override public String createTemporaryQueue() { IdGenerator idGenerator = config.getHazelcastInstance().getIdGenerator( "hzmqcontext-temporary-destination"); long tempDestId = idGenerator.newId(); String destination = Headers.DESTINATION_TEMPORARY_QUEUE_PREFIX + tempDestId; temporaryQueues.add(destination); return destination; }
/** * Constructs the dispatcher. */ public DedicatedThreadDispatcher() { this.dispatchReadyCondition = new StatefulCondition(); config.getExecutor().execute(this); }
public void restart() { if (hazelcast != null) { shutdown(); } // Hazelcast Instance hazelcast = Hazelcast.newHazelcastInstance(config); // HazelcastMQ Instance HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); mqInstance = HazelcastMQ.newHazelcastMQInstance(mqConfig); }
/** * Constructs the context which may be transacted. 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 DefaultLocalTxHazelcastMQContext(boolean transacted, DefaultHazelcastMQInstance hazelcastMQInstance) { super(hazelcastMQInstance); if (transacted) { HazelcastInstance hazelcast = this.config.getHazelcastInstance(); txnContext = hazelcast.newTransactionContext(); txnContext.beginTransaction(); } }
public void restart() { if (hazelcast != null) { shutdown(); } hazelcast = Hazelcast.newHazelcastInstance(config); HazelcastMQConfig mqConfig = new HazelcastMQConfig(); mqConfig.setHazelcastInstance(hazelcast); connectionFactory = HazelcastMQ.newHazelcastMQInstance(mqConfig); mqContext = connectionFactory.createContext(); }