github.com/aergoio/aergo@v1.3.1/pkg/component/types.go (about)

     1  /**
     2   *  @file
     3   *  @copyright defined in aergo/LICENSE.txt
     4   */
     5  
     6  package component
     7  
     8  import (
     9  	"time"
    10  
    11  	"github.com/aergoio/aergo-actor/actor"
    12  )
    13  
    14  // IComponent provides a common interface for easy management
    15  // and providing a communication channel between components
    16  // BaseComponent struct provides general implementation of this
    17  type IComponent interface {
    18  	GetName() string
    19  	Start()
    20  	Stop()
    21  	Status() Status
    22  	SetHub(hub *ComponentHub)
    23  	Hub() *ComponentHub
    24  	MsgQueueLen() int32
    25  
    26  	Tell(message interface{})
    27  	Request(message interface{}, sender *actor.PID)
    28  	RequestFuture(message interface{}, timeout time.Duration, tip string) *actor.Future
    29  
    30  	Receive(actor.Context)
    31  }
    32  
    33  // IActor describes functions that each components have to implement
    34  // A BeforeStart func is called before a IComponent.Start func
    35  // So developers can write component specific initalization codes in here
    36  // A BeforeStop func is called before a IComponent.Stop func
    37  // In a Receive func, component's actions is described
    38  // For each type of message, developer can define a behavior
    39  // If there is component specific statics or debug info are exists,
    40  // than developers can get those by defining it in Statistics func
    41  type IActor interface {
    42  	BeforeStart()
    43  	AfterStart()
    44  	BeforeStop()
    45  
    46  	Receive(actor.Context)
    47  
    48  	Statistics() *map[string]interface{}
    49  }
    50  
    51  type IComponentRequester interface {
    52  	TellTo(targetCompName string, message interface{})
    53  	RequestTo(targetCompName string, message interface{})
    54  	RequestToFutureResult(targetCompName string, message interface{}, timeout time.Duration, tip string) (interface{}, error)
    55  }