本文整理了Java中org.agrona.concurrent.AgentInvoker.invoke()
方法的一些代码示例,展示了AgentInvoker.invoke()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AgentInvoker.invoke()
方法的具体详情如下:
包路径:org.agrona.concurrent.AgentInvoker
类名称:AgentInvoker
方法名:invoke
[英]Invoke the Agent#doWork() method and return the work count.
If an error occurs then the AtomicCounter#increment() will be called on the errorCounter if not null and the Throwable will be passed to the ErrorHandler#onError(Throwable) method. If the error is an AgentTerminationException then #close() will be called after the error handler.
If not successfully started or after closed then this method will return without invoking the Agent.
[中]调用代理#doWork()方法并返回工时计数。
如果发生错误,则如果不为null,将在errorCounter上调用AtomicCounter#increment(),并将Throwable传递给ErrorHandler#onError(Throwable)方法。如果错误是AgentTerminationException,则将在错误处理程序之后调用#close()。
如果未成功启动或关闭,则此方法将返回,而不调用代理。
代码示例来源:origin: real-logic/aeron
protected void invokeAeronClient()
{
if (null != aeronClientInvoker)
{
aeronClientInvoker.invoke();
}
}
}
代码示例来源:origin: real-logic/aeron
private void invokeAeronClient()
{
if (null != aeronClientInvoker)
{
aeronClientInvoker.invoke();
}
}
代码示例来源:origin: real-logic/aeron
protected final int invokeDriverConductor()
{
return null != driverAgentInvoker ? driverAgentInvoker.invoke() : 0;
}
代码示例来源:origin: real-logic/aeron
protected int preWork()
{
return super.preWork() +
replayerAgentInvoker.invoke() +
invokeDriverConductor() +
recorderAgentInvoker.invoke() +
invokeDriverConductor();
}
代码示例来源:origin: real-logic/aeron
private void idle(final int workCount)
{
checkInterruptedStatus();
aeronClientInvoker.invoke();
idleStrategy.idle(workCount);
}
代码示例来源:origin: real-logic/aeron
private void idle()
{
checkInterruptedStatus();
aeronClientInvoker.invoke();
idleStrategy.idle();
}
代码示例来源:origin: real-logic/agrona
private void assertExceptionNotReported()
{
invoker.start();
invoker.invoke();
invoker.close();
verify(mockErrorHandler, never()).onError(any());
verify(mockAtomicCounter, never()).increment();
}
}
代码示例来源:origin: real-logic/agrona
@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();
}
代码示例来源:origin: real-logic/aeron
protected int preWork()
{
int workCount = 0;
final long nowMs = epochClock.time();
if (cachedEpochClock.time() != nowMs)
{
cachedEpochClock.update(nowMs);
markFile.updateActivityTimestamp(nowMs);
workCount += aeronAgentInvoker.invoke();
}
workCount += invokeDriverConductor();
workCount += runTasks(taskQueue);
return workCount;
}
代码示例来源:origin: real-logic/agrona
@Test
public void shouldFollowLifecycle() throws Exception
{
invoker.start();
invoker.start();
verify(mockAgent, times(1)).onStart();
verifyNoMoreInteractions(mockAgent);
invoker.invoke();
invoker.invoke();
verify(mockAgent, times(2)).doWork();
verifyNoMoreInteractions(mockAgent);
invoker.close();
invoker.close();
verify(mockAgent, times(1)).onClose();
verifyNoMoreInteractions(mockAgent);
}
代码示例来源:origin: real-logic/agrona
@Test
public void shouldReportExceptionThrownByAgent() throws Exception
{
final RuntimeException expectedException = new RuntimeException();
when(mockAgent.doWork()).thenThrow(expectedException);
invoker.start();
invoker.invoke();
verify(mockAgent).doWork();
verify(mockErrorHandler).onError(expectedException);
verify(mockAtomicCounter).increment();
verify(mockAgent, never()).onClose();
reset(mockAgent);
invoker.invoke();
verify(mockAgent).doWork();
reset(mockAgent);
invoker.close();
verify(mockAgent, never()).doWork();
verify(mockAgent).onClose();
}
代码示例来源:origin: real-logic/agrona
@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());
}
代码示例来源:origin: real-logic/agrona
@Test
public void shouldRemoveAgent() throws Exception
{
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();
verify(mockAgentOne, times(1)).onStart();
verify(mockAgentTwo, times(1)).onStart();
invoker.invoke();
verify(mockAgentOne, times(1)).doWork();
verify(mockAgentTwo, times(1)).doWork();
assertTrue(compositeAgent.tryRemove(mockAgentTwo));
assertFalse(compositeAgent.hasRemoveAgentCompleted());
invoker.invoke();
assertTrue(compositeAgent.hasRemoveAgentCompleted());
verify(mockAgentOne, times(2)).doWork();
verify(mockAgentTwo, times(1)).doWork();
verify(mockAgentOne, times(1)).onStart();
verify(mockAgentTwo, times(1)).onStart();
verify(mockAgentTwo, times(1)).onClose();
}
代码示例来源:origin: real-logic/agrona
@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());
}
代码示例来源:origin: real-logic/agrona
@Test
public void shouldAddAgent() throws Exception
{
final Agent mockAgentOne= mock(Agent.class);
final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME, mockAgentOne);
final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent);
assertThat(compositeAgent.roleName(), is(ROLE_NAME));
invoker.start();
verify(mockAgentOne, times(1)).onStart();
invoker.invoke();
verify(mockAgentOne, times(1)).onStart();
verify(mockAgentOne, times(1)).doWork();
final Agent mockAgentTwo = mock(Agent.class);
assertTrue(compositeAgent.tryAdd(mockAgentTwo));
assertFalse(compositeAgent.hasAddAgentCompleted());
invoker.invoke();
assertTrue(compositeAgent.hasAddAgentCompleted());
verify(mockAgentOne, times(1)).onStart();
verify(mockAgentOne, times(2)).doWork();
verify(mockAgentTwo, times(1)).onStart();
verify(mockAgentTwo, times(1)).doWork();
}
代码示例来源:origin: real-logic/aeron
aeronClientInvoker.invoke();
代码示例来源:origin: real-logic/agrona
@Test
public void shouldDetectConcurrentRemove()
{
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));
invoker.invoke();
assertTrue(compositeAgent.tryAdd(mockAgentTwo));
invoker.invoke();
assertTrue(compositeAgent.tryRemove(mockAgentOne));
assertFalse(compositeAgent.tryRemove(mockAgentTwo));
invoker.invoke();
assertTrue(compositeAgent.tryRemove(mockAgentTwo));
}
}
代码示例来源:origin: real-logic/aeron
private void snapshotState(final Publication publication, final long logPosition, final long leadershipTermId)
{
final ConsensusModuleSnapshotTaker snapshotTaker = new ConsensusModuleSnapshotTaker(
publication, idleStrategy, aeronClientInvoker);
snapshotTaker.markBegin(SNAPSHOT_TYPE_ID, logPosition, leadershipTermId, 0);
for (final ClusterSession session : sessionByIdMap.values())
{
if (session.state() == OPEN || session.state() == CLOSED)
{
snapshotTaker.snapshotSession(session);
}
}
aeronClientInvoker.invoke();
timerService.snapshot(snapshotTaker);
snapshotTaker.consensusModuleState(nextSessionId);
snapshotTaker.clusterMembers(memberId, highMemberId, clusterMembers);
snapshotTaker.markEnd(SNAPSHOT_TYPE_ID, logPosition, leadershipTermId, 0);
}
代码示例来源:origin: real-logic/agrona
@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));
}
代码示例来源:origin: real-logic/aeron
aeronClientInvoker.invoke();