本文整理汇总了Golang中github.com/looplab/fsm.Event类的典型用法代码示例。如果您正苦于以下问题:Golang Event类的具体用法?Golang Event怎么用?Golang Event使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Event类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: afterCompleted
// afterCompleted will need to handle COMPLETED event by sending message to the peer
func (handler *Handler) afterCompleted(e *fsm.Event) {
msg, ok := e.Args[0].(*pb.ChaincodeMessage)
if !ok {
e.Cancel(fmt.Errorf("Received unexpected message type"))
return
}
chaincodeLogger.Debugf("[%s]sending COMPLETED to validator for tid", shortuuid(msg.Uuid))
if err := handler.serialSend(msg); err != nil {
e.Cancel(fmt.Errorf("send COMPLETED failed %s", err))
}
}
开发者ID:RJAugust,项目名称:fabric,代码行数:12,代码来源:handler.go
示例17: enterReadyState
func (handler *Handler) enterReadyState(e *fsm.Event, state string) {
// Now notify
msg, ok := e.Args[0].(*pb.ChaincodeMessage)
handler.deleteIsTransaction(msg.Uuid)
if !ok {
e.Cancel(fmt.Errorf("Received unexpected message type"))
return
}
handler.notify(msg)
chaincodeLogger.Debug("Entered state %s", state)
}
开发者ID:masterDev1985,项目名称:obc-peer,代码行数:12,代码来源:handler.go
示例18: afterRangeQueryState
// afterRangeQueryState handles a RANGE_QUERY_STATE request from the chaincode.
func (handler *Handler) afterRangeQueryState(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("Received %s, invoking get state from ledger", pb.ChaincodeMessage_RANGE_QUERY_STATE)
// Query ledger for state
handler.handleRangeQueryState(msg)
chaincodeLogger.Debug("Exiting GET_STATE")
}
开发者ID:tenc,项目名称:obc-peer-pre-public,代码行数:13,代码来源:handler.go
示例19: enterTransactionState
// enterTransactionState will execute chaincode's Run if coming from a TRANSACTION event.
func (handler *Handler) enterTransactionState(e *fsm.Event) {
msg, ok := e.Args[0].(*pb.ChaincodeMessage)
if !ok {
e.Cancel(fmt.Errorf("Received unexpected message type"))
return
}
chaincodeLogger.Debugf("[%s]Received %s, invoking transaction on chaincode(Src:%s, Dst:%s)", shortuuid(msg.Uuid), msg.Type.String(), e.Src, e.Dst)
if msg.Type.String() == pb.ChaincodeMessage_TRANSACTION.String() {
// Call the chaincode's Run function to invoke transaction
handler.handleTransaction(msg)
}
}
开发者ID:RJAugust,项目名称:fabric,代码行数:13,代码来源:handler.go
示例20: afterCompleted
// afterCompleted will need to handle COMPLETED event by sending message to the peer
func (handler *Handler) afterCompleted(e *fsm.Event) {
chaincodeLogger.Debug("(afterCompleted)Completed in state %s", handler.FSM.Current())
msg, ok := e.Args[0].(*pb.ChaincodeMessage)
if !ok {
e.Cancel(fmt.Errorf("Received unexpected message type"))
return
}
//no need, now I AM in completed state if msg.Type.String() == pb.ChaincodeMessage_COMPLETED.String() {
// now that we are comfortably in READY, send message to peer side
chaincodeLogger.Debug("sending COMPLETED to validator for tid %s", msg.Uuid)
handler.ChatStream.Send(msg)
//}
}
开发者ID:masterDev1985,项目名称:obc-peer,代码行数:14,代码来源:handler.go
注:本文中的github.com/looplab/fsm.Event类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论