use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class ClientReliableTopicTest method testRemoveListener.
@Test
public void testRemoveListener() {
ITopic topic = client.getReliableTopic(randomString());
MessageListener listener = new MessageListener() {
public void onMessage(Message message) {
}
};
UUID id = topic.addMessageListener(listener);
assertTrue(topic.removeMessageListener(id));
}
use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class ClientReliableTopicOnClusterRestartTest method shouldContinue_OnClusterRestart_whenDataLoss_LossTolerant_afterInvocationTimeout.
@Test
public void shouldContinue_OnClusterRestart_whenDataLoss_LossTolerant_afterInvocationTimeout() throws InterruptedException {
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
int invocationTimeoutSeconds = 2;
clientConfig.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), String.valueOf(invocationTimeoutSeconds));
final HazelcastInstance member = hazelcastFactory.newHazelcastInstance(smallInstanceConfig());
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
AtomicLong messageCount = new AtomicLong();
CountDownLatch messageArrived = new CountDownLatch(1);
String topicName = "topic";
member.getReliableTopic(topicName).publish("message");
member.getReliableTopic(topicName).publish("message");
ClientReliableTopicProxy<?> topic = (ClientReliableTopicProxy<?>) client.getReliableTopic(topicName);
UUID registrationId = topic.addMessageListener(createListener(true, m -> {
messageCount.incrementAndGet();
messageArrived.countDown();
}));
member.shutdown();
final HazelcastInstance restartedMember = hazelcastFactory.newHazelcastInstance(smallInstanceConfig());
// wait some time for subscription
Thread.sleep(TimeUnit.SECONDS.toMillis(invocationTimeoutSeconds));
assertTrueEventually(() -> {
String item = "newItem " + UUID.randomUUID();
restartedMember.getReliableTopic(topicName).publish(item);
assertOpenEventually(messageArrived, 5);
});
assertFalse(topic.isListenerCancelled(registrationId));
assertTrue(messageCount.get() >= 1);
}
use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class TopicService method dispatchEvent.
@Override
public void dispatchEvent(Object event, Object listener) {
TopicEvent topicEvent = (TopicEvent) event;
ClusterService clusterService = nodeEngine.getClusterService();
MemberImpl member = clusterService.getMember(topicEvent.publisherAddress);
if (member == null) {
member = new MemberImpl.Builder(topicEvent.publisherAddress).version(nodeEngine.getVersion()).build();
}
Message message = new DataAwareMessage(topicEvent.name, topicEvent.data, topicEvent.publishTime, member, nodeEngine.getSerializationService());
incrementReceivedMessages(topicEvent.name);
MessageListener messageListener = (MessageListener) listener;
messageListener.onMessage(message);
}
use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class MessageRunner method toMessage.
private Message<E> toMessage(ReliableTopicMessage m) {
Member member = getMember(m);
E payload = serializationService.toObject(m.getPayload());
return new Message<E>(topicName, payload, m.getPublishTime(), member);
}
use of com.hazelcast.topic.Message in project hazelcast by hazelcast.
the class ClientReliableTopicOnClusterRestartTest method shouldContinue_OnClusterRestart_afterInvocationTimeout.
@Test
public void shouldContinue_OnClusterRestart_afterInvocationTimeout() throws InterruptedException {
HazelcastInstance member = hazelcastFactory.newHazelcastInstance(smallInstanceConfig());
ClientConfig clientConfig = new ClientConfig();
clientConfig.getConnectionStrategyConfig().getConnectionRetryConfig().setClusterConnectTimeoutMillis(Long.MAX_VALUE);
int invocationTimeoutSeconds = 2;
clientConfig.setProperty(ClientProperty.INVOCATION_TIMEOUT_SECONDS.getName(), String.valueOf(invocationTimeoutSeconds));
HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
final CountDownLatch messageArrived = new CountDownLatch(1);
String topicName = "topic";
ITopic<String> topic = client.getReliableTopic(topicName);
UUID registrationId = topic.addMessageListener(createListener(true, m -> messageArrived.countDown()));
member.shutdown();
// wait for the topic operation to timeout
Thread.sleep(TimeUnit.SECONDS.toMillis(invocationTimeoutSeconds));
member = hazelcastFactory.newHazelcastInstance(smallInstanceConfig());
member.getReliableTopic(topicName).publish("message");
assertOpenEventually(messageArrived);
ClientReliableTopicProxy<?> proxy = (ClientReliableTopicProxy<?>) topic;
assertFalse(proxy.isListenerCancelled(registrationId));
}
Aggregations