⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 messengerstate.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                /* RESOLVING       */                {Resolving, Nop, ResPending, Nop, ResolSat, Nop, Closed, Closein, Broken, Closein, Connected, Nop, Unresable, Closein, Resolving, Nop},                /* RESOLSATURATED  */                {ResolSat, Nop, ResPending, Nop, ResolSat, Nop, ResClosing, Closein, Broken, Closefail, SendingSat, Start, Unresable, Closefail, Resolving, Nop},                /* CONNECTED       */                {Connected, Nop, Sending, Start, SendingSat, Start, Closed, Closeio, Broken, Closeio, Connected, Nop, Disconned, Nop, Connected, Nop},                /* DISCONNECTED    */                {Disconned, Nop, Reconning, Connect, ReconSat, Connect, Closed, Closein, Broken, Closein, Connected, Nop, Disconned, Nop, Disconned, Nop},                /* RECONNECTING    */                {Reconning, Nop, Reconning, Nop, ReconSat, Nop, ReconClosing, Closein, Broken, Closefail, Sending, Start, Broken, Closefail, Disconned, Nop},                /* RECONSATURATED  */                {ReconSat, Nop, Reconning, Nop, ReconSat, Nop, ReconClosing, Closein, Broken, Closefail, SendingSat, Start, Broken, Closefail, Disconned, Nop},                /* SENDING         */                {Sending, Nop, Sending, Nop, SendingSat, Nop, Closing, Closein, Disconning, Closeio, Sending, Nop, Reconning, Connect, Connected, Nop},                /* SENDINGSATURATED*/                {SendingSat, Nop, Sending, Nop, SendingSat, Nop, Closing, Closein, Disconning, Closeio, SendingSat, Nop, ReconSat, Connect, Connected, Nop},                /* RESOLCLOSING    */                {ResClosing, Nop, ResClosing, Nop, ResClosing, Nop, ResClosing, Nop, Broken, Failall, Closing, Start, Unresable, Failall, ResClosing, Nop},                /* RECONCLOSING    */                {ReconClosing, Nop, ReconClosing, Nop, ReconClosing, Nop, ReconClosing, Nop, Broken, Failall, Closing, Start, Broken, Failall, ReconClosing, Nop},                /* CLOSING         */                {Closing, Nop, Closing, Nop, Closing, Nop, Closing, Nop, Disconning, Closeout, Closing, Nop, ReconClosing, Connect, Closed, Closeout},                /* DISCONNECTING   */                {Disconning, Nop, Disconning, Nop, Disconning, Nop, Disconning, Nop, Disconning, Nop, Disconning, Nop, Broken, Failall, Broken, Nop},                /* UNRESOLVABLE    */                {Unresable, Nop, Unresable, Nop, Unresable, Nop, Unresable, Nop, Unresable, Nop, Unresable, Closeout, Unresable, Nop, Unresable, Nop},                /* CLOSED          */                {Closed, Nop, Closed, Nop, Closed, Nop, Closed, Nop, Closed, Nop, Closed, Closeout, Closed, Nop, Closed, Nop},                /* BROKEN          */                {Broken, Nop, Broken, Nop, Broken, Nop, Broken, Nop, Broken, Nop, Broken, Closeout, Broken, Nop, Broken, Nop}        };        static {            // install the transitions map in its proper place.            Unresolved.init(INIT_TRANSITION_MAP[0]);            ResPending.init(INIT_TRANSITION_MAP[1]);            Resolving.init(INIT_TRANSITION_MAP[2]);            ResolSat.init(INIT_TRANSITION_MAP[3]);            Connected.init(INIT_TRANSITION_MAP[4]);            Disconned.init(INIT_TRANSITION_MAP[5]);            Reconning.init(INIT_TRANSITION_MAP[6]);            ReconSat.init(INIT_TRANSITION_MAP[7]);            Sending.init(INIT_TRANSITION_MAP[8]);            SendingSat.init(INIT_TRANSITION_MAP[9]);            ResClosing.init(INIT_TRANSITION_MAP[10]);            ReconClosing.init(INIT_TRANSITION_MAP[11]);            Closing.init(INIT_TRANSITION_MAP[12]);            Disconning.init(INIT_TRANSITION_MAP[13]);            Unresable.init(INIT_TRANSITION_MAP[14]);            Closed.init(INIT_TRANSITION_MAP[15]);            Broken.init(INIT_TRANSITION_MAP[16]);        }    }    /**     * The current state!     */    private volatile State state = null;    /**     * Constructs a new messenger state machine.     * <p/>     * The transition map is static and we refer to it only to grab the first     * state. After that, states refer to each other. The only reason they are     * members in the map is so that we can make references during init.     *     * @param connected If <tt>true</tt>, the initial state is {@link Messenger#CONNECTED} otherwise {@link Messenger#UNRESOLVED}.     */    protected MessengerState(boolean connected) {        state = connected ? TransitionMap.Connected : TransitionMap.Unresolved;    }    /**     * @return The current state.     */    public int getState() {        // getState is always just a peek. It needs no sync.        return state.number;    }    /**     * Event input.     */    public void resolveEvent() {        Action a = state.acResolve;        state = state.stResolve;        a.doIt(this);    }    /**     * Message event     */    public void msgsEvent() {        Action a = state.acMsgs;        state = state.stMsgs;        a.doIt(this);    }    /**     * Saturated Event     */    public void saturatedEvent() {        Action a = state.acSaturated;        state = state.stSaturated;        a.doIt(this);    }    /**     * Close Event     */    public void closeEvent() {        Action a = state.acClose;        state = state.stClose;        a.doIt(this);    }    /**     * Shutdown Event     */    public void shutdownEvent() {        Action a = state.acShutdown;        state = state.stShutdown;        a.doIt(this);    }    /**     * Up Event     */    public void upEvent() {        Action a = state.acUp;        state = state.stUp;        a.doIt(this);    }    /**     * Down Event     */    public void downEvent() {        Action a = state.acDown;        state = state.stDown;        a.doIt(this);    }    /**     * Idle Event     */    public void idleEvent() {        Action a = state.acIdle;        state = state.stIdle;        a.doIt(this);    }    /**     * Actions they're always called in sequence by event methods.     *     * Actions must not call event methods in sequence.     **/    /**     * Try to make a connection. Called whenever transitioning from a state that neither needs nor has a connection to a state     * that needs a connection and does not have it. Call upEvent when successful, or downEvent when failed.     */    protected abstract void connectAction();    /**     * Start sending. Called whenever transitioning to a state that has both a connection and messages to send from a state that     * lacked either attributes. So, will be called after sending stopped due to broken cnx or idle condition.  Call downEvent     * when stopping due to broken or closed connection, call {@link #idleEvent} when no pending message is left.     */    protected abstract void startAction();    /**     * Reject new messages from now on. Called whenever transitioning from a state that is {@link Messenger#USABLE} to a state     * that is not. No event expected once done.     */    protected abstract void closeInputAction();    /**     * Drain pending messages, all failed. Called once output is down and there are still pending messages.     * Call {@link #idleEvent} when done, as a normal result of no pending messages being left.     */    protected abstract void failAllAction();    /**     * Force close output. Called whenever the underlying connection is to be discarded and never to be needed again.  That is     * either because orderly close has completed, or shutdown is in progress. No event expected once done, but this action     * <b>must</b> cause any sending in progress to stop eventually. The fact that the sending has stopped must be reported as     * usual: either with a {@link #downEvent}, if the output closure caused the sending process to fail, or with an {@link     * #idleEvent} if the sending of the last message could be sent successfully despite the attempt at interrupting it.     * <p/>     * Sending is said to be in progress if, and only if, the last call to startAction is more recent than the last call to     * {@link #idleEvent} or {@link #downEvent}.     * <p/>     * It is advisable to also cancel an ongoing connect action, but not mandatory. If a {@link #connectAction} later succeeds,     * then {@link #upEvent} <b>must</b> be called as usual. This will result in another call to {@link #closeOutputAction}.     */    protected abstract void closeOutputAction();}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -