Skip to content

Commit 480b548

Browse files
committed
ObjectScript code
1 parent f0c418b commit 480b548

File tree

3 files changed

+186
-0
lines changed

3 files changed

+186
-0
lines changed

isc/zlib/Test.cls

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
Class isc.zlib.Test Extends %Persistent
2+
{
3+
4+
Parameter ZLIBID = 4995;
5+
6+
/// Get path to zlib callout shared library
7+
/// Library assumed to be in bin folder, unless specified otherwise
8+
ClassMethod getLibPath() [ CodeMode = expression ]
9+
{
10+
$g(^isc.zlib.Test, $g(^%SYS("bindir")) _ "zlibisc." _ $select($$$isWINDOWS:"dll", 1:"so"))
11+
}
12+
13+
/// Same callout library, but with immediate loading
14+
/// do ##class(isc.zlib.Test).callout3()
15+
ClassMethod callout3(text = "Hello World", rounds As %Integer = 10000)
16+
{
17+
set path = ..getLibPath()
18+
for i=1:1:rounds{
19+
kill out
20+
set out = $ZF(-3, path, "Compress", text)
21+
}
22+
do $ZF(-3, "")
23+
}
24+
25+
/// Done once per system start, so we don't count it.
26+
/// do ##class(isc.zlib.Test).callout6Init()
27+
ClassMethod callout6Init()
28+
{
29+
set sc = $ZF(-4,6,..#ZLIBID)
30+
set sc = $ZF(-4,5,..#ZLIBID, ..getLibPath())
31+
}
32+
33+
/// Callout library, but with system loading
34+
/// do ##class(isc.zlib.Test).callout6()
35+
ClassMethod callout6(text = "Hello World", rounds As %Integer = 10000)
36+
{
37+
for i=1:1:rounds{
38+
kill out
39+
set out = $ZF(-6, ..#ZLIBID, 1, text)
40+
}
41+
}
42+
43+
/// Java GateWay implementation
44+
/// do ##class(isc.zlib.Test).jgw()
45+
ClassMethod jgw(text = "Hello World", rounds As %Integer = 10000)
46+
{
47+
set gateway = ##class(isc.zlib.Utils).connect()
48+
for i=1:1:rounds{
49+
kill out
50+
set out = ##class(isc.zlib.Java).compress(gateway, text)
51+
}
52+
}
53+
54+
/// Default system implementation
55+
/// do ##class(isc.zlib.Test).system()
56+
ClassMethod system(text = "Hello World", rounds As %Integer = 10000)
57+
{
58+
for i=1:1:rounds{
59+
kill out
60+
set out = $extract($SYSTEM.Util.Compress(text), 2, *-1)
61+
}
62+
}
63+
64+
/// NodeJS implementation
65+
/// do ##class(isc.zlib.Test).node()
66+
ClassMethod node(text = "Hello World", rounds As %Integer = 10000)
67+
{
68+
set req = ##class(%Net.HttpRequest).%New()
69+
set req.Server = "localhost"
70+
set req.Port = 3000
71+
set req.Location = "/zlibapi/" _ text
72+
73+
for i=1:1:rounds{
74+
kill out
75+
set sc = req.Get(,,$$$NO)
76+
set out = req.HttpResponse.Data //.Read($$$MaxStringLength)
77+
}
78+
}
79+
80+
/// textLength - either text, or a number of symbols in text
81+
/// rounds - number of calls to zlib
82+
/// do ##class(isc.zlib.Test).test()
83+
ClassMethod test(textLength As %Integer = 100, rounds As %Integer = 10000)
84+
{
85+
set:textLength="" textLength = 100
86+
87+
if ($isvalidnum(textLength) && (textLength=$normalize(textLength, 0))) {
88+
set text = ##class(%PopulateUtils).StringMin(textLength, textLength)
89+
} else {
90+
set text = textLength
91+
set textLength = $l(text)
92+
}
93+
94+
do ..callout6Init()
95+
96+
write "Text: ", text, !
97+
write "Text length: ", $l(text), !
98+
write "Rounds: ", rounds, !
99+
for method="callout3", "callout6", "system", "jgw", "node" {
100+
set start = $zh
101+
do $classmethod(,method, text, rounds)
102+
set end = $zh
103+
104+
set time = end - start
105+
106+
write "Method: ", method, !
107+
write "Time: ", time, !
108+
write "Speed (Kb/sec): ", $normalize(textLength*rounds/1024/time, 0), !
109+
write "Speed (calls/sec): ", $normalize(rounds/time, 0), !
110+
}
111+
}
112+
113+
Storage Default
114+
{
115+
<Data name="TestDefaultData">
116+
<Value name="1">
117+
<Value>%%CLASSNAME</Value>
118+
</Value>
119+
</Data>
120+
<DataLocation>^isc.zlib.TestD</DataLocation>
121+
<DefaultData>TestDefaultData</DefaultData>
122+
<IdLocation>^isc.zlib.TestD</IdLocation>
123+
<IndexLocation>^isc.zlib.TestI</IndexLocation>
124+
<StreamLocation>^isc.zlib.TestS</StreamLocation>
125+
<Type>%Library.CacheStorage</Type>
126+
}
127+
128+
}
129+

isc/zlib/Utils.cls

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
Class isc.zlib.Utils
2+
{
3+
4+
Parameter CLASS = "isc.zlib.Java";
5+
6+
Parameter CLASSPATH = {$g(^%SYS("bindir")) _ "zlib.jar"};
7+
8+
Parameter GATEWAY = "ZLIB";
9+
10+
/// Create JGW. Java home must point to 1.8 jre.
11+
/// Write $System.Status.GetErrorText(##class(isc.zlib.Utils).createGateway())
12+
ClassMethod createGateway(gatewayName = {..#GATEWAY}, javaHome = {$SYSTEM.Util.GetEnviron("JAVA_HOME")}, path As %String = {..#CLASSPATH}, port As %Integer = 55559)
13+
{
14+
set sys = ##class(%Net.Remote.ObjectGateway).%New()
15+
set sys.Name = gatewayName
16+
set sys.Type = 1
17+
set sys.JavaHome = javaHome
18+
set sys.ClassPath = path
19+
set sys.Port = port
20+
quit sys.%Save()
21+
}
22+
23+
/// Load Jar from path.
24+
/// Write $System.Status.GetErrorText(##class(isc.zlib.Utils).updateJar())
25+
ClassMethod updateJar(gatewayName = {..#GATEWAY}, path As %String = {..#CLASSPATH})
26+
{
27+
#Dim sc As %Status = $$$OK
28+
29+
set sc = ##class(%Net.Remote.Service).StopGateway(gatewayName)
30+
31+
set gateway = ..connect(gatewayName, path, .sc)
32+
quit:$$$ISERR(sc) sc
33+
34+
set sc = gateway.%Import(..#CLASS)
35+
quit:$$$ISERR(sc) sc
36+
set:'##class(%Dictionary.CompiledClass).%ExistsId(..#CLASS) sc = $$$ERROR($$$GeneralError, $$$FormatText("Class '%1' does not exist",..#CLASS))
37+
quit:$$$ISERR(sc) sc
38+
39+
set sc = ##class(%Net.Remote.Service).StopGateway(gatewayName)
40+
41+
quit sc
42+
}
43+
44+
/// Get JGW object
45+
ClassMethod connect(gatewayName As %String = {..#GATEWAY}, path As %String = {..#CLASSPATH}, Output sc As %Status) As %Net.Remote.Gateway
46+
{
47+
set gateway = ""
48+
set sc = ##class(%Net.Remote.Service).OpenGateway(gatewayName, .gatewayConfig)
49+
quit:$$$ISERR(sc) gateway
50+
set sc = ##class(%Net.Remote.Service).ConnectGateway(gatewayConfig, .gateway, path, $$$YES)
51+
quit gateway
52+
}
53+
54+
}
55+

sc-list.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
isc.zlib.Test.cls
2+
isc.zlib.Utils.cls

0 commit comments

Comments
 (0)