This is the class that should be extended to implement a new specific Port.

This class implements some util logic to facilitate the creation of new Ports, for this reason is exposed as abstract class, instead of an interface. The basic operations that already implemented in the class are:

  • Health.Checks management: using the Port.addCheck method is possible to include new observed values that will be used in the observability layers.
  • Create a Port.uuid unique identifier for the port instance, this uuid is used in error traceability.
  • Establish the context for the logger to simplify the identification of the port in the logs, this is, it's not necessary to indicate the uuid and context in each logging function call.
  • Store the configuration PortConfig previously validated by the Manager.

What the user of this class should develop in the specific port:

  • The Port.start method, which is responsible initialize or stablish the connection to the resources.
  • The Port.stop method, which is responsible stop services or disconnect from the resources.
  • The Port.close method, which is responsible to destroy the services, resources or perform a simple disconnection.
  • The Port.state property, a boolean value that indicates if the port is connected healthy (true) or not (false).
  • The Port.client property, that return the PortClient instance that is used to interact with the resources.

class diagram

In the other hand, this class extends the EventEmitter class, so it's possible to emit events to notify the status of the port:

  • error: should be emitted to notify errors in the resource management or access, this will not change the provider state, but the error will be registered in the observability layers.
  • closed: should be emitted if the access to the resources is not longer possible. This event should not be emitted if Port.stop or Port.close methods are used.
  • unhealthy: should be emitted when the port has limited access to the resources.
  • healthy: should be emitted when the port has recovered the access to the resources.

class diagram

Check some examples of implementation in:

Hierarchy (View Summary)

Constructors

Accessors

Methods

Constructors

Accessors

  • get client(): Redis
  • Return the underlying port instance

    Returns Redis

  • get state(): boolean
  • Return the port state as a boolean value, true if the port is available, false in otherwise

    Returns boolean

Methods

  • Close the port, alias to stop

    Returns Promise<void>

  • Start the port, making it available

    Returns Promise<void>

  • Stop the port, making it unavailable

    Returns Promise<void>