miu 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -1
- data/Rakefile +1 -1
- data/lib/miu.rb +14 -14
- data/lib/miu/cli.rb +60 -19
- data/lib/miu/command.rb +30 -3
- data/lib/miu/dsl.rb +45 -0
- data/lib/miu/forwarder.rb +1 -1
- data/lib/miu/logger.rb +1 -0
- data/lib/miu/messages.rb +3 -0
- data/lib/miu/messages/base.rb +4 -7
- data/lib/miu/messages/enter.rb +16 -0
- data/lib/miu/messages/leave.rb +16 -0
- data/lib/miu/packet.rb +4 -0
- data/lib/miu/proxy.rb +3 -14
- data/lib/miu/publisher.rb +3 -3
- data/lib/miu/{subscribable.rb → readable.rb} +1 -1
- data/lib/miu/resources.rb +2 -0
- data/lib/miu/resources/base.rb +2 -2
- data/lib/miu/resources/content.rb +2 -1
- data/lib/miu/resources/enter_content.rb +22 -0
- data/lib/miu/resources/leave_content.rb +22 -0
- data/lib/miu/resources/network.rb +1 -1
- data/lib/miu/resources/room.rb +1 -1
- data/lib/miu/resources/text_content.rb +3 -3
- data/lib/miu/resources/user.rb +1 -1
- data/lib/miu/server.rb +14 -7
- data/lib/miu/{socket.rb → sockets.rb} +59 -4
- data/lib/miu/subscriber.rb +3 -3
- data/lib/miu/templates/config/miu.god +7 -0
- data/lib/miu/version.rb +1 -1
- data/lib/miu/{publishable.rb → writable.rb} +1 -1
- data/miu.gemspec +21 -20
- data/spec/miu/dsl_spec.rb +31 -0
- data/spec/miu/messages/base_spec.rb +2 -2
- data/spec/miu/messages/enter_spec.rb +35 -0
- data/spec/miu/messages/leave_spec.rb +35 -0
- data/spec/miu/nodes_spec.rb +4 -0
- data/spec/miu/publisher_spec.rb +0 -9
- data/spec/miu/{subscribable_spec.rb → readable_spec.rb} +2 -2
- data/spec/miu/sockets_spec.rb +97 -0
- data/spec/miu/subscriber_spec.rb +0 -9
- data/spec/miu/{publishable_spec.rb → writable_spec.rb} +2 -2
- data/spec/spec_helper.rb +2 -0
- data/spec/support/socket.rb +36 -0
- metadata +51 -55
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1443afae69b50846c4ac4aa4e14c88a54e99cfa8
|
4
|
+
data.tar.gz: a9b76bb0de214c17db275392a1595bbed00e4d40
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9ef756f4b8fd9d3b1763559cfe27d4e001a0243b3ae072b7b150f202baca1e79c1b73bcfc038cb783dc68620567a00005272d9007f80eaf274137d466941959b
|
7
|
+
data.tar.gz: f7adbd99ffe06db55ed71c07654623ddec8ee49098c0d674ad67645a0d3a0c2ecfa9c581f487be3e2c5cd077e6aca58ba4001556f41dce60d74142fcdd49e86b
|
data/.gitignore
CHANGED
data/Rakefile
CHANGED
data/lib/miu.rb
CHANGED
@@ -6,16 +6,16 @@ module Miu
|
|
6
6
|
autoload :CLI, 'miu/cli'
|
7
7
|
autoload :Utility, 'miu/utility'
|
8
8
|
|
9
|
-
autoload :Socket, 'miu/
|
10
|
-
autoload :PubSocket, 'miu/
|
11
|
-
autoload :SubSocket, 'miu/
|
12
|
-
autoload :XPubSocket, 'miu/
|
13
|
-
autoload :XSubSocket, 'miu/
|
9
|
+
autoload :Socket, 'miu/sockets'
|
10
|
+
autoload :PubSocket, 'miu/sockets'
|
11
|
+
autoload :SubSocket, 'miu/sockets'
|
12
|
+
autoload :XPubSocket, 'miu/sockets'
|
13
|
+
autoload :XSubSocket, 'miu/sockets'
|
14
14
|
|
15
15
|
autoload :Server, 'miu/server'
|
16
16
|
autoload :Packet, 'miu/packet'
|
17
|
-
autoload :
|
18
|
-
autoload :
|
17
|
+
autoload :Writable, 'miu/writable'
|
18
|
+
autoload :Readable, 'miu/readable'
|
19
19
|
autoload :Publisher, 'miu/publisher'
|
20
20
|
autoload :Subscriber, 'miu/subscriber'
|
21
21
|
autoload :Proxy, 'miu/proxy'
|
@@ -23,30 +23,30 @@ module Miu
|
|
23
23
|
|
24
24
|
autoload :Command, 'miu/command'
|
25
25
|
autoload :Node, 'miu/node'
|
26
|
-
autoload :
|
26
|
+
autoload :Nodes, 'miu/nodes'
|
27
27
|
autoload :Resources, 'miu/resources'
|
28
28
|
autoload :Messages, 'miu/messages'
|
29
29
|
|
30
30
|
class << self
|
31
31
|
def root
|
32
32
|
require 'pathname'
|
33
|
-
|
33
|
+
Pathname.new(ENV['MIU_ROOT'] || Dir.pwd)
|
34
34
|
end
|
35
35
|
|
36
36
|
def default_port
|
37
37
|
Integer(ENV['MIU_DEFAULT_PORT']) rescue 22200
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
default_port
|
40
|
+
def default_pub_port
|
41
|
+
default_port + 0
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
44
|
+
def default_sub_port
|
45
45
|
default_port + 1
|
46
46
|
end
|
47
47
|
|
48
|
-
def
|
49
|
-
default_port +
|
48
|
+
def default_god_port
|
49
|
+
default_port + 3
|
50
50
|
end
|
51
51
|
|
52
52
|
def default_god_config
|
data/lib/miu/cli.rb
CHANGED
@@ -6,7 +6,7 @@ module Miu
|
|
6
6
|
class CLI < CLIBase
|
7
7
|
class << self
|
8
8
|
def source_root
|
9
|
-
File.expand_path('
|
9
|
+
File.expand_path('../templates', __FILE__)
|
10
10
|
end
|
11
11
|
|
12
12
|
def destination_root
|
@@ -22,9 +22,7 @@ module Miu
|
|
22
22
|
|
23
23
|
desc 'init', 'Generates a miu configuration files'
|
24
24
|
def init
|
25
|
-
|
26
|
-
template 'miu.god'
|
27
|
-
end
|
25
|
+
directory 'config'
|
28
26
|
empty_directory 'log'
|
29
27
|
empty_directory 'tmp/pids'
|
30
28
|
end
|
@@ -38,7 +36,7 @@ module Miu
|
|
38
36
|
print_table table, :indent => 2, :truncate => true
|
39
37
|
end
|
40
38
|
|
41
|
-
desc '
|
39
|
+
desc 'server', 'Start miu server'
|
42
40
|
option 'pub-host', :type => :string, :default => '127.0.0.1', :desc => 'pub host'
|
43
41
|
option 'pub-port', :type => :numeric, :default => Miu.default_pub_port, :desc => 'pub port'
|
44
42
|
option 'sub-host', :type => :string, :default => '127.0.0.1', :desc => 'sub host'
|
@@ -46,7 +44,7 @@ module Miu
|
|
46
44
|
option 'bridge-host', :type => :string, :default => '127.0.0.1', :desc => 'bridge host'
|
47
45
|
option 'bridge-port', :type => :numeric, :desc => 'bridge port'
|
48
46
|
option 'verbose', :type => :boolean, :default => false, :desc => 'verbose output', :aliases => '-V'
|
49
|
-
def
|
47
|
+
def server
|
50
48
|
server = Miu::Server.new Miu::Utility.optionify_keys(options)
|
51
49
|
server.run
|
52
50
|
end
|
@@ -54,10 +52,9 @@ module Miu
|
|
54
52
|
desc 'cat TAG ROOM TEXT', 'Okaka kakeyoune'
|
55
53
|
option 'host', :type => :string, :default => '127.0.0.1', :desc => 'miu sub host'
|
56
54
|
option 'port', :type => :numeric, :default => Miu.default_sub_port, :desc => 'miu sub port'
|
57
|
-
option 'network', :type => :string, :default => '
|
55
|
+
option 'network', :type => :string, :default => 'cat', :desc => 'miu network name'
|
58
56
|
def cat(tag, room, text)
|
59
57
|
require 'miu/messages'
|
60
|
-
require 'json'
|
61
58
|
publisher = Miu::Publisher.new :host => options[:host], :port => options[:port]
|
62
59
|
message = Miu::Messages::Text.new do |m|
|
63
60
|
m.network.name = options[:network]
|
@@ -73,30 +70,74 @@ module Miu
|
|
73
70
|
Miu::Logger.exception e
|
74
71
|
end
|
75
72
|
|
76
|
-
desc 'supervise', 'Supervise
|
73
|
+
desc 'supervise', 'Supervise nodes'
|
77
74
|
def supervise(*args)
|
78
|
-
args.unshift
|
79
|
-
|
75
|
+
args.unshift(
|
76
|
+
'god',
|
77
|
+
"-c #{Miu.root.join(Miu.default_god_config)}",
|
78
|
+
"-l #{Miu.root.join('log/god.log')}",
|
79
|
+
'--no-syslog',
|
80
|
+
'--no-events',
|
81
|
+
)
|
82
|
+
run args.join(' '), :verbose => false
|
80
83
|
end
|
81
84
|
|
82
|
-
desc 'terminate', 'Terminate
|
85
|
+
desc 'terminate', 'Terminate nodes'
|
83
86
|
def terminate(*args)
|
84
|
-
args.unshift
|
87
|
+
args.unshift 'terminate'
|
88
|
+
run_god *args
|
89
|
+
end
|
90
|
+
|
91
|
+
desc 'start [NODE]', 'Start specified node or all nodes'
|
92
|
+
def start(node = :all, *args)
|
93
|
+
args.unshift 'start', node
|
94
|
+
run_god *args
|
95
|
+
end
|
96
|
+
|
97
|
+
desc 'stop [NODE]', 'Stop specified node or all nodes'
|
98
|
+
def stop(node = :all, *args)
|
99
|
+
args.unshift 'stop', node
|
100
|
+
run_god *args
|
101
|
+
end
|
102
|
+
|
103
|
+
desc 'restart [NODE]', 'Restart specified node or all nodes'
|
104
|
+
def restart(node = :all, *args)
|
105
|
+
args.unshift 'restart', node
|
106
|
+
run_god *args
|
107
|
+
end
|
108
|
+
|
109
|
+
desc 'monitor [NODE]', 'Monitor specified node or all nodes'
|
110
|
+
def monitor(node = :all, *args)
|
111
|
+
args.unshift 'monitor', node
|
112
|
+
run_god *args
|
113
|
+
end
|
114
|
+
|
115
|
+
desc 'unmonitor [NODE]', 'Unmonitor specified node or all nodes'
|
116
|
+
def unmonitor(node = :all, *args)
|
117
|
+
args.unshift 'unmonitor', node
|
118
|
+
run_god *args
|
119
|
+
end
|
120
|
+
|
121
|
+
desc 'status [NODE]', 'Show status of the specified node or all nodes'
|
122
|
+
def status(node = :all, *args)
|
123
|
+
args.unshift 'status', node
|
85
124
|
run_god *args
|
86
125
|
end
|
87
126
|
|
88
|
-
desc '
|
89
|
-
def
|
90
|
-
args.unshift "
|
127
|
+
desc 'reload', 'Reload config file'
|
128
|
+
def reload(*args)
|
129
|
+
args.unshift "load #{Miu.root.join(Miu.default_god_config)}"
|
91
130
|
run_god *args
|
92
131
|
end
|
93
132
|
|
94
133
|
private
|
95
134
|
|
96
135
|
def run_god(*args)
|
97
|
-
|
98
|
-
|
99
|
-
|
136
|
+
args.unshift(
|
137
|
+
'god',
|
138
|
+
"-p #{Miu.default_god_port}",
|
139
|
+
)
|
140
|
+
run args.join(' '), :verbose => false
|
100
141
|
end
|
101
142
|
end
|
102
143
|
end
|
data/lib/miu/command.rb
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
require 'miu'
|
2
|
-
require 'miu/cli_base'
|
3
2
|
|
4
3
|
module Miu
|
5
4
|
class Command
|
6
5
|
def self.new(name, node, options = {}, &block)
|
6
|
+
require 'miu/cli_base'
|
7
|
+
|
7
8
|
Class.new Miu::CLIBase do
|
8
9
|
attr_accessor :node
|
9
10
|
@node = node
|
@@ -22,15 +23,17 @@ module Miu
|
|
22
23
|
end
|
23
24
|
|
24
25
|
def add_miu_pub_options(name)
|
26
|
+
tag = ['miu', 'input', name].select { |s| s && !s.empty? }.join('.') + '.'
|
25
27
|
option 'pub-host', :type => :string, :default => '127.0.0.1', :desc => 'miu pub host'
|
26
28
|
option 'pub-port', :type => :numeric, :default => Miu.default_sub_port, :desc => 'miu pub port'
|
27
|
-
option 'pub-tag', :type => :string, :default =>
|
29
|
+
option 'pub-tag', :type => :string, :default => tag, :desc => 'miu pub tag'
|
28
30
|
end
|
29
31
|
|
30
32
|
def add_miu_sub_options(name)
|
33
|
+
tag = ['miu', 'output', name].select { |s| s && !s.empty? }.join('.') + '.'
|
31
34
|
option 'sub-host', :type => :string, :default => '127.0.0.1', :desc => 'miu sub host'
|
32
35
|
option 'sub-port', :type => :numeric, :default => Miu.default_pub_port, :desc => 'miu sub port'
|
33
|
-
option 'sub-tag', :type => :string, :default =>
|
36
|
+
option 'sub-tag', :type => :string, :default => tag, :desc => 'miu sub tag'
|
34
37
|
end
|
35
38
|
|
36
39
|
def add_miu_pub_sub_options(name)
|
@@ -39,6 +42,30 @@ module Miu
|
|
39
42
|
end
|
40
43
|
end
|
41
44
|
|
45
|
+
unless respond_to? :no_commands
|
46
|
+
class << self
|
47
|
+
alias_method :no_commands, :no_tasks
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
no_commands do
|
52
|
+
def invoke_command(command, *args)
|
53
|
+
Miu.logger.level = ::Logger::DEBUG if options['verbose'] && Miu.logger
|
54
|
+
super
|
55
|
+
end
|
56
|
+
|
57
|
+
def config(data = nil, &block)
|
58
|
+
data = block.call if !data && block
|
59
|
+
append_to_file Miu.root.join(Miu.default_god_config), "\n#{data}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class_option :force, :type => :boolean, :group => :runtime, :desc => 'Overwrite files that already exist'
|
64
|
+
class_option :pretend, :type => :boolean, :group => :runtime, :desc => 'Run but do not make any changes'
|
65
|
+
class_option :verbose, :type => :boolean, :group => :runtime, :desc => 'Verbose status output'
|
66
|
+
class_option :quiet, :type => :boolean, :group => :runtime, :desc => 'Suppress status output'
|
67
|
+
class_option :skip, :type => :boolean, :group => :runtime, :desc => 'Skip files that already exist'
|
68
|
+
|
42
69
|
namespace name
|
43
70
|
class_eval &block if block
|
44
71
|
end
|
data/lib/miu/dsl.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'miu'
|
2
|
+
require 'god/sugar'
|
3
|
+
require 'god/task'
|
4
|
+
require 'god/watch'
|
5
|
+
|
6
|
+
module Miu
|
7
|
+
class << self
|
8
|
+
def dump_cli_options(options)
|
9
|
+
options.map do |k, v|
|
10
|
+
v = case v
|
11
|
+
when Array
|
12
|
+
v.map { |x| "'#{x}'" }.join(' ')
|
13
|
+
else
|
14
|
+
v.to_s
|
15
|
+
end
|
16
|
+
"#{k}=#{v}"
|
17
|
+
end.join(' ')
|
18
|
+
end
|
19
|
+
|
20
|
+
def watch(name)
|
21
|
+
God.watch do |w|
|
22
|
+
w.dir = Miu.root
|
23
|
+
w.log = Miu.root.join("log/#{name}.log").to_s
|
24
|
+
w.name = name
|
25
|
+
w.group = 'all'
|
26
|
+
|
27
|
+
yield w if block_given?
|
28
|
+
|
29
|
+
[:start, :stop, :restart].each do |action|
|
30
|
+
value = w.public_send action
|
31
|
+
if value.is_a?(Array)
|
32
|
+
options = Miu::Utility.extract_options! value
|
33
|
+
value << dump_cli_options(options)
|
34
|
+
w.public_send "#{action}=", value.join(' ')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
if $load_god
|
43
|
+
God.port = Miu.default_god_port
|
44
|
+
God.pid_file_directory = Miu.root.join('tmp/pids').to_s
|
45
|
+
end
|
data/lib/miu/forwarder.rb
CHANGED
data/lib/miu/logger.rb
CHANGED
data/lib/miu/messages.rb
CHANGED
data/lib/miu/messages/base.rb
CHANGED
@@ -17,20 +17,17 @@ module Miu
|
|
17
17
|
yield self if block_given?
|
18
18
|
end
|
19
19
|
|
20
|
-
def
|
20
|
+
def to_h
|
21
21
|
{
|
22
|
-
:network => @network.
|
22
|
+
:network => @network.to_h,
|
23
23
|
:type => @type,
|
24
|
-
:content => @content ? @content.
|
24
|
+
:content => @content ? @content.to_h : {}
|
25
25
|
}
|
26
26
|
end
|
27
27
|
|
28
28
|
def to_msgpack(*args)
|
29
|
-
|
29
|
+
to_h.to_msgpack(*args)
|
30
30
|
end
|
31
31
|
end
|
32
|
-
|
33
|
-
class Unknown < Base
|
34
|
-
end
|
35
32
|
end
|
36
33
|
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'miu/resources'
|
2
|
+
require 'miu/messages/base'
|
3
|
+
|
4
|
+
module Miu
|
5
|
+
module Messages
|
6
|
+
class Enter < Base
|
7
|
+
def initialize(options = {})
|
8
|
+
options[:type] ||= 'enter'
|
9
|
+
options[:content] = Miu::Utility.adapt(Resources::EnterContent, options[:content] || {})
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
register :enter, Enter
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'miu/resources'
|
2
|
+
require 'miu/messages/base'
|
3
|
+
|
4
|
+
module Miu
|
5
|
+
module Messages
|
6
|
+
class Leave < Base
|
7
|
+
def initialize(options = {})
|
8
|
+
options[:type] ||= 'leave'
|
9
|
+
options[:content] = Miu::Utility.adapt(Resources::LeaveContent, options[:content] || {})
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
register :leave, Leave
|
15
|
+
end
|
16
|
+
end
|
data/lib/miu/packet.rb
CHANGED
data/lib/miu/proxy.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require 'miu/
|
1
|
+
require 'miu/sockets'
|
2
2
|
require 'ffi-rzmq'
|
3
3
|
|
4
4
|
module Miu
|
@@ -9,8 +9,8 @@ module Miu
|
|
9
9
|
PROXY_TO = '@__proxy_to__'
|
10
10
|
|
11
11
|
def initialize(frontends, backends)
|
12
|
-
@frontends = Array(frontends).map { |s|
|
13
|
-
@backends = Array(backends).map { |s|
|
12
|
+
@frontends = Array(frontends).map { |s| s.to_io rescue s }
|
13
|
+
@backends = Array(backends).map { |s| s.to_io rescue s }
|
14
14
|
|
15
15
|
@frontends.each { |s| s.instance_variable_set PROXY_TO, @backends }
|
16
16
|
@backends.each { |s| s.instance_variable_set PROXY_TO, @frontends }
|
@@ -42,16 +42,5 @@ module Miu
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
end
|
45
|
-
|
46
|
-
private
|
47
|
-
|
48
|
-
def unwrap(socket)
|
49
|
-
case socket
|
50
|
-
when Miu::Socket
|
51
|
-
socket.socket
|
52
|
-
else
|
53
|
-
socket
|
54
|
-
end
|
55
|
-
end
|
56
45
|
end
|
57
46
|
end
|