Search in sources :

Example 86 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ClientClusterServiceImpl method handleInitialMembershipEvent.

void handleInitialMembershipEvent(InitialMembershipEvent event) {
    synchronized (initialMembershipListenerMutex) {
        Set<Member> initialMembers = event.getMembers();
        LinkedHashMap<Address, Member> newMap = new LinkedHashMap<Address, Member>();
        for (Member initialMember : initialMembers) {
            newMap.put(initialMember.getAddress(), initialMember);
        }
        members.set(Collections.unmodifiableMap(newMap));
        fireInitialMembershipEvent(event);
    }
}
Also used : Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) Member(com.hazelcast.core.Member) LinkedHashMap(java.util.LinkedHashMap)

Example 87 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ClientScheduledFutureProxy method getStats.

@Override
public ScheduledTaskStatistics getStats() {
    checkAccessibleHandler();
    Address address = handler.getAddress();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    try {
        if (address != null) {
            ClientMessage request = ScheduledExecutorGetStatsFromAddressCodec.encodeRequest(schedulerName, taskName, address);
            ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
            ScheduledExecutorGetStatsFromAddressCodec.ResponseParameters responseParameters = ScheduledExecutorGetStatsFromAddressCodec.decodeResponse(response);
            return new ScheduledTaskStatisticsImpl(responseParameters.totalRuns, responseParameters.lastIdleTimeNanos, responseParameters.totalRunTimeNanos, responseParameters.totalIdleTimeNanos);
        } else {
            ClientMessage request = ScheduledExecutorGetStatsFromPartitionCodec.encodeRequest(schedulerName, taskName);
            ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
            ScheduledExecutorGetStatsFromAddressCodec.ResponseParameters responseParameters = ScheduledExecutorGetStatsFromAddressCodec.decodeResponse(response);
            return new ScheduledTaskStatisticsImpl(responseParameters.totalRuns, responseParameters.lastIdleTimeNanos, responseParameters.totalRunTimeNanos, responseParameters.totalIdleTimeNanos);
        }
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : Address(com.hazelcast.nio.Address) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) ScheduledExecutorGetStatsFromAddressCodec(com.hazelcast.client.impl.protocol.codec.ScheduledExecutorGetStatsFromAddressCodec) ScheduledTaskStatisticsImpl(com.hazelcast.scheduledexecutor.impl.ScheduledTaskStatisticsImpl) StaleTaskException(com.hazelcast.scheduledexecutor.StaleTaskException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 88 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ClientScheduledFutureProxy method cancel.

@Override
public boolean cancel(boolean mayInterruptIfRunning) {
    if (mayInterruptIfRunning) {
        // inside the TaskRunner but it adds extra complexity.
        throw new UnsupportedOperationException("mayInterruptIfRunning flag is not supported.");
    }
    checkAccessibleHandler();
    Address address = handler.getAddress();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    try {
        if (address != null) {
            ClientMessage request = ScheduledExecutorCancelFromAddressCodec.encodeRequest(schedulerName, taskName, address, false);
            ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
            return ScheduledExecutorCancelFromAddressCodec.decodeResponse(response).response;
        } else {
            ClientMessage request = ScheduledExecutorCancelFromPartitionCodec.encodeRequest(schedulerName, taskName, false);
            ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
            return ScheduledExecutorCancelFromPartitionCodec.decodeResponse(response).response;
        }
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : Address(com.hazelcast.nio.Address) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleTaskException(com.hazelcast.scheduledexecutor.StaleTaskException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 89 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ClientScheduledFutureProxy method isCancelled.

@Override
public boolean isCancelled() {
    checkAccessibleHandler();
    Address address = handler.getAddress();
    String schedulerName = handler.getSchedulerName();
    String taskName = handler.getTaskName();
    int partitionId = handler.getPartitionId();
    try {
        if (address != null) {
            ClientMessage request = ScheduledExecutorIsCancelledFromAddressCodec.encodeRequest(schedulerName, taskName, address);
            ClientMessage response = new ClientInvocation(getClient(), request, address).invoke().get();
            return ScheduledExecutorIsCancelledFromAddressCodec.decodeResponse(response).response;
        } else {
            ClientMessage request = ScheduledExecutorIsCancelledFromPartitionCodec.encodeRequest(schedulerName, taskName);
            ClientMessage response = new ClientInvocation(getClient(), request, partitionId).invoke().get();
            return ScheduledExecutorIsCancelledFromPartitionCodec.decodeResponse(response).response;
        }
    } catch (Exception e) {
        throw ExceptionUtil.rethrow(e);
    }
}
Also used : Address(com.hazelcast.nio.Address) ClientInvocation(com.hazelcast.client.spi.impl.ClientInvocation) ClientMessage(com.hazelcast.client.impl.protocol.ClientMessage) StaleTaskException(com.hazelcast.scheduledexecutor.StaleTaskException) TimeoutException(java.util.concurrent.TimeoutException) ExecutionException(java.util.concurrent.ExecutionException)

Example 90 with Address

use of com.hazelcast.nio.Address in project hazelcast by hazelcast.

the class ClientConnectionTest method destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce.

@Test
public void destroyConnection_whenDestroyedMultipleTimes_thenListenerRemoveCalledOnce() {
    HazelcastInstance server = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient();
    HazelcastClientInstanceImpl clientImpl = ClientTestUtil.getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    final CountingConnectionRemoveListener listener = new CountingConnectionRemoveListener();
    connectionManager.addConnectionListener(listener);
    final Address serverAddress = new Address(server.getCluster().getLocalMember().getSocketAddress());
    final Connection connectionToServer = connectionManager.getConnection(serverAddress);
    final CountDownLatch isConnected = new CountDownLatch(1);
    clientImpl.getLifecycleService().addLifecycleListener(new LifecycleListener() {

        @Override
        public void stateChanged(LifecycleEvent event) {
            if (LifecycleEvent.LifecycleState.CLIENT_CONNECTED == event.getState()) {
                isConnected.countDown();
            }
        }
    });
    connectionToServer.close(null, null);
    assertTrueEventually(new AssertTask() {

        @Override
        public void run() throws Exception {
            assertTrue(isConnected.await(5, TimeUnit.SECONDS));
        }
    });
    connectionToServer.close(null, null);
    assertEquals("connection removed should be called only once", 1, listener.count.get());
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) Address(com.hazelcast.nio.Address) InetSocketAddress(java.net.InetSocketAddress) Connection(com.hazelcast.nio.Connection) HazelcastClientInstanceImpl(com.hazelcast.client.impl.HazelcastClientInstanceImpl) LifecycleEvent(com.hazelcast.core.LifecycleEvent) AssertTask(com.hazelcast.test.AssertTask) LifecycleListener(com.hazelcast.core.LifecycleListener) CountDownLatch(java.util.concurrent.CountDownLatch) ClientConnectionManager(com.hazelcast.client.connection.ClientConnectionManager) ExecutionException(java.util.concurrent.ExecutionException) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

Address (com.hazelcast.nio.Address)274 Test (org.junit.Test)44 QuickTest (com.hazelcast.test.annotation.QuickTest)36 HashMap (java.util.HashMap)33 ParallelTest (com.hazelcast.test.annotation.ParallelTest)29 Member (com.hazelcast.core.Member)27 ArrayList (java.util.ArrayList)27 Map (java.util.Map)26 ILogger (com.hazelcast.logging.ILogger)25 InetAddress (java.net.InetAddress)25 MemberImpl (com.hazelcast.instance.MemberImpl)21 List (java.util.List)20 HashSet (java.util.HashSet)18 Connection (com.hazelcast.nio.Connection)17 NodeEngine (com.hazelcast.spi.NodeEngine)16 NodeEngineImpl (com.hazelcast.spi.impl.NodeEngineImpl)16 IOException (java.io.IOException)16 ClusterServiceImpl (com.hazelcast.internal.cluster.impl.ClusterServiceImpl)14 HazelcastInstance (com.hazelcast.core.HazelcastInstance)13 IPartitionService (com.hazelcast.spi.partition.IPartitionService)13