当前位置: 首页>>代码示例>>Golang>>正文


Golang fsm.NewFSM函数代码示例

本文整理汇总了Golang中github.com/looplab/fsm.NewFSM函数的典型用法代码示例。如果您正苦于以下问题:Golang NewFSM函数的具体用法?Golang NewFSM怎么用?Golang NewFSM使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了NewFSM函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: newChaincodeHandler

// NewChaincodeHandler returns a new instance of the shim side handler.
func newChaincodeHandler(peerChatStream PeerChaincodeStream, chaincode Chaincode) *Handler {
	v := &Handler{
		ChatStream: peerChatStream,
		cc:         chaincode,
	}
	v.responseChannel = make(map[string]chan pb.ChaincodeMessage)
	v.nextState = make(chan *nextStateInfo)

	// Create the shim side FSM
	v.FSM = fsm.NewFSM(
		"created",
		fsm.Events{
			{Name: pb.ChaincodeMessage_REGISTERED.String(), Src: []string{"created"}, Dst: "established"},
			{Name: pb.ChaincodeMessage_INIT.String(), Src: []string{"established"}, Dst: "init"},
			{Name: pb.ChaincodeMessage_READY.String(), Src: []string{"established"}, Dst: "ready"},
			{Name: pb.ChaincodeMessage_ERROR.String(), Src: []string{"init"}, Dst: "established"},
			{Name: pb.ChaincodeMessage_RESPONSE.String(), Src: []string{"init"}, Dst: "init"},
			{Name: pb.ChaincodeMessage_COMPLETED.String(), Src: []string{"init"}, Dst: "ready"},
			{Name: pb.ChaincodeMessage_TRANSACTION.String(), Src: []string{"ready"}, Dst: "transaction"},
			{Name: pb.ChaincodeMessage_COMPLETED.String(), Src: []string{"transaction"}, Dst: "ready"},
			{Name: pb.ChaincodeMessage_ERROR.String(), Src: []string{"transaction"}, Dst: "ready"},
			{Name: pb.ChaincodeMessage_RESPONSE.String(), Src: []string{"transaction"}, Dst: "transaction"},
			{Name: pb.ChaincodeMessage_RESPONSE.String(), Src: []string{"ready"}, Dst: "ready"},
		},
		fsm.Callbacks{
			"before_" + pb.ChaincodeMessage_REGISTERED.String(): func(e *fsm.Event) { v.beforeRegistered(e) },
			"after_" + pb.ChaincodeMessage_RESPONSE.String():    func(e *fsm.Event) { v.afterResponse(e) },
			"after_" + pb.ChaincodeMessage_ERROR.String():       func(e *fsm.Event) { v.afterError(e) },
			"enter_init":                                        func(e *fsm.Event) { v.enterInitState(e) },
			"enter_transaction":                                 func(e *fsm.Event) { v.enterTransactionState(e) },
		},
	)
	return v
}
开发者ID:hyperledger,项目名称:fabric,代码行数:35,代码来源:handler.go

示例2: NewNode

// Create and return a new Node. channels for sending and receiving messages are setup.
// And two goroutines are spawned Send and Receive to handle incoming and outgoing messages.
func NewNode(conn net.Conn) *Node {
	n := new(Node)
	n.Client = NewClient(conn)
	n.ID = uuid.NewRandom()
	n.Name = n.ID.String()
	n.State = UNKNOWN
	n.fsm = fsm.NewFSM(
		n.State.S(),
		fsm.Events{
			{Name: "offline", Src: StateList(ONLINE, READY, ASSIGNING, WORKING), Dst: OFFLINE.S()},
			{Name: "online", Src: StateList(UNKNOWN, READY, OFFLINE), Dst: ONLINE.S()},
			{Name: "ready", Src: StateList(ONLINE, WORKING, ASSIGNING), Dst: READY.S()},
			{Name: "assign", Src: StateList(READY), Dst: ASSIGNING.S()},
			{Name: "work", Src: StateList(ASSIGNING), Dst: WORKING.S()},
			{Name: "service", Src: StateList(UNKNOWN, ONLINE, OFFLINE), Dst: SERVICE.S()},
		},
		fsm.Callbacks{
			"after_event":    func(e *fsm.Event) { n.afterEvent(e) },
			"before_offline": func(e *fsm.Event) { n.beforeOffline(e) },
			OFFLINE.S():      func(e *fsm.Event) { n.offlineNode(e) },
		},
	)

	n.Send = make(chan *proto_msg.KamajiMessage)
	n.Receive = make(chan *proto_msg.KamajiMessage)
	n.done = make(chan bool)
	n.waitGroup = &sync.WaitGroup{}
	if n.Conn != nil {
		go n.messageTransmitter()
		go n.messageReciever()
	}
	return n
}
开发者ID:smaragden,项目名称:kamaji,代码行数:35,代码来源:node.go

示例3: NewCommand

// Create a new Command instance and return it.
func NewCommand(name string, task *Task) *Command {
	c := new(Command)
	c.ID = uuid.NewRandom()
	c.Name = name
	c.State = UNKNOWN
	c.Completion = 0.0
	c.created = time.Now()
	c.priority = 0
	c.Task = task
	if task != nil {
		task.Commands = append(task.Commands, c)
	}
	c.FSM = fsm.NewFSM(
		c.State.S(),
		fsm.Events{
			{Name: "ready", Src: StateList(UNKNOWN, STOPPED, ASSIGNING), Dst: READY.S()},
			{Name: "assign", Src: StateList(READY), Dst: ASSIGNING.S()},
			{Name: "start", Src: StateList(UNKNOWN, READY, ASSIGNING, STOPPED), Dst: WORKING.S()},
			{Name: "restart", Src: StateList(DONE), Dst: WORKING.S()},
			{Name: "finish", Src: StateList(WORKING), Dst: DONE.S()},
			{Name: "stop", Src: StateList(WORKING), Dst: STOPPED.S()},
		},
		fsm.Callbacks{
			"after_event": func(e *fsm.Event) { c.afterEvent(e) },
			DONE.S():      func(e *fsm.Event) { c.finishCommand(e) },
		},
	)
	return c
}
开发者ID:smaragden,项目名称:kamaji,代码行数:30,代码来源:command.go

示例4: Start

func (self *Core) Start() {
	mlog.Info("starting core service ...")

	events := []fsm.EventDesc{
		{Name: "import", Src: []string{"idle", "scanning"}, Dst: "scanning"},
		{Name: "found", Src: []string{"scanning"}, Dst: "scanning"},
		{Name: "scraped", Src: []string{"scanning"}, Dst: "scanning"},
		{Name: "status", Src: []string{"idle", "scanning"}, Dst: "scanning"},
		{Name: "finish", Src: []string{"scanning"}, Dst: "idle"},
	}

	// some initialization
	self.fsm = fsm.NewFSM(
		"idle",
		events,
		fsm.Callbacks{
			"import":  self.importer,
			"found":   self.found,
			"scraped": self.scraped,
			"finish":  self.finish,
		},
	)

	self.context = message.Context{Message: "Idle", Backdrop: "/mAwd34SAC8KqBKRm2MwHPLhLDU5.jpg", Completed: false}

	go self.react()

	mlog.Info("core service started")
}
开发者ID:sh4t,项目名称:mediabase,代码行数:29,代码来源:core.go

示例5: main

func main() {
	fsm := fsm.NewFSM(
		"closed",
		fsm.Events{
			{Name: "open", Src: []string{"closed"}, Dst: "open"},
			{Name: "close", Src: []string{"open"}, Dst: "closed"},
		},
		fsm.Callbacks{},
	)

	fmt.Println(fsm.Current())

	err := fsm.Event("open")
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(fsm.Current())

	err = fsm.Event("close")
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(fsm.Current())
}
开发者ID:ftwbzhao,项目名称:fsm-2,代码行数:26,代码来源:simple.go

示例6: NewPeerConnectionFSM

// NewPeerConnectionFSM creates and returns a PeerConnectionFSM
func NewPeerConnectionFSM(to string) *PeerConnectionFSM {
	d := &PeerConnectionFSM{
		To: to,
	}

	d.FSM = fsm.NewFSM(
		"created",
		fsm.Events{
			{Name: "HELLO", Src: []string{"created"}, Dst: "established"},
			{Name: "GET_PEERS", Src: []string{"established"}, Dst: "established"},
			{Name: "PEERS", Src: []string{"established"}, Dst: "established"},
			{Name: "PING", Src: []string{"established"}, Dst: "established"},
			{Name: "DISCONNECT", Src: []string{"created", "established"}, Dst: "closed"},
		},
		fsm.Callbacks{
			"enter_state":  func(e *fsm.Event) { d.enterState(e) },
			"before_HELLO": func(e *fsm.Event) { d.beforeHello(e) },
			"after_HELLO":  func(e *fsm.Event) { d.afterHello(e) },
			"before_PING":  func(e *fsm.Event) { d.beforePing(e) },
			"after_PING":   func(e *fsm.Event) { d.afterPing(e) },
		},
	)

	return d
}
开发者ID:RicHernandez2,项目名称:fabric,代码行数:26,代码来源:fsm.go

示例7: NewManager

func NewManager(_myId string, _members []string) *Manager {
	self := &Manager{
		myId:      _myId,
		members:   _members,
		votes:     make(Votes),
		threshold: util.ComputeQuorumThreshold(len(_members)),
		C:         make(chan bool, 100),
	}

	self.state = fsm.NewFSM(
		"idle",
		fsm.Events{
			{Name: "quorum", Src: []string{"idle", "elected"}, Dst: "electing"},
			{Name: "complete", Src: []string{"electing"}, Dst: "elected"},
			{Name: "next", Src: []string{"elected"}, Dst: "idle"},
		},
		fsm.Callbacks{
			"electing":      func(e *fsm.Event) { self.onElecting() },
			"enter_elected": func(e *fsm.Event) { self.onElected(e.Args[0].(string), e.Args[1].(int64)) },
			"leave_elected": func(e *fsm.Event) { self.view++ },
		},
	)

	fmt.Printf("EM: Initializing with %d members and a quorum threshold %d\n", len(self.members), self.threshold)

	return self
}
开发者ID:ghaskins,项目名称:go-cluster,代码行数:27,代码来源:manager.go

示例8: newChaincodeSupportHandler

func newChaincodeSupportHandler(chaincodeSupport *ChaincodeSupport, peerChatStream PeerChaincodeStream) *Handler {
	v := &Handler{
		ChatStream: peerChatStream,
	}
	v.chaincodeSupport = chaincodeSupport
	//we want this to block
	v.nextState = make(chan *nextStateInfo)

	v.FSM = fsm.NewFSM(
		createdstate,
		fsm.Events{
			//Send REGISTERED, then, if deploy { trigger INIT(via INIT) } else { trigger READY(via COMPLETED) }
			{Name: pb.ChaincodeMessage_REGISTER.String(), Src: []string{createdstate}, Dst: establishedstate},
			{Name: pb.ChaincodeMessage_INIT.String(), Src: []string{establishedstate}, Dst: initstate},
			{Name: pb.ChaincodeMessage_READY.String(), Src: []string{establishedstate}, Dst: readystate},
			{Name: pb.ChaincodeMessage_TRANSACTION.String(), Src: []string{readystate}, Dst: transactionstate},
			{Name: pb.ChaincodeMessage_PUT_STATE.String(), Src: []string{transactionstate}, Dst: busyxactstate},
			{Name: pb.ChaincodeMessage_DEL_STATE.String(), Src: []string{transactionstate}, Dst: busyxactstate},
			{Name: pb.ChaincodeMessage_INVOKE_CHAINCODE.String(), Src: []string{transactionstate}, Dst: busyxactstate},
			{Name: pb.ChaincodeMessage_PUT_STATE.String(), Src: []string{initstate}, Dst: busyinitstate},
			{Name: pb.ChaincodeMessage_DEL_STATE.String(), Src: []string{initstate}, Dst: busyinitstate},
			{Name: pb.ChaincodeMessage_INVOKE_CHAINCODE.String(), Src: []string{initstate}, Dst: busyinitstate},
			{Name: pb.ChaincodeMessage_COMPLETED.String(), Src: []string{initstate, readystate, transactionstate}, Dst: readystate},
			{Name: pb.ChaincodeMessage_GET_STATE.String(), Src: []string{readystate}, Dst: readystate},
			{Name: pb.ChaincodeMessage_GET_STATE.String(), Src: []string{initstate}, Dst: initstate},
			{Name: pb.ChaincodeMessage_GET_STATE.String(), Src: []string{busyinitstate}, Dst: busyinitstate},
			{Name: pb.ChaincodeMessage_GET_STATE.String(), Src: []string{transactionstate}, Dst: transactionstate},
			{Name: pb.ChaincodeMessage_GET_STATE.String(), Src: []string{busyxactstate}, Dst: busyxactstate},
			{Name: pb.ChaincodeMessage_RANGE_QUERY_STATE.String(), Src: []string{readystate}, Dst: readystate},
			{Name: pb.ChaincodeMessage_RANGE_QUERY_STATE.String(), Src: []string{initstate}, Dst: initstate},
			{Name: pb.ChaincodeMessage_RANGE_QUERY_STATE.String(), Src: []string{busyinitstate}, Dst: busyinitstate},
			{Name: pb.ChaincodeMessage_RANGE_QUERY_STATE.String(), Src: []string{transactionstate}, Dst: transactionstate},
			{Name: pb.ChaincodeMessage_RANGE_QUERY_STATE.String(), Src: []string{busyxactstate}, Dst: busyxactstate},
			{Name: pb.ChaincodeMessage_ERROR.String(), Src: []string{initstate}, Dst: endstate},
			{Name: pb.ChaincodeMessage_ERROR.String(), Src: []string{transactionstate}, Dst: readystate},
			{Name: pb.ChaincodeMessage_ERROR.String(), Src: []string{busyinitstate}, Dst: initstate},
			{Name: pb.ChaincodeMessage_ERROR.String(), Src: []string{busyxactstate}, Dst: transactionstate},
			{Name: pb.ChaincodeMessage_RESPONSE.String(), Src: []string{busyinitstate}, Dst: initstate},
			{Name: pb.ChaincodeMessage_RESPONSE.String(), Src: []string{busyxactstate}, Dst: transactionstate},
		},
		fsm.Callbacks{
			"before_" + pb.ChaincodeMessage_REGISTER.String():         func(e *fsm.Event) { v.beforeRegisterEvent(e, v.FSM.Current()) },
			"before_" + pb.ChaincodeMessage_COMPLETED.String():        func(e *fsm.Event) { v.beforeCompletedEvent(e, v.FSM.Current()) },
			"before_" + pb.ChaincodeMessage_INIT.String():             func(e *fsm.Event) { v.beforeInitState(e, v.FSM.Current()) },
			"after_" + pb.ChaincodeMessage_GET_STATE.String():         func(e *fsm.Event) { v.afterGetState(e, v.FSM.Current()) },
			"after_" + pb.ChaincodeMessage_RANGE_QUERY_STATE.String(): func(e *fsm.Event) { v.afterRangeQueryState(e, v.FSM.Current()) },
			"after_" + pb.ChaincodeMessage_PUT_STATE.String():         func(e *fsm.Event) { v.afterPutState(e, v.FSM.Current()) },
			"after_" + pb.ChaincodeMessage_DEL_STATE.String():         func(e *fsm.Event) { v.afterDelState(e, v.FSM.Current()) },
			"after_" + pb.ChaincodeMessage_INVOKE_CHAINCODE.String():  func(e *fsm.Event) { v.afterInvokeChaincode(e, v.FSM.Current()) },
			"enter_" + establishedstate:                               func(e *fsm.Event) { v.enterEstablishedState(e, v.FSM.Current()) },
			"enter_" + initstate:                                      func(e *fsm.Event) { v.enterInitState(e, v.FSM.Current()) },
			"enter_" + readystate:                                     func(e *fsm.Event) { v.enterReadyState(e, v.FSM.Current()) },
			"enter_" + busyinitstate:                                  func(e *fsm.Event) { v.enterBusyState(e, v.FSM.Current()) },
			"enter_" + busyxactstate:                                  func(e *fsm.Event) { v.enterBusyState(e, v.FSM.Current()) },
			"enter_" + endstate:                                       func(e *fsm.Event) { v.enterEndState(e, v.FSM.Current()) },
		},
	)

	return v
}
开发者ID:tenc,项目名称:obc-peer-pre-public,代码行数:60,代码来源:handler.go

示例9: main

func main() {
	fsm := fsm.NewFSM(
		"idle",
		fsm.Events{
			{Name: "scan", Src: []string{"idle"}, Dst: "scanning"},
			{Name: "working", Src: []string{"scanning"}, Dst: "scanning"},
			{Name: "situation", Src: []string{"scanning"}, Dst: "scanning"},
			{Name: "situation", Src: []string{"idle"}, Dst: "idle"},
			{Name: "finish", Src: []string{"scanning"}, Dst: "idle"},
		},
		fsm.Callbacks{
			"scan": func(e *fsm.Event) {
				fmt.Println("after_scan: " + e.FSM.Current())
			},
			"working": func(e *fsm.Event) {
				fmt.Println("working: " + e.FSM.Current())
			},
			"situation": func(e *fsm.Event) {
				fmt.Println("situation: " + e.FSM.Current())
			},
			"finish": func(e *fsm.Event) {
				fmt.Println("finish: " + e.FSM.Current())
			},
		},
	)

	fmt.Println(fsm.Current())

	err := fsm.Event("scan")
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("1:" + fsm.Current())

	err = fsm.Event("working")
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("2:" + fsm.Current())

	err = fsm.Event("situation")
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("3:" + fsm.Current())

	err = fsm.Event("finish")
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println("4:" + fsm.Current())

}
开发者ID:ftwbzhao,项目名称:fsm-2,代码行数:57,代码来源:alternate.go

示例10: NewPeerHandler

// NewPeerHandler returns a new Peer handler
// Is instance of HandlerFactory
func NewPeerHandler(coord MessageHandlerCoordinator, stream ChatStream, initiatedStream bool, nextHandler MessageHandler) (MessageHandler, error) {

	d := &Handler{
		ChatStream:      stream,
		initiatedStream: initiatedStream,
		Coordinator:     coord,
	}
	d.doneChan = make(chan struct{})

	d.snapshotRequestHandler = newSyncStateSnapshotRequestHandler()
	d.syncStateDeltasRequestHandler = newSyncStateDeltasHandler()
	d.syncBlocksRequestHandler = newSyncBlocksRequestHandler()
	d.FSM = fsm.NewFSM(
		"created",
		fsm.Events{
			{Name: pb.Message_DISC_HELLO.String(), Src: []string{"created"}, Dst: "established"},
			{Name: pb.Message_DISC_GET_PEERS.String(), Src: []string{"established"}, Dst: "established"},
			{Name: pb.Message_DISC_PEERS.String(), Src: []string{"established"}, Dst: "established"},
			{Name: pb.Message_SYNC_BLOCK_ADDED.String(), Src: []string{"established"}, Dst: "established"},
			{Name: pb.Message_SYNC_GET_BLOCKS.String(), Src: []string{"established"}, Dst: "established"},
			{Name: pb.Message_SYNC_BLOCKS.String(), Src: []string{"established"}, Dst: "established"},
			{Name: pb.Message_SYNC_STATE_GET_SNAPSHOT.String(), Src: []string{"established"}, Dst: "established"},
			{Name: pb.Message_SYNC_STATE_SNAPSHOT.String(), Src: []string{"established"}, Dst: "established"},
			{Name: pb.Message_SYNC_STATE_GET_DELTAS.String(), Src: []string{"established"}, Dst: "established"},
			{Name: pb.Message_SYNC_STATE_DELTAS.String(), Src: []string{"established"}, Dst: "established"},
		},
		fsm.Callbacks{
			"enter_state":                                           func(e *fsm.Event) { d.enterState(e) },
			"before_" + pb.Message_DISC_HELLO.String():              func(e *fsm.Event) { d.beforeHello(e) },
			"before_" + pb.Message_DISC_GET_PEERS.String():          func(e *fsm.Event) { d.beforeGetPeers(e) },
			"before_" + pb.Message_DISC_PEERS.String():              func(e *fsm.Event) { d.beforePeers(e) },
			"before_" + pb.Message_SYNC_BLOCK_ADDED.String():        func(e *fsm.Event) { d.beforeBlockAdded(e) },
			"before_" + pb.Message_SYNC_GET_BLOCKS.String():         func(e *fsm.Event) { d.beforeSyncGetBlocks(e) },
			"before_" + pb.Message_SYNC_BLOCKS.String():             func(e *fsm.Event) { d.beforeSyncBlocks(e) },
			"before_" + pb.Message_SYNC_STATE_GET_SNAPSHOT.String(): func(e *fsm.Event) { d.beforeSyncStateGetSnapshot(e) },
			"before_" + pb.Message_SYNC_STATE_SNAPSHOT.String():     func(e *fsm.Event) { d.beforeSyncStateSnapshot(e) },
			"before_" + pb.Message_SYNC_STATE_GET_DELTAS.String():   func(e *fsm.Event) { d.beforeSyncStateGetDeltas(e) },
			"before_" + pb.Message_SYNC_STATE_DELTAS.String():       func(e *fsm.Event) { d.beforeSyncStateDeltas(e) },
		},
	)

	// If the stream was initiated from this Peer, send an Initial HELLO message
	if d.initiatedStream {
		// Send intiial Hello
		helloMessage, err := d.Coordinator.NewOpenchainDiscoveryHello()
		if err != nil {
			return nil, fmt.Errorf("Error getting new HelloMessage: %s", err)
		}
		if err := d.SendMessage(helloMessage); err != nil {
			return nil, fmt.Errorf("Error creating new Peer Handler, error returned sending %s: %s", pb.Message_DISC_HELLO, err)
		}
	}

	return d, nil
}
开发者ID:tuand27613,项目名称:fabric,代码行数:57,代码来源:handler.go

示例11: NewController

func NewController(_id string, _peers IdentityMap, _connMgr *ConnectionManager) *Controller {

	var members []string

	for _, peer := range _peers {
		members = append(members, peer.Id)
	}

	self := &Controller{
		peers:           _peers,
		connMgr:         _connMgr,
		myId:            _id,
		activePeers:     make(map[string]*Peer),
		quorumThreshold: util.ComputeQuorumThreshold(len(_peers)) - 1, // We don't include ourselves
		timer:           time.NewTimer(0),
		pulse:           time.NewTicker(1),
		electionManager: election.NewManager(_id, members),
		minTmo:          500,
		maxTmo:          1000,
	}

	<-self.timer.C // drain the initial event
	self.pulse.Stop()
	<-self.pulse.C // drain the initial event

	self.state = fsm.NewFSM(
		"convening",
		fsm.Events{
			{Name: "quorum", Src: []string{"convening"}, Dst: "initializing"},
			{Name: "quorum-lost", Src: []string{"initializing", "electing", "electing-restart", "following", "leading"}, Dst: "convening"},
			{Name: "elected-self", Src: []string{"initializing", "electing"}, Dst: "leading"},
			{Name: "elected-other", Src: []string{"initializing", "electing"}, Dst: "following"},
			{Name: "timeout", Src: []string{"initializing", "following", "electing"}, Dst: "electing"},
			{Name: "election", Src: []string{"following", "leading"}, Dst: "electing"},
			{Name: "heartbeat", Src: []string{"following"}, Dst: "following"},
		},
		fsm.Callbacks{
			"convening":          func(e *fsm.Event) { self.onConvening() },
			"enter_initializing": func(e *fsm.Event) { self.onInitializing() },
			"leave_initializing": func(e *fsm.Event) { self.timer.Stop() },
			"enter_following":    func(e *fsm.Event) { self.onEnterFollowing() },
			"leave_following":    func(e *fsm.Event) { self.onLeaveFollowing() },
			"enter_electing":     func(e *fsm.Event) { self.onElecting() },
			"leave_electing":     func(e *fsm.Event) { self.timer.Stop() },
			"enter_leading":      func(e *fsm.Event) { self.onEnterLeading() },
			"leave_leading":      func(e *fsm.Event) { self.onLeaveLeading() },
			"heartbeat":          func(e *fsm.Event) { self.onHeartBeat(e.Args[0].(string), e.Args[1].(int64)) },
			"before_timeout":     func(e *fsm.Event) { self.onTimeout() },
		},
	)

	return self
}
开发者ID:ghaskins,项目名称:go-cluster,代码行数:53,代码来源:controller.go

示例12: NewDoor

func NewDoor(to string) *Door {
	d := &Door{
		To: to,
	}

	d.FSM = fsm.NewFSM(
		"closed",
		fsm.Events{
			{Name: "open", Src: []string{"closed"}, Dst: "open"},
			{Name: "close", Src: []string{"open"}, Dst: "closed"},
		},
		fsm.Callbacks{
			"enter_state": func(e *fsm.Event) { d.enterState(e) },
		},
	)

	return d
}
开发者ID:ftwbzhao,项目名称:fsm-2,代码行数:18,代码来源:struct.go

示例13: newChaincodeHandler

// NewChaincodeHandler returns a new instance of the shim side handler.
func newChaincodeHandler(to string, peerChatStream PeerChaincodeStream, chaincode Chaincode) *Handler {
	v := &Handler{
		To:         to,
		ChatStream: peerChatStream,
		cc:         chaincode,
	}
	v.responseChannel = make(map[string]chan pb.ChaincodeMessage)
	v.isTransaction = make(map[string]bool)

	// Create the shim side FSM
	v.FSM = fsm.NewFSM(
		"created",
		fsm.Events{
			{Name: pb.ChaincodeMessage_REGISTERED.String(), Src: []string{"created"}, Dst: "established"},
			{Name: pb.ChaincodeMessage_INIT.String(), Src: []string{"established"}, Dst: "init"},
			{Name: pb.ChaincodeMessage_READY.String(), Src: []string{"established"}, Dst: "ready"},
			{Name: pb.ChaincodeMessage_ERROR.String(), Src: []string{"init"}, Dst: "established"},
			{Name: pb.ChaincodeMessage_RESPONSE.String(), Src: []string{"init"}, Dst: "init"},
			{Name: pb.ChaincodeMessage_COMPLETED.String(), Src: []string{"init"}, Dst: "ready"},
			{Name: pb.ChaincodeMessage_TRANSACTION.String(), Src: []string{"ready"}, Dst: "transaction"},
			{Name: pb.ChaincodeMessage_COMPLETED.String(), Src: []string{"transaction"}, Dst: "ready"},
			{Name: pb.ChaincodeMessage_ERROR.String(), Src: []string{"transaction"}, Dst: "ready"},
			{Name: pb.ChaincodeMessage_RESPONSE.String(), Src: []string{"transaction"}, Dst: "transaction"},
			{Name: pb.ChaincodeMessage_QUERY.String(), Src: []string{"transaction"}, Dst: "transaction"},
			{Name: pb.ChaincodeMessage_QUERY.String(), Src: []string{"ready"}, Dst: "ready"},
			{Name: pb.ChaincodeMessage_RESPONSE.String(), Src: []string{"ready"}, Dst: "ready"},
		},
		fsm.Callbacks{
			"before_" + pb.ChaincodeMessage_REGISTERED.String(): func(e *fsm.Event) { v.beforeRegistered(e) },
			//"after_" + pb.ChaincodeMessage_INIT.String(): func(e *fsm.Event) { v.beforeInit(e) },
			//"after_" + pb.ChaincodeMessage_TRANSACTION.String(): func(e *fsm.Event) { v.beforeTransaction(e) },
			"after_" + pb.ChaincodeMessage_RESPONSE.String(): func(e *fsm.Event) { v.afterResponse(e) },
			"after_" + pb.ChaincodeMessage_ERROR.String():    func(e *fsm.Event) { v.afterError(e) },
			"enter_init":                                     func(e *fsm.Event) { v.enterInitState(e) },
			"enter_transaction":                              func(e *fsm.Event) { v.enterTransactionState(e) },
			//"enter_ready":                                     func(e *fsm.Event) { v.enterReadyState(e) },
			"after_" + pb.ChaincodeMessage_COMPLETED.String(): func(e *fsm.Event) { v.afterCompleted(e) },
			"before_" + pb.ChaincodeMessage_QUERY.String():    func(e *fsm.Event) { v.beforeQuery(e) }, //only checks for QUERY
		},
	)
	return v
}
开发者ID:masterDev1985,项目名称:obc-peer,代码行数:43,代码来源:handler.go

示例14: NewConnection

func NewConnection(conn *net.UDPConn, raddr *net.UDPAddr, local, remote *CryptoState) *Connection {

	if remote == nil {
		remote = NewCryptoState(new(KeyPair), nil, false)
	}

	if local == nil {
		panic("local is nil, fixme")
		return nil
	}

	c := &Connection{
		conn:          conn,
		raddr:         raddr,
		isEstablished: false,
		local:         local,
		remote:        remote,
		rand:          rand.Reader,
	}

	c.state = fsm.NewFSM("Reset", serverEvents, c.serverEventCallbacks())

	return c
}
开发者ID:lgierth,项目名称:cryptoauth,代码行数:24,代码来源:connection.go

示例15: NewJob

// NewJob create a new Job struct, generates a uuid for it and returns the job.
func NewJob(name string) *Job {
	j := new(Job)
	j.ID = uuid.NewRandom()
	j.Name = name
	j.State = UNKNOWN
	j.Completion = 0.0
	j.Children = []*Task{}
	j.created = time.Now()
	j.priority = 0
	j.FSM = fsm.NewFSM(
		j.State.String(),
		fsm.Events{
			{Name: "ready", Src: StateList(UNKNOWN, STOPPED), Dst: READY.S()},
			{Name: "start", Src: StateList(READY), Dst: WORKING.S()},
			{Name: "finish", Src: StateList(WORKING), Dst: DONE.S()},
			{Name: "restart", Src: StateList(DONE), Dst: WORKING.S()},
			{Name: "stop", Src: StateList(WORKING), Dst: STOPPED.S()},
		},
		fsm.Callbacks{
			"after_event": func(e *fsm.Event) { j.afterEvent(e) },
		},
	)
	return j
}
开发者ID:smaragden,项目名称:kamaji,代码行数:25,代码来源:job.go


注:本文中的github.com/looplab/fsm.NewFSM函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。