github.com/ergo-services/ergo@v1.999.224/apps/erlang/net_kernel.go (about)

     1  package erlang
     2  
     3  // https://github.com/erlang/otp/blob/master/lib/kernel/src/net_kernel.erl
     4  
     5  import (
     6  	"context"
     7  
     8  	"github.com/ergo-services/ergo/etf"
     9  	"github.com/ergo-services/ergo/gen"
    10  	"github.com/ergo-services/ergo/lib"
    11  )
    12  
    13  func CreateApp() gen.ApplicationBehavior {
    14  	return &kernelApp{}
    15  }
    16  
    17  // KernelApp
    18  type kernelApp struct {
    19  	gen.Application
    20  }
    21  
    22  // Load
    23  func (nka *kernelApp) Load(args ...etf.Term) (gen.ApplicationSpec, error) {
    24  	return gen.ApplicationSpec{
    25  		Name:        "erlang",
    26  		Description: "Erlang support app",
    27  		Version:     "v.1.0",
    28  		Children: []gen.ApplicationChildSpec{
    29  			{
    30  				Child: &netKernelSup{},
    31  				Name:  "net_kernel_sup",
    32  			},
    33  		},
    34  	}, nil
    35  }
    36  
    37  // Start
    38  func (nka *kernelApp) Start(p gen.Process, args ...etf.Term) {}
    39  
    40  type netKernelSup struct {
    41  	gen.Supervisor
    42  }
    43  
    44  // Init
    45  func (nks *netKernelSup) Init(args ...etf.Term) (gen.SupervisorSpec, error) {
    46  	return gen.SupervisorSpec{
    47  		Children: []gen.SupervisorChildSpec{
    48  			{
    49  				Name:  "net_kernel",
    50  				Child: &netKernel{},
    51  			},
    52  			{
    53  				Name:  "global_name_server",
    54  				Child: &globalNameServer{},
    55  			},
    56  			{
    57  				Name:  "erlang",
    58  				Child: &erlang{},
    59  			},
    60  		},
    61  		Strategy: gen.SupervisorStrategy{
    62  			Type:      gen.SupervisorStrategyOneForOne,
    63  			Intensity: 10,
    64  			Period:    5,
    65  			Restart:   gen.SupervisorStrategyRestartPermanent,
    66  		},
    67  	}, nil
    68  }
    69  
    70  type netKernel struct {
    71  	gen.Server
    72  	routinesCtx map[etf.Pid]context.CancelFunc
    73  }
    74  
    75  // Init
    76  func (nk *netKernel) Init(process *gen.ServerProcess, args ...etf.Term) error {
    77  	lib.Log("NET_KERNEL: Init: %#v", args)
    78  	nk.routinesCtx = make(map[etf.Pid]context.CancelFunc)
    79  	return nil
    80  }
    81  
    82  // HandleCall
    83  func (nk *netKernel) HandleCall(process *gen.ServerProcess, from gen.ServerFrom, message etf.Term) (reply etf.Term, status gen.ServerStatus) {
    84  	lib.Log("NET_KERNEL: HandleCall: %#v, From: %#v", message, from)
    85  	return
    86  }
    87  
    88  // HandleInfo
    89  func (nk *netKernel) HandleInfo(process *gen.ServerProcess, message etf.Term) gen.ServerStatus {
    90  	lib.Log("NET_KERNEL: HandleInfo: %#v", message)
    91  	return gen.ServerStatusOK
    92  }