jubilee 0.5.0 → 1.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +57 -12
- data/Rakefile +3 -3
- data/VERSION +1 -1
- data/bin/jubilee_d +6 -3
- data/examples/client/sockjs-0.3.4.min.js +27 -0
- data/examples/client/vertxbus.js +216 -0
- data/examples/jubilee.conf.rb +18 -0
- data/jars/hazelcast-2.6.jar +0 -0
- data/jars/jackson-annotations-2.2.2.jar +0 -0
- data/jars/jackson-databind-2.2.2.jar +0 -0
- data/java/src/org/jruby/jubilee/Server.java +138 -119
- data/java/src/org/jruby/jubilee/vertx/JubileeVertx.java +38 -0
- data/jubilee.gemspec +16 -6
- data/lib/jubilee/cli.rb +30 -18
- data/lib/jubilee/configuration.rb +130 -18
- data/lib/jubilee/jubilee.jar +0 -0
- data/lib/jubilee.rb +3 -0
- data/lib/vertx/README.md +7 -0
- data/lib/vertx/buffer.rb +251 -0
- data/lib/vertx/event_bus.rb +206 -0
- data/lib/vertx/shared_data.rb +214 -0
- data/lib/vertx.rb +26 -0
- data/test/jubilee/{test_config.rb → test_configuration.rb} +2 -1
- metadata +17 -10
- data/examples/ssl/ServerTest.java +0 -19
- data/examples/ssl/webroot/index.html +0 -10
@@ -2,148 +2,167 @@ package org.jruby.jubilee;
|
|
2
2
|
|
3
3
|
import org.jruby.*;
|
4
4
|
import org.jruby.anno.JRubyMethod;
|
5
|
+
import org.jruby.jubilee.vertx.JubileeVertx;
|
5
6
|
import org.jruby.runtime.Block;
|
6
7
|
import org.jruby.runtime.ObjectAllocator;
|
7
8
|
import org.jruby.runtime.ThreadContext;
|
8
9
|
import org.jruby.runtime.builtin.IRubyObject;
|
9
10
|
import org.vertx.java.core.Handler;
|
10
11
|
import org.vertx.java.core.Vertx;
|
11
|
-
import org.vertx.java.core.VertxFactory;
|
12
12
|
import org.vertx.java.core.http.HttpServer;
|
13
13
|
import org.vertx.java.core.http.HttpServerRequest;
|
14
14
|
import org.vertx.java.core.json.JsonArray;
|
15
15
|
import org.vertx.java.core.json.JsonObject;
|
16
16
|
|
17
17
|
public class Server extends RubyObject {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
18
|
+
private Vertx vertx;
|
19
|
+
private HttpServer httpServer;
|
20
|
+
private RackApplication app;
|
21
|
+
private boolean running = false;
|
22
|
+
private boolean ssl = false;
|
23
|
+
private String keyStorePath;
|
24
|
+
private String keyStorePassword;
|
25
|
+
private String eventBusPrefix;
|
26
|
+
private int numberOfWorkers;
|
27
|
+
private int port;
|
28
|
+
private String host;
|
29
|
+
private int clusterPort;
|
30
|
+
private String clusterHost;
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
public static void createServerClass(Ruby runtime) {
|
33
|
+
RubyModule mJubilee = runtime.defineModule("Jubilee");
|
34
|
+
RubyClass serverClass = mJubilee.defineClassUnder("VertxServer", runtime.getObject(), ALLOCATOR);
|
35
|
+
serverClass.defineAnnotatedMethods(Server.class);
|
36
|
+
}
|
37
|
+
|
38
|
+
private static ObjectAllocator ALLOCATOR = new ObjectAllocator() {
|
39
|
+
public IRubyObject allocate(Ruby ruby, RubyClass rubyClass) {
|
40
|
+
return new Server(ruby, rubyClass);
|
41
|
+
}
|
42
|
+
};
|
35
43
|
|
36
|
-
|
37
|
-
|
38
|
-
return new Server(ruby, rubyClass);
|
44
|
+
public Server(Ruby ruby, RubyClass rubyClass) {
|
45
|
+
super(ruby, rubyClass);
|
39
46
|
}
|
40
|
-
};
|
41
47
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
48
|
+
/**
|
49
|
+
* Initialize jubilee server, take a rack application and a configuration hash as parameter
|
50
|
+
*
|
51
|
+
* @param context
|
52
|
+
* @param args
|
53
|
+
* @param block
|
54
|
+
* @return
|
55
|
+
*/
|
56
|
+
@JRubyMethod(name = "initialize")
|
57
|
+
public IRubyObject initialize(ThreadContext context, IRubyObject app, IRubyObject config, Block block) {
|
58
|
+
Ruby runtime = getRuntime();
|
59
|
+
/* configuration keys */
|
60
|
+
RubyHash options = config.convertToHash();
|
61
|
+
RubySymbol port_k = runtime.newSymbol("Port");
|
62
|
+
RubySymbol host_k = runtime.newSymbol("Host");
|
63
|
+
RubySymbol cluster_port_k = runtime.newSymbol("cluster_port");
|
64
|
+
RubySymbol cluster_host_k = runtime.newSymbol("cluster_host");
|
65
|
+
RubySymbol ssl_k = runtime.newSymbol("ssl");
|
66
|
+
RubySymbol keystore_path_k = runtime.newSymbol("keystore_path");
|
67
|
+
RubySymbol keystore_password_k = runtime.newSymbol("keystore_password");
|
68
|
+
RubySymbol eventbus_prefix_k = runtime.newSymbol("eventbus_prefix");
|
69
|
+
RubySymbol number_of_workers_k = runtime.newSymbol("number_of_workers");
|
47
70
|
|
48
|
-
|
49
|
-
|
50
|
-
* @param context
|
51
|
-
* @param args
|
52
|
-
* @param block
|
53
|
-
* @return
|
54
|
-
*/
|
55
|
-
@JRubyMethod(name = "initialize")
|
56
|
-
public IRubyObject initialize(ThreadContext context, IRubyObject app, IRubyObject config, Block block) {
|
57
|
-
Ruby runtime = getRuntime();
|
58
|
-
RubyHash options = config.convertToHash();
|
59
|
-
RubySymbol port_k = runtime.newSymbol("Port");
|
60
|
-
RubySymbol host_k = runtime.newSymbol("Host");
|
61
|
-
RubySymbol ssl_k = runtime.newSymbol("ssl");
|
62
|
-
RubySymbol keystore_path_k = runtime.newSymbol("keystore_path");
|
63
|
-
RubySymbol keystore_password_k = runtime.newSymbol("keystore_password");
|
64
|
-
RubySymbol eventbus_prefix_k = runtime.newSymbol("eventbus_prefix");
|
65
|
-
RubySymbol number_of_workers_k = runtime.newSymbol("number_of_workers");
|
66
|
-
this.port = RubyInteger.fix2int(options.op_aref(context, port_k));
|
67
|
-
if (options.has_key_p(host_k).isTrue()) {
|
71
|
+
/* retrieve from passed in options */
|
72
|
+
this.port = Integer.parseInt(options.op_aref(context, port_k).toString());
|
68
73
|
this.host = options.op_aref(context, host_k).toString();
|
69
|
-
|
70
|
-
this.
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
74
|
+
|
75
|
+
this.ssl = options.op_aref(context, ssl_k).isTrue();
|
76
|
+
this.numberOfWorkers = Integer.parseInt(options.op_aref(context, number_of_workers_k).toString());
|
77
|
+
if (options.has_key_p(keystore_path_k).isTrue()) {
|
78
|
+
this.keyStorePath = options.op_aref(context, keystore_path_k).toString();
|
79
|
+
this.keyStorePassword = options.op_aref(context, keystore_password_k).toString();
|
80
|
+
}
|
81
|
+
this.app = new RackApplication(app, this.ssl, this.numberOfWorkers);
|
82
|
+
if (options.has_key_p(eventbus_prefix_k).isTrue())
|
83
|
+
this.eventBusPrefix = options.op_aref(context, eventbus_prefix_k).toString();
|
84
|
+
|
85
|
+
/* init vertx */
|
86
|
+
if (options.has_key_p(cluster_host_k).isTrue()) {
|
87
|
+
this.clusterHost = options.op_aref(context, cluster_host_k).toString();
|
88
|
+
if (options.has_key_p(cluster_port_k).isTrue()) {
|
89
|
+
this.clusterPort = Integer.parseInt(options.op_aref(context, cluster_port_k).toString());
|
90
|
+
this.vertx = JubileeVertx.init(clusterPort, clusterHost);
|
91
|
+
}
|
92
|
+
this.vertx = JubileeVertx.init(clusterHost);
|
93
|
+
} else {
|
94
|
+
this.vertx = JubileeVertx.init();
|
95
|
+
}
|
96
|
+
|
97
|
+
httpServer = vertx.createHttpServer();
|
98
|
+
return this;
|
82
99
|
}
|
83
|
-
running = false;
|
84
|
-
return this;
|
85
|
-
}
|
86
100
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
101
|
+
/**
|
102
|
+
* Start http server, initialize states
|
103
|
+
*
|
104
|
+
* @param context
|
105
|
+
* @param block
|
106
|
+
* @return
|
107
|
+
*/
|
108
|
+
@JRubyMethod(name = "start")
|
109
|
+
public IRubyObject start(final ThreadContext context, final Block block) {
|
110
|
+
httpServer.setAcceptBacklog(10000);
|
111
|
+
httpServer.requestHandler(new Handler<HttpServerRequest>() {
|
112
|
+
public void handle(final HttpServerRequest req) {
|
113
|
+
app.call(req);
|
114
|
+
}
|
115
|
+
});
|
116
|
+
if (eventBusPrefix != null) {
|
117
|
+
JsonObject config = new JsonObject().putString("prefix", eventBusPrefix);
|
118
|
+
JsonArray allowAll = new JsonArray();
|
119
|
+
allowAll.add(new JsonObject());
|
120
|
+
// TODO read inbounds and outbounds from config file
|
121
|
+
vertx.createSockJSServer(httpServer).bridge(config, allowAll, allowAll);
|
122
|
+
}
|
123
|
+
if (ssl) httpServer.setSSL(true).setKeyStorePath(this.keyStorePath)
|
124
|
+
.setKeyStorePassword(this.keyStorePassword);
|
125
|
+
httpServer.listen(this.port, this.host);
|
126
|
+
this.running = true;
|
127
|
+
return this;
|
106
128
|
}
|
107
|
-
if (ssl) httpServer.setSSL(true).setKeyStorePath(this.keyStorePath)
|
108
|
-
.setKeyStorePassword(this.keyStorePassword);
|
109
|
-
httpServer.listen(this.port, this.host);
|
110
|
-
return this;
|
111
|
-
}
|
112
129
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
130
|
+
/**
|
131
|
+
* Set timeout for keep alive connection
|
132
|
+
*
|
133
|
+
* @param context
|
134
|
+
* @param timeout (in TimeUnit.SECONDS)
|
135
|
+
* @return this
|
136
|
+
*/
|
137
|
+
@JRubyMethod(name = "persistent_timeout=")
|
138
|
+
public IRubyObject setPersistentTimeout(final ThreadContext context, final IRubyObject timeout) {
|
139
|
+
// FIXME
|
140
|
+
//httpServer.setPersistentTimeout(RubyInteger.fix2long(timeout) * 1000);
|
141
|
+
return this;
|
142
|
+
}
|
125
143
|
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
144
|
+
/**
|
145
|
+
* Stop the HttpServer
|
146
|
+
*
|
147
|
+
* @param context
|
148
|
+
* @param args if shutdown abruptly
|
149
|
+
* @param block callback on close
|
150
|
+
* @return
|
151
|
+
*/
|
152
|
+
@JRubyMethod(name = {"stop", "close"}, optional = 1)
|
153
|
+
public IRubyObject close(ThreadContext context, IRubyObject[] args, Block block) {
|
154
|
+
if (running) {
|
155
|
+
if (args.length == 1)
|
156
|
+
app.shutdown(args[0].isTrue());
|
157
|
+
else
|
158
|
+
app.shutdown(false);
|
140
159
|
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
160
|
+
this.running = false;
|
161
|
+
httpServer.close();
|
162
|
+
if (block.isGiven()) block.yieldSpecific(context);
|
163
|
+
} else {
|
164
|
+
getRuntime().getOutputStream().println("jubilee server not running?");
|
165
|
+
}
|
166
|
+
return getRuntime().getNil();
|
146
167
|
}
|
147
|
-
return getRuntime().getNil();
|
148
|
-
}
|
149
168
|
}
|
@@ -0,0 +1,38 @@
|
|
1
|
+
package org.jruby.jubilee.vertx;
|
2
|
+
|
3
|
+
import org.vertx.java.core.Vertx;
|
4
|
+
import org.vertx.java.core.VertxFactory;
|
5
|
+
import org.vertx.java.core.eventbus.EventBus;
|
6
|
+
import org.vertx.java.core.shareddata.SharedData;
|
7
|
+
|
8
|
+
/**
|
9
|
+
* Created with IntelliJ IDEA.
|
10
|
+
* User: isaiah
|
11
|
+
* Date: 20/09/2013
|
12
|
+
* Time: 15:24
|
13
|
+
*/
|
14
|
+
public class JubileeVertx {
|
15
|
+
public static Vertx vertx;
|
16
|
+
private JubileeVertx() {
|
17
|
+
}
|
18
|
+
public static synchronized Vertx init(int port, String host) {
|
19
|
+
if (vertx != null) return vertx;
|
20
|
+
vertx = VertxFactory.newVertx(port, host);
|
21
|
+
return vertx;
|
22
|
+
}
|
23
|
+
public static synchronized Vertx init(String host) {
|
24
|
+
if (vertx != null) return vertx;
|
25
|
+
vertx = VertxFactory.newVertx(host);
|
26
|
+
return vertx;
|
27
|
+
}
|
28
|
+
public static synchronized Vertx init() {
|
29
|
+
if (vertx != null) return vertx;
|
30
|
+
vertx = VertxFactory.newVertx();
|
31
|
+
return vertx;
|
32
|
+
}
|
33
|
+
|
34
|
+
public synchronized static Vertx vertx() {
|
35
|
+
if (vertx == null) init();
|
36
|
+
return vertx;
|
37
|
+
}
|
38
|
+
}
|
data/jubilee.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "jubilee"
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "1.0.0.beta1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Isaiah Peng"]
|
12
|
-
s.date = "2013-09-
|
12
|
+
s.date = "2013-09-22"
|
13
13
|
s.description = "Jubilee is a experimental webserver built for speed, it's based on Vertx."
|
14
14
|
s.email = "issaria@gmail.com"
|
15
15
|
s.executables = ["jubilee", "jubilee_d"]
|
@@ -28,11 +28,15 @@ Gem::Specification.new do |s|
|
|
28
28
|
"VERSION",
|
29
29
|
"bin/jubilee",
|
30
30
|
"bin/jubilee_d",
|
31
|
+
"examples/client/sockjs-0.3.4.min.js",
|
32
|
+
"examples/client/vertxbus.js",
|
33
|
+
"examples/jubilee.conf.rb",
|
31
34
|
"examples/jubilee/keystore.jks",
|
32
35
|
"examples/jubilee/server-keystore.jks",
|
33
|
-
"
|
34
|
-
"
|
36
|
+
"jars/hazelcast-2.6.jar",
|
37
|
+
"jars/jackson-annotations-2.2.2.jar",
|
35
38
|
"jars/jackson-core-2.2.2.jar",
|
39
|
+
"jars/jackson-databind-2.2.2.jar",
|
36
40
|
"jars/netty-all-4.0.4.Final.jar",
|
37
41
|
"jars/vertx-core-2.1.0-SNAPSHOT.jar",
|
38
42
|
"java/src/jubilee/JubileeService.java",
|
@@ -48,6 +52,7 @@ Gem::Specification.new do |s|
|
|
48
52
|
"java/src/org/jruby/jubilee/impl/NullIO.java",
|
49
53
|
"java/src/org/jruby/jubilee/impl/RubyIORackErrors.java",
|
50
54
|
"java/src/org/jruby/jubilee/impl/RubyIORackInput.java",
|
55
|
+
"java/src/org/jruby/jubilee/vertx/JubileeVertx.java",
|
51
56
|
"jubilee.gemspec",
|
52
57
|
"lib/jubilee.rb",
|
53
58
|
"lib/jubilee/application.rb",
|
@@ -59,10 +64,15 @@ Gem::Specification.new do |s|
|
|
59
64
|
"lib/jubilee/server.rb",
|
60
65
|
"lib/jubilee/version.rb",
|
61
66
|
"lib/rack/handler/jubilee.rb",
|
67
|
+
"lib/vertx.rb",
|
68
|
+
"lib/vertx/README.md",
|
69
|
+
"lib/vertx/buffer.rb",
|
70
|
+
"lib/vertx/event_bus.rb",
|
71
|
+
"lib/vertx/shared_data.rb",
|
62
72
|
"test/.ruby-version",
|
63
73
|
"test/config/app.rb",
|
64
74
|
"test/jubilee/test_cli.rb",
|
65
|
-
"test/jubilee/
|
75
|
+
"test/jubilee/test_configuration.rb",
|
66
76
|
"test/jubilee/test_rack_server.rb",
|
67
77
|
"test/jubilee/test_response.rb",
|
68
78
|
"test/jubilee/test_server.rb",
|
@@ -77,7 +87,7 @@ Gem::Specification.new do |s|
|
|
77
87
|
s.licenses = ["MIT"]
|
78
88
|
s.require_paths = ["lib"]
|
79
89
|
s.rubygems_version = "1.8.24"
|
80
|
-
s.summary = "
|
90
|
+
s.summary = "More than a server for rack applications."
|
81
91
|
|
82
92
|
if s.respond_to? :specification_version then
|
83
93
|
s.specification_version = 3
|
data/lib/jubilee/cli.rb
CHANGED
@@ -12,20 +12,26 @@ module Jubilee
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def parse_options
|
15
|
-
|
15
|
+
argv = @argv.dup
|
16
|
+
@parser.parse! argv
|
16
17
|
if @argv.last
|
17
|
-
@options[:rackup] =
|
18
|
+
@options[:rackup] = argv.shift
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
22
|
def run
|
22
23
|
parse_options
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
if @options[:daemon]
|
25
|
+
puts "Starting Jubilee in daemon mode..."
|
26
|
+
`jubilee_d #{(@argv - ["-d", "--daemon"]).join(" ")}`
|
27
|
+
else
|
28
|
+
@config = Jubilee::Configuration.new(@options)
|
29
|
+
server = Jubilee::Server.new(@config.app, @config.options)
|
30
|
+
server.start
|
31
|
+
puts "Jubilee is listening on port #{@config.options[:Port]}, press Ctrl+C to quit"
|
32
|
+
starter = org.jruby.jubilee.deploy.Starter.new
|
33
|
+
starter.block
|
34
|
+
end
|
29
35
|
end
|
30
36
|
|
31
37
|
def setup_options
|
@@ -40,17 +46,17 @@ module Jubilee
|
|
40
46
|
o.separator ""
|
41
47
|
o.separator "Server options:"
|
42
48
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
+
o.on "-c", "--config PATH", "Load PATH as a config file" do |arg|
|
50
|
+
@options[:config_file] = arg
|
51
|
+
end
|
52
|
+
o.on "-d", "--daemon", "Daemonize the server" do
|
53
|
+
@options[:daemon] = true
|
54
|
+
end
|
49
55
|
o.on "--dir DIR", "Change to DIR before starting" do |arg|
|
50
|
-
@options[:
|
56
|
+
@options[:working_directory] = arg
|
51
57
|
end
|
52
58
|
o.on "-p", "--port PORT", "Defind which PORT the server should bind" do |arg|
|
53
|
-
@options[:Port] = arg
|
59
|
+
@options[:Port] = arg.to_i
|
54
60
|
end
|
55
61
|
o.on "--host HOST", "Defind which HOST the server should bind, default 0.0.0.0" do |arg|
|
56
62
|
@options[:Host] = arg
|
@@ -70,11 +76,17 @@ module Jubilee
|
|
70
76
|
@options[:keystore_password] = arg
|
71
77
|
end
|
72
78
|
o.separator ""
|
73
|
-
o.separator "Event bus options"
|
74
|
-
o.on "--eventbus PREFIX", "Event bus prefix" do |arg|
|
79
|
+
o.separator "Event bus options:"
|
80
|
+
o.on "--eventbus PREFIX", "Event bus prefix, use allow-all policy by default" do |arg|
|
75
81
|
@options[:eventbus_prefix] = arg
|
76
82
|
end
|
77
83
|
|
84
|
+
o.separator ""
|
85
|
+
o.separator "Clustering options:"
|
86
|
+
o.on "--cluster", "Enable clustering" do
|
87
|
+
@options[:cluster_host] = "0.0.0.0"
|
88
|
+
end
|
89
|
+
|
78
90
|
o.separator ""
|
79
91
|
o.separator "Common options:"
|
80
92
|
o.on "--verbose", "Log low level debug information" do
|
@@ -1,10 +1,25 @@
|
|
1
|
+
# -*- encoding: binary -*-
|
2
|
+
|
1
3
|
module Jubilee
|
4
|
+
# Implements a simple DSL for configuring a Jubilee server
|
5
|
+
#
|
6
|
+
# See https://github.com/isaiah/jubilee/examples/jubilee.conf.rb
|
7
|
+
# for example configuration files.
|
2
8
|
class Configuration
|
3
|
-
|
9
|
+
|
10
|
+
attr_accessor :config_file
|
11
|
+
attr_reader :options
|
4
12
|
|
5
13
|
def initialize(options, &block)
|
6
|
-
|
14
|
+
config_file = options.delete(:config_file)
|
15
|
+
@options = options.dup
|
7
16
|
@block = block
|
17
|
+
|
18
|
+
reload
|
19
|
+
end
|
20
|
+
|
21
|
+
def reload
|
22
|
+
instance_eval(File.read(config_file), config_file) if config_file
|
8
23
|
end
|
9
24
|
|
10
25
|
def app
|
@@ -17,24 +32,82 @@ module Jubilee
|
|
17
32
|
end
|
18
33
|
end
|
19
34
|
|
20
|
-
|
21
|
-
|
35
|
+
# sets the host and port jubilee listens to +address+ may be an Integer port
|
36
|
+
# number for a TCP port or an "IP_ADDRESS:PORT" for TCP listeners
|
37
|
+
#
|
38
|
+
# listen 3000 # listen to port 3000 on all TCP interfaces
|
39
|
+
# listen "127.0.0.1:3000" # listen to port 3000 on the loopback interface
|
40
|
+
# listen "[::1]:3000" # listen to port 3000 on the IPv6 loopback interface
|
41
|
+
def listen(address)
|
42
|
+
@options[:host], @options[:port] = expand_addr(address)
|
43
|
+
end
|
44
|
+
|
45
|
+
# sets the working directory for jubilee
|
46
|
+
def working_directory(path)
|
47
|
+
path = File.expand_path(path)
|
48
|
+
if config_file && config_file[0] != ?/ && ! File.readable?("#{path}/#{config_file}")
|
49
|
+
raise ArgumentError,
|
50
|
+
"config_file=#{config_file} would not be accessible in" \
|
51
|
+
" working_directory=#{path}"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
# sets the number of worker threads in the threads pool, Each worker thread
|
56
|
+
# will serve exactly one client at a time.
|
57
|
+
def worker_threads(nr)
|
58
|
+
set_int(:worker_threads, nr, 1)
|
22
59
|
end
|
23
60
|
|
24
|
-
|
25
|
-
|
61
|
+
# set the event bus bridge prefix, prefix, options
|
62
|
+
# eventbus /eventbus, inbound: {foo:bar}, outbound: {foo: bar}
|
63
|
+
# will set the event bus prefix as eventbus "/eventbus", it can be
|
64
|
+
# connected via new EventBus("http://localhost:3215/eventbus"), inbound and
|
65
|
+
# outbound options are security measures that will filter the messages
|
66
|
+
def eventbus(prefix, options = {})
|
67
|
+
@options[:event_bus][:prefix] = prefix
|
68
|
+
@options[:event_bus][:inbound] = options[:inbound]
|
69
|
+
@options[:event_bus][:outbound] = options[:outbound]
|
26
70
|
end
|
27
71
|
|
28
|
-
|
29
|
-
|
72
|
+
# Set the host and port to be discovered by other jubilee instances in the network
|
73
|
+
# +address+ may be an Integer port number for a TCP port or an
|
74
|
+
# "IP_ADDRESS:PORT" for TCP listeners, or "IP_ADDRESS" and let the system
|
75
|
+
# to assign a port
|
76
|
+
def clustering(address)
|
77
|
+
@options[:cluster_host], @options[:cluster_port] = expand_addr(address)
|
30
78
|
end
|
31
|
-
|
32
|
-
|
33
|
-
|
79
|
+
|
80
|
+
# enable debug messages
|
81
|
+
def debug(bool)
|
82
|
+
set_bool(:debug, bool)
|
34
83
|
end
|
35
84
|
|
36
|
-
|
37
|
-
|
85
|
+
# enable daemon mode
|
86
|
+
def daemonize(bool)
|
87
|
+
set_bool(:debug, bool)
|
88
|
+
end
|
89
|
+
|
90
|
+
# enable https mode, provide the :keystore path and password
|
91
|
+
def ssl(options = {})
|
92
|
+
set_path(:ssl_keystore, options[:keystore])
|
93
|
+
@options[:ssl_password] = options[:password]
|
94
|
+
@options[:ssl] = true
|
95
|
+
end
|
96
|
+
|
97
|
+
# sets the path for the PID file of the jubilee event loop
|
98
|
+
def pid(path)
|
99
|
+
set_path(:pid, path)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Allows redirecting $stderr to a given path, if you are daemonizing and
|
103
|
+
# useing the default +logger+, this defautls to log/jubilee.stderr.log
|
104
|
+
def stderr_path(path)
|
105
|
+
set_path(:stderr_path, path)
|
106
|
+
end
|
107
|
+
|
108
|
+
# live stderr_path, this defaults to log/jubilee.stdout.log when daemonized
|
109
|
+
def stdout_path(path)
|
110
|
+
set_path(:stdout_path, path)
|
38
111
|
end
|
39
112
|
|
40
113
|
private
|
@@ -51,11 +124,50 @@ module Jubilee
|
|
51
124
|
end
|
52
125
|
end
|
53
126
|
inner_app
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
127
|
+
end
|
128
|
+
|
129
|
+
def expand_addr(addr)
|
130
|
+
return ["0.0.0.0", addr] if addr === Integer
|
131
|
+
case addr
|
132
|
+
when %r{\A(?:\*:)?(\d+)\z}
|
133
|
+
["0.0.0.0", $1]
|
134
|
+
when %r{\A\[([a-fA-F0-9:]+)\]:(\d+)\z}, %r{\A(.*):(\d+)\z}
|
135
|
+
canonicalize_tcp($1, $2.to_i)
|
136
|
+
when %r{\A?:\*\z}
|
137
|
+
[addr, nil]
|
138
|
+
else
|
139
|
+
raise ArgumentError, "unrecognizable address #{var}=#{addr.inspect}"
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
def set_int(var, n, min)
|
144
|
+
Integer === n or raise ArgumentError, "not an integer: #{var}=#{n.inspect}"
|
145
|
+
n >= min or raise ArgumentError, "too low (< #{min}): #{var}=#{n.inspect}"
|
146
|
+
@options[var] = n
|
147
|
+
end
|
148
|
+
|
149
|
+
def set_path(var, path)
|
150
|
+
case path
|
151
|
+
when NilClass, String
|
152
|
+
@options[var] = path
|
153
|
+
else
|
154
|
+
raise ArgumentError
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def set_bool(var, bool)
|
159
|
+
case bool
|
160
|
+
when true, false
|
161
|
+
@options[var] = bool
|
162
|
+
else
|
163
|
+
raise ArgumentError, "#{var}=#{bool.inspect} not a boolean"
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def canonicalize_tcp(addr, port)
|
168
|
+
packed = Socket.pack_sockaddr_in(port, addr)
|
169
|
+
port, addr = Socket.unpack_sockaddr_in(packed)
|
170
|
+
/:/ =~ addr ? ["[#{addr}]",port] : [addr, port]
|
59
171
|
end
|
60
172
|
end
|
61
173
|
end
|
data/lib/jubilee/jubilee.jar
CHANGED
Binary file
|
data/lib/jubilee.rb
CHANGED
@@ -1,4 +1,7 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), "../jars/jackson-core-2.2.2.jar")
|
2
|
+
require File.join(File.dirname(__FILE__), "../jars/jackson-databind-2.2.2.jar")
|
3
|
+
require File.join(File.dirname(__FILE__), "../jars/jackson-annotations-2.2.2.jar")
|
4
|
+
require File.join(File.dirname(__FILE__), "../jars/hazelcast-2.6.jar")
|
2
5
|
require File.join(File.dirname(__FILE__), "../jars/vertx-core-2.1.0-SNAPSHOT.jar")
|
3
6
|
require File.join(File.dirname(__FILE__), "../jars/netty-all-4.0.4.Final.jar")
|
4
7
|
|
data/lib/vertx/README.md
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Because embeded Vertx doesn't support modules, I have to copy the ruby api
|
2
|
+
from the [mod-lang-jruby](https://github.com/vert-x/mod-lang-jruby) project.
|
3
|
+
|
4
|
+
Some of the files that are not required for the jubilee api are removed.
|
5
|
+
|
6
|
+
These files are exactly the same as the original project, except the directory
|
7
|
+
name changed to follow the ruby conversion of namespaces.
|