/** * Creates the handler for messages in connected state. * Overwrite and extend by additional matchers. * * @return an FSM function builder */ protected FSMStateFunctionBuilder<BaseClientState, BaseClientData> inConnectedState() { return matchEvent(CloseConnection.class, BaseClientData.class, this::closeConnection); }
/** * Creates the handler for messages in connected state. * Overwrite and extend by additional matchers. * * @return an FSM function builder */ protected FSMStateFunctionBuilder<BaseClientState, BaseClientData> inConnectedState() { return matchEvent(CloseConnection.class, BaseClientData.class, this::closeConnection); }
/** * Creates the handler for messages in disconnected state. * Overwrite and extend by additional matchers. * * @return an FSM function builder */ protected FSMStateFunctionBuilder<BaseClientState, BaseClientData> inDisconnectedState() { return matchEvent(OpenConnection.class, BaseClientData.class, this::openConnection) .event(TestConnection.class, BaseClientData.class, this::testConnection); }
/** * Creates the handler for messages in disconnected state. * Overwrite and extend by additional matchers. * * @return an FSM function builder */ protected FSMStateFunctionBuilder<BaseClientState, BaseClientData> inDisconnectedState() { return matchEvent(OpenConnection.class, BaseClientData.class, this::openConnection) .event(TestConnection.class, BaseClientData.class, this::testConnection); }
/** * Creates the handler for messages common to all states. * <p> * Overwrite and extend by additional matchers. * </p> * * @return an FSM function builder */ protected FSMStateFunctionBuilder<BaseClientState, BaseClientData> inAnyState() { return matchEvent(RetrieveConnectionMetrics.class, BaseClientData.class, this::retrieveConnectionMetrics) .event(OutboundSignal.WithExternalMessage.class, BaseClientData.class, (outboundSignal, data) -> { handleExternalMessage(outboundSignal); return stay(); }) .event(OutboundSignal.class, BaseClientData.class, (signal, data) -> { handleOutboundSignal(signal); return stay(); }); }
/** * Creates the handler for messages common to all states. * <p> * Overwrite and extend by additional matchers. * </p> * * @return an FSM function builder */ protected FSMStateFunctionBuilder<BaseClientState, BaseClientData> inAnyState() { return matchEvent(RetrieveConnectionMetrics.class, BaseClientData.class, this::retrieveConnectionMetrics) .event(OutboundSignal.WithExternalMessage.class, BaseClientData.class, (outboundSignal, data) -> { handleExternalMessage(outboundSignal); return stay(); }) .event(OutboundSignal.class, BaseClientData.class, (signal, data) -> { handleOutboundSignal(signal); return stay(); }); }
/** * Creates the handler for messages in testing state. * Overwrite and extend by additional matchers. * * @return an FSM function builder */ protected FSMStateFunctionBuilder<BaseClientState, BaseClientData> inTestingState() { return matchEvent(Status.Status.class, (e, d) -> Objects.equals(getSender(), getSelf()), (status, data) -> { final Status.Status answerToPublish = getStatusToReport(status); data.getSessionSender().ifPresent(sender -> sender.tell(answerToPublish, getSelf())); return stop(); }) .eventEquals(StateTimeout(), BaseClientData.class, (stats, data) -> { log.info("test timed out."); data.getSessionSender().ifPresent(sender -> { final DittoRuntimeException error = ConnectionFailedException.newBuilder(connectionId()) .description(String.format("Failed to open requested connection within <%d> seconds!", TEST_CONNECTION_TIMEOUT)) .dittoHeaders(data.getSessionHeaders()) .build(); sender.tell(new Status.Failure(error), getSelf()); }); return stop(); }); }
/** * Creates the handler for messages in testing state. * Overwrite and extend by additional matchers. * * @return an FSM function builder */ protected FSMStateFunctionBuilder<BaseClientState, BaseClientData> inTestingState() { return matchEvent(Status.Status.class, (e, d) -> Objects.equals(getSender(), getSelf()), (status, data) -> { final Status.Status answerToPublish = getStatusToReport(status); data.getSessionSender().ifPresent(sender -> sender.tell(answerToPublish, getSelf())); return stop(); }) .eventEquals(StateTimeout(), BaseClientData.class, (stats, data) -> { log.info("test timed out."); data.getSessionSender().ifPresent(sender -> { final DittoRuntimeException error = ConnectionFailedException.newBuilder(connectionId()) .description(String.format("Failed to open requested connection within <%d> seconds!", TEST_CONNECTION_TIMEOUT)) .dittoHeaders(data.getSessionHeaders()) .build(); sender.tell(new Status.Failure(error), getSelf()); }); return stop(); }); }
private FSMStateFunctionBuilder<BaseClientState, BaseClientData> inUnknownState() { return matchEvent(OpenConnection.class, BaseClientData.class, this::openConnection) .event(CloseConnection.class, BaseClientData.class, this::closeConnection) .event(TestConnection.class, BaseClientData.class, this::testConnection) .eventEquals(StateTimeout(), BaseClientData.class, (state, data) -> { if (ConnectionStatus.OPEN == data.getDesiredConnectionStatus()) { log.info("Did not receive connect command within init-timeout, connecting"); final OpenConnection openConnection = OpenConnection.of(connectionId(), DittoHeaders.empty()); getSelf().tell(openConnection, getSelf()); } else if (ConnectionStatus.CLOSED == data.getDesiredConnectionStatus()) { log.info( "Did not receive connect command within init-timeout, desired state is closed, going to disconnected state."); return goTo(DISCONNECTED); } else { log.info( "Did not receive connect command within init-timeout, desired state is {}, do nothing.", data.getDesiredConnectionStatus()); } return stay(); // handle self-told commands later }); }
private FSMStateFunctionBuilder<BaseClientState, BaseClientData> inUnknownState() { return matchEvent(OpenConnection.class, BaseClientData.class, this::openConnection) .event(CloseConnection.class, BaseClientData.class, this::closeConnection) .event(TestConnection.class, BaseClientData.class, this::testConnection) .eventEquals(StateTimeout(), BaseClientData.class, (state, data) -> { if (ConnectionStatus.OPEN == data.getDesiredConnectionStatus()) { log.info("Did not receive connect command within init-timeout, connecting"); final OpenConnection openConnection = OpenConnection.of(connectionId(), DittoHeaders.empty()); getSelf().tell(openConnection, getSelf()); } else if (ConnectionStatus.CLOSED == data.getDesiredConnectionStatus()) { log.info( "Did not receive connect command within init-timeout, desired state is closed, going to disconnected state."); return goTo(DISCONNECTED); } else { log.info( "Did not receive connect command within init-timeout, desired state is {}, do nothing.", data.getDesiredConnectionStatus()); } return stay(); // handle self-told commands later }); }