當前位置: 首頁>>代碼示例>>Python>>正文


Python TransitionTable.addTransitions方法代碼示例

本文整理匯總了Python中machinist.TransitionTable.addTransitions方法的典型用法代碼示例。如果您正苦於以下問題:Python TransitionTable.addTransitions方法的具體用法?Python TransitionTable.addTransitions怎麽用?Python TransitionTable.addTransitions使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在machinist.TransitionTable的用法示例。


在下文中一共展示了TransitionTable.addTransitions方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: build_convergence_loop_fsm

# 需要導入模塊: from machinist import TransitionTable [as 別名]
# 或者: from machinist.TransitionTable import addTransitions [as 別名]
def build_convergence_loop_fsm(reactor, deployer):
    """
    Create a convergence loop FSM.

    :param IReactorTime reactor: Used to schedule delays in the loop.

    :param IDeployer deployer: Used to discover local state and calcualte
        necessary changes to match desired configuration.
    """
    I = ConvergenceLoopInputs
    O = ConvergenceLoopOutputs
    S = ConvergenceLoopStates

    table = TransitionTable()
    table = table.addTransition(
        S.STOPPED, I.STATUS_UPDATE, [O.STORE_INFO, O.CONVERGE], S.CONVERGING)
    table = table.addTransitions(
        S.CONVERGING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.STOP: ([], S.CONVERGING_STOPPING),
            I.ITERATION_DONE: ([O.CONVERGE], S.CONVERGING),
        })
    table = table.addTransitions(
        S.CONVERGING_STOPPING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.ITERATION_DONE: ([], S.STOPPED),
        })

    loop = ConvergenceLoop(reactor, deployer)
    fsm = constructFiniteStateMachine(
        inputs=I, outputs=O, states=S, initial=S.STOPPED, table=table,
        richInputs=[_ClientStatusUpdate], inputContext={},
        world=MethodSuffixOutputer(loop))
    loop.fsm = fsm
    return fsm
開發者ID:Waynelemars,項目名稱:flocker,代碼行數:37,代碼來源:_loop.py

示例2: _build_convergence_loop_table

# 需要導入模塊: from machinist import TransitionTable [as 別名]
# 或者: from machinist.TransitionTable import addTransitions [as 別名]
def _build_convergence_loop_table():
    """
    Create the ``TransitionTable`` needed by the convergence loop FSM.

    :return TransitionTable: The transition table for the state machine for
        converging on the cluster configuration.
    """
    I = ConvergenceLoopInputs
    O = ConvergenceLoopOutputs
    S = ConvergenceLoopStates

    table = TransitionTable()
    table = table.addTransition(
        S.STOPPED, I.STATUS_UPDATE, [O.STORE_INFO, O.CONVERGE], S.CONVERGING)
    table = table.addTransitions(
        S.CONVERGING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.STOP: ([], S.CONVERGING_STOPPING),
            I.SLEEP: ([O.SCHEDULE_WAKEUP], S.SLEEPING),
        })
    table = table.addTransitions(
        S.CONVERGING_STOPPING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.SLEEP: ([], S.STOPPED),
        })
    table = table.addTransitions(
        S.SLEEPING, {
            I.WAKEUP: ([O.CLEAR_WAKEUP, O.CONVERGE], S.CONVERGING),
            I.STOP: ([O.CLEAR_WAKEUP], S.STOPPED),
            I.STATUS_UPDATE: (
                [O.STORE_INFO, O.UPDATE_MAYBE_WAKEUP], S.SLEEPING),
            })
    return table
開發者ID:PradeepSingh1988,項目名稱:flocker,代碼行數:35,代碼來源:_loop.py

示例3: build_cluster_status_fsm

# 需要導入模塊: from machinist import TransitionTable [as 別名]
# 或者: from machinist.TransitionTable import addTransitions [as 別名]
def build_cluster_status_fsm(convergence_loop_fsm):
    """
    Create a new cluster status FSM.

    The automatic reconnection logic is handled by the
    ``AgentLoopService``; the world object here just gets notified of
    disconnects, it need schedule the reconnect itself.

    :param convergence_loop_fsm: A convergence loop FSM as output by
    ``build_convergence_loop_fsm``.
    """
    S = ClusterStatusStates
    I = ClusterStatusInputs
    O = ClusterStatusOutputs
    table = TransitionTable()
    # We may be shut down in any state, in which case we disconnect if
    # necessary.
    table = table.addTransitions(
        S.DISCONNECTED,
        {
            # Store the client, then wait for cluster status to be sent
            # over AMP:
            I.CONNECTED_TO_CONTROL_SERVICE: ([O.STORE_CLIENT], S.IGNORANT),
            I.SHUTDOWN: ([], S.SHUTDOWN),
        },
    )
    table = table.addTransitions(
        S.IGNORANT,
        {
            # We never told agent to start, so no need to tell it to stop:
            I.DISCONNECTED_FROM_CONTROL_SERVICE: ([], S.DISCONNECTED),
            # Tell agent latest cluster status, implicitly starting it:
            I.STATUS_UPDATE: ([O.UPDATE_STATUS], S.KNOWLEDGEABLE),
            I.SHUTDOWN: ([O.DISCONNECT], S.SHUTDOWN),
        },
    )
    table = table.addTransitions(
        S.KNOWLEDGEABLE,
        {
            # Tell agent latest cluster status:
            I.STATUS_UPDATE: ([O.UPDATE_STATUS], S.KNOWLEDGEABLE),
            I.DISCONNECTED_FROM_CONTROL_SERVICE: ([O.STOP], S.DISCONNECTED),
            I.SHUTDOWN: ([O.STOP, O.DISCONNECT], S.SHUTDOWN),
        },
    )
    table = table.addTransitions(
        S.SHUTDOWN, {I.DISCONNECTED_FROM_CONTROL_SERVICE: ([], S.SHUTDOWN), I.STATUS_UPDATE: ([], S.SHUTDOWN)}
    )

    return constructFiniteStateMachine(
        inputs=I,
        outputs=O,
        states=S,
        initial=S.DISCONNECTED,
        table=table,
        richInputs=[_ConnectedToControlService, _StatusUpdate],
        inputContext={},
        world=MethodSuffixOutputer(ClusterStatus(convergence_loop_fsm)),
    )
開發者ID:hackday-profilers,項目名稱:flocker,代碼行數:61,代碼來源:_loop.py

示例4: test_addTransitionsDoesNotMutate

# 需要導入模塊: from machinist import TransitionTable [as 別名]
# 或者: from machinist.TransitionTable import addTransitions [as 別名]
 def test_addTransitionsDoesNotMutate(self):
     """
     L{TransitionTable.addTransitions} does not change the
     L{TransitionTable} it is called on.
     """
     table = TransitionTable({"foo": {"bar": Transition("baz", "quux")}})
     table.addTransitions("apple", {"banana": ("clementine", "date")})
     self.assertEqual({"foo": {"bar": Transition("baz", "quux")}}, table.table)
開發者ID:ClusterHQ,項目名稱:machinist,代碼行數:10,代碼來源:test_fsm.py

示例5: _build_cluster_status_fsm_table

# 需要導入模塊: from machinist import TransitionTable [as 別名]
# 或者: from machinist.TransitionTable import addTransitions [as 別名]
def _build_cluster_status_fsm_table():
    """
    Create the ``TransitionTable`` needed by the cluster status FSM.

    :return TransitionTable: The transition table for the state machine for
        keeping track of cluster state and configuration.
    """
    S = ClusterStatusStates
    I = ClusterStatusInputs
    O = ClusterStatusOutputs
    table = TransitionTable()
    # We may be shut down in any state, in which case we disconnect if
    # necessary.
    table = table.addTransitions(
        S.DISCONNECTED, {
            # Store the client, then wait for cluster status to be sent
            # over AMP:
            I.CONNECTED_TO_CONTROL_SERVICE: ([O.STORE_CLIENT], S.IGNORANT),
            I.SHUTDOWN: ([], S.SHUTDOWN),
        })
    table = table.addTransitions(
        S.IGNORANT, {
            # We never told agent to start, so no need to tell it to stop:
            I.DISCONNECTED_FROM_CONTROL_SERVICE: ([], S.DISCONNECTED),
            # Tell agent latest cluster status, implicitly starting it:
            I.STATUS_UPDATE: ([O.UPDATE_STATUS], S.KNOWLEDGEABLE),
            I.SHUTDOWN: ([O.DISCONNECT], S.SHUTDOWN),
        })
    table = table.addTransitions(
        S.KNOWLEDGEABLE, {
            # Tell agent latest cluster status:
            I.STATUS_UPDATE: ([O.UPDATE_STATUS], S.KNOWLEDGEABLE),
            I.DISCONNECTED_FROM_CONTROL_SERVICE: ([O.STOP], S.DISCONNECTED),
            I.SHUTDOWN: ([O.STOP, O.DISCONNECT], S.SHUTDOWN),
        })
    table = table.addTransitions(
        S.SHUTDOWN, {
            I.DISCONNECTED_FROM_CONTROL_SERVICE: ([], S.SHUTDOWN),
            I.STATUS_UPDATE: ([], S.SHUTDOWN),
            })
    return table
開發者ID:PradeepSingh1988,項目名稱:flocker,代碼行數:43,代碼來源:_loop.py

示例6: test_addTransitions

# 需要導入模塊: from machinist import TransitionTable [as 別名]
# 或者: from machinist.TransitionTable import addTransitions [as 別名]
 def test_addTransitions(self):
     """
     L{TransitionTable.addTransitions} accepts a state and a mapping from
     inputs to output, next state pairs and adds all of those transitions to
     the given state to a new L{TransitionTable} which it returns.
     """
     table = TransitionTable()
     more = table.addTransitions(
         "apple", {
             "banana": ("clementine", "date"),
             "eggplant": ("fig", "grape")})
     self.assertEqual(
         {"apple": {
                 "banana": Transition("clementine", "date"),
                 "eggplant": Transition("fig", "grape")}},
         more.table)
開發者ID:ClusterHQ,項目名稱:machinist,代碼行數:18,代碼來源:test_fsm.py

示例7: NamedConstant

# 需要導入模塊: from machinist import TransitionTable [as 別名]
# 或者: from machinist.TransitionTable import addTransitions [as 別名]
    ARM_TURNED = NamedConstant()
    ARM_LOCKED = NamedConstant()

class TurnstileOutput(Names):
    ENGAGE_LOCK = NamedConstant()
    DISENGAGE_LOCK = NamedConstant()

class TurnstileState(Names):
    LOCKED = NamedConstant()
    UNLOCKED = NamedConstant()
    ACTIVE = NamedConstant()

table = TransitionTable()
table = table.addTransitions(
    TurnstileState.UNLOCKED, {
        TurnstileInput.ARM_TURNED:
            ([TurnstileOutput.ENGAGE_LOCK], TurnstileState.ACTIVE),
    })
table = table.addTransitions(
    TurnstileState.ACTIVE, {
        TurnstileInput.ARM_LOCKED: ([], TurnstileState.LOCKED),
        TurnstileInput.ARM_UNLOCKED: ([], TurnstileState.UNLOCKED),
    })
table = table.addTransitions(
    TurnstileState.LOCKED, {
        TurnstileInput.FARE_PAID:
            ([TurnstileOutput.DISENGAGE_LOCK], TurnstileState.ACTIVE),
      })

class Turnstile(object):
    def __init__(self, hardware):
開發者ID:glyph,項目名稱:machinist,代碼行數:33,代碼來源:turnstile.py

示例8: build_convergence_loop_fsm

# 需要導入模塊: from machinist import TransitionTable [as 別名]
# 或者: from machinist.TransitionTable import addTransitions [as 別名]
def build_convergence_loop_fsm(reactor, deployer):
    """
    Create a convergence loop FSM.

    Once cluster config+cluster state updates from control service are
    received the basic loop is:

    1. Discover local state.
    2. Calculate ``IStateChanges`` based on local state and cluster
       configuration and cluster state we received from control service.
    3. Execute the change.
    4. Sleep.

    However, if an update is received during sleep then we calculate based
    on that updated config+state whether a ``IStateChange`` needs to
    happen. If it does that means this change will have impact on what we
    do, so we interrupt the sleep. If calculation suggests a no-op then we
    keep sleeping. Notably we do **not** do a discovery of local state
    when an update is received while sleeping, since that is an expensive
    operation that can involve talking to external resources. Moreover an
    external update only implies external state/config changed, so we're
    not interested in the latest local state in trying to decide if this
    update requires us to do something; a recently cached version should
    suffice.

    :param IReactorTime reactor: Used to schedule delays in the loop.

    :param IDeployer deployer: Used to discover local state and calcualte
        necessary changes to match desired configuration.
    """
    I = ConvergenceLoopInputs
    O = ConvergenceLoopOutputs
    S = ConvergenceLoopStates

    table = TransitionTable()
    table = table.addTransition(
        S.STOPPED, I.STATUS_UPDATE, [O.STORE_INFO, O.CONVERGE], S.CONVERGING)
    table = table.addTransitions(
        S.CONVERGING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.STOP: ([], S.CONVERGING_STOPPING),
            I.SLEEP: ([O.SCHEDULE_WAKEUP], S.SLEEPING),
        })
    table = table.addTransitions(
        S.CONVERGING_STOPPING, {
            I.STATUS_UPDATE: ([O.STORE_INFO], S.CONVERGING),
            I.SLEEP: ([], S.STOPPED),
        })
    table = table.addTransitions(
        S.SLEEPING, {
            I.WAKEUP: ([O.CLEAR_WAKEUP, O.CONVERGE], S.CONVERGING),
            I.STOP: ([O.CLEAR_WAKEUP], S.STOPPED),
            I.STATUS_UPDATE: (
                [O.STORE_INFO, O.UPDATE_MAYBE_WAKEUP], S.SLEEPING),
            })

    loop = ConvergenceLoop(reactor, deployer)
    fsm = constructFiniteStateMachine(
        inputs=I, outputs=O, states=S, initial=S.STOPPED, table=table,
        richInputs=[_ClientStatusUpdate, _Sleep], inputContext={},
        world=MethodSuffixOutputer(loop))
    loop.fsm = fsm
    return fsm
開發者ID:bertothunder,項目名稱:flocker,代碼行數:65,代碼來源:_loop.py

示例9: Outputer

# 需要導入模塊: from machinist import TransitionTable [as 別名]
# 或者: from machinist.TransitionTable import addTransitions [as 別名]
# end table def

# begin first transition
table = table.addTransition(
    State.LOCKED, Input.FARE_PAID, [Output.DISENGAGE_LOCK], State.ACTIVE)
# end first transition

# begin second transition
table = table.addTransition(
    State.UNLOCKED, Input.ARM_TURNED, [Output.ENGAGE_LOCK], State.ACTIVE)
# end second transition

# begin last transitions
table = table.addTransitions(
    State.ACTIVE, {
        Input.ARM_UNLOCKED: ([], State.UNLOCKED),
        Input.ARM_LOCKED: ([], State.LOCKED),
        })
# end last transitions

# begin outputer
from machinist import MethodSuffixOutputer

class Outputer(object):
    def output_ENGAGE_LOCK(self, engage):
        print("Engaging the lock.")

    def output_DISENGAGE_LOCK(self, disengage):
        print("Disengaging the lock.")

outputer = MethodSuffixOutputer(Outputer())
開發者ID:ClusterHQ,項目名稱:machinist,代碼行數:33,代碼來源:turnstile.py


注:本文中的machinist.TransitionTable.addTransitions方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。