Skip to content

Commit 5f3cbcd

Browse files
committed
Open Source
0 parents  commit 5f3cbcd

18 files changed

Lines changed: 782 additions & 0 deletions

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.DS_Store
2+
*.DS_Store
3+
.idea
4+
.gradle
5+
.vscode
6+
build
7+
out

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Swim Tutorial
2+
3+
Swim is a completely integrated solution for building scalable, end-to-end streaming applications. Instead of requiring separate message brokers, app servers, and databases, Swim applications consist of just two pieces:
4+
5+
- A **Swim server** with *built-in* persistence, messaging, scheduling, clustering, replication, introspection, and security
6+
7+
- A **user interface** that uses Swim's streaming UI frameworks to visualize data from Swim servers in real-time
8+
9+
Visit [server](https://github.com/swimos/swim-tutorial/blob/master/server) to learn how to stand up your data in a Swim server.
10+
11+
Then, visit [ui](https://github.com/swimos/swim-tutorial/blob/master/ui) to see this data like never before.

server/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Swim Server
2+
3+
Swim unifies the traditionally disparate roles of database, message broker, job manager, and application server, into a few simple constructs.
4+
5+
## Web Agents
6+
7+
Swim implements a general purpose distributed object model. The "objects" in this model are **Web Agents**.
8+
9+
[Creating a class](http://github.com/swimos/swim-tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L13) that extends `swim.api.agent.AbstractAgent` defines a *template* for Web Agents (though not a useful one until we add some [lanes](#lanes)).
10+
11+
Visit the [documentation](https://developer.swim.ai/concepts/agents/) for further details about Web Agents.
12+
13+
## Lanes
14+
15+
If Web Agents are objects, then **lanes** serve as the "fields" of those objects. Lanes come in many flavors, e.g. value lanes, map lanes, and command lanes.
16+
17+
Continuing our analogy, *lane callback* functions serve as the "methods" of Web Agents.
18+
19+
Each lane type defines a set of overridable (default no-op) lifecycle callbacks. For example, [sending a command message](#sending-data-do-swim) to any command lane will trigger its [`onCommand` callback](http://github.com/swimos/swim-tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L51-L54). On the other hand, [setting a value lane](http://github.com/swimos/swim-tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L53) will trigger its `willSet` callback, then update its value, then trigger its [`didSet` callback](http://github.com/swimos/swim-tutorial/tree/master/server/src/main/java/swim/tutorial/UnitAgent.java#L40-L47).
20+
21+
Visit the [documentation](https://developer.swim.ai/concepts/lanes/) for further details about lanes.
22+
23+
## Standing a Swim Server
24+
25+
A Swim server is loaded with a **plane**, which provides the runtime for Web Agents and routes messages to the correct lanes.
26+
27+
A plane must [declare an `AgentType` field](http://github.com/swimos/swim-tutorial/tree/master/server/src/main/java/swim/tutorial/TutorialPlane.java#L13-L14) for each Web Agent type.
28+
29+
Use the `ServerLoader` utility class to [load a plane into a Swim server](http://github.com/swimos/swim-tutorial/tree/master/server/src/main/java/swim/tutorial/TutorialPlane.java#L18). Note that your module must [`provide` `swim.api.plane.Plane` with your custom plane class](http://github.com/swimos/swim-tutorial/tree/master/server/src/main/java/module-info.java#L8).
30+
31+
Visit the [documentation](https://developer.swim.ai/concepts) for further details about these concepts.
32+
33+
## Populating a Swim Server With Your Data
34+
35+
Every Swim server can be written to and read from by external processes using the Swim API. The simplest way to utilize this API is to use a **Swim client** instance to [send commands to command lanes](http://github.com/swimos/swim-tutorial/tree/master/server/src/main/java/swim/tutorial/TutorialPlane.java#L40).
36+
37+
Visit the [documentation](https://developer.swim.ai/concepts) for further details about these concepts.
38+
39+
## Subscribing to Swim Server Data
40+
41+
Swim client instances use Swim **links** to pull data from a Swim lanes. Like their corresponding lanes, links have overridable callback functions that can be used to [populate UIs](http://github.com/swimos/swim-tutorial/tree/master/ui/index.html#L111-L133).
42+
43+
Visit the [documentation](https://developer.swim.ai/concepts/links/) for further details about links.

server/build.gradle

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
import java.util.regex.Matcher
2+
3+
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+
}
10+
}
11+
12+
apply plugin: 'java'
13+
apply plugin: 'java-library'
14+
apply plugin: 'application'
15+
apply plugin: 'nebula.ospackage-application'
16+
17+
group = 'ai.swim'
18+
description = 'tutorial Web Agents'
19+
ext.moduleName = 'swim.tutorial'
20+
sourceCompatibility = 1.9
21+
version = project.property('application.version')
22+
mainClassName = 'swim.tutorial.TutorialPlane'
23+
24+
//def moduleName = 'swim.tutorial'
25+
def jvmVersion = System.getProperty('java.version').split('\\.')[0] as Integer
26+
def useModules = jvmVersion >= 9 && !project.hasProperty('no-modules')
27+
28+
repositories {
29+
jcenter()
30+
maven {
31+
url "https://oss.sonatype.org/content/repositories/snapshots/"
32+
}
33+
34+
}
35+
36+
dependencies {
37+
compile 'ai.swim:swim-loader:3.9.1-SNAPSHOT'
38+
compile 'ai.swim:swim-server:3.9.1-SNAPSHOT'
39+
compile 'ai.swim:swim-client:3.9.1-SNAPSHOT'
40+
}
41+
42+
afterEvaluate {
43+
compileJava {
44+
if (useModules) {
45+
doFirst {
46+
options.compilerArgs += [
47+
'--module-path', classpath.asPath,
48+
]
49+
classpath = files()
50+
}
51+
}
52+
options.compilerArgs += ['-Xlint']
53+
options.encoding = 'UTF-8'
54+
}
55+
56+
jar {
57+
inputs.property('moduleName', moduleName)
58+
manifest {
59+
attributes(
60+
'Implementation-Title': moduleName,
61+
'Implementation-Version': version,
62+
'Main-Class': mainClassName)
63+
}
64+
}
65+
66+
tasks.withType(JavaCompile) {
67+
options.encoding = 'UTF-8'
68+
if (!useModules) {
69+
exclude '*module-info*'
70+
}
71+
}
72+
73+
run {
74+
dependsOn jar
75+
doFirst {
76+
jvmArgs += [
77+
'--module-path', files(configurations.runtimeClasspath, jar.archivePath).asPath,
78+
'--module', "${moduleName}/${mainClassName}"
79+
]
80+
classpath = files()
81+
}
82+
}
83+
84+
startScripts {
85+
inputs.property("moduleName", moduleName)
86+
doFirst {
87+
classpath = files()
88+
defaultJvmOpts = [
89+
'-Dswim.config=/etc/swim-tutorial/server.recon',
90+
'-Xms3g',
91+
'-Xmx3g',
92+
'--module-path', 'APP_HOME_LIBS',
93+
'--module', "${moduleName}/${mainClassName}"
94+
]
95+
}
96+
doLast {
97+
def bashFile = new File(outputDir, applicationName)
98+
String bashContent = bashFile.text
99+
bashFile.text = bashContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('$APP_HOME/lib'))
100+
101+
def batFile = new File(outputDir, applicationName + ".bat")
102+
String batContent = batFile.text
103+
batFile.text = batContent.replaceFirst('APP_HOME_LIBS', Matcher.quoteReplacement('%APP_HOME%\\lib'))
104+
}
105+
}
106+
107+
ospackage {
108+
release '1'
109+
prefix '/opt/swim-tutorial'
110+
}
111+
112+
task packageDeb(type: Deb) {
113+
maintainer = 'developer@swim.ai'
114+
115+
configurationFile("/etc/sysconfig/${project.name}")
116+
preInstall "addgroup --quiet --system ${project.name}"
117+
preInstall "adduser --quiet --system --ingroup ${project.name} --no-create-home --disabled-password ${project.name}"
118+
postInstall "systemctl preset ${project.name} > /dev/null 2>&1"
119+
postInstall "systemctl start ${project.name} > /dev/null 2>&1"
120+
preUninstall "systemctl disable ${project.name} > /dev/null 2>&1"
121+
preUninstall "systemctl stop ${project.name} > /dev/null 2>&1"
122+
postUninstall "systemctl daemon-reload > /dev/null 2>&1"
123+
124+
from('pkg') {
125+
into '/etc/systemd/system'
126+
include '*.service'
127+
addParentDirs false
128+
expand project.properties
129+
user 'root'
130+
permissionGroup 'root'
131+
fileMode = 0644
132+
}
133+
134+
from('pkg') {
135+
into '/etc/sysconfig'
136+
include "${project.name}"
137+
user 'root'
138+
permissionGroup 'root'
139+
fileMode = 0644
140+
fileType CONFIG | NOREPLACE
141+
}
142+
}
143+
}

server/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
application.version=3.9.0
53.9 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
distributionBase=GRADLE_USER_HOME
2+
distributionPath=wrapper/dists
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists

server/gradlew

Lines changed: 172 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)