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);
}
}
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);
}
}
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);
}
}
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);
}
}
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());
}
Aggregations