use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class ClientListenerServiceImpl method registerListener.
@Nonnull
@Override
public UUID registerListener(final ListenerMessageCodec codec, final EventHandler handler) {
// This method should not be called from registrationExecutor
assert (!Thread.currentThread().getName().contains("eventRegistration"));
Future<UUID> future = registrationExecutor.submit(() -> {
UUID userRegistrationId = UuidUtil.newUnsecureUUID();
ClientListenerRegistration registration = new ClientListenerRegistration(handler, codec);
registrations.put(userRegistrationId, registration);
Collection<Connection> connections = clientConnectionManager.getActiveConnections();
for (Connection connection : connections) {
try {
invoke(registration, connection);
} catch (Exception e) {
if (connection.isAlive()) {
deregisterListenerInternal(userRegistrationId);
throw new HazelcastException("Listener can not be added ", e);
}
}
}
return userRegistrationId;
});
try {
return future.get();
} catch (Exception e) {
throw ExceptionUtil.rethrow(e);
}
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class TcpServerConnectionManager_AbstractConnectMemberTest method getOrConnect_whenAlreadyConnectedSameConnectionReturned.
@Test
public void getOrConnect_whenAlreadyConnectedSameConnectionReturned() {
startAllTcpServers();
Connection c1 = connect(tcpServerA, addressB);
Connection c2 = tcpServerA.getConnectionManager(MEMBER).getOrConnect(addressB);
assertSame(c1, c2);
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class TcpServerConnectionManager_ConnectionListenerTest method whenConnectionAdded.
@Test
public void whenConnectionAdded() {
startAllTcpServers();
ConnectionListener listener = mock(ConnectionListener.class);
tcpServerA.getConnectionManager(MEMBER).addConnectionListener(listener);
Connection c = connect(tcpServerA, addressB);
assertTrueEventually(() -> listener.connectionAdded(c));
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class TcpServerConnectionManager_ConnectionListenerTest method whenConnectionDestroyed.
@Test
public void whenConnectionDestroyed() {
startAllTcpServers();
ConnectionListener listener = mock(ConnectionListener.class);
tcpServerA.getConnectionManager(MEMBER).addConnectionListener(listener);
Connection c = connect(tcpServerA, addressB);
c.close(null, null);
assertTrueEventually(() -> listener.connectionRemoved(c));
}
use of com.hazelcast.internal.nio.Connection in project hazelcast by hazelcast.
the class AbstractListenersOnReconnectTest method validateRegistrations.
private void validateRegistrations(final int clusterSize, final UUID registrationId, final HazelcastClientInstanceImpl clientInstanceImpl) {
final boolean smartRouting = clientInstanceImpl.getClientConfig().getNetworkConfig().isSmartRouting();
assertTrueEventually(() -> {
int size = smartRouting ? clusterSize : 1;
Map<Connection, ClientConnectionRegistration> registrations = getClientEventRegistrations(client, registrationId);
assertEquals(size, registrations.size());
if (smartRouting) {
Collection<Member> members = clientInstanceImpl.getClientClusterService().getMemberList();
for (Connection registeredSubscriber : registrations.keySet()) {
boolean contains = false;
for (Member member : members) {
contains |= registeredSubscriber.getRemoteAddress().equals(member.getAddress());
}
assertTrue("Registered member " + registeredSubscriber + " is not in the cluster member list " + members, contains);
}
} else {
Iterator<Connection> expectedIterator = registrations.keySet().iterator();
assertTrue(expectedIterator.hasNext());
Iterator<Connection> iterator = clientInstanceImpl.getConnectionManager().getActiveConnections().iterator();
assertTrue(iterator.hasNext());
assertEquals(iterator.next(), expectedIterator.next());
}
});
}
Aggregations