-
-
Save jheusser/1cb33999f281e5a7719a07ad158bbb21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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