use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class GroupMismatchOperation method run.
@Override
public void run() {
NodeEngineImpl nodeEngine = (NodeEngineImpl) getNodeEngine();
Connection connection = getConnection();
String message = "Node could not join cluster at node: " + connection.getEndPoint() + " Cause: the target cluster has a different group-name";
connection.close(message, null);
ILogger logger = nodeEngine.getLogger("com.hazelcast.cluster");
logger.warning(message);
Node node = nodeEngine.getNode();
node.getJoiner().blacklist(getCallerAddress(), true);
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class OperationServiceImpl method send.
@Override
public boolean send(Operation op, Address target) {
checkNotNull(target, "Target is required!");
if (thisAddress.equals(target)) {
throw new IllegalArgumentException("Target is this node! -> " + target + ", op: " + op);
}
byte[] bytes = serializationService.toBytes(op);
int partitionId = op.getPartitionId();
Packet packet = new Packet(bytes, partitionId).setPacketType(Packet.Type.OPERATION);
if (op.isUrgent()) {
packet.raiseFlags(FLAG_URGENT);
}
ConnectionManager connectionManager = node.getConnectionManager();
Connection connection = connectionManager.getOrConnect(target);
return connectionManager.transmit(packet, connection);
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class OutboundResponseHandler method sendResponse.
@Override
public void sendResponse(Operation operation, Object obj) {
Response response = toResponse(operation, obj);
if (!send(response, operation.getCallerAddress())) {
Connection conn = operation.getConnection();
logger.warning("Cannot send response: " + obj + " to " + conn.getEndPoint() + ". " + operation);
}
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class ClientHeartbeatTest method testAddingListenerToNewConnectionFailedBecauseOfHeartbeat.
@Test
public void testAddingListenerToNewConnectionFailedBecauseOfHeartbeat() throws Exception {
hazelcastFactory.newHazelcastInstance();
ClientConfig clientConfig = new ClientConfig();
clientConfig.setProperty(ClientProperty.HEARTBEAT_TIMEOUT.getName(), "4000");
clientConfig.setProperty(ClientProperty.HEARTBEAT_INTERVAL.getName(), "1000");
final HazelcastInstance client = hazelcastFactory.newHazelcastClient(clientConfig);
HazelcastClientInstanceImpl clientInstanceImpl = getHazelcastClientInstanceImpl(client);
final ClientListenerService clientListenerService = clientInstanceImpl.getListenerService();
final CountDownLatch blockIncoming = new CountDownLatch(1);
final CountDownLatch heartbeatStopped = new CountDownLatch(1);
final CountDownLatch onListenerRegister = new CountDownLatch(2);
clientInstanceImpl.getConnectionManager().addConnectionHeartbeatListener(new ConnectionHeartbeatListener() {
@Override
public void heartbeatResumed(Connection connection) {
}
@Override
public void heartbeatStopped(Connection connection) {
heartbeatStopped.countDown();
}
});
clientListenerService.registerListener(createPartitionLostListenerCodec(), new EventHandler() {
AtomicInteger count = new AtomicInteger(0);
@Override
public void handle(Object event) {
}
@Override
public void beforeListenerRegister() {
if (count.incrementAndGet() == 2) {
try {
blockIncoming.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void onListenerRegister() {
onListenerRegister.countDown();
}
});
HazelcastInstance hazelcastInstance2 = hazelcastFactory.newHazelcastInstance();
assertSizeEventually(2, clientInstanceImpl.getConnectionManager().getActiveConnections());
blockMessagesFromInstance(hazelcastInstance2, client);
assertOpenEventually(heartbeatStopped);
blockIncoming.countDown();
unblockMessagesFromInstance(hazelcastInstance2, client);
assertOpenEventually(onListenerRegister);
}
use of com.hazelcast.nio.Connection in project hazelcast by hazelcast.
the class AbstractListenersOnReconnectTest method validateRegistrations.
private void validateRegistrations(final int clusterSize, final String registrationId, final HazelcastClientInstanceImpl clientInstanceImpl) {
final boolean smartRouting = clientInstanceImpl.getClientConfig().getNetworkConfig().isSmartRouting();
assertTrueEventually(new AssertTask() {
@Override
public void run() throws Exception {
int size = smartRouting ? clusterSize : 1;
Collection<ClientEventRegistration> registrations = getClientEventRegistrations(client, registrationId);
assertEquals(size, registrations.size());
if (smartRouting) {
Collection<Member> members = clientInstanceImpl.getClientClusterService().getMemberList();
for (ClientEventRegistration registration : registrations) {
Connection registeredSubscriber = registration.getSubscriber();
boolean contains = false;
for (Member member : members) {
contains |= registeredSubscriber.getEndPoint().equals(member.getAddress());
}
assertTrue("Registered member " + registeredSubscriber + " is not in the cluster member list " + members, contains);
}
} else {
ClientEventRegistration registration = registrations.iterator().next();
assertEquals(clientInstanceImpl.getClientClusterService().getOwnerConnectionAddress(), registration.getSubscriber().getEndPoint());
}
}
});
}
Aggregations