github.com/pingcap/ticdc@v0.0.0-20220526033649-485a10ef2652/pkg/pipeline/node.go (about) 1 // Copyright 2020 PingCAP, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 package pipeline 15 16 // Node represents a handle unit for the message stream in the pipeline 17 // The following functions in this interface will be called in one goroutine. 18 // It's NO NEED to consider concurrency issues 19 type Node interface { 20 21 // Init initializes the node 22 // when the pipeline is started, this function will be called in order 23 // you can call `ctx.SendToNextNode(msg)` to send the message to the next node 24 // but it will return nil if you try to call the `ctx.Message()` 25 Init(ctx NodeContext) error 26 27 // Receive receives the message from the previous node 28 // when the node receives a message, this function will be called 29 // you can call `ctx.Message()` to receive the message 30 // you can call `ctx.SendToNextNode(msg)` to send the message to the next node 31 Receive(ctx NodeContext) error 32 33 // Destory frees the resources in this node 34 // you can call `ctx.SendToNextNode(msg)` to send the message to the next node 35 // but it will return nil if you try to call the `ctx.Message()` 36 Destroy(ctx NodeContext) error 37 }