Search in sources :

Example 36 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class PacketDecoder method onRead.

@Override
public HandlerStatus onRead() throws Exception {
    upcast(src).flip();
    try {
        while (src.hasRemaining()) {
            Packet packet = packetReader.readFrom(src);
            if (packet == null) {
                break;
            }
            onPacketComplete(packet);
        }
        return CLEAN;
    } finally {
        compactOrClear(src);
    }
}
Also used : Packet(com.hazelcast.internal.nio.Packet)

Example 37 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class SendMemberHandshakeTask method run.

@Override
public void run() {
    connection.setRemoteAddress(remoteAddress);
    serverContext.onSuccessfulConnection(remoteAddress);
    // make sure memberHandshake packet is the first packet sent to the end point.
    if (logger.isFinestEnabled()) {
        logger.finest("Sending memberHandshake packet to " + remoteAddress);
    }
    MemberHandshake memberHandshake = new MemberHandshake(SCHEMA_VERSION_2, getConfiguredLocalAddresses(), remoteAddress, reply, serverContext.getThisUuid()).addOption(OPTION_PLANE_COUNT, planeCount).addOption(OPTION_PLANE_INDEX, planeIndex);
    byte[] bytes = serverContext.getSerializationService().toBytes(memberHandshake);
    Packet packet = new Packet(bytes).setPacketType(Packet.Type.SERVER_CONTROL);
    connection.write(packet);
// now you can send anything...
}
Also used : Packet(com.hazelcast.internal.nio.Packet) MemberHandshake(com.hazelcast.internal.cluster.impl.MemberHandshake)

Example 38 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class TcpServerConnectionManager_TransmitTest method withAddress_whenConnectionCantBeEstablished.

@Test
public void withAddress_whenConnectionCantBeEstablished() throws UnknownHostException {
    final Packet packet = new Packet(serializationService.toBytes("foo"));
    boolean result = tcpServerA.getConnectionManager(MEMBER).transmit(packet, new Address(addressA.getHost(), 6701));
    // true is being returned because there is no synchronization on the connection being established
    assertTrue(result);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) Address(com.hazelcast.cluster.Address) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 39 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class TcpServerConnectionManager_TransmitTest method withAddress_whenConnectionExists.

@Test
public void withAddress_whenConnectionExists() {
    tcpServerB.start();
    final Packet packet = new Packet(serializationService.toBytes("foo"));
    connect(tcpServerA, addressB);
    boolean result = tcpServerA.getConnectionManager(MEMBER).transmit(packet, addressB);
    assertTrue(result);
    assertTrueEventually(() -> assertContains(packetsB, packet));
}
Also used : Packet(com.hazelcast.internal.nio.Packet) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 40 with Packet

use of com.hazelcast.internal.nio.Packet in project hazelcast by hazelcast.

the class TcpServerControlTest method memberHandshakeMessage.

private Packet memberHandshakeMessage() {
    MemberHandshake handshake = new MemberHandshake(SCHEMA_VERSION_2, localAddresses, new Address(CLIENT_SOCKET_ADDRESS), reply, MEMBER_UUID);
    Packet packet = new Packet(serializationService.toBytes(handshake));
    connection = new TcpServerConnection(connectionManager, lifecycleListener, 1, channel, false);
    if (connectionType != null) {
        connection.setConnectionType(connectionType);
    }
    packet.setConn(connection);
    return packet;
}
Also used : Packet(com.hazelcast.internal.nio.Packet) Address(com.hazelcast.cluster.Address) InetSocketAddress(java.net.InetSocketAddress) MemberHandshake(com.hazelcast.internal.cluster.impl.MemberHandshake)

Aggregations

Packet (com.hazelcast.internal.nio.Packet)65 Test (org.junit.Test)46 QuickTest (com.hazelcast.test.annotation.QuickTest)41 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)19 Operation (com.hazelcast.spi.impl.operationservice.Operation)11 ByteBuffer (java.nio.ByteBuffer)10 NormalResponse (com.hazelcast.spi.impl.operationservice.impl.responses.NormalResponse)9 AssertTask (com.hazelcast.test.AssertTask)6 PacketIOHelper (com.hazelcast.internal.nio.PacketIOHelper)5 SerializationConcurrencyTest (com.hazelcast.internal.serialization.impl.SerializationConcurrencyTest)3 OperationRunner (com.hazelcast.spi.impl.operationexecutor.OperationRunner)3 IOException (java.io.IOException)3 Address (com.hazelcast.cluster.Address)2 MemberHandshake (com.hazelcast.internal.cluster.impl.MemberHandshake)2 HandlerStatus (com.hazelcast.internal.networking.HandlerStatus)2 InternalSerializationService (com.hazelcast.internal.serialization.InternalSerializationService)2 HeapData (com.hazelcast.internal.serialization.impl.HeapData)2 ServerConnection (com.hazelcast.internal.server.ServerConnection)2 ServerConnectionManager (com.hazelcast.internal.server.ServerConnectionManager)2 OperationRunnerFactory (com.hazelcast.spi.impl.operationexecutor.OperationRunnerFactory)2