Skip to content

Commit 2bfb05f

Browse files
author
SirCipher
committed
Updates formatting
1 parent 3503524 commit 2bfb05f

6 files changed

Lines changed: 130 additions & 133 deletions

File tree

server/build.gradle

Lines changed: 103 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import java.util.regex.Matcher
22

33
buildscript {
4-
repositories {
5-
maven { url 'https://plugins.gradle.org/m2/' }
6-
}
7-
dependencies {
8-
classpath 'com.netflix.nebula:gradle-ospackage-plugin:6.1.1'
9-
}
4+
repositories {
5+
maven { url 'https://plugins.gradle.org/m2/' }
6+
}
7+
dependencies {
8+
classpath 'com.netflix.nebula:gradle-ospackage-plugin:6.1.1'
9+
}
1010
}
1111

1212
apply plugin: 'java'
@@ -20,123 +20,123 @@ group = 'ai.swim'
2020
description = 'Tutorial- Web Agents'
2121
ext.moduleName = 'swim.tutorial'
2222
sourceCompatibility = 1.9
23-
version = project.property('application.version')
23+
version = project.property('swim.version')
2424
mainClassName = 'swim.tutorial.TutorialPlane'
2525

2626
//def moduleName = 'swim.tutorial'
2727
def jvmVersion = System.getProperty('java.version').split('\\.')[0] as Integer
2828
def useModules = jvmVersion >= 9 && !project.hasProperty('no-modules')
2929

3030
repositories {
31-
mavenCentral()
32-
maven { url 'https://swimos.bintray.com/maven/' }
33-
maven { url 'http://packages.confluent.io/maven/' }
31+
mavenCentral()
32+
maven { url 'https://swimos.bintray.com/maven/' }
33+
maven { url 'http://packages.confluent.io/maven/' }
3434
}
3535

3636
dependencies {
37-
api group: 'org.swimos', name: 'swim-server', version: version
38-
api group: 'org.swimos', name: 'swim-client', version: version
37+
api group: 'org.swimos', name: 'swim-server', version: version
38+
api group: 'org.swimos', name: 'swim-client', version: version
3939
}
4040

4141
afterEvaluate {
42-
compileJava {
43-
if (useModules) {
44-
doFirst {
45-
options.compilerArgs += [
46-
'--module-path', classpath.asPath,
47-
]
48-
classpath = files()
49-
}
42+
compileJava {
43+
if (useModules) {
44+
doFirst {
45+
options.compilerArgs += [
46+
'--module-path', classpath.asPath,
47+
]
48+
classpath = files()
49+
}
50+
}
51+
options.compilerArgs += ['-Xlint']
52+
options.encoding = 'UTF-8'
5053
}
51-
options.compilerArgs += ['-Xlint']
52-
options.encoding = 'UTF-8'
53-
}
54-
55-
jar {
56-
inputs.property('moduleName', moduleName)
57-
manifest {
58-
attributes(
59-
'Implementation-Title': moduleName,
60-
'Implementation-Version': version,
61-
'Main-Class': mainClassName)
62-
}
63-
}
6454

65-
tasks.withType(JavaCompile) {
66-
options.encoding = 'UTF-8'
67-
if (!useModules) {
68-
exclude '*module-info*'
55+
jar {
56+
inputs.property('moduleName', moduleName)
57+
manifest {
58+
attributes(
59+
'Implementation-Title': moduleName,
60+
'Implementation-Version': version,
61+
'Main-Class': mainClassName)
62+
}
6963
}
70-
}
71-
72-
run {
73-
dependsOn jar
74-
doFirst {
75-
jvmArgs += [
76-
'--module-path', files(configurations.runtimeClasspath, jar.archiveFile).asPath,
77-
'--module', "${moduleName}/${mainClassName}"
78-
]
79-
classpath = files()
64+
65+
tasks.withType(JavaCompile) {
66+
options.encoding = 'UTF-8'
67+
if (!useModules) {
68+
exclude '*module-info*'
69+
}
8070
}
81-
}
82-
83-
startScripts {
84-
inputs.property("moduleName", moduleName)
85-
doFirst {
86-
classpath = files()
87-
defaultJvmOpts = [
88-
'-Dswim.config=/server.recon',
89-
'-Xms3g',
90-
'-Xmx3g',
91-
'--module-path', 'APP_HOME_LIBS',
92-
'--module', "${moduleName}/${mainClassName}"
93-
]
71+
72+
run {
73+
dependsOn jar
74+
doFirst {
75+
jvmArgs += [
76+
'--module-path', files(configurations.runtimeClasspath, jar.archiveFile).asPath,
77+
'--module', "${moduleName}/${mainClassName}"
78+
]
79+
classpath = files()
80+
}
9481
}
95-
doLast {
96-
def bashFile = new File(outputDir, applicationName)
97-
String bashContent = bashFile.text
98-
bashFile.text = bashContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('$APP_HOME/lib'))
99-
100-
def batFile = new File(outputDir, applicationName + ".bat")
101-
String batContent = batFile.text
102-
batFile.text = batContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('%APP_HOME%\\lib'))
82+
83+
startScripts {
84+
inputs.property("moduleName", moduleName)
85+
doFirst {
86+
classpath = files()
87+
defaultJvmOpts = [
88+
'-Dswim.config=/server.recon',
89+
'-Xms3g',
90+
'-Xmx3g',
91+
'--module-path', 'APP_HOME_LIBS',
92+
'--module', "${moduleName}/${mainClassName}"
93+
]
94+
}
95+
doLast {
96+
def bashFile = new File(outputDir, applicationName)
97+
String bashContent = bashFile.text
98+
bashFile.text = bashContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('$APP_HOME/lib'))
99+
100+
def batFile = new File(outputDir, applicationName + ".bat")
101+
String batContent = batFile.text
102+
batFile.text = batContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('%APP_HOME%\\lib'))
103+
}
103104
}
104-
}
105-
106-
ospackage {
107-
release '1'
108-
prefix '/opt/swim-tutorial'
109-
}
110-
111-
task packageDeb(type: Deb) {
112-
maintainer = 'developer@swim.ai'
113-
114-
configurationFile("/etc/sysconfig/${project.name}")
115-
preInstall "addgroup --quiet --system ${project.name}"
116-
preInstall "adduser --quiet --system --ingroup ${project.name} --no-create-home --disabled-password ${project.name}"
117-
postInstall "systemctl preset ${project.name} > /dev/null 2>&1"
118-
postInstall "systemctl start ${project.name} > /dev/null 2>&1"
119-
preUninstall "systemctl disable ${project.name} > /dev/null 2>&1"
120-
preUninstall "systemctl stop ${project.name} > /dev/null 2>&1"
121-
postUninstall "systemctl daemon-reload > /dev/null 2>&1"
122-
123-
from('pkg') {
124-
into '/etc/systemd/system'
125-
include '*.service'
126-
addParentDirs false
127-
expand project.properties
128-
user 'root'
129-
permissionGroup 'root'
130-
fileMode = 0644
105+
106+
ospackage {
107+
release '1'
108+
prefix '/opt/swim-tutorial'
131109
}
132110

133-
from('pkg') {
134-
into '/etc/sysconfig'
135-
include "${project.name}"
136-
user 'root'
137-
permissionGroup 'root'
138-
fileMode = 0644
139-
fileType CONFIG | NOREPLACE
111+
task packageDeb(type: Deb) {
112+
maintainer = 'developer@swim.ai'
113+
114+
configurationFile("/etc/sysconfig/${project.name}")
115+
preInstall "addgroup --quiet --system ${project.name}"
116+
preInstall "adduser --quiet --system --ingroup ${project.name} --no-create-home --disabled-password ${project.name}"
117+
postInstall "systemctl preset ${project.name} > /dev/null 2>&1"
118+
postInstall "systemctl start ${project.name} > /dev/null 2>&1"
119+
preUninstall "systemctl disable ${project.name} > /dev/null 2>&1"
120+
preUninstall "systemctl stop ${project.name} > /dev/null 2>&1"
121+
postUninstall "systemctl daemon-reload > /dev/null 2>&1"
122+
123+
from('pkg') {
124+
into '/etc/systemd/system'
125+
include '*.service'
126+
addParentDirs false
127+
expand project.properties
128+
user 'root'
129+
permissionGroup 'root'
130+
fileMode = 0644
131+
}
132+
133+
from('pkg') {
134+
into '/etc/sysconfig'
135+
include "${project.name}"
136+
user 'root'
137+
permissionGroup 'root'
138+
fileMode = 0644
139+
fileType CONFIG | NOREPLACE
140+
}
140141
}
141-
}
142142
}

server/gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
application.version=3.11.0-SNAPSHOT
1+
swim.version=3.11.0-SNAPSHOT

server/src/main/java/swim/tutorial/DataSource.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,5 @@ void sendCommands() throws InterruptedException {
4646
Thread.sleep(750);
4747
}
4848
}
49+
4950
}

server/src/main/java/swim/tutorial/TutorialPlane.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,14 @@
33
import swim.api.SwimRoute;
44
import swim.api.agent.AgentRoute;
55
import swim.api.plane.AbstractPlane;
6-
import swim.api.space.Space;
76
import swim.client.ClientRuntime;
87
import swim.kernel.Kernel;
98
import swim.server.ServerLoader;
109

1110
public class TutorialPlane extends AbstractPlane {
1211

1312
@SwimRoute("/unit/:id")
14-
AgentRoute<UnitAgent> unitAgent;
13+
private AgentRoute<UnitAgent> unitAgent;
1514

1615
public static void main(String[] args) throws InterruptedException {
1716
final Kernel kernel = ServerLoader.loadServer();
Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package swim.tutorial;
22

3-
import java.util.Iterator;
43
import swim.api.SwimLane;
54
import swim.api.agent.AbstractAgent;
65
import swim.api.lane.CommandLane;
@@ -10,35 +9,18 @@
109
import swim.recon.Recon;
1110
import swim.structure.Record;
1211
import swim.structure.Value;
12+
import java.util.Iterator;
1313

1414
public class UnitAgent extends AbstractAgent {
1515

1616
@SwimLane("histogram")
17-
protected final MapLane<Long, Value> histogram = this.<Long, Value>mapLane()
18-
.didUpdate((k,n,o) -> {
17+
private final MapLane<Long, Value> histogram = this.<Long, Value>mapLane()
18+
.didUpdate((k, n, o) -> {
1919
logMessage("histogram: replaced " + k + "'s value to " + Recon.toString(n) + " from " + Recon.toString(o));
2020
dropOldData();
2121
});
22-
23-
24-
private void dropOldData() {
25-
final long now = System.currentTimeMillis();
26-
final Iterator<Long> iterator = histogram.keyIterator();
27-
while(iterator.hasNext()) {
28-
long key = iterator.next();
29-
if ((now - key) > 2*60*1000L) {
30-
// remove items that are older than 2 minutes
31-
histogram.remove(key);
32-
} else {
33-
// map is sorted by the sort order of the keys, so break out of the loop on the first
34-
// key that is newer than 2 minutes
35-
break;
36-
}
37-
}
38-
}
39-
4022
@SwimLane("history")
41-
protected final ListLane<Value> history = this.<Value>listLane()
23+
private final ListLane<Value> history = this.<Value>listLane()
4224
.didUpdate((idx, newValue, oldValue) -> {
4325
logMessage("history: appended {" + idx + ", " + Recon.toString(newValue) + "}");
4426
final long bucket = newValue.getItem(0).longValue() / 5000 * 5000;
@@ -47,25 +29,39 @@ private void dropOldData() {
4729
final int willDrop = Math.max(0, this.history.size() - 200);
4830
this.history.drop(willDrop);
4931
});
50-
5132
@SwimLane("latest")
52-
protected final ValueLane<Value> latest = this.<Value>valueLane()
33+
private final ValueLane<Value> latest = this.<Value>valueLane()
5334
.didSet((newValue, oldValue) -> {
5435
logMessage("latest: set to " + Recon.toString(newValue) + " from " + Recon.toString(oldValue));
5536
this.history.add(
5637
Record.create(2)
5738
.item(System.currentTimeMillis())
5839
.item(newValue)
59-
);
40+
);
6041
});
61-
6242
@SwimLane("publish")
6343
public final CommandLane<Value> publish = this.<Value>commandLane()
6444
.onCommand(v -> {
6545
logMessage("publish: commanded with " + Recon.toString(v));
6646
latest.set(v);
6747
});
6848

49+
private void dropOldData() {
50+
final long now = System.currentTimeMillis();
51+
final Iterator<Long> iterator = histogram.keyIterator();
52+
while (iterator.hasNext()) {
53+
long key = iterator.next();
54+
if ((now - key) > 2 * 60 * 1000L) {
55+
// remove items that are older than 2 minutes
56+
histogram.remove(key);
57+
} else {
58+
// map is sorted by the sort order of the keys, so break out of the loop on the first
59+
// key that is newer than 2 minutes
60+
break;
61+
}
62+
}
63+
}
64+
6965
private void logMessage(Object o) {
7066
System.out.println("[" + nodeUri() + "] " + o);
7167
}
@@ -74,4 +70,5 @@ private void logMessage(Object o) {
7470
public void didStart() {
7571
logMessage("Hello, world!");
7672
}
73+
7774
}

server/src/main/resources/server.recon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ tutorial: @fabric {
99
serverCompressionLevel: 0# -1 = default; 0 = off; 1-9 = deflate level
1010
clientCompressionLevel: 0# -1 = default; 0 = off; 1-9 = deflate level
1111
}
12-
}
12+
}

0 commit comments

Comments
 (0)