murmur-rpc 0.0.7 → 0.0.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/interfaces/ice.rb +159 -158
- data/lib/murmur-rpc.rb +1 -1
- metadata +3 -3
data/lib/interfaces/ice.rb
CHANGED
@@ -1,158 +1,159 @@
|
|
1
|
-
require 'timeout'
|
2
|
-
require 'benchmark'
|
3
|
-
require 'Glacier2'
|
4
|
-
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "vendor", "ice", "Murmur.rb")
|
5
|
-
module Murmur
|
6
|
-
module Ice
|
7
|
-
class ::InvalidMetaException < Exception; end
|
8
|
-
class ::Murmur::Ice::InvalidServerException < Exception; end
|
9
|
-
class Meta
|
10
|
-
def initialize(glacierHost = nil, glacierPort = nil, user = nil, pass = nil, host = "127.0.0.1", port = "6502", icesecret = nil, idletime = nil)
|
11
|
-
ic = nil
|
12
|
-
if icesecret and icesecret != ""
|
13
|
-
props = ::Ice::createProperties
|
14
|
-
props.setProperty "Ice.ImplicitContext", "Shared"
|
15
|
-
props.setProperty "Ice.
|
16
|
-
props.setProperty "Ice.
|
17
|
-
|
18
|
-
idd
|
19
|
-
|
20
|
-
ic
|
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
|
-
method
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
s.
|
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
|
-
@interface.
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
@interface.
|
135
|
-
@
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
@
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
method
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
end
|
1
|
+
require 'timeout'
|
2
|
+
require 'benchmark'
|
3
|
+
require 'Glacier2'
|
4
|
+
require File.join(File.expand_path(File.dirname(__FILE__)), "..", "..", "vendor", "ice", "Murmur.rb")
|
5
|
+
module Murmur
|
6
|
+
module Ice
|
7
|
+
class ::InvalidMetaException < Exception; end
|
8
|
+
class ::Murmur::Ice::InvalidServerException < Exception; end
|
9
|
+
class Meta
|
10
|
+
def initialize(glacierHost = nil, glacierPort = nil, user = nil, pass = nil, host = "127.0.0.1", port = "6502", icesecret = nil, connect_timeout=nil, idletime = nil)
|
11
|
+
ic = nil
|
12
|
+
if icesecret and icesecret != ""
|
13
|
+
props = ::Ice::createProperties
|
14
|
+
props.setProperty "Ice.ImplicitContext", "Shared"
|
15
|
+
props.setProperty "Ice.Override.ConnectTimeout", connect_timeout.to_s unless connect_timeout == nil
|
16
|
+
props.setProperty "Ice.MessageSizeMax", "65536"
|
17
|
+
props.setProperty "Ice.ACM.Client", idletime.to_s unless idletime == nil
|
18
|
+
idd = ::Ice::InitializationData.new
|
19
|
+
idd.properties = props
|
20
|
+
ic = ::Ice::initialize idd
|
21
|
+
ic.getImplicitContext.put("secret", icesecret)
|
22
|
+
else
|
23
|
+
ic = ::Ice::initialize
|
24
|
+
end
|
25
|
+
|
26
|
+
if glacierHost and glacierHost != "" then
|
27
|
+
@glacierHost = glacierHost
|
28
|
+
@glacierPort = glacierPort
|
29
|
+
validate_connection(glacierHost, glacierPort)
|
30
|
+
prx = ic.stringToProxy("Glacier2/router:tcp -h #{glacierHost} -p #{glacierPort}")
|
31
|
+
@router = ::Glacier2::RouterPrx::uncheckedCast(prx).ice_router(nil)
|
32
|
+
@session = @router.createSession(user, pass)
|
33
|
+
end
|
34
|
+
conn = "tcp -h #{host} -p #{port}"
|
35
|
+
@meta = add_proxy_router(Murmur::MetaPrx::checkedCast(ic.stringToProxy("Meta:#{conn}")))
|
36
|
+
raise "Invalid proxy" unless @meta
|
37
|
+
|
38
|
+
@servers = {}
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy
|
42
|
+
begin
|
43
|
+
@router.destroySession @session unless @router.nil?
|
44
|
+
rescue ::Ice::ConnectionLostException
|
45
|
+
# Expected - Ice raises this when the connection is terminated. Yay for exceptions as flow control?
|
46
|
+
end
|
47
|
+
return nil
|
48
|
+
end
|
49
|
+
|
50
|
+
def add_proxy_router(prx)
|
51
|
+
@router ? prx.ice_router(@router) : prx
|
52
|
+
end
|
53
|
+
|
54
|
+
def get_server(id)
|
55
|
+
@servers[id] ||= Server.new(self, @meta, id)
|
56
|
+
end
|
57
|
+
|
58
|
+
def uncache_server(id)
|
59
|
+
@servers[id] = nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def list_servers(only_booted = false)
|
63
|
+
method = only_booted ? :getBootedServers : :getAllServers
|
64
|
+
@meta.send(method).collect do |server|
|
65
|
+
server = add_proxy_router(server)
|
66
|
+
@servers[server.id] ||= Server.new(self, @meta, nil, server)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def validate
|
71
|
+
@meta.getVersion
|
72
|
+
return true
|
73
|
+
end
|
74
|
+
|
75
|
+
def new_server(port = nil)
|
76
|
+
server = @meta.newServer
|
77
|
+
@servers[server.id] = Server.new(self, @meta, nil, add_proxy_router(server))
|
78
|
+
end
|
79
|
+
|
80
|
+
def method_missing(method, *args)
|
81
|
+
method = method.to_s
|
82
|
+
method.gsub!(/_([a-z])/) { $1.upcase }
|
83
|
+
@meta.send method, *args
|
84
|
+
end
|
85
|
+
|
86
|
+
def validate_connection(host, port)
|
87
|
+
Timeout::timeout(2) do
|
88
|
+
begin
|
89
|
+
s = TCPSocket.new(host, port)
|
90
|
+
s.close
|
91
|
+
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
|
92
|
+
raise InvalidMetaException
|
93
|
+
end
|
94
|
+
end
|
95
|
+
rescue Timeout::Error
|
96
|
+
raise InvalidMetaException
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
class Server
|
101
|
+
def initialize(host, meta, id = nil, interface = nil)
|
102
|
+
@meta = meta
|
103
|
+
@host = host
|
104
|
+
if id.nil? and interface.nil? then
|
105
|
+
raise "Must pass either a server ID or a server interface instance"
|
106
|
+
end
|
107
|
+
@interface = interface || begin
|
108
|
+
server = @meta.getServer(id)
|
109
|
+
raise ::Murmur::Ice::InvalidServerException if server.nil?
|
110
|
+
host.add_proxy_router(server)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def id
|
115
|
+
@interface.id
|
116
|
+
end
|
117
|
+
|
118
|
+
def running?
|
119
|
+
@interface.isRunning
|
120
|
+
end
|
121
|
+
|
122
|
+
def config
|
123
|
+
@config = @meta.getDefaultConf.merge(@interface.getAllConf)
|
124
|
+
end
|
125
|
+
|
126
|
+
def destroy!
|
127
|
+
@interface.stop if running?
|
128
|
+
@host.uncache_server @interface.id
|
129
|
+
@interface.delete
|
130
|
+
end
|
131
|
+
alias :delete :destroy!
|
132
|
+
|
133
|
+
def restart!
|
134
|
+
@interface.stop if running?
|
135
|
+
@interface.start
|
136
|
+
@running = nil
|
137
|
+
end
|
138
|
+
|
139
|
+
def [](key)
|
140
|
+
config[key]
|
141
|
+
end
|
142
|
+
|
143
|
+
def []=(key, val)
|
144
|
+
@interface.setConf(key, val.to_s)
|
145
|
+
@config = nil
|
146
|
+
end
|
147
|
+
|
148
|
+
def setConf(key, val)
|
149
|
+
self[key] = val
|
150
|
+
end
|
151
|
+
|
152
|
+
def method_missing(method, *args)
|
153
|
+
method = method.to_s
|
154
|
+
method.gsub!(/_([a-z])/) { $1.upcase }
|
155
|
+
ret = @interface.send method, *args
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
data/lib/murmur-rpc.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: murmur-rpc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.8
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Brian Stolz
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-05-05 00:00:00 +00:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
requirements: []
|
68
68
|
|
69
69
|
rubyforge_project:
|
70
|
-
rubygems_version: 1.
|
70
|
+
rubygems_version: 1.6.2
|
71
71
|
signing_key:
|
72
72
|
specification_version: 3
|
73
73
|
summary: RPC interface for Murmur
|