@Test public void shouldDetectConcurrentAdd() { final Agent mockAgentOne = mock(Agent.class); final Agent mockAgentTwo = mock(Agent.class); final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME, mockAgentOne, mockAgentTwo); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); invoker.start(); assertTrue(compositeAgent.tryAdd(mockAgentOne)); assertFalse(compositeAgent.tryAdd(mockAgentTwo)); invoker.invoke(); assertTrue(compositeAgent.tryAdd(mockAgentTwo)); }
@Test public void shouldReturnAgent() { assertThat(invoker.agent(), is(mockAgent)); }
public void onStart() { super.onStart(); replayerAgentInvoker = new AgentInvoker(errorHandler, ctx.errorCounter(), replayer); recorderAgentInvoker = new AgentInvoker(errorHandler, ctx.errorCounter(), recorder); replayerAgentInvoker.start(); recorderAgentInvoker.start(); }
close(); Thread.currentThread().interrupt(); handleError(ex); close(); handleError(throwable);
private void invokeAeronClient() { if (null != aeronClientInvoker) { aeronClientInvoker.invoke(); } }
@Test public void shouldReportExceptionThrownOnStart() throws Exception { final RuntimeException expectedException = new RuntimeException(); Mockito.doThrow(expectedException).when(mockAgent).onStart(); invoker.start(); invoker.invoke(); verify(mockAgent, never()).doWork(); verify(mockErrorHandler).onError(expectedException); verify(mockAgent).onClose(); assertTrue(invoker.isStarted()); assertFalse(invoker.isRunning()); assertTrue(invoker.isClosed()); }
private Archive start() { if (ArchiveThreadingMode.INVOKER == ctx.threadingMode()) { conductorInvoker.start(); } else { AgentRunner.startOnThread(conductorRunner, ctx.threadFactory()); } return this; }
Aeron(final Context ctx) { ctx.conclude(); this.ctx = ctx; clientId = ctx.clientId(); commandBuffer = ctx.toDriverBuffer(); conductor = new ClientConductor(ctx); if (ctx.useConductorAgentInvoker()) { conductorInvoker = new AgentInvoker(ctx.errorHandler(), null, conductor); conductorRunner = null; } else { conductorInvoker = null; conductorRunner = new AgentRunner(ctx.idleStrategy(), ctx.errorHandler(), null, conductor); } }
@Test public void shouldHandleAgentTerminationExceptionThrownByAgent() throws Exception { final RuntimeException expectedException = new AgentTerminationException(); when(mockAgent.doWork()).thenThrow(expectedException); invoker.start(); invoker.invoke(); verify(mockAgent).doWork(); verify(mockErrorHandler).onError(expectedException); verify(mockAtomicCounter).increment(); verify(mockAgent).onClose(); assertTrue(invoker.isClosed()); reset(mockAgent); invoker.invoke(); verify(mockAgent, never()).doWork(); assertTrue(invoker.isClosed()); }
@Test(expected = IllegalStateException.class) public void shouldNotAllowRemoveAfterClose() { final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); invoker.close(); compositeAgent.tryRemove(mock(Agent.class)); }
@Test public void shouldNotDoWorkOnClosedRunnerButCallOnClose() throws Exception { invoker.close(); invoker.invoke(); verify(mockAgent, never()).onStart(); verify(mockAgent, never()).doWork(); verify(mockErrorHandler, never()).onError(any()); verify(mockAtomicCounter, never()).increment(); verify(mockAgent).onClose(); }
/** * Clean up and release all Aeron client resources and shutdown conductor thread if not using * {@link Context#useConductorAgentInvoker(boolean)}. * <p> * This will close all currently open {@link Publication}s, {@link Subscription}s, and {@link Counter}s created * from this client. */ public void close() { if (IS_CLOSED_UPDATER.compareAndSet(this, 0, 1)) { if (null != conductorRunner) { conductorRunner.close(); } else { conductorInvoker.close(); } } }
protected void invokeAeronClient() { if (null != aeronClientInvoker) { aeronClientInvoker.invoke(); } } }
public void onStart() { super.onStart(); replayerAgentInvoker = new AgentInvoker(errorHandler, ctx.errorCounter(), replayer); recorderAgentInvoker = new AgentInvoker(errorHandler, ctx.errorCounter(), recorder); replayerAgentInvoker.start(); recorderAgentInvoker.start(); }
aeron.conductorInvoker.start();
Archive(final Context ctx) { this.ctx = ctx; ctx.conclude(); final ArchiveConductor conductor = ArchiveThreadingMode.DEDICATED == ctx.threadingMode() ? new DedicatedModeArchiveConductor(ctx) : new SharedModeArchiveConductor(ctx); if (ArchiveThreadingMode.INVOKER == ctx.threadingMode()) { conductorInvoker = new AgentInvoker(ctx.errorHandler(), ctx.errorCounter(), conductor); conductorRunner = null; } else { conductorInvoker = null; conductorRunner = new AgentRunner(ctx.idleStrategy(), ctx.errorHandler(), ctx.errorCounter(), conductor); } }
@Test(expected = IllegalStateException.class) public void shouldNotAllowAddAfterClose() { final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); invoker.close(); compositeAgent.tryAdd(mock(Agent.class)); }
/** * Mark the invoker as started and call the {@link Agent#onStart()} method. * <p> * Startup logic will only be performed once. */ public void start() { try { if (!isStarted) { isStarted = true; agent.onStart(); isRunning = true; } } catch (final Throwable throwable) { errorHandler.onError(throwable); close(); } }
close(); Thread.currentThread().interrupt(); handleError(ex); close(); handleError(throwable);