-
Notifications
You must be signed in to change notification settings - Fork 2
/
vecdbclt.dyalog
165 lines (140 loc) · 4.28 KB
/
vecdbclt.dyalog
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
:Namespace vecdbclt
(⎕IO ⎕ML)←1 1
SERVER←''
∇ r←Clt(connection address port)
:If 1111=⊃r←##.DRC.Clt connection address port
{}⎕DL 0.5
:AndIf 1111=⊃r←##.DRC.Clt connection address port
{}⎕DL 1
:AndIf 1111=⊃r←##.DRC.Clt connection address port
{}⎕DL 3
:AndIf 1111=⊃r←##.DRC.Clt connection address port
{}⎕DL 5
:AndIf 1111=⊃r←##.DRC.Clt connection address port
(⍕r)⎕SIGNAL 11
:EndIf
∇
∇ {r}←{connection}Connect(address port user)
⍝ Connect to vecdb server process
:If 0=⎕NC'connection' ⋄ connection←'VECDB' ⋄ :EndIf
:If 0=⊃r←##.DRC.Init''
:If 0≠⍴connection ⋄ {}##.DRC.Close connection ⋄ :EndIf
:AndIf 0=⊃r←Clt connection address port
CONNECTION←2⊃r
:Else
('Error: ',,⍕r)⎕SIGNAL 11
:EndIf
∇
∇ r←SrvDo(client cmd)
⍝ Send a command to vecdb and await the result
r←SrvRcv SrvSend client cmd
∇
∇ cmd←SrvSend(client cmd);r
⍝ Return command name to wait on
:If 0=⊃r←##.DRC.Send client cmd
cmd←2⊃r
:Else
(⍕r)⎕SIGNAL 11
:EndIf
∇
∇ r←SrvRcv c;done;wr;z
⍝ Wait for result from vecdb, signal DOMAIN ERROR if it fails
:Repeat
:If ~done←∧/100 0≠1⊃r←##.DRC.Wait c 10000 ⍝ Only wait 10 seconds
:Select 3⊃r
:Case 'Error'
done←1
:Case 'Progress'
⎕←'Progress: ',4⊃r
:Case 'Receive'
:If 0=⊃r
r←4⊃r
:AndIf 0=⊃r
r←2⊃r
done←1
:Else
('Error: ',,⍕r)⎕SIGNAL 11
:EndIf
:EndSelect
:EndIf
:Until done
∇
∇ r←Open folder
⍝ Cover-function for call to Lock from a Client
r←⎕NEW vecdbproxy(folder CONNECTION)
∇
:Class vecdbproxy
⍝ Produce a vecdb proxy object for a served vecdb
∇ Open(folder connection)
:Access Public
:Implements Constructor
(FOLDER CONNECTION)←folder connection
:If 0=⊃r←##.SrvDo CONNECTION('Open'folder)
⎕DF'[vecdbclt: ',folder,']'
:Else
(⍕r)⎕SIGNAL 11
:EndIf
∇
∇ {r}←Shutdown msg
:Access Public
:If 0=⊃r←##.SrvDo CONNECTION('Shutdown'msg)
{}#.DRC.Close CONNECTION
CONNECTION←''
:EndIf
∇
∇ Close
:Access Public
:If 0=⊃r←##.SrvDo CONNECTION('Close'⍬)
{}#.DRC.Close CONNECTION
CONNECTION←''
:EndIf
∇
∇ r←Count
:Access Public
:If 0≠⍴CONNECTION
r←##.SrvDo CONNECTION('Count'(FOLDER ⍬))
r←+/r
:Else
'CONNECTION CLOSED'⎕SIGNAL 11
:EndIf
∇
∇ r←Append args
:Access Public
:If 0≠⍴CONNECTION
r←##.SrvDo CONNECTION('Append'(FOLDER args))
:Else
'CONNECTION CLOSED'⎕SIGNAL 11
:EndIf
∇
∇ r←Query args
:Access Public
:If 0≠⍴CONNECTION
r←##.SrvDo CONNECTION('Query'(FOLDER args))
:If 2=⍴⍴⊃r
r←⊃⍪/r
:Else
r←⊃,¨/r
:EndIf
:Else
'CONNECTION CLOSED'⎕SIGNAL 11
:EndIf
∇
∇ r←Read args
:Access Public
:If 0≠⍴CONNECTION
r←##.SrvDo CONNECTION('Read'(FOLDER args))
r←⊃,¨/r
:Else
'CONNECTION CLOSED'⎕SIGNAL 11
:EndIf
∇
∇ r←Update args
:Access Public
:If 0≠⍴CONNECTION
r←##.SrvDo CONNECTION('Update'(FOLDER args))
:Else
'CONNECTION CLOSED'⎕SIGNAL 11
:EndIf
∇
:EndClass
:EndNamespace