use of com.hazelcast.client.impl.spi.EventHandler in project hazelcast by hazelcast.
the class ClientTestSupport method getAllEventHandlers.
protected Map<Long, EventHandler> getAllEventHandlers(HazelcastInstance client) {
ClientConnectionManager connectionManager = getHazelcastClientInstanceImpl(client).getConnectionManager();
Collection<Connection> activeConnections = connectionManager.getActiveConnections();
HashMap<Long, EventHandler> map = new HashMap<>();
for (Connection activeConnection : activeConnections) {
map.putAll(((ClientConnection) activeConnection).getEventHandlers());
}
return map;
}
use of com.hazelcast.client.impl.spi.EventHandler in project hazelcast by hazelcast.
the class NearCachedClientCacheProxy method registerInvalidationListener.
private void registerInvalidationListener() {
if (!invalidateOnChange) {
return;
}
EventHandler eventHandler = new NearCacheInvalidationEventHandler();
invalidationListenerId = addNearCacheInvalidationListener(eventHandler);
}
use of com.hazelcast.client.impl.spi.EventHandler in project hazelcast by hazelcast.
the class ClientListenerServiceImpl method handleEventMessageOnCallingThread.
public void handleEventMessageOnCallingThread(ClientMessage clientMessage) {
long correlationId = clientMessage.getCorrelationId();
ClientConnection connection = (ClientConnection) clientMessage.getConnection();
EventHandler eventHandler = connection.getEventHandler(correlationId);
if (eventHandler == null) {
if (logger.isFineEnabled()) {
logger.fine("No eventHandler for callId: " + correlationId + ", event: " + clientMessage);
}
return;
}
eventHandler.handle(clientMessage);
}
use of com.hazelcast.client.impl.spi.EventHandler in project hazelcast by hazelcast.
the class ClientHeartbeatTest method testAddingListenerToNewConnectionFailedBecauseOfHeartbeat.
@Test
public void testAddingListenerToNewConnectionFailedBecauseOfHeartbeat() throws Exception {
hazelcastFactory.newHazelcastInstance();
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
final ClientListenerService clientListenerService = clientInstanceImpl.getListenerService();
final CountDownLatch blockIncoming = new CountDownLatch(1);
final CountDownLatch heartbeatStopped = new CountDownLatch(1);
final CountDownLatch onListenerRegister = new CountDownLatch(2);
clientInstanceImpl.getConnectionManager().addConnectionListener(new ConnectionListener() {
@Override
public void connectionAdded(Connection connection) {
}
@Override
public void connectionRemoved(Connection connection) {
heartbeatStopped.countDown();
}
});
clientListenerService.registerListener(createPartitionLostListenerCodec(), new EventHandler() {
AtomicInteger count = new AtomicInteger(0);
@Override
public void handle(Object event) {
}
@Override
public void beforeListenerRegister(Connection connection) {
if (count.incrementAndGet() == 2) {
try {
blockIncoming.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void onListenerRegister(Connection connection) {
onListenerRegister.countDown();
}
});
HazelcastInstance hazelcastInstance2 = hazelcastFactory.newHazelcastInstance();
assertSizeEventually(2, clientInstanceImpl.getConnectionManager().getActiveConnections());
blockMessagesFromInstance(hazelcastInstance2, client);
assertOpenEventually(heartbeatStopped);
blockIncoming.countDown();
unblockMessagesFromInstance(hazelcastInstance2, client);
assertOpenEventually(onListenerRegister);
}
use of com.hazelcast.client.impl.spi.EventHandler in project hazelcast by hazelcast.
the class ClientCacheClearTest method testClientInvalidationListenerCallCount.
@Test
public void testClientInvalidationListenerCallCount() {
ICache<String, String> cache = createCache();
Map<String, String> entries = createAndFillEntries();
for (Map.Entry<String, String> entry : entries.entrySet()) {
cache.put(entry.getKey(), entry.getValue());
}
// Verify that put works
for (Map.Entry<String, String> entry : entries.entrySet()) {
String key = entry.getKey();
String expectedValue = entries.get(key);
String actualValue = cache.get(key);
assertEquals(expectedValue, actualValue);
}
final AtomicInteger counter = new AtomicInteger(0);
CacheConfig config = cache.getConfiguration(CacheConfig.class);
registerInvalidationListener(new EventHandler() {
@Override
public void handle(Object event) {
counter.getAndIncrement();
}
}, config.getNameWithPrefix());
cache.clear();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
assertEquals(1, counter.get());
}
});
// Make sure that the callback is not called for a while
assertTrueAllTheTime(new AssertTask() {
@Override
public void run() throws Exception {
assertTrue(counter.get() <= 1);
}
}, 3);
}
Aggregations