View Javadoc

1   /**
2      This file is part of GoldenGate Project (named also GoldenGate or GG).
3   
4      Copyright 2009, Frederic Bregier, and individual contributors by the @author
5      tags. See the COPYRIGHT.txt in the distribution for a full listing of
6      individual contributors.
7   
8      All GoldenGate Project is free software: you can redistribute it and/or 
9      modify it under the terms of the GNU General Public License as published 
10     by the Free Software Foundation, either version 3 of the License, or
11     (at your option) any later version.
12  
13     GoldenGate is distributed in the hope that it will be useful,
14     but WITHOUT ANY WARRANTY; without even the implied warranty of
15     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16     GNU General Public License for more details.
17  
18     You should have received a copy of the GNU General Public License
19     along with GoldenGate .  If not, see <http://www.gnu.org/licenses/>.
20   */
21  package openr66.context;
22  
23  import goldengate.common.state.MachineState;
24  import goldengate.common.state.Transition;
25  
26  import java.util.EnumSet;
27  import java.util.concurrent.ConcurrentHashMap;
28  
29  /**
30   * Finite Dual State Machine for OpenR66 (Requester=R, requesteD=D, Sender=S, Receive=R)
31   * 
32   * @author Frederic Bregier
33   *
34   */
35  public enum R66FiniteDualStates {
36      OPENEDCHANNEL, CLOSEDCHANNEL, ERROR,
37      STARTUP, 
38      AUTHENTR, AUTHENTD,
39      REQUESTR, REQUESTD, VALID, 
40      DATAR, DATAS, 
41      ENDTRANSFERR, ENDREQUESTR, 
42      ENDTRANSFERS, ENDREQUESTS,
43      TEST, INFORMATION, VALIDOTHER,
44      SHUTDOWN, BUSINESSR, BUSINESSD; 
45      // not used in LSH
46      // CONNECTERROR, 
47      // KEEPALIVEPACKET;
48      
49      private enum R66Transition {
50          tOPENEDCHANNEL(OPENEDCHANNEL, EnumSet.of(STARTUP, CLOSEDCHANNEL, ERROR)),
51          tSTARTUP(STARTUP, EnumSet.of(AUTHENTR, AUTHENTD, CLOSEDCHANNEL, ERROR)),
52          tAUTHENTR(AUTHENTR, EnumSet.of(AUTHENTD, CLOSEDCHANNEL, ERROR)),
53          tAUTHENTD(AUTHENTD, EnumSet.of(REQUESTR, VALIDOTHER, INFORMATION, SHUTDOWN, TEST, BUSINESSR, BUSINESSD, ENDREQUESTS, CLOSEDCHANNEL, ERROR)),
54          tREQUESTR(REQUESTR, EnumSet.of(VALID, REQUESTD, CLOSEDCHANNEL, ERROR)),
55          tREQUESTD(REQUESTD, EnumSet.of(DATAS, DATAR, CLOSEDCHANNEL, ERROR)),
56          tVALID(VALID, EnumSet.of(REQUESTD, DATAR, CLOSEDCHANNEL, ERROR)),
57          tDATAS(DATAS, EnumSet.of(DATAS, ENDTRANSFERS, CLOSEDCHANNEL, ERROR)),
58          tDATAR(DATAR, EnumSet.of(DATAR, ENDTRANSFERS, CLOSEDCHANNEL, ERROR)),
59          tENDTRANSFERS(ENDTRANSFERS, EnumSet.of(ENDTRANSFERR, CLOSEDCHANNEL, ERROR)),
60          tENDTRANSFERR(ENDTRANSFERR, EnumSet.of(ENDREQUESTS, CLOSEDCHANNEL, ERROR)),
61          tENDREQUESTS(ENDREQUESTS, EnumSet.of(ENDREQUESTR, CLOSEDCHANNEL, ERROR)),
62          tENDREQUESTR(ENDREQUESTR, EnumSet.of(CLOSEDCHANNEL, ERROR)),
63          tINFORMATION(INFORMATION, EnumSet.of(VALIDOTHER, CLOSEDCHANNEL, ERROR)),
64          tTEST(TEST, EnumSet.of(TEST, VALIDOTHER)),
65          tVALIDOTHER(VALIDOTHER, EnumSet.of(VALIDOTHER,CLOSEDCHANNEL, ERROR)),
66          tSHUTDOWN(SHUTDOWN, EnumSet.of(CLOSEDCHANNEL, SHUTDOWN, ERROR)),
67          tERROR(ERROR, EnumSet.of(ERROR, CLOSEDCHANNEL)),
68          tCLOSEDCHANNEL(CLOSEDCHANNEL, EnumSet.noneOf(R66FiniteDualStates.class)),
69          tBUSINESSR(BUSINESSR, EnumSet.of(ERROR, BUSINESSD, CLOSEDCHANNEL, VALIDOTHER)),
70          tBUSINESSD(BUSINESSD, EnumSet.of(ERROR, BUSINESSD, BUSINESSR, CLOSEDCHANNEL, VALIDOTHER));
71          
72          public Transition<R66FiniteDualStates> elt;
73          private R66Transition(R66FiniteDualStates state, EnumSet<R66FiniteDualStates> set) {
74              this.elt = new Transition<R66FiniteDualStates>(state, set);
75          }
76      }
77      
78      private static ConcurrentHashMap<R66FiniteDualStates, EnumSet<?>> stateMap =
79          new ConcurrentHashMap<R66FiniteDualStates, EnumSet<?>>();
80      /**
81       * This method should be called once at startup to initialize the Finite States association.
82       */
83      public static void initR66FiniteStates() {
84          for (R66Transition trans: R66Transition.values()) {
85              stateMap.put(trans.elt.state, trans.elt.set);
86          }
87      }
88      /**
89       * 
90       * @return a new Session MachineState for OpenR66
91       */
92      public static MachineState<R66FiniteDualStates> newSessionMachineState() {
93          MachineState<R66FiniteDualStates> machine = 
94              new MachineState<R66FiniteDualStates>(OPENEDCHANNEL, stateMap);
95          return machine;
96      }
97      /**
98       * 
99       * @param machine the Session MachineState to release
100      */
101     public static void endSessionMachineSate(MachineState<R66FiniteDualStates> machine) {
102         machine.release();
103     }
104 }