/** * Signal that a robot is done running. Synchronized with ensureRunnable since * that method needs to have a synchronized view on the runnableRobots for * submitting task to the executor. * * @param robot the {@link Robot} which is done working. */ public synchronized void doneRunning(Robot robot) { runnableRobots.remove(robot.getRobotName()); }
/** * Ensures that a robot is submitted to the executor, might submit the * {@link Robot} if it hasn't been submitted yet. * * <p> * Synchronized in combination with done() to keep proper track of the robots * that have been submitted. * * @param robot the {@link Robot} to enqueue */ public synchronized void ensureScheduled(Robot robot) { if (!runnableRobots.contains(robot.getRobotName())) { LOG.info("Enqueing robot: " + robot.getRobotName()); runnableRobots.add(robot.getRobotName()); executor.execute(robot); } }
/** * Updates a {@link Robot} with information about a waveletUpdate event. * * @param robot The robot to process the update for. * @param wavelet the wavelet on which the update is occuring. * @param deltas the deltas the have been applied to the given wavelet. */ private void updateRobot(Robot robot, ReadableWaveletData wavelet, DeltaSequence deltas) { try { robot.waveletUpdate(wavelet, deltas); ensureScheduled(robot); } catch (OperationException e) { LOG.warning("Unable to update robot(" + robot.getRobotName() + ")", e); } }
public void testEnsureRunnableCallsRobot() throws Exception { Robot robot = mock(Robot.class); when(robot.getRobotName()).thenReturn(RobotName.fromAddress("robot@example.com")); gateway.ensureScheduled(robot); executor.runAllCommands(); verify(robot).run(); }
public void testEnsureRunnableCallsRobot() throws Exception { Robot robot = mock(Robot.class); when(robot.getRobotName()).thenReturn(RobotName.fromAddress("robot@example.com")); gateway.ensureScheduled(robot); executor.runAllCommands(); verify(robot).run(); }