-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d9e5365
commit 6900982
Showing
11 changed files
with
345 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
### **Try Node** | ||
|
||
The **Try Node** handles errors that may occur during packet processing. When a packet is processed and an error occurs, | ||
it directs the error to the error output port for appropriate handling. | ||
|
||
## **Specification** | ||
|
||
- **None**: The Try Node operates by default without any additional configuration. | ||
|
||
## **Ports** | ||
|
||
- **in**: Receives and processes incoming packets. | ||
- **out**: Outputs the original input packet if processed without error. | ||
- **error**: Outputs any errors that occur during packet processing. | ||
|
||
## **Example** | ||
|
||
```yaml | ||
- kind: try | ||
ports: | ||
out: | ||
- name: next | ||
port: in | ||
error: | ||
- name: catch | ||
port: in | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# **Try Node** | ||
|
||
**Try Node**는 패킷 처리 중 발생할 수 있는 오류를 처리하는 노드입니다. 이 노드는 패킷을 처리하면서 오류가 발생하면, 이를 오류 출력 포트로 전달하여 적절한 처리를 할 수 있도록 합니다. | ||
|
||
## **명세** | ||
|
||
- **없음**: Try 노드는 별도의 추가 설정 없이 기본적으로 동작합니다. | ||
|
||
## **포트** | ||
|
||
- **in**: 패킷을 수신하여 처리합니다. | ||
- **out**: 원래의 입력 패킷을 그대로 출력합니다. | ||
- **error**: 패킷 처리 중 오류가 발생하면 해당 오류를 이 포트를 통해 출력합니다. | ||
|
||
## **예시** | ||
|
||
```yaml | ||
- kind: try | ||
ports: | ||
out: | ||
- name: next | ||
port: in | ||
error: | ||
- name: catch | ||
port: in | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
package control | ||
|
||
import ( | ||
"github.com/siyul-park/uniflow/pkg/node" | ||
"github.com/siyul-park/uniflow/pkg/packet" | ||
"github.com/siyul-park/uniflow/pkg/port" | ||
"github.com/siyul-park/uniflow/pkg/process" | ||
"github.com/siyul-park/uniflow/pkg/scheme" | ||
"github.com/siyul-park/uniflow/pkg/spec" | ||
"github.com/siyul-park/uniflow/pkg/types" | ||
) | ||
|
||
// TryNodeSpec defines the specification for creating a TryNode. | ||
type TryNodeSpec struct { | ||
spec.Meta `map:",inline"` | ||
} | ||
|
||
// TryNode represents a node that processes packets and handles errors. | ||
type TryNode struct { | ||
tracer *packet.Tracer | ||
inPort *port.InPort | ||
outPort *port.OutPort | ||
errPort *port.OutPort | ||
} | ||
|
||
const KindTry = "try" | ||
|
||
var _ node.Node = (*TryNode)(nil) | ||
|
||
// NewTryNodeCodec creates a codec for decoding TryNodeSpec. | ||
func NewTryNodeCodec() scheme.Codec { | ||
return scheme.CodecWithType(func(_ *TryNodeSpec) (node.Node, error) { | ||
return NewTryNode(), nil | ||
}) | ||
} | ||
|
||
// NewTryNode creates a new TryNode. | ||
func NewTryNode() *TryNode { | ||
n := &TryNode{ | ||
tracer: packet.NewTracer(), | ||
inPort: port.NewIn(), | ||
outPort: port.NewOut(), | ||
errPort: port.NewOut(), | ||
} | ||
|
||
n.inPort.AddListener(port.ListenFunc(n.forward)) | ||
n.outPort.AddListener(port.ListenFunc(n.backward)) | ||
n.errPort.AddListener(port.ListenFunc(n.catch)) | ||
|
||
return n | ||
} | ||
|
||
// In returns the input port for the given name. | ||
func (n *TryNode) In(name string) *port.InPort { | ||
switch name { | ||
case node.PortIn: | ||
return n.inPort | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
// Out returns the output port for the given name. | ||
func (n *TryNode) Out(name string) *port.OutPort { | ||
switch name { | ||
case node.PortOut: | ||
return n.outPort | ||
case node.PortError: | ||
return n.errPort | ||
default: | ||
return nil | ||
} | ||
} | ||
|
||
// Close closes the TryNode and its ports. | ||
func (n *TryNode) Close() error { | ||
n.inPort.Close() | ||
n.outPort.Close() | ||
n.errPort.Close() | ||
n.tracer.Close() | ||
return nil | ||
} | ||
|
||
func (n *TryNode) forward(proc *process.Process) { | ||
inReader := n.inPort.Open(proc) | ||
var outWriter *packet.Writer | ||
var errWriter *packet.Writer | ||
|
||
for inPck := range inReader.Read() { | ||
n.tracer.Read(inReader, inPck) | ||
|
||
if outWriter == nil { | ||
outWriter = n.outPort.Open(proc) | ||
} | ||
|
||
n.tracer.AddHook(inPck, packet.HookFunc(func(backPck *packet.Packet) { | ||
n.tracer.Transform(inPck, backPck) | ||
if _, ok := backPck.Payload().(types.Error); ok { | ||
if errWriter == nil { | ||
errWriter = n.errPort.Open(proc) | ||
} | ||
n.tracer.Write(errWriter, backPck) | ||
} else { | ||
n.tracer.Reduce(backPck) | ||
} | ||
})) | ||
|
||
n.tracer.Write(outWriter, inPck) | ||
} | ||
} | ||
|
||
func (n *TryNode) backward(proc *process.Process) { | ||
outWriter := n.outPort.Open(proc) | ||
|
||
for backPck := range outWriter.Receive() { | ||
n.tracer.Receive(outWriter, backPck) | ||
} | ||
} | ||
|
||
func (n *TryNode) catch(proc *process.Process) { | ||
errWriter := n.errPort.Open(proc) | ||
|
||
for backPck := range errWriter.Receive() { | ||
n.tracer.Receive(errWriter, backPck) | ||
} | ||
} |
Oops, something went wrong.