Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Synchronet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Main
Synchronet
Commits
39e8ed20
Commit
39e8ed20
authored
13 years ago
by
mcmlxxix
Browse files
Options
Downloads
Patches
Plain Diff
new db query "KEYS" returns an array of object keys
parent
caae4a1f
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
exec/load/json-client.js
+33
-25
33 additions, 25 deletions
exec/load/json-client.js
exec/load/json-db.js
+26
-1
26 additions, 1 deletion
exec/load/json-db.js
with
59 additions
and
26 deletions
exec/load/json-client.js
+
33
−
25
View file @
39e8ed20
...
@@ -14,19 +14,25 @@ load("json-sock.js");
...
@@ -14,19 +14,25 @@ load("json-sock.js");
- JSONClient.cycle();
- JSONClient.cycle();
- JSONClient.connect();
- JSONClient.connect();
- JSONClient.disconnect();
- JSONClient.disconnect();
- JSONClient.read();
- JSONClient.read(scope,location,lock);
- JSONClient.pop();
- JSONClient.pop(scope,location,lock);
- JSONClient.shift();
- JSONClient.shift(scope,location,lock);
- JSONClient.write();
- JSONClient.write(scope,location,lock);
- JSONClient.push();
- JSONClient.push(scope,location,lock);
- JSONClient.unshift();
- JSONClient.unshift(scope,location,lock);
- JSONClient.lock();
- JSONClient.lock(scope,location,lock);
- JSONClient.unlock();
- JSONClient.unlock(scope,location);
- JSONClient.subscribe();
- JSONClient.subscribe(scope,location);
- JSONClient.unsubscribe();
- JSONClient.unsubscribe(scope,location);
- JSONClient.status();
- JSONClient.status(scope,location);
- JSONClient.who();
- JSONClient.who(scope,location);
- JSONClient.ident();
- JSONClient.ident(scope,username,password);
NOTE: scope is the module or root service you wish to send the command to,
location is a dot-notated object property, and lock is one of the following:
LOCK_READ = 1
LOCK_WRITE = 2
LOCK_UNLOCK = -1
indirect methods: these will generally be called automatically by the other methods
indirect methods: these will generally be called automatically by the other methods
and you will not typically need to use them
and you will not typically need to use them
...
@@ -43,22 +49,14 @@ load("json-sock.js");
...
@@ -43,22 +49,14 @@ load("json-sock.js");
sample usage:
sample usage:
var LOCK_READ = 1;
var LOCK_WRITE = 2;
var UNLOCK = -1;
load("json-client.js");
load("json-client.js");
var client=new JSONClient(myServer,myPort);
var client=new JSONClient(myServer,myPort);
function callback(data) {
myData = data;
}
while(1) {
while(1) {
doSomething();
doSomething();
client.lock("mydatabase.dong",LOCK_READ);
client.lock("
myscript","
mydatabase.dong",LOCK_READ);
var dong=client.read("mydatabase.dong");
var dong=client.read("
myscript","
mydatabase.dong");
client.unlock("mydatabase.dong");
client.unlock("
myscript","
mydatabase.dong");
print("look at my " + dong);
print("look at my " + dong);
client.cycle();
client.cycle();
}
}
...
@@ -143,6 +141,16 @@ function JSONClient(serverAddr,serverPort) {
...
@@ -143,6 +141,16 @@ function JSONClient(serverAddr,serverPort) {
return
this
.
wait
(
"
RESPONSE
"
);
return
this
.
wait
(
"
RESPONSE
"
);
}
}
/* read object keys (lock for reading or writing, blocking) */
this
.
keys
=
function
(
scope
,
location
,
lock
)
{
this
.
send
(
scope
,
"
QUERY
"
,{
oper
:
"
KEYS
"
,
location
:
location
,
lock
:
lock
});
return
this
.
wait
(
"
RESPONSE
"
);
}
/* shift object data (lock for reading or writing, blocking) */
/* shift object data (lock for reading or writing, blocking) */
this
.
shift
=
function
(
scope
,
location
,
lock
)
{
this
.
shift
=
function
(
scope
,
location
,
lock
)
{
this
.
send
(
scope
,
"
QUERY
"
,{
this
.
send
(
scope
,
"
QUERY
"
,{
...
...
This diff is collapsed.
Click to expand it.
exec/load/json-db.js
+
26
−
1
View file @
39e8ed20
...
@@ -87,7 +87,8 @@ function JSONdb (fileName) {
...
@@ -87,7 +87,8 @@ function JSONdb (fileName) {
SUBSCRIBE
:
8
,
SUBSCRIBE
:
8
,
UNSUBSCRIBE
:
9
,
UNSUBSCRIBE
:
9
,
WHO
:
10
,
WHO
:
10
,
STATUS
:
11
STATUS
:
11
,
KEYS
:
12
}
}
/* error constants */
/* error constants */
...
@@ -358,6 +359,27 @@ function JSONdb (fileName) {
...
@@ -358,6 +359,27 @@ function JSONdb (fileName) {
}
}
};
};
/* retrieve a list of object keys */
this
.
keys
=
function
(
client
,
record
)
{
var
keys
=
[];
/* if the requested data does not exist, result is undefined */
if
(
record
.
data
===
undefined
)
{
send_packet
(
client
,
undefined
,
"
RESPONSE
"
);
return
true
;
}
/* if this client has this record locked, read */
if
(
record
.
info
.
lock
[
client
.
id
])
{
for
(
var
k
in
record
.
data
[
record
.
child_name
])
keys
.
push
(
k
);
send_packet
(
client
,
keys
,
"
RESPONSE
"
);
return
true
;
}
/* if there is no lock for this client, error */
else
{
return
false
;
}
}
/* remove a record from the database (requires WRITE_LOCK) */
/* remove a record from the database (requires WRITE_LOCK) */
this
.
remove
=
function
(
client
,
record
)
{
this
.
remove
=
function
(
client
,
record
)
{
/* if the requested data does not exist, do nothing */
/* if the requested data does not exist, do nothing */
...
@@ -619,6 +641,9 @@ function JSONdb (fileName) {
...
@@ -619,6 +641,9 @@ function JSONdb (fileName) {
case
"
WRITE
"
:
case
"
WRITE
"
:
result
=
this
.
write
(
request
.
client
,
record
,
request
.
data
);
result
=
this
.
write
(
request
.
client
,
record
,
request
.
data
);
break
;
break
;
case
"
KEYS
"
:
result
=
this
.
keys
(
request
.
client
,
record
);
break
;
case
"
PUSH
"
:
case
"
PUSH
"
:
result
=
this
.
push
(
request
.
client
,
record
,
request
.
data
);
result
=
this
.
push
(
request
.
client
,
record
,
request
.
data
);
break
;
break
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment