Search in sources :

Example 1 with GeneralEventImpl

use of io.zeebe.client.event.impl.GeneralEventImpl in project zeebe by zeebe-io.

the class SubscribedEventCollector method onMessage.

@Override
public boolean onMessage(ClientOutput output, RemoteAddress remoteAddress, DirectBuffer buffer, int offset, int length) {
    messageHeaderDecoder.wrap(buffer, offset);
    offset += MessageHeaderDecoder.ENCODED_LENGTH;
    final int templateId = messageHeaderDecoder.templateId();
    final boolean messageHandled;
    if (templateId == SubscribedEventDecoder.TEMPLATE_ID) {
        subscribedEventDecoder.wrap(buffer, offset, messageHeaderDecoder.blockLength(), messageHeaderDecoder.version());
        final SubscriptionType subscriptionType = subscribedEventDecoder.subscriptionType();
        final long key = subscribedEventDecoder.key();
        final long subscriberKey = subscribedEventDecoder.subscriberKey();
        final long position = subscribedEventDecoder.position();
        final int partitionId = subscribedEventDecoder.partitionId();
        final byte[] eventBuffer = readBytes(subscribedEventDecoder::getEvent, subscribedEventDecoder::eventLength);
        final GeneralEventImpl event = new GeneralEventImpl(partitionId, key, position, EventTypeMapping.mapEventType(subscribedEventDecoder.eventType()), eventBuffer, converter);
        messageHandled = eventHandler.onEvent(subscriptionType, subscriberKey, event);
    } else {
        // ignoring
        messageHandled = true;
    }
    return messageHandled;
}
Also used : SubscriptionType(io.zeebe.protocol.clientapi.SubscriptionType) GeneralEventImpl(io.zeebe.client.event.impl.GeneralEventImpl)

Example 2 with GeneralEventImpl

use of io.zeebe.client.event.impl.GeneralEventImpl in project zeebe by zeebe-io.

the class Subscriber method pollEvents.

protected int pollEvents(CheckedConsumer<GeneralEventImpl> pollHandler) {
    final int currentlyAvailableEvents = size();
    int handledEvents = 0;
    GeneralEventImpl event;
    // in case the broker continuously produces new tasks
    while (handledEvents < currentlyAvailableEvents && isOpen()) {
        event = pendingEvents.poll();
        if (event == null) {
            break;
        }
        eventsInProcessing.incrementAndGet();
        try {
            // subscription
            if (!isOpen()) {
                break;
            }
            handledEvents++;
            logHandling(event);
            try {
                pollHandler.accept(event);
            } catch (Exception e) {
                onUnhandledEventHandlingException(event, e);
            }
        } finally {
            eventsInProcessing.decrementAndGet();
            eventsProcessedSinceLastReplenishment.incrementAndGet();
            if (shouldReplenishEventSource()) {
                replenishmentTrigger.signal();
            }
        }
    }
    return handledEvents;
}
Also used : GeneralEventImpl(io.zeebe.client.event.impl.GeneralEventImpl)

Aggregations

GeneralEventImpl (io.zeebe.client.event.impl.GeneralEventImpl)2 SubscriptionType (io.zeebe.protocol.clientapi.SubscriptionType)1