Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

distributed-lock-manager

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

distributed-lock-manager - npm Package Compare versions

Comparing version 0.0.1 to 1.0.1

images/screenshot.png

3

dist/dlm-server.js

@@ -28,2 +28,5 @@ "use strict";

const result = await distributedLockManager.waitAcquire();
if (this.logFn && result) {
this.logFn(`Lock acquired for '${distributedLockManager.name}'`);
}
return result ? 'TRUE\r\n' : 'FALSE\r\n';

@@ -30,0 +33,0 @@ }

@@ -11,2 +11,4 @@ "use strict";

this.server = http.createServer((request, response) => this.handleRequest(request, response));
this.server.on('clientError', (err) => {
});
}

@@ -27,2 +29,5 @@ handleRequest(request, response) {

response.end();
}).catch((err) => {
response.write('ERROR');
response.end();
});

@@ -35,3 +40,2 @@ command = [];

socketBuffer = Buffer.from(command);
}).on('end', () => {
});

@@ -38,0 +42,0 @@ }

2

dist/package.json
{
"name": "distributed-lock-manager",
"version": "1.0.0",
"version": "0.0.1",
"description": "A distributed lock manager (DLM) runs in every machine in a cluster, with an identical copy of a cluster-wide lock database.",

@@ -5,0 +5,0 @@ "main": "gulpfile.js",

@@ -14,2 +14,4 @@ "use strict";

let socketBuffer = null;
socket.on('error', (err) => {
});
socket.on('data', (data) => {

@@ -26,2 +28,4 @@ socketBuffer = socketBuffer ? Buffer.concat([socketBuffer, data]) : data;

socket.write(result);
}).catch((err) => {
socket.write('ERROR');
});

@@ -28,0 +32,0 @@ command = [];

{
"name": "distributed-lock-manager",
"version": "0.0.1",
"version": "1.0.1",
"description": "A distributed lock manager (DLM) runs in every machine in a cluster, with an identical copy of a cluster-wide lock database.",

@@ -5,0 +5,0 @@ "main": "gulpfile.js",

# Distributed Lock Manager
A distributed lock manager (DLM) runs in every machine in a cluster, with an identical copy of a cluster-wide lock database.
## Installation
`npm install -g distributed-lock-manager`
## Usage
`dlm-server --httpPort 5000 --tcpPort 5001 --maximumWaitForAcquireInMilliseconds 2000 --timeoutInMiliseconds 5000`
## Screenshot
![screenshot](https://github.com/barend-erasmus/distributed-lock-manager/raw/master/images/screenshot.png)
## Commands
### Acquire
This command will try to acquire the lock for the given name and return `TRUE<newline>` when successfully acquired and `FALSE<newline>` when not acquired.
`aquire <name><newline>`
### Release
This command will release the lock for the given name and return `OK<newline>`.
`release <name><newline>`
### Wait Acquire
This command is exactly the same as the `acquire` command except that it will wait if it could not acquire the lock immediately.
`waitAcquire <name><newline>`
## HTTP Interface
### CSharp
```CSharp
var client = new RestClient();
client.BaseUrl = new Uri("http://localhost:5000");
var request = new RestRequest(Method.POST);
request.AddParameter("text/text", "acquire mylock\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
if (response.Content == "TRUE\r\n")
{
Console.WriteLine("Lock acquired");
}
else
{
Console.WriteLine("Failed to acquire lock");
}
```
### Node.js
```javascript
const rp = require('request-promise');
const response = await rp({
body: `acquire mylock\r\n`,
method: 'POST',
uri: 'http://localhost:5000',
});
if (response === 'TRUE\r\n') {
console.log('Lock acquired');
} else {
console.log('Failed to acquire lock');
}
```
## TCP Interface
### CSharp
```CSharp
var client = new TcpClient("127.0.0.1", 5001);
var stream = client.GetStream();
var messageSend = Encoding.ASCII.GetBytes("acquire mylock\r\n");
stream.Write(messageSend, 0, messageSend.Length);
byte[] bytesReceived = new byte[100];
int numberOfBytesReceived = stream.Read(bytesReceived, 0, 100);
var messageReceived = '';
for (int index = 0; index < numberOfBytesReceived; index++)
{
messageReceived += (char)bytesReceived[index];
}
if (messageReceived == "TRUE\r\n")
{
Console.WriteLine("Lock acquired");
} else
{
Console.WriteLine("Failed to acquire lock");
}
stream.Close();
client.Close();
```
### Node.js
```javascript
const net = require('net');
const client = new net.Socket();
client.connect(5001, '127.0.0.1', () => {
client.write(`acquire mylock\r\n`);
});
client.on('data', (data) => {
if (data.toString() === 'TRUE\r\n') {
console.log('Lock acquired');
} else {
console.log('Failed to acquire lock');
}
client.destroy();
});
```
## Performance
### Acquire
* Mean: 2.907 ms
* Median: 3 ms
* Standard Deviation: 1.4595
* 95th Percentile: 5 ms
### Release
* Mean: 2.829 ms
* Median: 3 ms
* Standard Deviation: 1.5325
* 95th Percentile: 5 ms

@@ -18,2 +18,6 @@ import * as http from 'http';

this.server = http.createServer((request: http.IncomingMessage, response: http.ServerResponse) => this.handleRequest(request, response));
this.server.on('clientError', (err: Error) => {
});
}

@@ -20,0 +24,0 @@

@@ -23,2 +23,6 @@ import * as net from 'net';

socket.on('error', (err: Error) => {
});
socket.on('data', (data: Buffer) => {

@@ -25,0 +29,0 @@ socketBuffer = socketBuffer ? Buffer.concat([socketBuffer, data]) : data;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc