@Override public <T extends PubSubMessage> void subscribe(PubSubType type, final PubSubListener<T> listener, Class<T> clazz) { String name = type.toString(); ITopic<T> topic = hazelcastSub.getTopic(name); String regId = topic.addMessageListener(new MessageListener<T>() { @Override public void onMessage(Message<T> message) { PubSubMessage msg = message.getMessageObject(); if (!nodeId.equals(msg.getNodeId())) { listener.onMessage(message.getMessageObject()); } } }); Queue<String> list = map.get(name); if (list == null) { list = new ConcurrentLinkedQueue<String>(); Queue<String> oldList = map.putIfAbsent(name, list); if (oldList != null) { list = oldList; } } list.add(regId); }
@Test public void doTest() { logger.info( "do test" ); Hazelcast.addInstanceListener( this ); ITopic<Object> topic = Hazelcast.getTopic( "default" ); topic.addMessageListener( this ); topic.publish( "my-message-object" ); Collection<Instance> instances = Hazelcast.getInstances(); for ( Instance instance : instances ) { logger.info( "ID: [" + instance.getId() + "] Type: [" + instance.getInstanceType() + "]" ); } Set<Member> setMembers = Hazelcast.getCluster().getMembers(); for ( Member member : setMembers ) { logger.info( "isLocalMember " + member.localMember() ); logger.info( "member.inetsocketaddress " + member.getInetSocketAddress() ); } }
private FixedSizeMessageBox(final int capacity, final ITopic<TransferObject> topic, final String localMember, final Predicate<? super MessageEvent> filter, final Function<? super MessageEvent, ? extends V> messageParser){ super(capacity); this.filter = Objects.requireNonNull(filter); this.topic = Objects.requireNonNull(topic); this.subscription = topic.addMessageListener(this); this.localMemberID = localMember; this.messageParser = Objects.requireNonNull(messageParser); }
private TransferObjectListener(final ITopic<TransferObject> topic, final String localMember, final Predicate<? super HazelcastIncomingMessage> filter, final MessageListener listener){ this.localMemberID = localMember; this.filter = Objects.requireNonNull(filter); this.listener = Objects.requireNonNull(listener); this.topic = Objects.requireNonNull(topic); this.subscription = topic.addMessageListener(this); }
private MessageReceiver(final ITopic<TransferObject> topic, final String localMember, final Predicate<? super HazelcastIncomingMessage> filter, final Function<? super MessageEvent, ? extends V> messageParser){ this.filter = Objects.requireNonNull(filter); this.topic = Objects.requireNonNull(topic); this.localMemberID = localMember; this.subscription = topic.addMessageListener(this); this.messageParser = Objects.requireNonNull(messageParser); }
private LinkedMessageBox(final ITopic<TransferObject> topic, final String localMember, final Predicate<? super MessageEvent> filter, final Function<? super MessageEvent, ? extends V> messageParser) { this.filter = Objects.requireNonNull(filter); this.topic = Objects.requireNonNull(topic); this.subscription = topic.addMessageListener(this); this.localMemberID = localMember; this.messageParser = Objects.requireNonNull(messageParser); }
/** * Attaches a listener to {@link ITopic} which passes published items to the specified consumer * * @param topic topic instance which the listener will be added * @param consumer message consumer that the added items will be passed on. */ private static void addListener(ITopic<String> topic, Consumer<String> consumer) { topic.addMessageListener(event -> consumer.accept(event.getMessageObject())); }
public HealthManagementImpl(HazelcastInstance hzInstance) { this.hzInstance = hzInstance; ITopic<HealthState> hTopic = hzInstance.getTopic(TPN_XDM_HEALTH); hTopic.addMessageListener(this); // TODO: get initial state somehow! }
private static void executeTopic() { System.out.println("### Topic Execution Started... ###"); ITopic<String> topic = (ITopic<String>) context.getBean("topic", ITopic.class); topic.addMessageListener(new MessageListener<String>() { @Override public void onMessage(Message<String> message) { System.out.println("Topic Received Message: " + message + "\n"); } }); topic.publish("object"); }
AsyncInvalidationListener(Cluster cluster, CachedReference<?> localReference, ITopic<ReferenceKey> topic) { this.cluster = cluster; this.localReferenceRef = new WeakReference<>(localReference); this.topic = topic; this.topicListenerId = topic.addMessageListener(this); this.membershipListenerId = cluster.addMembershipListener(this); }
public static void main(String[] args) { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); ITopic<Date> topic = hz.getTopic("topic"); topic.addMessageListener(new MessageListenerImpl("topic")); System.out.println("Subscribed"); }
public static void main(String[] args) { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); ITopic<Date> topic = hz.getTopic("topic"); topic.addMessageListener(new MessageListenerImpl()); System.out.println("Subscribed"); }
public static void main(String[] args) { HazelcastInstance hz = Hazelcast.newHazelcastInstance(); ITopic<Long> topic = hz.getReliableTopic("sometopic"); topic.addMessageListener(new MessageListenerImpl()); }
/** * 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); }
private void listenOnHazelCastMsg() { LOG.info("Subscribing to Hazelcast topic. TopicName={}", "moquette"); HazelcastInstance hz = getHazelcastInstance(); ITopic<HazelcastMsg> topic = hz.getTopic("moquette"); topic.addMessageListener(new HazelcastListener(this)); }
public EventHzSynchronizer(HzCluster cluster, GeoServer gs) { super(cluster, gs); ackTopic = cluster.getHz().getTopic("geoserver.config.ack"); ackTopic.addMessageListener(ackListener = new AckListener()); }
public static void main(String[] args) { // Start the Embedded Hazelcast Cluster Member. HazelcastInstance hz = Hazelcast.newHazelcastInstance(); // Get a Topic called "my-distributed-topic" ITopic<String> topic = hz.getTopic("my-distributed-topic"); // Add a Listener to the Topic topic.addMessageListener(new TopicSample()); // Publish a message to the Topic topic.publish("Hello to distributed world"); // Shutdown the Hazelcast Cluster Member hz.shutdown(); } }
public HazelcastTopicConsumer(HazelcastInstance hazelcastInstance, Endpoint endpoint, Processor processor, String cacheName, boolean reliable) { super(hazelcastInstance, endpoint, processor, cacheName); ITopic<Object> topic; if (!reliable) { topic = hazelcastInstance.getTopic(cacheName); } else { topic = hazelcastInstance.getReliableTopic(cacheName); } topic.addMessageListener(new CamelMessageListener(this, cacheName)); }
public static void main(String[] args) { // Start the Hazelcast Client and connect to an already running Hazelcast Cluster on 127.0.0.1 HazelcastInstance hz = HazelcastClient.newHazelcastClient(); // Get a Topic called "my-distributed-topic" ITopic<String> topic = hz.getTopic("my-distributed-topic"); // Add a Listener to the Topic topic.addMessageListener(new TopicSample()); // Publish a message to the Topic topic.publish("Hello to distributed world"); // Shutdown this Hazelcast Client hz.shutdown(); } }
public HzSynchronizer(HzCluster cluster, GeoServer gs) { this.cluster = cluster; this.gs = gs; topic = cluster.getHz().getTopic("geoserver.config"); topic.addMessageListener(this); executor = getNewExecutor(); gs.addListener(this); gs.getCatalog().addListener(this); }