Listener: Listener

Isolated

The server listener of which one or more services can be registered so that the Ballerina program can offer a service through this listener.

Constructor

Gets called when the endpoint is being initialized during the module init time.

1listener grpc:Listener listenerEp = new (9092);
init (int port, *ListenerConfiguration config)
  • port int
  • The listener port

LifeCycle Methods

attach

Gets called every time a service attaches itself to this endpoint - also happens at module init time.

Methods

'start

Starts the registered service.

gracefulStop

Stops the service listener gracefully.

immediateStop

Stops the registered service.

detach

Detaches an HTTP or WebSocket service from the listener.

attach

function attach(Service grpcService, string[ ] | string? name) returns error?
Isolated Function

Gets called every time a service attaches itself to this endpoint - also happens at module init time.

1error? result = listenerEp.attach(helloService);

Parameters

  • grpcService Service
  • The type of the service to be registered

Return Type

(error?)

An error if an error occurs while attaching the service or else ()

'start

function 'start() returns error?
Isolated Function

Starts the registered service.

1error? result = listenerEp.'start();

Return Type

(error?)

An error if an error occurs while starting the server or else ()

gracefulStop

function gracefulStop() returns error?
Isolated Function

Stops the service listener gracefully. Already-accepted requests will be served before the connection closure.

1error? result = listenerEp.gracefulStop();

Return Type

(error?)

An error if an error occurred during the listener stopping process or else ()

immediateStop

function immediateStop() returns error?
Isolated Function

Stops the registered service.

1error? result = listenerEp.immediateStop();

Return Type

(error?)

An error if an error occurs while stopping the server or else ()

detach

function detach(Service grpcService) returns error?
Isolated Function

Detaches an HTTP or WebSocket service from the listener. Note that detaching a WebSocket service would not affect the functionality of the existing connections.

1error? result = listenerEp.detach(helloService);

Parameters

  • grpcService Service
  • The service to be detached

Return Type

(error?)

An error if an error occurred during the detaching of the service or else ()