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

Pool can have a companion ticker thread #236

Merged
merged 5 commits into from
Oct 12, 2018
Merged

Conversation

matthieun
Copy link
Collaborator

Description:

This change brings the ability to schedule a companion ticker thread that allows time-based reporting on the initial Runnable or Callable execution.

Potential Impact:

No impact, it is a new feature.

Unit Test Approach:

Tested the new option with Callable and Runnable, and made sure they still report errors properly.

Test Results:

Companion thread has the same lifespan as other thread.


In doubt: Contributing Guidelines

lucaspcram
lucaspcram previously approved these changes Oct 11, 2018
Copy link
Contributor

@lucaspcram lucaspcram left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me. LogTicker should be great for debugging.

ticker.close();
}
};
this.pool.execute(ticker);
Copy link
Contributor

@lucaspcram lucaspcram Oct 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to note here. When using the Pool with a Runnable, it fails fast if the Runnable throws an exception. So you could have a case where the ticker throws an exception before the queue method even gets to the next line.

I'd be curious to see what happens if you test this with a Ticker implementation that looks like:

public class ExceptionTicker extends Ticker
 {
     public ExceptionTicker(final String name, final Duration tickerTime)
     {
         super(name, tickerTime);
     }

     @Override
     protected void tickAction(final Duration sinceStart)
     {
         throw new RuntimeException("Error!");
     }
 }

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure I follow here... What I have is a wrapper that makes sure to tell the ticker thread to stop when the initial command failed. I don't think the ticker itself needs to throw an exception, it can just stop... Here the try block does not have a catch, so the command would still push its own exception even after the ticker is closed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually you are right, let me add ticker error handling!

@matthieun
Copy link
Collaborator Author

Rhaaaaaa!

@matthieun matthieun closed this Oct 12, 2018
@matthieun matthieun reopened this Oct 12, 2018
logger.info("{}: {}", getName(), sinceStart);
if ("Ticker 3".equals(getName()))
{
throw new CoreException("I am rogue Ticker 3");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hahaha "rogue ticker" I love this :D

Copy link
Contributor

@MikeGost MikeGost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice functionality and tests!

@lucaspcram lucaspcram merged commit a892cb4 into osmlab:dev Oct 12, 2018
@matthieun matthieun deleted the pool branch October 12, 2018 17:28
@matthieun matthieun added this to the 5.1.14 milestone Oct 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants