diff --git a/package.json b/package.json index d0b1c27..8b8c78c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "mutex-server", - "version": "0.6.0", + "version": "0.6.1", "description": "Mutex Server using WebSocket", "main": "lib/index.js", "typings": "lib/index.d.ts", diff --git a/src/MutexAcceptor.ts b/src/MutexAcceptor.ts index 98838db..8f06fa6 100644 --- a/src/MutexAcceptor.ts +++ b/src/MutexAcceptor.ts @@ -8,7 +8,7 @@ import { ProviderGroup } from "./server/ProviderGroup"; * - available only in NodeJS. * * The {@link MutexAcceptor} is a communicator class interacting with the remote client, through - * websocket and [RFC](https://github.com/samchon/tgrid#13-remote-function-call) protocol, in the + * websocket and [RPC](https://tgrid.com/docs/remote-procedure-call/) protocol, in the * `mutex-server`. The {@link MutexAcceptor} objects are always created by the {@link MutexServer} * class, whenever a remote client connects to the `mutex-server`. * @@ -16,17 +16,12 @@ import { ProviderGroup } from "./server/ProviderGroup"; * method. If you {@link accept} the connection, the interaction would be started and the client * can access to critical component sections of this `mutex-server`. * - * Also, when declaring this {@link MutexAcceptor} 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` + * Also, when declaring this {@link MutexAcceptor} type, you've to define one template argument, + * *Header*. 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. * * @template Header Type of the header containing initial data. - * @template Provider Type of additional features provided for the remote client. * @author Jeongho Nam - https://github.com/samchon */ export class MutexAcceptor
{ @@ -73,11 +68,6 @@ export class MutexAcceptor
{ * acquired and tried would be automatically unlocked and cancelled by this `mutex-server`. * Also, remote critical section components had assigned to the client would be returned, too. * - * In addition, the disconnection destories all [RFC](https://github.com/samchon/tgrid#13-remote-function-call)s - * between the remote client. Therefore, if the remote client is providing custom features to - * your `mutex-server` and there're uncompleted method calls to the `Provider` through - * `Driver`, {@link RuntimeError} exceptions would be thrown. - * * @param code Closing code. * @param reason Reason why. * @throw DomainError when the connection is not online. @@ -158,33 +148,6 @@ export class MutexAcceptor
{ return this.base_.state; } - // /** - // * Get Driver for [RFC](https://github.com/samchon/tgrid#13-remote-function-call). - // * - // * If remote client provides custom features for this `mutex-server`, you can utilize - // * those features thorugh returned `Driver` object by this method. To use this method, you - // * should define the `Controller` template argument, a type of interface who is defining - // * additionla features provided from the remote client. - // * - // * The returned object `Driver` makes to call remote functions, defined in the `Controller` - // * and provided by `Provider` in the remote client, possible. In other words, callling a - // * function in the `Driver`, it means to call a matched function in the remote - // * client's `Provider` object. - // * - // * - `Controller`: Definition only - // * - `Driver`: [Remote Function Call](https://github.com/samchon/tgrid#13-remote-function-call) - // * - // * @template Controller An interface for provided features (functions & objects) from the remote client (`Provider`). - // * @template UseParametric Whether to convert type of function parameters to be compatible with their pritimive. - // * @return A `Driver` for the [RFC](https://github.com/samchon/tgrid#13-remote-function-call). - // */ - // public getDriver< - // Controller extends object, - // UseParametric extends boolean = false, - // >(): Driver { - // return this.base_.getDriver(); - // } - /* ---------------------------------------------------------------- HANDSHAKES ---------------------------------------------------------------- */ diff --git a/src/MutexConnector.ts b/src/MutexConnector.ts index 71be770..570fcf4 100644 --- a/src/MutexConnector.ts +++ b/src/MutexConnector.ts @@ -1,4 +1,4 @@ -import { Driver, WebSocketConnector } from "tgrid"; +import { WebSocketConnector } from "tgrid"; import { RemoteBarrier } from "./client/RemoteBarrier"; import { RemoteConditionVariable } from "./client/RemoteConditionVariable"; @@ -11,7 +11,7 @@ import { ProviderGroup } from "./server/ProviderGroup"; * Mutex server connector for client. * * The {@link MutexConnector} is a communicator class who can connect to a remote `mutex-server` - * and interact with it through websocket and [RFC](https://github.com/samchon/tgrid#13-remote-function-call) + * and interact with it through websocket and [RPC](https://tgrid.com/docs/remote-procedure-call/) * protocol. * * You can connect to the websocket `mutex-server` using {@link connect} method. After the @@ -28,17 +28,12 @@ import { ProviderGroup } from "./server/ProviderGroup"; * - {@link getBarrier} * - {@link getLatch} * - * Also, when declaring this {@link 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`. + * Also, when declaring this {@link MutexConnector} type, you've to define one template argument, + * *Header*. 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. * * @template Header Type of the *header* containing initial data. - * @template Provider Type of additional features provided for the remote server. If no plan to provide anything, declare `null`. * @author Jeongho Nam - https://github.com/samchon */ export class MutexConnector
{ @@ -47,11 +42,6 @@ export class MutexConnector
{ */ private connector_: WebSocketConnector; - /** - * @hidden - */ - private driver_: Driver; - /* ----------------------------------------------------------- CONSTRUCTORS ----------------------------------------------------------- */ @@ -59,11 +49,9 @@ export class MutexConnector
{ * Initializer Constructor. * * @param header Initial data sending to the remote server after connection. Hope to use it as an activation tool. - * @param provider Additional feature provided for the remote server. If don't plan to provide anything to the remote server, assign `null`. */ public constructor(header: Header) { this.connector_ = new WebSocketConnector(header, null); - this.driver_ = this.connector_.getDriver(); } /** @@ -97,11 +85,6 @@ export class MutexConnector
{ * tried to get locks through the remote critical section components by calling their methods, * those methods would throw {@link RuntimeError} exceptions. * - * Also, the disconnection destories all [RFC](https://github.com/samchon/tgrid#13-remote-function-call)s - * 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`, - * {@link RuntimeError} exceptions would be thrown. - * * @throw DomainError when the connection is not online. */ public async close(): Promise { @@ -172,33 +155,9 @@ export class MutexConnector
{ return this.connector_.header; } - /** - * Get Driver for [RFC](https://github.com/samchon/tgrid#13-remote-function-call). - * - * If your target {@link 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`, it means to call a matched function in the remote - * server's `Provider` object. - * - * - `Controller`: Definition only - * - `Driver`: [Remote Function Call](https://github.com/samchon/tgrid#13-remote-function-call) - * - * @template Controller An interface for provided features (functions & objects) from the remote system (`Provider`). - * @template UseParametric Whether to convert type of function parameters to be compatible with their pritimive. - * @return A `Driver` for the [RFC](https://github.com/samchon/tgrid#13-remote-function-call). - */ - public getDriver(): Driver { - return this.driver_; - } - /* ----------------------------------------------------------- - THREAD COMPONENTS - ----------------------------------------------------------- */ + THREAD COMPONENTS + ----------------------------------------------------------- */ /** * Get remote condition variable. * @@ -213,7 +172,7 @@ export class MutexConnector
{ */ public getConditionVariable(key: string): Promise { return RemoteConditionVariable.create( - this.driver_.condition_variables, + this.connector_.getDriver().condition_variables, key, ); } @@ -231,7 +190,7 @@ export class MutexConnector
{ * @return A {@link RemoteMutex} object. */ public getMutex(key: string): Promise { - return RemoteMutex.create(this.driver_.mutexes, key); + return RemoteMutex.create(this.connector_.getDriver().mutexes, key); } /** @@ -251,7 +210,11 @@ export class MutexConnector
{ * @return A {@link RemoteSemaphore} object. */ public getSemaphore(key: string, count: number): Promise { - return RemoteSemaphore.create(this.driver_.semaphores, key, count); + return RemoteSemaphore.create( + this.connector_.getDriver().semaphores, + key, + count, + ); } /** @@ -271,7 +234,11 @@ export class MutexConnector
{ * @return A {@link RemoteBarrier} object. */ public getBarrier(key: string, count: number): Promise { - return RemoteBarrier.create(this.driver_.barriers, key, count); + return RemoteBarrier.create( + this.connector_.getDriver().barriers, + key, + count, + ); } /** @@ -291,7 +258,11 @@ export class MutexConnector
{ * @return A {@link RemoteLatch} object. */ public getLatch(identifier: string, count: number): Promise { - return RemoteLatch.create(this.driver_.latches, identifier, count); + return RemoteLatch.create( + this.connector_.getDriver().latches, + identifier, + count, + ); } } diff --git a/src/MutexServer.ts b/src/MutexServer.ts index f71a4fb..7fd8a8e 100644 --- a/src/MutexServer.ts +++ b/src/MutexServer.ts @@ -16,26 +16,21 @@ import { GlobalGroup } from "./server/GlobalGroup"; * * The {@link MutexServer} is a class who can open an `mutex-server`. Clients connecting to the * `mutex-server` would communicate with this server through {@link MutexAcceptor} objects using - * websocket and [RFC](https://github.com/samchon/tgrid#13-remote-function-call) protocol. + * websocket and [RPC](https://tgrid.com/docs/remote-procedure-call/) protocol. * * To open the `mutex-server`, call the {@link open} method with your custom callback function * which would be called whenever a {@link MutexAcceptor} has been newly created by a client's * connection. * - * Also, when declaring this {@link 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`. + * Also, when declaring this {@link MutexServer} type, you've to define one template argument, + * *Header*. 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. * * @template Header Type of the *header* containing initial data. - * @template Provider Type of additional features provided for the remote client. * @author Jeongho Nam - https://github.com/samchon */ -export class MutexServer { +export class MutexServer
{ /** * @hidden */ @@ -112,8 +107,8 @@ export class MutexServer { * Therefore, clients who are using the {@link MutexConnector} class, they can't use the * remote critical section components more. * - * Also, closing the server means that all of the [RFC](https://github.com/samchon/tgrid#13-remote-function-call)s - * between the server and had connected clients would be destroied. Therefore, all of the [RFC](https://github.com/samchon/tgrid#13-remote-function-call)s + * Also, closing the server means that all of the [RPC](https://tgrid.com/docs/remote-procedure-call/)s + * between the server and had connected clients would be destroied. Therefore, all of the [RPC](https://tgrid.com/docs/remote-procedure-call/)s * that are not returned (completed) yet would ge {@link RuntimeError} exception. */ public close(): Promise { diff --git a/test/index.ts b/test/index.ts index d04e676..ccf1784 100644 --- a/test/index.ts +++ b/test/index.ts @@ -14,7 +14,7 @@ const HEADER = { password: "some_password" }; interface IModule { [key: string]: ( factory: ConnectionFactory, - server: MutexServer, + server: MutexServer, ) => Promise; } @@ -26,7 +26,7 @@ async function measure(job: () => Promise): Promise { async function iterate( factory: ConnectionFactory, - server: MutexServer, + server: MutexServer, path: string, ): Promise { const fileList: string[] = await fs.promises.readdir(path); @@ -71,7 +71,7 @@ async function main(): Promise { console.log("=========================================================="); // OPEN SERVER - let server: MutexServer = new MutexServer(); + const server: MutexServer = new MutexServer(); await server.open(PORT, async (acceptor) => { if (acceptor.header.password === HEADER.password) await acceptor.accept(); else await acceptor.reject(); @@ -104,9 +104,10 @@ async function main(): Promise { console.log(` - elapsed time: ${time} ms`); // MEMORY USAGE - let memory: NodeJS.MemoryUsage = process.memoryUsage(); - for (let property in memory) { - let amount: number = memory[property as keyof NodeJS.MemoryUsage] / 10 ** 6; + const memory: NodeJS.MemoryUsage = process.memoryUsage(); + for (const property in memory) { + const amount: number = + memory[property as keyof NodeJS.MemoryUsage] / 10 ** 6; console.log(` - ${property}: ${amount} MB`); } console.log("----------------------------------------------------------\n"); @@ -114,7 +115,7 @@ async function main(): Promise { //---- // TERMINATE //---- - for (let connector of connectorList) + for (const connector of connectorList) if (connector.state === MutexConnector.State.OPEN) await connector.close(); await server.close(); diff --git a/test/manual/remote-mutex.ts b/test/manual/remote-mutex.ts index ebe903f..438b0e6 100644 --- a/test/manual/remote-mutex.ts +++ b/test/manual/remote-mutex.ts @@ -31,7 +31,7 @@ async function client(index: number, character: string): Promise { async function main(): Promise { // OPEN SERVER - const server: MutexServer = new MutexServer(); + const server: MutexServer = new MutexServer(); await server.open(PORT, async (acceptor) => { if (acceptor.header === PASSWORD) await acceptor.accept(); else await acceptor.reject(); diff --git a/test/test_destructors.ts b/test/test_destructors.ts index 8f96ff6..d7cce19 100644 --- a/test/test_destructors.ts +++ b/test/test_destructors.ts @@ -16,9 +16,9 @@ async function test(factory: ConnectionFactory): Promise { export async function test_destructors( factory: ConnectionFactory, - server: MutexServer, + server: MutexServer, ): Promise { - let promises: Promise[] = []; + const promises: Promise[] = []; for (let i: number = 0; i < 4; ++i) promises.push(test(factory)); await Promise.all(promises);