Search in sources :

Example 1 with EventImpl

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

the class CommandRequestHandler method getResult.

@Override
public EventImpl getResult(DirectBuffer buffer, int offset, int blockLength, int version) {
    decoder.wrap(buffer, offset, blockLength, version);
    final long key = decoder.key();
    final int partitionId = decoder.partitionId();
    final long position = decoder.position();
    final int eventLength = decoder.eventLength();
    final DirectBufferInputStream inStream = new DirectBufferInputStream(buffer, decoder.limit() + ExecuteCommandResponseDecoder.eventHeaderLength(), eventLength);
    final EventImpl result;
    try {
        result = objectMapper.readValue(inStream, event.getClass());
    } catch (Exception e) {
        throw new ClientException("Cannot deserialize event in response", e);
    }
    result.setKey(key);
    result.setPartitionId(partitionId);
    result.setTopicName(event.getMetadata().getTopicName());
    result.setEventPosition(position);
    if (expectedState != null && !expectedState.equals(result.getState())) {
        throw new ClientCommandRejectedException(errorFunction.apply(event, result));
    }
    return result;
}
Also used : DirectBufferInputStream(org.agrona.io.DirectBufferInputStream) EventImpl(io.zeebe.client.event.impl.EventImpl) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException) ClientException(io.zeebe.client.cmd.ClientException) ClientException(io.zeebe.client.cmd.ClientException) ClientCommandRejectedException(io.zeebe.client.cmd.ClientCommandRejectedException)

Aggregations

ClientCommandRejectedException (io.zeebe.client.cmd.ClientCommandRejectedException)1 ClientException (io.zeebe.client.cmd.ClientException)1 EventImpl (io.zeebe.client.event.impl.EventImpl)1 DirectBufferInputStream (org.agrona.io.DirectBufferInputStream)1