synchronized void updatePulseStatus(IJobUpdateKey key, JobUpdateStatus status) { PulseState state = pulseStates.get(key); if (state != null) { pulseStates.put( key, new PulseState(status, state.getPulseTimeoutMs(), state.getLastPulseMs())); } }
@Override public JobUpdatePulseStatus pulse(final IJobUpdateKey key) throws UpdateStateException { final PulseState state = pulseHandler.pulseAndGet(key); if (state == null) { LOG.info("Not pulsing inactive job update: " + key); return JobUpdatePulseStatus.FINISHED; } LOG.fine( String.format( "Job update %s has been pulsed. Timeout of %d msec is reset.", key, state.getPulseTimeoutMs())); if (JobUpdateStateMachine.isAwaitingPulse(state.getStatus())) { // Attempt to unblock a job update previously blocked on expired pulse. executor.execute( () -> { try { unscopedChangeUpdateStatus( key, status -> new JobUpdateEvent().setStatus(GET_UNBLOCKED_STATE.apply(status))); } catch (UpdateStateException e) { LOG.severe("Error while processing job update pulse: " + e); } }); } return JobUpdatePulseStatus.OK; }
synchronized PulseState pulseAndGet(IJobUpdateKey key) { PulseState state = pulseStates.get(key); if (state != null) { state = pulseStates.put( key, new PulseState(state.getStatus(), state.getPulseTimeoutMs(), clock.nowMillis())); } return state; }