Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need to reset event when translateTo occur exception in RingBuffer.translateAndPublish? #244

Closed
luoxn28 opened this issue Nov 12, 2018 · 2 comments

Comments

@luoxn28
Copy link

luoxn28 commented Nov 12, 2018

If translateTo occur exception in RingBuffer.translateAndPublish,like this:

private <A> void translateAndPublish(EventTranslatorOneArg<E, A> translator, long sequence, A arg0)
{
    try
    {
        // exception occur, this event is not ok
        translator.translateTo(get(sequence), sequence, arg0);
    }
    finally
    {
        sequencer.publish(sequence);
    }
}

If occur exception, this event is incomplete, may it's old data,need reset this it?like this:

private <A> void translateAndPublish(EventTranslatorOneArg<E, A> translator, long sequence, A arg0)
{
    try
    {
        translator.translateTo(get(sequence), sequence, arg0);
    }
    catch (Exception e) {
        resetElementAt(sequence);
        throw e;
    }
    finally
    {
        sequencer.publish(sequence);
    }
}

protected final void resetElementAt(long sequence) {
    entries[BUFFER_PAD + (int) (sequence & indexMask)] = eventFactory.newInstance();
}
@mikeb01
Copy link
Contributor

mikeb01 commented Nov 12, 2018

Personally I would do the reset in the EventHandler after the event is being processed. In the case of an exception you will need to leave some information on the event that will indicate that the event has been processed correctly, so if an exception occurs, that information will indicate that the data is not complete so the handle will discard the data, but can still reset the state of the event object.

@luoxn28
Copy link
Author

luoxn28 commented Nov 12, 2018

As you say with this handling, flexibility is better for developers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants