Search in sources :

Example 1 with SendEventOperation

use of com.hazelcast.spi.impl.eventservice.impl.operations.SendEventOperation in project hazelcast by hazelcast.

the class EventServiceImpl method sendEvent.

private void sendEvent(Address subscriber, EventEnvelope eventEnvelope, int orderKey) {
    final String serviceName = eventEnvelope.getServiceName();
    final 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(SEND_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
        } 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);
        if (!nodeEngine.getNode().getConnectionManager().transmit(packet, subscriber)) {
            if (nodeEngine.isRunning()) {
                logFailure("Failed to send event packet to: %s , connection might not alive.", subscriber);
            }
        }
    }
}
Also used : Packet(com.hazelcast.nio.Packet) Future(java.util.concurrent.Future) SendEventOperation(com.hazelcast.spi.impl.eventservice.impl.operations.SendEventOperation) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException)

Aggregations

Packet (com.hazelcast.nio.Packet)1 SendEventOperation (com.hazelcast.spi.impl.eventservice.impl.operations.SendEventOperation)1 IOException (java.io.IOException)1 Future (java.util.concurrent.Future)1 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)1