@Test public void testWorkWithSlowTactic() throws Exception { double timeout = getField(getField(tactic, "ticker"), "timeout"); long durationLongCommand = (long) timeout * 5; boolean[] isInterrupted = new boolean[1]; Tactic tacticSlow = new DoNothingTactic() { @Override protected void calculateTactics() { try { Thread.sleep(durationLongCommand); } catch (InterruptedException e) { isInterrupted[0] = true; } } }; long executeStart = System.currentTimeMillis(); tacticSlow.work(); long executeEnd = System.currentTimeMillis(); Assert.assertTrue(isInterrupted[0]); Assert.assertTrue(executeEnd - executeStart < durationLongCommand); }
@Override protected final void work() throws InterruptedException { if (ticker.timeIsExceeded()) { ticker.reset(); Thread t = new Thread(this::calculateTactics); t.start(); workTimoutTimer.reset(); while (t.isAlive()) { if (workTimoutTimer.timeIsExceeded()) { t.interrupt(); } } } }
Tactic extends ManagedThread implements Subscriber { @Override protected final void work() throws InterruptedException { if (ticker.timeIsExceeded()) { ticker.reset(); Thread t = new Thread(this::calculateTactics); t.start(); workTimoutTimer.reset(); while (t.isAlive()) { if (workTimoutTimer.timeIsExceeded()) { t.interrupt(); } } } } }
Tactic extends ManagedThread implements Subscriber { @Override protected final void work() throws InterruptedException { if (ticker.timeIsExceeded()) { ticker.reset(); Thread t = new Thread(this::calculateTactics); t.start(); workTimoutTimer.reset(); while (t.isAlive()) { if (workTimoutTimer.timeIsExceeded()) { t.interrupt(); } } } }  }
Tactic extends ManagedThread implements Subscriber { @Override protected final void work() throws InterruptedException { if (ticker.timeIsExceeded()) { ticker.reset(); Thread t = new Thread(this::calculateTactics); t.start(); workTimoutTimer.reset(); while (t.isAlive()) { if (workTimoutTimer.timeIsExceeded()) { t.interrupt(); } } } }  Radar getRadar(); GPS getGps(); Engine getEngine(); Gun getGun(); Radio getRadio(); final void startTactic(); final void stopTactic(); @Override @Deprecated final void destroy(); @Override void receive(Object msg, MultipartCallbacks multipartCallbacks); final String getIdentifier(); final Set<String> getAvailableComponents(); }
Tactic extends ManagedThread implements Subscriber { @Override protected final void work() throws InterruptedException { if (ticker.timeIsExceeded()) { ticker.reset(); Thread t = new Thread(this::calculateTactics); t.start(); workTimoutTimer.reset(); while (t.isAlive()) { if (workTimoutTimer.timeIsExceeded()) { t.interrupt(); } } } }  Radar getRadar(); GPS getGps(); Engine getEngine(); Gun getGun(); Radio getRadio(); final void startTactic(); final void stopTactic(); @Override @Deprecated final void destroy(); @Override void receive(Object msg, MultipartCallbacks multipartCallbacks); final String getIdentifier(); final Set<String> getAvailableComponents();  }