public InputState getRunningInputState(String inputStateId) { for (InputState inputState : inputStates) { if (inputState.getMessageInput().getId().equals(inputStateId)) return inputState; } return null; }
public List<InputState> getRunningInputs() { List<InputState> runningInputs = Lists.newArrayList(); for (InputState inputState : inputStates) { if (inputState.getState() == InputState.InputStateType.RUNNING) runningInputs.add(inputState); } return inputStates; }
@Override protected void shutDown() throws Exception { LOG.debug("Stopping InputSetupService"); eventBus.unregister(this); for (InputState state : inputRegistry.getRunningInputs()) { MessageInput input = state.getMessageInput(); LOG.info( "Attempting to close input <{}> [{}].", input.getUniqueReadableId(), input.getName()); Stopwatch s = Stopwatch.createStarted(); try { input.stop(); LOG.info( "Input <{}> closed. Took [{}ms]", input.getUniqueReadableId(), s.elapsed(TimeUnit.MILLISECONDS)); } catch (Exception e) { LOG.error( "Unable to stop input <{}> [{}]: " + e.getMessage(), input.getUniqueReadableId(), input.getName()); } finally { s.stop(); } } LOG.debug("Stopped InputSetupService"); }
public boolean hasTypeRunning(Class klazz) { for (InputState inputState : inputStates) { if (inputState.getMessageInput().getClass().equals(klazz)) { return true; } } return false; }
public InputState terminate(MessageInput input) { InputState inputState = stop(input); if (inputState != null) { inputState.setState(InputState.InputStateType.TERMINATED); finishedTermination(inputState); } return inputState; }
public void removeFromRunning(MessageInput input) { // Remove from running list. InputState thisInputState = null; for (InputState inputState : inputStates) { if (inputState.getMessageInput().equals(input)) { thisInputState = inputState; } } inputStates.remove(thisInputState); }
public InputState stop(MessageInput input) { InputState inputState = getRunningInputState(input.getId()); if (inputState != null) { try { input.stop(); } catch (Exception e) { LOG.warn("Stopping input <{}> failed, removing anyway: {}", input.getId(), e); } removeFromRunning(input); inputState.setState(InputState.InputStateType.STOPPED); finishedStop(inputState); } return inputState; }
protected void handleLaunchException(Throwable e, MessageInput input, InputState inputState) { StringBuilder msg = new StringBuilder( "The [" + input.getClass().getCanonicalName() + "] input with ID <" + input.getId() + "> misfired. Reason: "); String causeMsg = extractMessageCause(e); msg.append(causeMsg); LOG.error(msg.toString(), e); // Clean up. // cleanInput(input); inputState.setState(InputState.InputStateType.FAILED); inputState.setDetailedMessage(causeMsg); }