hadoop 2-state machine-(1)

1.what  

  in many scenarios,we see some figures like this:some state node,some events triggered state changes,and certain directed-arcs.it look likes a running-machine with misc commands ,say like events.so it is called "State Machine".

  yep,through these elements,we know a clear flow of running,so it's simple and easily-understandable.

 

2.why

  bases on it's concept above,we know 'State machine' is targeted to simplify logics,decrease couples,and facilitate to tune programs.

 

3.how

  in hadoop yarn,there are many state machines in different modules,eg. RMAppImpl,RMAppAtttemptImpl,RMContainerImpl,RMNodeImpl etc.from the construction of it,there are at least certain items exists in it:

  prestate/current state--current status before any event comes in to be handled.

  post state--in contrast with prestate,this is the next state after triggering certain events

  event--that is the cuase to trigger to state to be moved on

  handler--what to do if any event comes in .in hadoop this is called by 'callback'

  here is a simple outline below:

prestate1 -------event1----------> post state1  
  - - - - event2 - - - -> post state1  
  - - - - event 3 - - - -> post state2  
prestate2 -------event2--------> post state2  
  -------event2--------> post state1  
..... ... ...  

  so  the relationship between event and post state may be N:M

  e.g.in RMAppImpl,there is a 'stateMachine' class varibale defined to render all flows from old to new states,of course ,related handlers are registered when starting up StateMachineFactory#installTopology()

你可能感兴趣的:(hadoop)