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);
}
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);
}
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);
}
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();
}
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);
}
}
}
}
Aggregations