Options
All
  • Public
  • Public/Protected
  • All
Menu

Class MutexConnector<Header, Provider>

Mutex server connector for client.

The MutexConnector is a communicator class who can connect to a remote mutex-server and interact with it through websocket and RFC protocol.

You can connect to the websocket mutex-server using connect method. After the connection, get network level remote critical section components using one of below methods. After utilizing those components, please do not forget to realising the component by calling {@link IRemoteComponent.destructor} or closing connection with the mutex-server by calling the close method to prevent waste of resources of the mutex-server.

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

The second template argument Provider represents the custom features provided for the remote mutex-server. If you don't have any plan to provide any feature to the mutex-server, 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 server. If no plan to provide anything, declare null.

Hierarchy

  • MutexConnector

Index

Constructors

constructor

  • new MutexConnector(header: Header, provider: Provider): MutexConnector
  • Initializer Constructor.

    Parameters

    • header: Header

      Initial data sending to the remote server after connection. Hope to use it as an activation tool.

    • provider: Provider

      Additional feature provided for the remote server. If don't plan to provide anything to the remote server, assign null.

    Returns MutexConnector

Properties

Static State

State: State

Current state of the MutexConnector

Accessors

header

  • get header(): Header

state

url

  • get url(): string | undefined

Methods

close

  • close(): Promise<void>
  • Close connection.

    Close connection from the remote mutex-server.

    When connection with the mutex-server has been closed, all of the locks you had acquired and tried would be automatically unlocked and cancelled by the server. Therefore, if you've tried to get locks through the remote critical section components by calling their methods, those methods would throw RuntimeError exceptions.

    Also, the disconnection destories all RFCs between the remote server. Therefore, if you or server has an additional Provider and there're uncompleted method calls to the Provideer through the Driver<Controller>, RuntimeError exceptions would be thrown.

    throw

    DomainError when the connection is not online.

    Returns Promise<void>

connect

  • connect(url: string, timeout?: undefined | number): Promise<void>
  • Connect to a remote mutex-server.

    Try connection to the remote mutex-server with its address and waiting for the server to accept the trial. If the mutex-server accepts your connection, the function would be returned. Otherwise, the server rejects your connection, an exception would be thrown.

    After the connection and your business (using remote critical sections) has been completed, please don't forget closing the connection in time to prevent waste of the server resource.

    throw

    DomainError when connection is not offline .

    throw

    WebError when target server is not following adequate protocol.

    throw

    WebError when server rejects your connection.

    throw

    WebError when server does not accept your connection until timeout.

    Parameters

    • url: string

      URL address to connect.

    • Optional timeout: undefined | number

    Returns Promise<void>

getBarrier

  • Get remote barrier.

    Get remote barrier from the mutex-server.

    If the mutex-server doesn't have the key named barrier, the server will create a new barrier instance with your count*. Otherwise, the server already has the *key named barrier, server will return it directly.

    Therefore, if the server already has the key named barrier, its downward counter can be different with your count.

    Parameters

    • key: string

      An identifier name to be created or search for.

    • count: number

      Downward counter of the target barrier, if newly created.

    Returns Promise<RemoteBarrier>

    A RemoteBarrier object.

getConditionVariable

  • Get remote condition variable.

    Get remote condition variable from the mutex-server.

    If the mutex-server doesn't have the key named condition variable, the server will create a new condition variable instance. Otherwise, the server already has the key named condition variable, server will return it directly.

    Parameters

    • key: string

      An identifier name to be created or search for.

    Returns Promise<RemoteConditionVariable>

    A RemoteConditionVariable object.

getDriver

  • getDriver<Controller, UseParametric>(): Driver.Promisive<Controller, UseParametric>
  • Get Driver for RFC.

    If your target MutexServer provides additional features, you can utilize those features through returned Driver object by this method. To use this method, you should define the Controller template argument, a type of interface who is defining additional features provided from the remote server.

    The returned object Driver makes to call remote functions, defined in the Controller and provided by Provider in the remote server, possible. In other words, callling a function in the Driver<Controller>, it means to call a matched function in the remote server's Provider object.

    Type parameters

    • Controller: object

      An interface for provided features (functions & objects) from the remote system (Provider).

    • UseParametric: boolean

      Whether to convert type of function parameters to be compatible with their pritimive.

    Returns Driver.Promisive<Controller, UseParametric>

    A Driver for the RFC.

getLatch

  • getLatch(identifier: string, count: number): Promise<RemoteLatch>
  • Get remote latch.

    Get remote latch from the mutex-server.

    If the mutex-server doesn't have the key named latch, the server will create a new latch instance with your count*. Otherwise, the server already has the *key named latch, server will return it directly.

    Therefore, if the server already has the key named latch, its downward counter can be different with your count.

    Parameters

    • identifier: string

      An identifier name to be created or search for.

    • count: number

      Downward counter of the target latch, if newly created.

    Returns Promise<RemoteLatch>

    A RemoteLatch object.

getMutex

  • Get remote mutex.

    Get remote mutex from the mutex-server.

    If the mutex-server doesn't have the key named mutex, the server will create a new mutex instance. Otherwise, the server already has the key named mutex, server will return it directly.

    Parameters

    • key: string

      An identifier name to be created or search for.

    Returns Promise<RemoteMutex>

    A RemoteMutex object.

getSemaphore

  • Get remote semaphore.

    Get remote semaphore from the mutex-server.

    If the mutex-server doesn't have the key named semaphore, the server will create a new semaphore instance with your count*. Otherwise, the server already has the *key named semaphore, server will return it directly.

    Therefore, if the server already has the key named semaphore, its RemoteSemaphore.max can be different with your count.

    Parameters

    • key: string

      An identifier name to be created or search for.

    • count: number

      Downward counter of the target semaphore, if newly created.

    Returns Promise<RemoteSemaphore>

    A RemoteSemaphore object.

join

  • join(): Promise<void>
  • join(ms: number): Promise<boolean>
  • join(at: Date): Promise<boolean>
  • Join connection.

    Wait until connection with the server to be closed.

    Returns Promise<void>

  • Join connection until timeout.

    Wait until connection with the server to be clsoed until timeout.

    Parameters

    • ms: number

      The maximum miliseconds for waiting.

    Returns Promise<boolean>

    Whether succeeded to waiting in the given time.

  • Join connection until time expiration.

    Wait until connection with the server to be closed until time expiration.

    Parameters

    • at: Date

      The maximum time point to wait.

    Returns Promise<boolean>

    Whether succeeded to waiting in the given time.

Generated using TypeDoc