officer 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -61,13 +61,22 @@ Run Officer in the background (production mode) and listen on a specific IP and
61
61
 
62
62
  - Useful if you use Officer with Phusion Passenger and smart spawning. See [Passenger's documentation](http://www.modrails.com/documentation/Users%20guide%20Apache.html#_smart_spawning_gotcha_1_unintential_file_descriptor_sharing) for more information.
63
63
 
64
+ ### Locks
65
+
66
+ client.locks
67
+
68
+ - Returns the internal state of all the server's locks.
69
+
70
+ ### Connections
71
+
72
+ client.connections
73
+
74
+ - Returns the internal state of all the server's connections.
75
+
64
76
  ## Planned Features
65
77
 
66
- - Lock statistics.
67
- - Retrieve the complete list of locks.
68
78
  - Retrieve the list of locks for the current connection.
69
79
  - Client: Option to abort a lock request if there is already a certain number of clients waiting for the lock.
70
- - Server: Make IP and port configurable.
71
80
 
72
81
  ## Copyright
73
82
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/bin/officer CHANGED
@@ -41,7 +41,7 @@ def parse_command_line
41
41
  end
42
42
  end
43
43
 
44
- Daemons.run_proc('officer', daemon_options) do
44
+ #Daemons.run_proc('officer', daemon_options) do
45
45
  parse_command_line
46
46
  Officer::Server.new(Choice.choices).run
47
- end
47
+ #end
@@ -29,11 +29,11 @@ module Officer
29
29
  end
30
30
 
31
31
  def lock name, options={}
32
- execute({:command => 'lock', :name => name, :timeout => options[:timeout]}.to_json)
32
+ execute :command => 'lock', :name => name, :timeout => options[:timeout]
33
33
  end
34
34
 
35
35
  def unlock name
36
- execute({:command => 'unlock', :name => name}.to_json)
36
+ execute :command => 'unlock', :name => name
37
37
  end
38
38
 
39
39
  def with_lock name, options={}
@@ -55,7 +55,15 @@ module Officer
55
55
  end
56
56
 
57
57
  def reset
58
- execute({:command => 'reset'}.to_json)
58
+ execute :command => 'reset'
59
+ end
60
+
61
+ def locks
62
+ execute :command => 'locks'
63
+ end
64
+
65
+ def connections
66
+ execute :command => 'connections'
59
67
  end
60
68
 
61
69
  private
@@ -72,6 +80,7 @@ module Officer
72
80
  end
73
81
 
74
82
  def execute command
83
+ command = command.to_json
75
84
  @socket.write command + "\n"
76
85
  result = @socket.gets "\n"
77
86
  JSON.parse result.chomp
@@ -96,5 +96,21 @@ module Officer
96
96
  Officer::LockStore.instance.reset @connection
97
97
  end
98
98
  end
99
+
100
+ class Locks < Base
101
+ register
102
+
103
+ def execute
104
+ Officer::LockStore.instance.locks @connection
105
+ end
106
+ end
107
+
108
+ class Connections < Base
109
+ register
110
+
111
+ def execute
112
+ Officer::LockStore.instance.connections @connection
113
+ end
114
+ end
99
115
  end
100
116
  end
@@ -25,7 +25,7 @@ module Officer
25
25
  end
26
26
  end
27
27
 
28
- module LockCallbacks
28
+ module LockStoreCallbacks
29
29
  def acquired name
30
30
  @timers.delete(name).cancel if @timers[name]
31
31
 
@@ -63,11 +63,24 @@ module Officer
63
63
  @timers.delete name
64
64
  send_line({:result => 'timed_out', :name => name}.to_json)
65
65
  end
66
+
67
+ def locks locks_hash
68
+ send_line({:result => 'locks', :value => locks_hash}.to_json)
69
+ end
70
+
71
+ def connections conns_hash
72
+ send_line({:result => 'connections', :value => conns_hash}.to_json)
73
+ end
66
74
  end
67
75
 
68
76
  class Connection < EventMachine::Protocols::LineAndTextProtocol
69
77
  include EmCallbacks
70
- include LockCallbacks
78
+ include LockStoreCallbacks
79
+
80
+ def to_host_s
81
+ port, ip = Socket.unpack_sockaddr_in get_peername
82
+ "#{ip}:#{port}"
83
+ end
71
84
 
72
85
  private
73
86
  attr_reader :connected
@@ -114,6 +114,26 @@ module Officer
114
114
 
115
115
  connection.timed_out name
116
116
  end
117
+
118
+ def locks connection
119
+ locks = {}
120
+
121
+ @locks.each do |name, lock|
122
+ locks[name] = lock.queue.map {|conn| conn.to_host_s}
123
+ end
124
+
125
+ connection.locks locks
126
+ end
127
+
128
+ def connections connection
129
+ connections = {}
130
+
131
+ @connections.each do |conn, names|
132
+ connections[conn.to_host_s] = names
133
+ end
134
+
135
+ connection.connections connections
136
+ end
117
137
  end
118
138
 
119
139
  end
data/lib/officer/log.rb CHANGED
@@ -33,4 +33,4 @@ module Officer
33
33
  end
34
34
 
35
35
  L = Officer::Log.instance
36
- LOG_LEVEL = :info
36
+ LOG_LEVEL = :debug
@@ -1,12 +1,12 @@
1
+ require 'ruby-debug'
2
+
1
3
  module Officer
2
4
 
3
5
  class Server
4
- def initialize options={}
5
- options.reverse_merge! :port => 11500, :host => '0.0.0.0', :verbose => false
6
-
7
- @port = options[:port]
8
- @host = options[:host]
9
- @verbose = options[:verbose]
6
+ def initialize opts={}
7
+ @port = opts[:port] || 11500
8
+ @host = opts[:host] || '0.0.0.0'
9
+ @verbose = opts[:verbose] || false
10
10
  end
11
11
 
12
12
  def run
@@ -20,7 +20,7 @@ module Officer
20
20
  Officer::LockStore.instance.log_state
21
21
  end
22
22
  end
23
-
23
+
24
24
  EM::start_server @host, @port, Connection::Connection
25
25
  end
26
26
  end
data/officer.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{officer}
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Chad Remesch"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: officer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chad Remesch