Class: Jubilee::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/jubilee/configuration.rb

Overview

Implements a simple DSL for configuring a Jubilee server

See github.com/isaiah/jubilee/examples/jubilee.conf.rb for example configuration files.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, &block) ⇒ Configuration

Returns a new instance of Configuration.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/jubilee/configuration.rb', line 13

def initialize(options, &block)
  @config_file = options.delete(:config_file)
  @options = options.dup
  @block = block

  reload
  # initialize vertx as early as possible
  if chost = @options[:cluster_host]
    if cport = @options[:cluster_port]
      org.jruby.jubilee.vertx.JubileeVertx.init(cport.to_java(:int), chost.to_java)
    else
      org.jruby.jubilee.vertx.JubileeVertx.init(chost.to_java)
    end
  else
    org.jruby.jubilee.vertx.JubileeVertx.init()
  end
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.



10
11
12
# File 'lib/jubilee/configuration.rb', line 10

def config_file
  @config_file
end

#optionsObject (readonly)

Returns the value of attribute options.



11
12
13
# File 'lib/jubilee/configuration.rb', line 11

def options
  @options
end

Instance Method Details

#appObject



35
36
37
38
39
40
41
42
43
# File 'lib/jubilee/configuration.rb', line 35

def app
  @app ||= load_rack_adapter(@options, &@block)
  if !@options[:quiet] and @options[:environment] == "development"
    logger = @options[:logger] || STDOUT
    Rack::CommonLogger.new(@app, logger)
  else
    @app
  end
end

#clustering(address) ⇒ Object

Set the host and port to be discovered by other jubilee instances in the network address may be an Integer port number for a TCP port or an “IP_ADDRESS:PORT” for TCP listeners, or “IP_ADDRESS” and let the system to assign a port

clustering true # enable cluster mode, default to "0.0.0.0:5701"
clustering "0.0.0.0"
clustering "0.0.0.0:5701"
clustering 5701


85
86
87
88
89
90
91
# File 'lib/jubilee/configuration.rb', line 85

def clustering(address)
  if address == true
    @options[:cluster_host] = "0.0.0.0"
  else
    @options[:cluster_host], @options[:cluster_port] = expand_addr(address, :clustering)
  end
end

#daemonize(bool) ⇒ Object

enable daemon mode



99
100
101
# File 'lib/jubilee/configuration.rb', line 99

def daemonize(bool)
  set_bool(:deamon, bool)
end

#debug(bool) ⇒ Object

enable debug messages



94
95
96
# File 'lib/jubilee/configuration.rb', line 94

def debug(bool)
  set_bool(:debug, bool)
end

#environment(env) ⇒ Object

sets the RACK_ENV environment variable



61
62
63
# File 'lib/jubilee/configuration.rb', line 61

def environment(env)
  @options[:environment] = env
end

#eventbus(prefix, options = {}) ⇒ Object

set the event bus bridge prefix, prefix, options eventbus /eventbus, inbound: [foo:bar], outbound: [bar] will set the event bus prefix as eventbus “/eventbus”, it can be connected via new EventBus(“localhost:8080/eventbus”), inbound and outbound options are security measures that will filter the messages



70
71
72
73
74
# File 'lib/jubilee/configuration.rb', line 70

def eventbus(prefix, options = {})
  @options[:eventbus_prefix] = prefix
  @options[:eventbus_inbound] = options[:inbound]
  @options[:eventbus_outbound] = options[:outbound]
end

#listen(address) ⇒ Object

sets the host and port jubilee listens to address may be an Integer port number for a TCP port or an “IP_ADDRESS:PORT” for TCP listeners

listen 3000 # listen to port 3000 on all TCP interfaces
listen "127.0.0.1:3000"  # listen to port 3000 on the loopback interface
listen "[::1]:3000" # listen to port 3000 on the IPv6 loopback interface


51
52
53
# File 'lib/jubilee/configuration.rb', line 51

def listen(address)
  @options[:Host], @options[:Port] = expand_addr(address, :listen)
end

#pid(path) ⇒ Object

sets the path for the PID file of the jubilee event loop



111
112
113
# File 'lib/jubilee/configuration.rb', line 111

def pid(path)
  set_path(:pid, path)
end

#reloadObject



31
32
33
# File 'lib/jubilee/configuration.rb', line 31

def reload
  instance_eval(File.read(config_file), config_file) if config_file
end

#ssl(options = {}) ⇒ Object

enable https mode, provide the :keystore path and password



104
105
106
107
108
# File 'lib/jubilee/configuration.rb', line 104

def ssl(options = {})
  set_path(:ssl_keystore, options[:keystore])
  @options[:ssl_password] = options[:password]
  @options[:ssl] = true
end

#stderr_path(path) ⇒ Object

Allows redirecting $stderr to a given path, if you are daemonizing and useing the default logger, this defautls to log/jubilee.stderr.log



117
118
119
# File 'lib/jubilee/configuration.rb', line 117

def stderr_path(path)
  set_path(:stderr_path, path)
end

#stdout_path(path) ⇒ Object

live stderr_path, this defaults to log/jubilee.stdout.log when daemonized



122
123
124
# File 'lib/jubilee/configuration.rb', line 122

def stdout_path(path)
  set_path(:stdout_path, path)
end

#working_directory(path) ⇒ Object

sets the working directory for jubilee



56
57
58
# File 'lib/jubilee/configuration.rb', line 56

def working_directory(path)
  @options[:chdir] = File.expand_path(path)
end