use of com.hazelcast.internal.server.ServerConnectionManager in project hazelcast by hazelcast.
the class SingleProtocolHandlerRegressionTest method testWrongProtocolRegressionTest.
/**
* Regression test for #19756
*/
@Test
@Repeat(50)
public void testWrongProtocolRegressionTest() {
HazelcastInstance instance = Hazelcast.newHazelcastInstance(createMemberEndpointConfig());
ServerConnectionManager connectionManager = ((HazelcastInstanceProxy) instance).getOriginal().node.getServer().getConnectionManager(CLIENT);
// Get address of the client endpoint
InetAddress address = instance.getCluster().getLocalMember().getSocketAddress(CLIENT).getAddress();
int port = instance.getCluster().getLocalMember().getSocketAddress(CLIENT).getPort();
textProtocolClient = new TextProtocolClient(address, port);
textProtocolClient.connect();
assertTrueEventually(() -> assertTrue(textProtocolClient.isConnected()), ASSERT_TRUE_TIMEOUT_SECS);
assertTrueEventually(() -> assertEquals(connectionManager.getConnections().size(), 1), ASSERT_TRUE_TIMEOUT_SECS);
// Send wrong protocol data to client endpoint
textProtocolClient.sendData("AAACP2CP2");
// Assert that connection must be closed on the member side
assertTrueEventually(() -> assertTrue("Connection must be closed on the member side", connectionManager.getConnections().isEmpty()), ASSERT_TRUE_TIMEOUT_SECS);
}
use of com.hazelcast.internal.server.ServerConnectionManager in project hazelcast by hazelcast.
the class TcpServerConnectionManager_AbstractConnectMemberTest method assertIsDestroyed.
public void assertIsDestroyed(TcpServerConnection connection) {
ServerConnectionManager networkingService = connection.getConnectionManager();
assertFalse(connection.isAlive());
assertNull(networkingService.get(connection.getRemoteAddress()));
}
use of com.hazelcast.internal.server.ServerConnectionManager in project hazelcast by hazelcast.
the class OutboundResponseHandler method sendResponse.
@Override
public void sendResponse(Operation operation, Object obj) {
Address target = operation.getCallerAddress();
ServerConnectionManager connectionManager = operation.getConnection().getConnectionManager();
boolean send;
if (obj == null) {
send = sendNormalResponse(connectionManager, target, operation.getCallId(), 0, operation.isUrgent(), null);
} else if (obj.getClass() == NormalResponse.class) {
NormalResponse response = (NormalResponse) obj;
send = sendNormalResponse(connectionManager, target, response.getCallId(), response.getBackupAcks(), response.isUrgent(), response.getValue());
} else if (obj.getClass() == ErrorResponse.class || obj.getClass() == CallTimeoutResponse.class) {
send = send(connectionManager, target, (Response) obj);
} else if (obj instanceof Throwable) {
send = send(connectionManager, target, new ErrorResponse((Throwable) obj, operation.getCallId(), operation.isUrgent()));
} else {
// most regular responses not wrapped in a NormalResponse. So we are now completely skipping the
// NormalResponse instance
send = sendNormalResponse(connectionManager, target, operation.getCallId(), 0, operation.isUrgent(), obj);
}
if (!send) {
logger.warning("Cannot send response: " + obj + " to " + target + ". " + operation);
}
}
use of com.hazelcast.internal.server.ServerConnectionManager in project hazelcast by hazelcast.
the class EventServiceImpl method sendEvent.
/**
* Sends a remote event to the {@code subscriber}.
* Each event segment keeps track of the published event count. On every {@link #eventSyncFrequency} the event will
* be sent synchronously.
* A synchronous event means that we send the event as an {@link SendEventOperation} and in case of failure
* we increase the failure count and log the failure (see {@link EventProcessor})
* Otherwise, we send an asynchronous event. This means that we don't wait to see if the processing failed with an
* exception (see {@link RemoteEventProcessor})
*/
private void sendEvent(Address subscriber, EventEnvelope eventEnvelope, int orderKey) {
String serviceName = eventEnvelope.getServiceName();
EventServiceSegment segment = getSegment(serviceName, true);
boolean sync = segment.incrementPublish() % eventSyncFrequency == 0;
if (sync) {
SendEventOperation op = new SendEventOperation(eventEnvelope, orderKey);
Future f = nodeEngine.getOperationService().createInvocationBuilder(serviceName, op, subscriber).setTryCount(SEND_RETRY_COUNT).invoke();
try {
f.get(sendEventSyncTimeoutMillis, MILLISECONDS);
} catch (Exception e) {
syncDeliveryFailureCount.inc();
if (logger.isFinestEnabled()) {
logger.finest("Sync event delivery failed. Event: " + eventEnvelope, e);
}
}
} else {
Packet packet = new Packet(serializationService.toBytes(eventEnvelope), orderKey).setPacketType(Packet.Type.EVENT);
ServerConnectionManager cm = nodeEngine.getNode().getServer().getConnectionManager(MEMBER);
if (!cm.transmit(packet, subscriber)) {
if (nodeEngine.isRunning()) {
logFailure("Failed to send event packet to: %s, connection might not be alive.", subscriber);
}
}
}
}
use of com.hazelcast.internal.server.ServerConnectionManager in project hazelcast by hazelcast.
the class HttpGetCommandProcessor method handleCluster.
/**
* Sets the HTTP response to a string containing basic cluster information:
* <ul>
* <li>Member list</li>
* <li>Client connection count</li>
* <li>Connection count</li>
* </ul>
*
* @param command the HTTP request
*/
private void handleCluster(HttpGetCommand command) {
Node node = textCommandService.getNode();
Server server = node.getServer();
ClusterServiceImpl clusterService = node.getClusterService();
JsonArray membersArray = new JsonArray();
clusterService.getMembers().stream().map(m -> new JsonObject().add("address", m.getAddress().toString()).add("liteMember", m.isLiteMember()).add("localMember", m.localMember()).add("uuid", m.getUuid().toString()).add("memberVersion", m.getVersion().toString())).forEach(membersArray::add);
ServerConnectionManager cm = server.getConnectionManager(CLIENT);
int clientCount = cm == null ? 0 : cm.connectionCount(ServerConnection::isClient);
JsonObject response = new JsonObject().add("members", membersArray).add("connectionCount", clientCount).add("allConnectionCount", server.connectionCount());
prepareResponse(command, response);
}
Aggregations