Class: Dorsal::Controller

Inherits:
Object
  • Object
show all
Includes:
Privates
Defined in:
lib/dorsal/controller.rb

Overview

the Controller Class, provide access and control of the Ring Server and services, via the Ring Server

Examples:

usage

dorsal = Dorsal::Controller::new
# or 
dorsal = Dorsal::Contoller::new :host => 'dorsal.example.com', 
                                :port => "8888", :dir => '/a/writable/path', :description => 'My Own Dorsal Ring Server'

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Privates

#daemonize, #start, #status, #stop

Constructor Details

#initialize(_options = {}) ⇒ Controller

Note:

see default values from Dorsal namespace Constants

contructor for Dorsal::Controller

Examples:

usage

dorsal = Dorsal::Controller::new
# or 
dorsal = Dorsal::Contoller::new :host => 'dorsal.example.com', 
                                :port => "8888", :dir => '/a/writable/path', :description => 'My Own Dorsal Ring Server'

Parameters:

  • _options (Hash) (defaults to: {})

    (all options are optionals

Options Hash (_options):

  • :name (String)

    the name of the ringserver instance

  • :description (String)

    the detail name of the the ring server, use for $0

  • :port (String)

    the port where to bind ring server

  • :host (String)

    the host name share between ring server and hosted DRb services

  • :dir (String)

    a writable path where to write pid files and more.

  • :debug (TruClass, FalseClass)

    to run Dorsal Ring server in foreground, with more traces



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/dorsal/controller.rb', line 50

def initialize(_options = {})
  @options = Methodic::get_options(_options)
  @options.specify_defaults_values :description => Dorsal::DEFAULT_RINGSERVER_DESCRIPTION, 
  :debug => Dorsal::DEFAULT_DEBUG, 
  :host => Dorsal::DEFAULT_HOST, 
  :port => Dorsal::DEFAULT_PORT, 
  :dir => Dorsal::DEFAULT_DIR
  @options.merge
  @options[:dir].chomp!('/')
  @options[:name] = Dorsal::DEFAULT_RINGSERVER_NAME
  @options[:uri] = "druby://#{options[:host]}:#{options[:port]}"
  Dir::mkdir(@options[:dir]) unless File::exist?(@options[:dir])
  @options[:pid_file] = "#{@options[:dir]}/#{@options[:name]}.pid"
  @options[:object] = Dorsal::ImplementationServer::new({ :dir => @options[:dir], :host => @options[:host], :debug => @options[:debug]})
end

Instance Attribute Details

#optionsObject (readonly)

Examples:

read

dorsal = Dorsal::Controller::new
p dorsal.options                                                                                                                                                             


34
35
36
# File 'lib/dorsal/controller.rb', line 34

def options
  @options
end

Instance Method Details

#bind_to_ringDRbObject?

accessor to ring server if up

Examples:

usage

dorsal = Dorsal::Controller::new
dorsal.start_ring_server
ring = dorsal.bin_to_ring

Returns:

  • (DRbObject, nil)

    the ring server Drb Object if Up or nil



72
73
74
75
76
77
78
79
# File 'lib/dorsal/controller.rb', line 72

def bind_to_ring
  if ring_server_status then
    DRb.start_service
    return DRbObject.new nil, @options[:uri]
  else
    return nil
  end
end

#ring_server_statusTrueClass, FalseClass

return the running status of the ring server

Examples:

usage

dorsal = Dorsal::Controller::new
dorsal.start_ring_server #=> a Fixnum for the PID
dorsal.ring_server_status #=> true
dorsal.stop_ring_server #=> true
dorsal.ring_server_status #=> false

Returns:

  • (TrueClass, FalseClass)

    true if up, false if down



127
128
129
# File 'lib/dorsal/controller.rb', line 127

def ring_server_status
  return status @options
end

#start_ring_serverFixnum, FalseClass

start the ring server if not

Examples:

usage

dorsal = Dorsal::Controller::new
dorsal.start_ring_server #=> a Fixnum for the PID
dorsal.start_ring_server #=> false

Returns:

  • (Fixnum, FalseClass)

    the pid of the ring server or false if already start



87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/dorsal/controller.rb', line 87

def start_ring_server 
  unless ring_server_status then
      res = start(@options) do
        DRb.start_service(@options[:uri], @options[:object])
        DRb.thread.join
      end
    return res      
  else
    return false
  end
  
end

#stop_ring_serverTrueClass, FalseClass

stop the ring server if up

Examples:

usage

dorsal = Dorsal::Controller::new
dorsal.start_ring_server #=> a Fixnum for the PID
dorsal.stop_ring_server #=> true
dorsal.stop_ring_server #=> false

Returns:

  • (TrueClass, FalseClass)

    true if really shutdown, false otherwise



107
108
109
110
111
112
113
114
115
116
117
# File 'lib/dorsal/controller.rb', line 107

def stop_ring_server
  if ring_server_status then
    ring = self.bind_to_ring
    ring.list_services.keys.each do |service|
      ring.destroy_service :name => service
    end
    return stop @options
  else
    return false
  end
end