Search in sources :

Example 1 with StripedRunnable

use of com.hazelcast.util.executor.StripedRunnable in project hazelcast by hazelcast.

the class MockConnectionManager method onClose.

public void onClose(final Connection connection) {
    final Address endPoint = connection.getEndPoint();
    if (mapConnections.remove(endPoint, connection)) {
        logger.info("Removed connection to endpoint: " + endPoint + ", connection: " + connection);
        ioService.getEventService().executeEventCallback(new StripedRunnable() {

            @Override
            public void run() {
                for (ConnectionListener listener : connectionListeners) {
                    listener.connectionRemoved(connection);
                }
            }

            @Override
            public int getKey() {
                return endPoint.hashCode();
            }
        });
    }
}
Also used : StripedRunnable(com.hazelcast.util.executor.StripedRunnable) Address(com.hazelcast.nio.Address) ConnectionListener(com.hazelcast.nio.ConnectionListener)

Example 2 with StripedRunnable

use of com.hazelcast.util.executor.StripedRunnable in project hazelcast by hazelcast.

the class TcpIpConnectionManager method registerConnection.

@Override
public synchronized boolean registerConnection(final Address remoteEndPoint, final Connection connection) {
    try {
        if (remoteEndPoint.equals(ioService.getThisAddress())) {
            return false;
        }
        if (!connection.isAlive()) {
            if (logger.isFinestEnabled()) {
                logger.finest(connection + " to " + remoteEndPoint + " is not registered since connection is not active.");
            }
            return false;
        }
        if (connection instanceof TcpIpConnection) {
            TcpIpConnection tcpConnection = (TcpIpConnection) connection;
            Address currentEndPoint = tcpConnection.getEndPoint();
            if (currentEndPoint != null && !currentEndPoint.equals(remoteEndPoint)) {
                throw new IllegalArgumentException(connection + " has already a different endpoint than: " + remoteEndPoint);
            }
            tcpConnection.setEndPoint(remoteEndPoint);
            if (!connection.isClient()) {
                TcpIpConnectionMonitor connectionMonitor = getConnectionMonitor(remoteEndPoint, true);
                tcpConnection.setMonitor(connectionMonitor);
            }
        }
        connectionsMap.put(remoteEndPoint, connection);
        ioService.getEventService().executeEventCallback(new StripedRunnable() {

            @Override
            public void run() {
                for (ConnectionListener listener : connectionListeners) {
                    listener.connectionAdded(connection);
                }
            }

            @Override
            public int getKey() {
                return remoteEndPoint.hashCode();
            }
        });
        return true;
    } finally {
        connectionsInProgress.remove(remoteEndPoint);
    }
}
Also used : StripedRunnable(com.hazelcast.util.executor.StripedRunnable) Address(com.hazelcast.nio.Address) ConnectionListener(com.hazelcast.nio.ConnectionListener)

Example 3 with StripedRunnable

use of com.hazelcast.util.executor.StripedRunnable in project hazelcast by hazelcast.

the class MockConnectionManager method registerConnection.

@Override
public boolean registerConnection(final Address remoteEndpoint, final Connection connection) {
    mapConnections.put(remoteEndpoint, connection);
    ioService.getEventService().executeEventCallback(new StripedRunnable() {

        @Override
        public void run() {
            for (ConnectionListener listener : connectionListeners) {
                listener.connectionAdded(connection);
            }
        }

        @Override
        public int getKey() {
            return remoteEndpoint.hashCode();
        }
    });
    return true;
}
Also used : StripedRunnable(com.hazelcast.util.executor.StripedRunnable) ConnectionListener(com.hazelcast.nio.ConnectionListener)

Aggregations

ConnectionListener (com.hazelcast.nio.ConnectionListener)3 StripedRunnable (com.hazelcast.util.executor.StripedRunnable)3 Address (com.hazelcast.nio.Address)2