Search in sources :

Example 6 with ServerConnectionManager

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);
}
Also used : HazelcastInstance(com.hazelcast.core.HazelcastInstance) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) TextProtocolClient(com.hazelcast.internal.nio.ascii.TextProtocolClient) InetAddress(java.net.InetAddress) NightlyTest(com.hazelcast.test.annotation.NightlyTest) Test(org.junit.Test) Repeat(com.hazelcast.test.annotation.Repeat)

Example 7 with ServerConnectionManager

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()));
}
Also used : ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager)

Example 8 with ServerConnectionManager

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);
    }
}
Also used : ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse) CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) Response(com.hazelcast.spi.impl.operationservice.impl.responses.Response) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) CallTimeoutResponse(com.hazelcast.spi.impl.operationservice.impl.responses.CallTimeoutResponse) Address(com.hazelcast.cluster.Address) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) NormalResponse(com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse) ErrorResponse(com.hazelcast.spi.impl.operationservice.impl.responses.ErrorResponse)

Example 9 with ServerConnectionManager

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);
            }
        }
    }
}
Also used : Packet(com.hazelcast.internal.nio.Packet) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) Future(java.util.concurrent.Future) CompletableFuture(java.util.concurrent.CompletableFuture) InternalCompletableFuture.newCompletedFuture(com.hazelcast.spi.impl.InternalCompletableFuture.newCompletedFuture) SendEventOperation(com.hazelcast.spi.impl.eventservice.impl.operations.SendEventOperation) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException)

Example 10 with ServerConnectionManager

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);
}
Also used : JsonArray(com.hazelcast.internal.json.JsonArray) Address(com.hazelcast.cluster.Address) LoggingServiceImpl(com.hazelcast.logging.impl.LoggingServiceImpl) ServerConnection(com.hazelcast.internal.server.ServerConnection) JsonArray(com.hazelcast.internal.json.JsonArray) Level(java.util.logging.Level) Json(com.hazelcast.internal.json.Json) ClusterService(com.hazelcast.internal.cluster.ClusterService) SC_500(com.hazelcast.internal.ascii.rest.HttpStatusCode.SC_500) CPGroup(com.hazelcast.cp.CPGroup) InternalPartitionService(com.hazelcast.internal.partition.InternalPartitionService) StringUtil.equalsIgnoreCase(com.hazelcast.internal.util.StringUtil.equalsIgnoreCase) CPSession(com.hazelcast.cp.session.CPSession) JsonObject(com.hazelcast.internal.json.JsonObject) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) CPGroupId(com.hazelcast.cp.CPGroupId) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) TextCommandService(com.hazelcast.internal.ascii.TextCommandService) StringUtil(com.hazelcast.internal.util.StringUtil) ExceptionUtil.peel(com.hazelcast.internal.util.ExceptionUtil.peel) CPSubsystemManagementService(com.hazelcast.cp.CPSubsystemManagementService) Collection(java.util.Collection) Server(com.hazelcast.internal.server.Server) NodeState(com.hazelcast.instance.impl.NodeState) MAP(com.hazelcast.internal.ascii.rest.RestCallExecution.ObjectType.MAP) Node(com.hazelcast.instance.impl.Node) CLIENT(com.hazelcast.instance.EndpointQualifier.CLIENT) CompletionStage(java.util.concurrent.CompletionStage) CPMember(com.hazelcast.cp.CPMember) ClusterState(com.hazelcast.cluster.ClusterState) CPSubsystem(com.hazelcast.cp.CPSubsystem) QUEUE(com.hazelcast.internal.ascii.rest.RestCallExecution.ObjectType.QUEUE) Server(com.hazelcast.internal.server.Server) ServerConnectionManager(com.hazelcast.internal.server.ServerConnectionManager) Node(com.hazelcast.instance.impl.Node) ClusterServiceImpl(com.hazelcast.internal.cluster.impl.ClusterServiceImpl) JsonObject(com.hazelcast.internal.json.JsonObject)

Aggregations

ServerConnectionManager (com.hazelcast.internal.server.ServerConnectionManager)11 Address (com.hazelcast.cluster.Address)3 HazelcastInstance (com.hazelcast.core.HazelcastInstance)3 ServerConnection (com.hazelcast.internal.server.ServerConnection)3 Node (com.hazelcast.instance.impl.Node)2 Packet (com.hazelcast.internal.nio.Packet)2 Test (org.junit.Test)2 ClusterState (com.hazelcast.cluster.ClusterState)1 CPGroup (com.hazelcast.cp.CPGroup)1 CPGroupId (com.hazelcast.cp.CPGroupId)1 CPMember (com.hazelcast.cp.CPMember)1 CPSubsystem (com.hazelcast.cp.CPSubsystem)1 CPSubsystemManagementService (com.hazelcast.cp.CPSubsystemManagementService)1 CPSession (com.hazelcast.cp.session.CPSession)1 CLIENT (com.hazelcast.instance.EndpointQualifier.CLIENT)1 MEMCACHE (com.hazelcast.instance.EndpointQualifier.MEMCACHE)1 HazelcastInstanceFactory.newHazelcastInstance (com.hazelcast.instance.impl.HazelcastInstanceFactory.newHazelcastInstance)1 NodeState (com.hazelcast.instance.impl.NodeState)1 OutOfMemoryErrorDispatcher (com.hazelcast.instance.impl.OutOfMemoryErrorDispatcher)1 ADD (com.hazelcast.internal.ascii.TextCommandConstants.TextCommandType.ADD)1