Class: Trinidad::WebApp
- Inherits:
-
Object
show all
- Defined in:
- lib/trinidad/web_app.rb
Defined Under Namespace
Classes: Holder
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(config, default_config) ⇒ WebApp
Returns a new instance of WebApp.
12
13
14
15
16
|
# File 'lib/trinidad/web_app.rb', line 12
def initialize(config, default_config)
@config, @default_config = config, default_config || {}
complete_config!
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
4
5
6
|
# File 'lib/trinidad/web_app.rb', line 4
def config
@config
end
|
#default_config ⇒ Object
Returns the value of attribute default_config.
4
5
6
|
# File 'lib/trinidad/web_app.rb', line 4
def default_config
@default_config
end
|
Class Method Details
.create(config, default_config = Trinidad.configuration) ⇒ Object
Instance Method Details
#[](key) ⇒ Object
18
19
20
21
|
# File 'lib/trinidad/web_app.rb', line 18
def [](key)
key = key.to_sym
config.has_key?(key) ? config[key] : default_config[key]
end
|
#add_context_param(param_name, param_value) ⇒ Object
60
61
62
63
64
65
|
# File 'lib/trinidad/web_app.rb', line 60
def add_context_param(param_name, param_value)
@context_params ||= {}
if ! param_value.nil? && ! web_xml_context_param(param_name)
@context_params[param_name] = param_value.to_s
end
end
|
#class_loader ⇒ Object
82
83
84
|
# File 'lib/trinidad/web_app.rb', line 82
def class_loader
@class_loader ||= org.jruby.util.JRubyClassLoader.new(JRuby.runtime.jruby_class_loader)
end
|
#class_loader! ⇒ Object
86
87
88
|
# File 'lib/trinidad/web_app.rb', line 86
def class_loader!
( @class_loader = nil ) || class_loader
end
|
#context_params ⇒ Object
48
49
50
51
52
53
54
55
56
|
# File 'lib/trinidad/web_app.rb', line 48
def context_params
@context_params ||= {}
add_context_param 'jruby.min.runtimes', jruby_min_runtimes
add_context_param 'jruby.max.runtimes', jruby_max_runtimes
add_context_param 'jruby.initial.runtimes', jruby_min_runtimes
add_context_param 'jruby.compat.version', jruby_compat_version || RUBY_VERSION
add_context_param 'public.root', File.join('/', public_root)
@context_params
end
|
#default_deployment_descriptor ⇒ Object
75
76
77
78
79
80
|
# File 'lib/trinidad/web_app.rb', line 75
def default_deployment_descriptor
@default_deployment_descriptor ||= if default_web_xml
file = File.expand_path(File.join(work_dir, default_web_xml))
File.exist?(file) ? file : nil
end
end
|
#default_web_xml ⇒ Object
30
|
# File 'lib/trinidad/web_app.rb', line 30
def default_web_xml; self[:default_web_xml]; end
|
#define_lifecycle ⇒ Object
#deployment_descriptor ⇒ Object
67
68
69
70
71
72
|
# File 'lib/trinidad/web_app.rb', line 67
def deployment_descriptor
@deployment_descriptor ||= if web_xml
file = File.expand_path(File.join(work_dir, web_xml))
File.exist?(file) ? file : nil
end
end
|
#environment ⇒ Object
33
|
# File 'lib/trinidad/web_app.rb', line 33
def environment; self[:environment] || 'development'; end
|
#extensions ⇒ Object
37
38
39
40
41
42
|
# File 'lib/trinidad/web_app.rb', line 37
def extensions
@extensions ||= begin
extensions = default_config[:extensions] || {}
extensions.merge(config[:extensions] || {})
end
end
|
#generate_class_loader ⇒ Object
90
|
# File 'lib/trinidad/web_app.rb', line 90
def generate_class_loader; class_loader!; end
|
#init_params ⇒ Object
58
|
# File 'lib/trinidad/web_app.rb', line 58
def init_params; context_params; end
|
#log_dir ⇒ Object
35
|
# File 'lib/trinidad/web_app.rb', line 35
def log_dir; self[:log_dir] || File.join(work_dir, 'log'); end
|
#monitor ⇒ Object
44
45
46
|
# File 'lib/trinidad/web_app.rb', line 44
def monitor
File.expand_path(self[:monitor] || 'tmp/restart.txt', work_dir)
end
|
#public_root ⇒ Object
32
|
# File 'lib/trinidad/web_app.rb', line 32
def public_root; self[:public] || 'public'; end
|
#rack_listener ⇒ Object
126
127
128
|
# File 'lib/trinidad/web_app.rb', line 126
def rack_listener
context_listener unless web_xml_listener?(context_listener)
end
|
#rack_servlet ⇒ Object
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/trinidad/web_app.rb', line 104
def rack_servlet
return nil if @rack_servlet == false
@rack_servlet ||= begin
servlet_config = self[:servlet] || {}
servlet_class = servlet_config[:class] || 'org.jruby.rack.RackServlet'
servlet_name = servlet_config[:name] || 'RackServlet'
if ! web_xml_servlet?(servlet_class, servlet_name) &&
! web_xml_filter?('org.jruby.rack.RackFilter')
{
:class => servlet_class, :name => servlet_name,
:async_supported => !! servlet_config[:async_supported],
:instance => servlet_config[:instance]
}
else
false end
end || nil
end
|
#reset! ⇒ Object
Reset the hold web application state so it gets re-initialized. Please note that the received configuration object are not cleared.
98
99
100
101
102
|
# File 'lib/trinidad/web_app.rb', line 98
def reset!
vars = instance_variables.map(&:to_sym)
vars = vars - [ :'@config', :'@default_config' ]
vars.each { |var| instance_variable_set(var, nil) }
end
|
#servlet ⇒ Object
124
|
# File 'lib/trinidad/web_app.rb', line 124
def servlet; rack_servlet; end
|
#solo? ⇒ Boolean
132
133
134
|
# File 'lib/trinidad/web_app.rb', line 132
def solo?
! is_a?(WarWebApp) && config[:solo]
end
|
#threadsafe? ⇒ Boolean
136
137
138
|
# File 'lib/trinidad/web_app.rb', line 136
def threadsafe?
jruby_min_runtimes.to_i == 1 && jruby_max_runtimes.to_i == 1
end
|
#war? ⇒ Boolean
130
|
# File 'lib/trinidad/web_app.rb', line 130
def war?; self.class.war?(config); end
|
#web_xml ⇒ Object
29
|
# File 'lib/trinidad/web_app.rb', line 29
def web_xml; self[:web_xml] || self[:default_web_xml]; end
|
#web_xml_context_param(name) ⇒ Object
172
173
174
175
176
177
|
# File 'lib/trinidad/web_app.rb', line 172
def web_xml_context_param(name)
if web_xml_doc &&
param = web_xml_doc.root.elements["/web-app/context-param[param-name = '#{name}']"]
param.elements['param-value'].text
end
end
|
#web_xml_filter?(filter_class) ⇒ Boolean
159
160
161
162
163
164
|
# File 'lib/trinidad/web_app.rb', line 159
def web_xml_filter?(filter_class)
!!( web_xml_doc && (
web_xml_doc.root.elements["/web-app/filter[filter-class = '#{filter_class}']"]
)
)
end
|
#web_xml_listener?(listener_class) ⇒ Boolean
166
167
168
169
170
|
# File 'lib/trinidad/web_app.rb', line 166
def web_xml_listener?(listener_class)
!!( web_xml_doc &&
web_xml_doc.root.elements["/web-app/listener[listener-class = '#{listener_class}']"]
)
end
|
#web_xml_servlet?(servlet_class, servlet_name = nil) ⇒ Boolean
152
153
154
155
156
157
|
# File 'lib/trinidad/web_app.rb', line 152
def web_xml_servlet?(servlet_class, servlet_name = nil)
!!( web_xml_doc && (
web_xml_doc.root.elements["/web-app/servlet[servlet-class = '#{servlet_class}']"]
)
)
end
|
#work_dir ⇒ Object
34
|
# File 'lib/trinidad/web_app.rb', line 34
def work_dir; self[:work_dir] || web_app_dir; end
|