use of org.opendaylight.yangtools.concepts.Identifier in project controller by opendaylight.
the class MessageSlicer method initializeSlicing.
private boolean initializeSlicing(final SliceOptions options, final FileBackedOutputStream fileBackedStream) {
final Identifier identifier = options.getIdentifier();
MessageSliceIdentifier messageSliceId = new MessageSliceIdentifier(identifier, id);
SlicedMessageState<ActorRef> state = null;
try {
state = new SlicedMessageState<>(messageSliceId, fileBackedStream, messageSliceSize, maxSlicingTries, options.getReplyTo(), options.getOnFailureCallback(), logContext);
final Serializable message = options.getMessage();
if (state.getTotalSlices() == 1 && message != null) {
LOG.debug("{}: Message does not need to be sliced - sending original message", logContext);
state.close();
sendTo(options, message, options.getReplyTo());
return false;
}
final MessageSlice firstSlice = getNextSliceMessage(state);
LOG.debug("{}: Sending first slice: {}", logContext, firstSlice);
stateCache.put(messageSliceId, state);
sendTo(options, firstSlice, ActorRef.noSender());
return true;
} catch (IOException e) {
LOG.error("{}: Error initializing SlicedMessageState for {}", logContext, identifier, e);
if (state != null) {
state.close();
} else {
fileBackedStream.cleanup();
}
options.getOnFailureCallback().accept(e);
return false;
}
}
use of org.opendaylight.yangtools.concepts.Identifier in project controller by opendaylight.
the class MessageSlicingIntegrationTest method testSlicing.
@SuppressWarnings("unchecked")
private void testSlicing(final String logContext, final int messageSliceSize, final int expTotalSlices, final byte[] messageData) {
reset(mockAssembledMessageCallback);
final BytesMessage message = new BytesMessage(messageData);
try (MessageSlicer slicer = newMessageSlicer(logContext, messageSliceSize)) {
final boolean wasSliced = slice(slicer, IDENTIFIER, message, sendToProbe.ref(), replyToProbe.ref(), mockOnFailureCallback);
assertTrue(wasSliced);
Identifier slicingId = null;
int expLastSliceHashCode = SlicedMessageState.INITIAL_SLICE_HASH_CODE;
for (int sliceIndex = 1; sliceIndex <= expTotalSlices; sliceIndex++) {
final MessageSlice sliceMessage = sendToProbe.expectMsgClass(MessageSlice.class);
slicingId = sliceMessage.getIdentifier();
assertMessageSlice(sliceMessage, IDENTIFIER, sliceIndex, expTotalSlices, expLastSliceHashCode, replyToProbe.ref());
assembler.handleMessage(sliceMessage, sendToProbe.ref());
final MessageSliceReply reply = replyToProbe.expectMsgClass(MessageSliceReply.class);
assertSuccessfulMessageSliceReply(reply, IDENTIFIER, sliceIndex);
expLastSliceHashCode = Arrays.hashCode(sliceMessage.getData());
slicer.handleMessage(reply);
}
assertAssembledMessage(message, replyToProbe.ref());
assertFalse("MessageSlicer did not remove state for " + slicingId, slicer.hasState(slicingId));
assertFalse("MessageAssembler did not remove state for " + slicingId, assembler.hasState(slicingId));
}
}
use of org.opendaylight.yangtools.concepts.Identifier in project controller by opendaylight.
the class MessageSlicingIntegrationTest method testSlicingWithMaxRetriesReached.
@Test
public void testSlicingWithMaxRetriesReached() {
LOG.info("testSlicingWithMaxRetriesReached starting");
final BytesMessage message = new BytesMessage(new byte[] { 1, 2, 3 });
final int messageSliceSize = SerializationUtils.serialize(message).length / 2;
try (MessageSlicer slicer = newMessageSlicer("testSlicingWithMaxRetriesReached", messageSliceSize)) {
slice(slicer, IDENTIFIER, message, sendToProbe.ref(), replyToProbe.ref(), mockOnFailureCallback);
Identifier slicingId = null;
for (int i = 0; i < MessageSlicer.DEFAULT_MAX_SLICING_TRIES; i++) {
MessageSlice sliceMessage = sendToProbe.expectMsgClass(MessageSlice.class);
slicingId = sliceMessage.getIdentifier();
assertMessageSlice(sliceMessage, IDENTIFIER, 1, DONT_CARE, SlicedMessageState.INITIAL_SLICE_HASH_CODE, replyToProbe.ref());
assembler.handleMessage(sliceMessage, sendToProbe.ref());
// Swallow the reply and send the MessageSlicer a reply with an invalid index.
final MessageSliceReply reply = replyToProbe.expectMsgClass(MessageSliceReply.class);
assertSuccessfulMessageSliceReply(reply, IDENTIFIER, sliceMessage.getSliceIndex());
slicer.handleMessage(MessageSliceReply.success(reply.getIdentifier(), 100000, reply.getSendTo()));
final AbortSlicing abortSlicing = sendToProbe.expectMsgClass(AbortSlicing.class);
assertEquals("Identifier", slicingId, abortSlicing.getIdentifier());
assembler.handleMessage(abortSlicing, sendToProbe.ref());
}
slicer.handleMessage(MessageSliceReply.success(slicingId, 100000, sendToProbe.ref()));
assertFailureCallback(RuntimeException.class);
assertFalse("MessageSlicer did not remove state for " + slicingId, slicer.hasState(slicingId));
assertFalse("MessageAssembler did not remove state for " + slicingId, assembler.hasState(slicingId));
}
LOG.info("testSlicingWithMaxRetriesReached ending");
}
Aggregations