use of com.hazelcast.internal.util.executor.StripedRunnable in project hazelcast by hazelcast.
the class TcpServerConnectionManager method register.
@Override
public synchronized boolean register(Address primaryAddress, Address targetAddress, Collection<Address> remoteAddressAliases, UUID remoteUuid, final ServerConnection c, int planeIndex) {
Plane plane = planes[planeIndex];
TcpServerConnection connection = (TcpServerConnection) c;
try {
if (!connection.isAlive()) {
if (logger.isFinestEnabled()) {
logger.finest(connection + " to " + remoteUuid + " is not registered since connection is not active.");
}
return false;
}
connection.setRemoteAddress(primaryAddress);
connection.setRemoteUuid(remoteUuid);
if (!connection.isClient()) {
connection.setErrorHandler(getErrorHandler(primaryAddress, plane.index).reset());
}
registerAddresses(remoteUuid, primaryAddress, targetAddress, remoteAddressAliases);
// handle self connection
if (remoteUuid.equals(serverContext.getThisUuid())) {
connection.close("Connecting to self!", null);
return false;
}
plane.putConnection(remoteUuid, connection);
serverContext.getEventService().executeEventCallback(new StripedRunnable() {
@Override
public void run() {
connectionListeners.forEach(listener -> listener.connectionAdded(connection));
}
@Override
public int getKey() {
return primaryAddress.hashCode();
}
});
return true;
} finally {
if (targetAddress != null) {
plane.removeConnectionInProgress(targetAddress);
}
}
}
Aggregations