github.com/aporeto-inc/trireme-lib@v10.358.0+incompatible/monitor/external/interfaces.go (about)

     1  package external
     2  
     3  import (
     4  	"context"
     5  
     6  	"go.aporeto.io/enforcerd/trireme-lib/common"
     7  )
     8  
     9  // ReceiveEvents can be implemented by monitors which receive their monitoring events
    10  // for processing from different parts of the stack.
    11  type ReceiveEvents interface {
    12  	// Event will receive event `data` for processing a common.Event in the monitor.
    13  	// The sent data is implementation specific - therefore it has no type in the interface.
    14  	// If the sent data is of an unexpected type, its implementor must return an error
    15  	// indicating so.
    16  	Event(ctx context.Context, ev common.Event, data interface{}) error
    17  
    18  	// SenderReady will be called by the sender to notify the receiver that the sender
    19  	// is now ready to send events.
    20  	SenderReady()
    21  }
    22  
    23  // ReceiverRegistration allows the trireme monitors to register themselves to receive events
    24  // from an implementor. This interface is expected to be implemented outside of the monitor
    25  // for the component which generates the event data for the registering monitor.
    26  // The implementor must have a unique name which gets returned from `SenderName()`.
    27  // The implementor is responsible for calling `Event()` on all monitors once they have
    28  // registered through `Register()`.
    29  type ReceiverRegistration interface {
    30  	// SenderName must return a globally unique name of the implementor.
    31  	SenderName() string
    32  
    33  	// Register will register the given `monitor` for receiving events under `name`.
    34  	// The registering monitor must implement `ReceiveEvents` before it can register.
    35  	// Multiple calls to this function for the same `name` must update the internal
    36  	// state of the implementor to now send events to the newly regitered monitor of this
    37  	// name. Only one registration of a monitor of the same name is allowed.
    38  	Register(name string, monitor ReceiveEvents) error
    39  }