Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MutexServer<Header, Provider>

The Mutex Server.

The MutexServer is a class who can open an mutex-server. Clients connecting to the mutex-server would communicate with this server through MutexAcceptor objects using websocket and RFC protocol.

To open the mutex-server, call the open method with your custom callback function which would be called whenever a MutexAcceptor has been newly created by a client's connection.

Also, when declaring this MutexServer type, you've to define two template arguments, Header and Provider*. The *Header type repersents an initial data gotten from the remote client after the connection. I hope you and client not to omit it and utilize it as an activation tool to enhance security.

The second template argument Provider represents the additional features provided for the remote client. If you don't have any plan to provide additional feature to the remote client, just declare it as null.

author

Jeongho Nam - https://github.com/samchon

Type parameters

  • Header

    Type of the header containing initial data.

  • Provider: object | null

    Type of additional features provided for the remote client.

Hierarchy

  • MutexServer

Index

Constructors

Properties

Accessors

Methods

Constructors

constructor

Properties

Static State

State: State

Current state of the MutexServer

Accessors

state

Methods

close

  • close(): Promise<void>
  • Close the mutex-server.

    Close the mutex-server and disconnect all the remote connections between its clients. Therefore, clients who are using the MutexConnector class, they can't use the remote-thread-components more.

    Also, closing the server means that all of the RFCs between the server and had connected clients would be destroied. Therefore, all of the RFCs that are not returned (completed) yet would ge RuntimeError exception.

    Returns Promise<void>

open

  • open(port: number, handler: (acceptor: MutexAcceptor<Header, Provider>) => Promise<void>): Promise<void>
  • Open a mutex-server.

    Open a mutex-server through web-socket protocol, with its port number and predicator function determining whether to accept the client's connection or not. After the mutex-server has been opened, clients can connect to that mutex-server by using the MutexConnector class.

    When implementing the predicator function, returns true if you want to accept a new client's connection. Otherwise you dont't want to accept the client and reject its connection, returns false instead.

    Note that, this mutex-server handles the global critical sections on the entire network level. If you define the predicator function to accept every client's connection, some bad guy can spoil your own mutex-server by monopolying those critical sections. Therefore, don't implement the predicator function to returns only true, but filter clients' connections by considering their MutexAcceptor.header data.

    Parameters

    • port: number

      Port number to listen.

    • handler: (acceptor: MutexAcceptor<Header, Provider>) => Promise<void>

      A handler function determining whether to accept the client's connection or not.

        • Parameters

          Returns Promise<void>

    Returns Promise<void>

Generated using TypeDoc