Search in sources :

Example 31 with Packet

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

the class PacketEncoderTest method whenNotEnoughSpace.

@Test
public void whenNotEnoughSpace() {
    final Packet packet = new Packet(serializationService.toBytes(new byte[2000]));
    ByteBuffer dst = ByteBuffer.allocate(1000);
    upcast(dst).flip();
    PacketSupplier src = new PacketSupplier();
    src.queue.add(packet);
    encoder.dst(dst);
    encoder.src(src);
    HandlerStatus result = encoder.onWrite();
    assertEquals(DIRTY, result);
}
Also used : Packet(com.hazelcast.internal.nio.Packet) HandlerStatus(com.hazelcast.internal.networking.HandlerStatus) ByteBuffer(java.nio.ByteBuffer) ParallelJVMTest(com.hazelcast.test.annotation.ParallelJVMTest) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test)

Example 32 with Packet

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

the class OutboundResponseHandler method sendNormalResponse.

private boolean sendNormalResponse(ServerConnectionManager connectionManager, Address target, long callId, int backupAcks, boolean urgent, Object value) {
    checkTarget(target);
    Packet packet = toNormalResponsePacket(callId, (byte) backupAcks, urgent, value);
    return transmit(target, packet, connectionManager);
}
Also used : Packet(com.hazelcast.internal.nio.Packet)

Example 33 with Packet

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

the class OutboundResponseHandler method send.

public boolean send(ServerConnectionManager connectionManager, Address target, Response response) {
    checkNotNull(target, "Target is required!");
    if (thisAddress.equals(target)) {
        throw new IllegalArgumentException("Target is this node! -> " + target + ", response: " + response);
    }
    byte[] bytes = serializationService.toBytes(response);
    Packet packet = newResponsePacket(bytes, response.isUrgent());
    return transmit(target, packet, connectionManager);
}
Also used : Packet(com.hazelcast.internal.nio.Packet)

Example 34 with Packet

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

the class SenderTasklet method call.

@Nonnull
@Override
public ProgressState call() {
    progTracker.reset();
    tryFillInbox();
    if (progTracker.isDone()) {
        return progTracker.toProgressState();
    }
    if (tryFillOutputBuffer()) {
        progTracker.madeProgress();
        if (!connection.write(new Packet(outputBuffer.toByteArray()).setPacketType(Packet.Type.JET))) {
            throw new RestartableException("Connection write failed in " + toString());
        }
    }
    return progTracker.toProgressState();
}
Also used : Packet(com.hazelcast.internal.nio.Packet) RestartableException(com.hazelcast.jet.RestartableException) Nonnull(javax.annotation.Nonnull)

Example 35 with Packet

use of com.hazelcast.internal.nio.Packet 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)

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