@Test public void shouldNotAllowAddAfterClose() { final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); invoker.close(); assertThrows(IllegalStateException.class, () -> compositeAgent.tryAdd(mock(Agent.class))); }
public boolean tryAdd(final Agent agent) { Objects.requireNonNull(agent, "agent cannot be null"); if (Status.ACTIVE != status) { throw new IllegalStateException("add called when not active"); } return addAgent.compareAndSet(null, agent); }
DynamicCompositeAgent implements Agent { public boolean tryAdd(final Agent agent) { Objects.requireNonNull(agent, "agent cannot be null"); if (Status.ACTIVE != status) { throw new IllegalStateException("add called when not active"); } return addAgent.compareAndSet(null, agent); } }
DynamicCompositeAgent implements Agent { public boolean tryAdd(final Agent agent) { Objects.requireNonNull(agent, "agent cannot be null"); if (Status.ACTIVE != status) { throw new IllegalStateException("add called when not active"); } return addAgent.compareAndSet(null, agent); } DynamicCompositeAgent(final String roleName);  DynamicCompositeAgent(final String roleName, final List<? extends Agent> agents);  DynamicCompositeAgent(final String roleName, final Agent... agents); }
DynamicCompositeAgent implements Agent { public boolean tryAdd(final Agent agent) { Objects.requireNonNull(agent, "agent cannot be null"); if (Status.ACTIVE != status) { throw new IllegalStateException("add called when not active"); } return addAgent.compareAndSet(null, agent); } DynamicCompositeAgent(final String roleName);  DynamicCompositeAgent(final String roleName, final List<? extends Agent> agents);  DynamicCompositeAgent(final String roleName, final Agent... agents); Status status(); void onStart(); int doWork(); void onClose(); String roleName(); boolean tryAdd(final Agent agent); boolean hasAddAgentCompleted(); boolean tryRemove(final Agent agent); boolean hasRemoveAgentCompleted(); }
DynamicCompositeAgent implements Agent { public boolean tryAdd(final Agent agent) { Objects.requireNonNull(agent, "agent cannot be null"); if (Status.ACTIVE != status) { throw new IllegalStateException("add called when not active"); } return addAgent.compareAndSet(null, agent); } DynamicCompositeAgent(final String roleName);  DynamicCompositeAgent(final String roleName, final List<? extends Agent> agents);  DynamicCompositeAgent(final String roleName, final Agent... agents); Status status(); void onStart(); int doWork(); void onClose(); String roleName(); boolean tryAdd(final Agent agent); boolean hasAddAgentCompleted(); boolean tryRemove(final Agent agent); boolean hasRemoveAgentCompleted();  }