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


Golang fsm.Event類代碼示例

本文整理匯總了Golang中github.com/looplab/fsm.Event的典型用法代碼示例。如果您正苦於以下問題:Golang Event類的具體用法?Golang Event怎麽用?Golang Event使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: CanSendKeyPacket

func (c *Connection) CanSendKeyPacket(e *fsm.Event) {
	log.Printf("CanSendKeyPacket")

	if c.isEstablished == true {
		e.Cancel(errKeySendDuringEstablished)
	}
}
開發者ID:lgierth,項目名稱:cryptoauth,代碼行數:7,代碼來源:key.go

示例2: beforeSyncBlocks

func (d *Handler) beforeSyncBlocks(e *fsm.Event) {
	peerLogger.Debug("Received message: %s", e.Event)
	msg, ok := e.Args[0].(*pb.Message)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	// Forward the received SyncBlocks to the channel
	syncBlocks := &pb.SyncBlocks{}
	err := proto.Unmarshal(msg.Payload, syncBlocks)
	if err != nil {
		e.Cancel(fmt.Errorf("Error unmarshalling SyncBlocks in beforeSyncBlocks: %s", err))
		return
	}

	peerLogger.Debug("Sending block onto channel for start = %d and end = %d", syncBlocks.Range.Start, syncBlocks.Range.End)

	// Send the message onto the channel, allow for the fact that channel may be closed on send attempt.
	defer func() {
		if x := recover(); x != nil {
			peerLogger.Error(fmt.Sprintf("Error sending syncBlocks to channel: %v", x))
		}
	}()
	// Use non-blocking send, will WARN if missed message.
	select {
	case d.syncBlocks <- syncBlocks:
	default:
		peerLogger.Warning("Did NOT send SyncBlocks message to channel for range: %d - %d", syncBlocks.Range.Start, syncBlocks.Range.End)
	}
}
開發者ID:RicHernandez2,項目名稱:fabric,代碼行數:30,代碼來源:handler.go

示例3: beforeSyncStateDeltas

func (d *Handler) beforeSyncStateDeltas(e *fsm.Event) {
	peerLogger.Debug("Received message: %s", e.Event)
	msg, ok := e.Args[0].(*pb.Message)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	// Forward the received SyncStateDeltas to the channel
	syncStateDeltas := &pb.SyncStateDeltas{}
	err := proto.Unmarshal(msg.Payload, syncStateDeltas)
	if err != nil {
		e.Cancel(fmt.Errorf("Error unmarshalling SyncStateDeltas in beforeSyncStateDeltas: %s", err))
		return
	}
	peerLogger.Debug("Sending state delta onto channel for start = %d and end = %d", syncStateDeltas.Range.Start, syncStateDeltas.Range.End)

	// Send the message onto the channel, allow for the fact that channel may be closed on send attempt.
	defer func() {
		if x := recover(); x != nil {
			peerLogger.Error(fmt.Sprintf("Error sending syncStateDeltas to channel: %v", x))
		}
	}()

	// Use non-blocking send, will WARN and close channel if missed message.
	d.syncStateDeltasRequestHandler.Lock()
	defer d.syncStateDeltasRequestHandler.Unlock()
	select {
	case d.syncStateDeltasRequestHandler.channel <- syncStateDeltas:
	default:
		// Was not able to write to the channel, in which case the SyncStateDeltasRequest stream is incomplete, and must be discarded, closing the channel
		peerLogger.Warning("Did NOT send SyncStateDeltas message to channel for block range %d-%d, closing channel as the message has been discarded", syncStateDeltas.Range.Start, syncStateDeltas.Range.End)
		d.syncStateDeltasRequestHandler.reset()
	}

}
開發者ID:RicHernandez2,項目名稱:fabric,代碼行數:35,代碼來源:handler.go

示例4: beforePeers

func (d *Handler) beforePeers(e *fsm.Event) {
	peerLogger.Debugf("Received %s, grabbing peers message", e.Event)
	// Parse out the PeerEndpoint information
	if _, ok := e.Args[0].(*pb.Message); !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	msg := e.Args[0].(*pb.Message)

	peersMessage := &pb.PeersMessage{}
	err := proto.Unmarshal(msg.Payload, peersMessage)
	if err != nil {
		e.Cancel(fmt.Errorf("Error unmarshalling PeersMessage: %s", err))
		return
	}

	peerLogger.Debugf("Received PeersMessage with Peers: %s", peersMessage)
	d.Coordinator.PeersDiscovered(peersMessage)

	// // Can be used to demonstrate Broadcast function
	// if viper.GetString("peer.id") == "jdoe" {
	// 	d.Coordinator.Broadcast(&pb.Message{Type: pb.Message_UNDEFINED})
	// }

}
開發者ID:tuand27613,項目名稱:fabric,代碼行數:25,代碼來源:handler.go

示例5: beforeRegistered

// beforeRegistered is called to handle the REGISTERED message.
func (handler *Handler) beforeRegistered(e *fsm.Event) {
	if _, ok := e.Args[0].(*pb.ChaincodeMessage); !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	chaincodeLogger.Debugf("Received %s, ready for invocations", pb.ChaincodeMessage_REGISTERED)
}
開發者ID:RJAugust,項目名稱:fabric,代碼行數:8,代碼來源:handler.go

示例6: afterPutState

// afterPutState handles a PUT_STATE request from the chaincode.
func (handler *Handler) afterPutState(e *fsm.Event, state string) {
	_, ok := e.Args[0].(*pb.ChaincodeMessage)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	chaincodeLogger.Debug("Received %s in state %s, invoking put state to ledger", pb.ChaincodeMessage_PUT_STATE, state)

	// Put state into ledger handled within enterBusyState
}
開發者ID:tenc,項目名稱:obc-peer-pre-public,代碼行數:11,代碼來源:handler.go

示例7: afterDelState

// afterDelState handles a DEL_STATE request from the chaincode.
func (handler *Handler) afterDelState(e *fsm.Event, state string) {
	_, ok := e.Args[0].(*pb.ChaincodeMessage)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	chaincodeLogger.Debug("Received %s, invoking delete state from ledger", pb.ChaincodeMessage_DEL_STATE)

	// Delete state from ledger handled within enterBusyState
}
開發者ID:tenc,項目名稱:obc-peer-pre-public,代碼行數:11,代碼來源:handler.go

示例8: afterResponse

// afterResponse is called to deliver a response or error to the chaincode stub.
func (handler *Handler) afterResponse(e *fsm.Event) {
	msg, ok := e.Args[0].(*pb.ChaincodeMessage)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}

	handler.responseChannel[msg.Uuid] <- *msg
	chaincodeLogger.Debug("Received %s, communicated on responseChannel(state:%s)", msg.Type, handler.FSM.Current())
}
開發者ID:masterDev1985,項目名稱:obc-peer,代碼行數:11,代碼來源:handler.go

示例9: afterInvokeChaincode

// afterInvokeChaincode handles an INVOKE_CHAINCODE request from the chaincode.
func (handler *Handler) afterInvokeChaincode(e *fsm.Event, state string) {
	_, ok := e.Args[0].(*pb.ChaincodeMessage)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	chaincodeLogger.Debug("Received %s in state %s, invoking another chaincode", pb.ChaincodeMessage_INVOKE_CHAINCODE, state)

	// Invoke another chaincode handled within enterBusyState
}
開發者ID:tenc,項目名稱:obc-peer-pre-public,代碼行數:11,代碼來源:handler.go

示例10: beforeCompletedEvent

// beforeCompletedEvent is invoked when chaincode has completed execution of init, invoke or query.
func (handler *Handler) beforeCompletedEvent(e *fsm.Event, state string) {
	msg, ok := e.Args[0].(*pb.ChaincodeMessage)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	// Notify on channel once into READY state
	chaincodeLogger.Debug("[%s]beforeCompleted - not in ready state will notify when in readystate", shortuuid(msg.Uuid))
	return
}
開發者ID:tenc,項目名稱:obc-peer-pre-public,代碼行數:11,代碼來源:handler.go

示例11: beforeBlockAdded

func (d *Handler) beforeBlockAdded(e *fsm.Event) {
	peerLogger.Debugf("Received message: %s", e.Event)
	msg, ok := e.Args[0].(*pb.Message)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	// Add the block and any delta state to the ledger
	_ = msg
}
開發者ID:tuand27613,項目名稱:fabric,代碼行數:10,代碼來源:handler.go

示例12: enterReadyState

func (handler *Handler) enterReadyState(e *fsm.Event, state string) {
	// Now notify
	msg, ok := e.Args[0].(*pb.ChaincodeMessage)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	chaincodeLogger.Debugf("[%s]Entered state %s", shorttxid(msg.Txid), state)
	handler.notify(msg)
}
開發者ID:hyperledger,項目名稱:fabric,代碼行數:10,代碼來源:handler.go

示例13: beforeQuery

// beforeQuery is invoked when a query message is received from the validator
func (handler *Handler) beforeQuery(e *fsm.Event) {
	if e.Args != nil {
		msg, ok := e.Args[0].(*pb.ChaincodeMessage)
		if !ok {
			e.Cancel(fmt.Errorf("Received unexpected message type"))
			return
		}
		handler.handleQuery(msg)
	}
}
開發者ID:RJAugust,項目名稱:fabric,代碼行數:11,代碼來源:handler.go

示例14: beforeQuery

// beforeQuery is invoked when a query message is received from the validator
func (handler *Handler) beforeQuery(e *fsm.Event) {
	chaincodeLogger.Debug("(beforeQuery)in state %s", handler.FSM.Current())
	if e.Args != nil {
		msg, ok := e.Args[0].(*pb.ChaincodeMessage)
		if !ok {
			e.Cancel(fmt.Errorf("Received unexpected message type"))
			return
		}
		handler.handleQuery(msg)
	}
}
開發者ID:masterDev1985,項目名稱:obc-peer,代碼行數:12,代碼來源:handler.go

示例15: afterGetState

// afterGetState handles a GET_STATE request from the chaincode.
func (handler *Handler) afterGetState(e *fsm.Event, state string) {
	msg, ok := e.Args[0].(*pb.ChaincodeMessage)
	if !ok {
		e.Cancel(fmt.Errorf("Received unexpected message type"))
		return
	}
	chaincodeLogger.Debug("[%s]Received %s, invoking get state from ledger", shortuuid(msg.Uuid), pb.ChaincodeMessage_GET_STATE)

	// Query ledger for state
	handler.handleGetState(msg)
}
開發者ID:tenc,項目名稱:obc-peer-pre-public,代碼行數:12,代碼來源:handler.go


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