Skip to content

Instantly share code, notes, and snippets.

@jheusser
Created May 25, 2016 09:08
Show Gist options
  • Save jheusser/1cb33999f281e5a7719a07ad158bbb21 to your computer and use it in GitHub Desktop.
Save jheusser/1cb33999f281e5a7719a07ad158bbb21 to your computer and use it in GitHub Desktop.
import uk.co.real_logic.agrona.ErrorHandler;
import uk.co.real_logic.agrona.concurrent.Agent;
import uk.co.real_logic.agrona.concurrent.AgentRunner;
import uk.co.real_logic.agrona.concurrent.BusySpinIdleStrategy;
public class AgentTest {
static class SomeAgent implements Agent {
@Override
public int doWork() throws Exception {
throw new RuntimeException("Error");
}
@Override
public String roleName() {
return "SomeAgent";
}
@Override
public void onClose() {
System.out.println("This is never called");
}
}
static class RunOnError implements ErrorHandler {
private Runnable r;
void action(Runnable r) {
this.r = r;
}
@Override
public void onError(Throwable throwable) {
r.run();
}
}
public static void main(String[] args) throws Exception {
RunOnError closeOnError = new RunOnError();
AgentRunner agentRunner = new AgentRunner(new BusySpinIdleStrategy(), closeOnError, null, new SomeAgent());
closeOnError.action(agentRunner::close);
AgentRunner.startOnThread(agentRunner);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment