Search in sources :

Example 1 with StripedRunnable

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);
        }
    }
}
Also used : REST_CLIENT(com.hazelcast.internal.nio.ConnectionType.REST_CLIENT) Address(com.hazelcast.cluster.Address) TCP_TAG_ENDPOINT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_TAG_ENDPOINT) ServerConnection(com.hazelcast.internal.server.ServerConnection) TimeoutException(java.util.concurrent.TimeoutException) Packet(com.hazelcast.internal.nio.Packet) TCP_PREFIX_CONNECTION(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_PREFIX_CONNECTION) TCP_METRIC_ENDPOINT_MANAGER_IN_PROGRESS_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_ENDPOINT_MANAGER_IN_PROGRESS_COUNT) Future(java.util.concurrent.Future) SocketChannel(java.nio.channels.SocketChannel) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) DynamicMetricsProvider(com.hazelcast.internal.metrics.DynamicMetricsProvider) ChannelInitializer(com.hazelcast.internal.networking.ChannelInitializer) TCP_DISCRIMINATOR_BINDADDRESS(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_DISCRIMINATOR_BINDADDRESS) ServerContext(com.hazelcast.internal.server.ServerContext) Probe(com.hazelcast.internal.metrics.Probe) Collection(java.util.Collection) ExceptionUtil(com.hazelcast.internal.util.ExceptionUtil) Set(java.util.Set) IOUtil.close(com.hazelcast.internal.nio.IOUtil.close) UUID(java.util.UUID) EndpointConfig(com.hazelcast.config.EndpointConfig) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) TCP_METRIC_CLIENT_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_CLIENT_COUNT) Arrays.stream(java.util.Arrays.stream) MANDATORY(com.hazelcast.internal.metrics.ProbeLevel.MANDATORY) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) TCP_DISCRIMINATOR_ENDPOINT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_DISCRIMINATOR_ENDPOINT) Function(java.util.function.Function) ProtocolType(com.hazelcast.instance.ProtocolType) IOUtil.setChannelOptions(com.hazelcast.internal.nio.IOUtil.setChannelOptions) MetricDescriptor(com.hazelcast.internal.metrics.MetricDescriptor) NetworkStats(com.hazelcast.internal.server.NetworkStats) Networking(com.hazelcast.internal.networking.Networking) Nonnull(javax.annotation.Nonnull) ConnectionListener(com.hazelcast.internal.nio.ConnectionListener) IOUtil(com.hazelcast.internal.nio.IOUtil) COUNT(com.hazelcast.internal.metrics.ProbeUnit.COUNT) EndpointQualifier(com.hazelcast.instance.EndpointQualifier) StripedRunnable(com.hazelcast.internal.util.executor.StripedRunnable) MetricsCollectionContext(com.hazelcast.internal.metrics.MetricsCollectionContext) MEMCACHE_CLIENT(com.hazelcast.internal.nio.ConnectionType.MEMCACHE_CLIENT) IOException(java.io.IOException) Preconditions.checkNotNull(com.hazelcast.internal.util.Preconditions.checkNotNull) Channel(com.hazelcast.internal.networking.Channel) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Collections.unmodifiableSet(java.util.Collections.unmodifiableSet) TCP_METRIC_ENDPOINT_MANAGER_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_ENDPOINT_MANAGER_COUNT) Collections(java.util.Collections) TCP_METRIC_TEXT_COUNT(com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_TEXT_COUNT) StripedRunnable(com.hazelcast.internal.util.executor.StripedRunnable)

Aggregations

Address (com.hazelcast.cluster.Address)1 EndpointConfig (com.hazelcast.config.EndpointConfig)1 EndpointQualifier (com.hazelcast.instance.EndpointQualifier)1 ProtocolType (com.hazelcast.instance.ProtocolType)1 DynamicMetricsProvider (com.hazelcast.internal.metrics.DynamicMetricsProvider)1 MetricDescriptor (com.hazelcast.internal.metrics.MetricDescriptor)1 TCP_DISCRIMINATOR_BINDADDRESS (com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_DISCRIMINATOR_BINDADDRESS)1 TCP_DISCRIMINATOR_ENDPOINT (com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_DISCRIMINATOR_ENDPOINT)1 TCP_METRIC_CLIENT_COUNT (com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_CLIENT_COUNT)1 TCP_METRIC_ENDPOINT_MANAGER_COUNT (com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_ENDPOINT_MANAGER_COUNT)1 TCP_METRIC_ENDPOINT_MANAGER_IN_PROGRESS_COUNT (com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_ENDPOINT_MANAGER_IN_PROGRESS_COUNT)1 TCP_METRIC_TEXT_COUNT (com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_METRIC_TEXT_COUNT)1 TCP_PREFIX_CONNECTION (com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_PREFIX_CONNECTION)1 TCP_TAG_ENDPOINT (com.hazelcast.internal.metrics.MetricDescriptorConstants.TCP_TAG_ENDPOINT)1 MetricsCollectionContext (com.hazelcast.internal.metrics.MetricsCollectionContext)1 Probe (com.hazelcast.internal.metrics.Probe)1 MANDATORY (com.hazelcast.internal.metrics.ProbeLevel.MANDATORY)1 COUNT (com.hazelcast.internal.metrics.ProbeUnit.COUNT)1 Channel (com.hazelcast.internal.networking.Channel)1 ChannelInitializer (com.hazelcast.internal.networking.ChannelInitializer)1