Class: StompingGround::Server

Inherits:
Object
  • Object
show all
Includes:
Celluloid::IO
Defined in:
lib/stomping_ground/server.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(host, port, options = {}) ⇒ Server

Returns a new instance of Server.



9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/stomping_ground/server.rb', line 9

def initialize(host, port, options = {})
  @host = host
  @port = port

  @message_body     = options[:message]
  @queue_name       = options[:queue_name]
  @sent_message_dir = options[:sent_message_dir]

  @server = TCPServer.new(@host, @port)

  async.run
end

Instance Attribute Details

#message_bodyObject

Returns the value of attribute message_body.



5
6
7
# File 'lib/stomping_ground/server.rb', line 5

def message_body
  @message_body
end

#queue_nameObject

Returns the value of attribute queue_name.



6
7
8
# File 'lib/stomping_ground/server.rb', line 6

def queue_name
  @queue_name
end

#sent_message_dirObject

Returns the value of attribute sent_message_dir.



7
8
9
# File 'lib/stomping_ground/server.rb', line 7

def sent_message_dir
  @sent_message_dir
end

Class Method Details

.start(*opts) ⇒ Object



22
23
24
# File 'lib/stomping_ground/server.rb', line 22

def self.start(*opts)
  supervise(*opts)
end

Instance Method Details

#finalizeObject



34
35
36
# File 'lib/stomping_ground/server.rb', line 34

def finalize
  @server.close if @server
end

#handle_connection(socket) ⇒ Object



30
31
32
# File 'lib/stomping_ground/server.rb', line 30

def handle_connection(socket)
  Connection.new(self, socket).handle
end

#runObject



26
27
28
# File 'lib/stomping_ground/server.rb', line 26

def run
  loop { async.handle_connection @server.accept }
end