trinidad_lifecycle_extension 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -2,11 +2,14 @@
2
2
 
3
3
  This extension allows you to add lifecycle listeners (written in ruby) to the
4
4
  [Trinidad](https://github.com/trinidad/trinidad/) server container as well as to
5
- each deployed web application context running on top of Trinidad.
5
+ deployed web application contexts running on top of it.
6
6
 
7
- This extension also allows to enable the JMX monitoring capabilities of Tomcat.
8
- The configuration that Tomcat needs can be set as JAVA_OPTS properties or
9
- through the Trinidad's configuration file.
7
+ This extension no longer bundles the **catalina-jmx-remote.jar** and thus for
8
+ configuring remote JMX monitoring capabilities using the `JmxRemoteLifecycleListener`
9
+ you will need to provide and load the Java class (e.g. by downloading and
10
+ loading the .jar). Alternatively, there's a separate
11
+ [trinidad_jmx_remote_extension](http://github.com/kares/trinidad_jmx_remote_extension)
12
+ for enabling JMX with SSH if that's all you're looking for here.
10
13
 
11
14
  ## Install
12
15
 
@@ -31,7 +34,7 @@ the path to the directory where the listener .rb files are located e.g. :
31
34
  # ...
32
35
  extensions:
33
36
  lifecycle:
34
- path: 'lib/lifecycle' # defaults to lib/lifecycle
37
+ listeners_path: "lib/lifecycle" # defaults to lib/lifecycle
35
38
  ```
36
39
 
37
40
  Trinidad will try to require the *.rb files from the lifecycle directory and
@@ -81,15 +84,32 @@ they will be instantiated and configured as listeners e.g. :
81
84
  module Trinidad
82
85
  module Lifecycle
83
86
  module Server
84
- SIMPLE_CLUSTER = org.apache.catalina.ha.tcp.SimpleTcpCluster
87
+ SECURITY_SETUP = org.apache.catalina.security.SecurityListener
85
88
  end
86
89
  end
87
90
  end
88
91
  ```
89
92
 
93
+ Of you may sub-class them and perform desired setup when instantiated :
94
+
95
+ ```ruby
96
+ module Trinidad
97
+ module Lifecycle
98
+ module Server
99
+ class UserSecurity < org.apache.catalina.security.SecurityListener
100
+ def initialize
101
+ setCheckedOsUsers('root,public,nobody')
102
+ end
103
+ end
104
+ end
105
+ end
106
+ end
107
+ ```
108
+
109
+
90
110
  ### WebApp Lifecycle Listener
91
111
 
92
- The very same rulez apply as for the Server Listener above except that we add
112
+ The very same rules apply as for the Server listeners above except that we add
93
113
  listener classes under the `Trinidad::Lifecycle::WebApp` module e.g. :
94
114
 
95
115
  ```ruby
@@ -114,20 +134,21 @@ module Trinidad
114
134
  end
115
135
  ```
116
136
 
117
- Lifecycle listeners might be exported as configured instances as well e.g. :
137
+ Lifecycle listeners might be exported as (configured) instances as well e.g. :
118
138
 
119
139
  ```ruby
120
140
  module Trinidad
121
141
  module Lifecycle
122
- module Server
142
+ module WebApp
123
143
 
124
- def self.configure_cluster
125
- cluster = org.apache.catalina.ha.tcp.SimpleTcpCluster.new
126
- cluster.setClusterName('Trinidad')
127
- cluster
144
+ def self.configure_jre_memory_leak_prevention_listener
145
+ listener = org.apache.catalina.core.JreMemoryLeakPreventionListener.new
146
+ listener.setGcDaemonProtection(true)
147
+ listener.setUrlCacheProtection(true)
148
+ listener
128
149
  end
129
150
 
130
- CONFIGURED_CLUSTER = self.configure_cluster
151
+ MEMORY_LEAK_LISTENER = self.configure_jre_memory_leak_prevention_listener
131
152
 
132
153
  end
133
154
  end
@@ -14,13 +14,22 @@ module Trinidad
14
14
  @@_constants = self.constants.dup
15
15
 
16
16
  def self.listeners
17
+ listener_constants.map do |name|
18
+ const = self.const_get(name)
19
+ const.is_a?(Class) ? const.new : const
20
+ end
21
+ end
22
+
23
+ def self.listener_constants
17
24
  listeners = self.constants - @@_constants
18
25
  listeners.map! do |name|
19
26
  const = self.const_get(name)
20
27
  if const.is_a?(Class) && const.included_modules.include?(Listener)
21
- const.new
28
+ name
22
29
  elsif const.is_a?(Listener)
23
- const
30
+ name
31
+ else
32
+ nil
24
33
  end
25
34
  end
26
35
  listeners.compact
@@ -33,13 +42,29 @@ module Trinidad
33
42
  module Extensions
34
43
  module Lifecycle
35
44
 
45
+ DEFAULT_LISTENERS_PATH = 'lib/lifecycle'
46
+
47
+ protected
48
+
49
+ def listeners_path(type = nil)
50
+ options[:listeners_path] || options[:path] || DEFAULT_LISTENERS_PATH
51
+ end
52
+
36
53
  private
37
54
 
38
- def init_listeners(container, path, base_mod)
39
- path ||= File.join('lib', 'lifecycle')
40
-
41
- Dir.glob("#{path}/*.rb").each { |rb| require rb }
55
+ LOAD_METHOD = :load
56
+
57
+ def init_listeners(base_mod, listeners_path, container)
58
+ # allow listeners_path to be a glob itself :
59
+ load_files = Dir.glob(listeners_path)
60
+ if load_files.size == 0 ||
61
+ ( load_files.size == 1 && File.directory?(load_files[0]) )
62
+ load_files = Dir.glob(File.join(listeners_path, '*.rb'))
63
+ end
64
+
65
+ load_files.each { |rb_file| send LOAD_METHOD, rb_file }
42
66
 
67
+ # e.g. Trinidad::Lifecycle::Server.listeners
43
68
  base_mod.listeners.each do |listener|
44
69
  container.add_lifecycle_listener listener
45
70
  end
@@ -51,7 +76,7 @@ module Trinidad
51
76
  include Lifecycle
52
77
 
53
78
  def configure(tomcat)
54
- init_listeners(tomcat.server, @options[:path], Trinidad::Lifecycle::Server)
79
+ init_listeners(Trinidad::Lifecycle::Server, listeners_path(:server), tomcat.server)
55
80
  end
56
81
 
57
82
  end
@@ -59,18 +84,11 @@ module Trinidad
59
84
  class LifecycleWebAppExtension < WebAppExtension
60
85
  include Lifecycle
61
86
 
62
- def configure(tomcat, context)
63
- init_listeners(context, @options[:path], Trinidad::Lifecycle::WebApp)
87
+ def configure(context)
88
+ init_listeners(Trinidad::Lifecycle::WebApp, listeners_path(:webapp), context)
64
89
  end
65
90
 
66
91
  end
67
-
68
- class LifecycleOptionsExtension < OptionsExtension
69
- def configure(parser, default_options)
70
- default_options[:extensions] ||= {}
71
- default_options[:extensions][:lifecycle] = {}
72
- end
73
- end
74
92
 
75
93
  end
76
94
  end
@@ -1,7 +1,7 @@
1
1
  module Trinidad
2
2
  module Extensions
3
3
  module Lifecycle
4
- VERSION = '0.3.0'
4
+ VERSION = '0.4.0'
5
5
  end
6
6
  end
7
7
  end
@@ -1,35 +1,22 @@
1
1
  module Trinidad
2
2
  module Lifecycle
3
3
  module Server
4
-
5
- CONSTANT = 42
6
-
4
+ ANSWER = 42
7
5
  class FakeStart < Base
8
-
9
6
  def start
10
7
  put "#{self.inspect} start"
11
8
  end
12
-
13
9
  end
14
-
15
- USER_CONFIG = org.apache.catalina.startup.UserConfig
16
-
17
10
  end
18
11
  module WebApp
19
-
20
12
  class HelperClass; end
21
-
22
13
  class FakeListener
23
14
  include Trinidad::Tomcat::LifecycleListener
24
15
 
25
16
  def lifecycleEvent(event)
26
17
  put "#{self.inspect} lifecycle event: #{event}"
27
18
  end
28
-
29
19
  end
30
-
31
- SECURITY = org.apache.catalina.security.SecurityListener.new
32
-
33
20
  end
34
21
  end
35
22
  end
@@ -0,0 +1,10 @@
1
+ module Trinidad
2
+ module Lifecycle
3
+ module Server
4
+ USER_CONFIG = org.apache.catalina.startup.UserConfig
5
+ end
6
+ module WebApp
7
+ SECURITY = org.apache.catalina.security.SecurityListener.new
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,9 @@
1
+ module Trinidad
2
+ module Lifecycle
3
+ module Server
4
+ Security = org.apache.catalina.security.SecurityListener
5
+ end
6
+ module WebApp
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Trinidad
2
+ module Lifecycle
3
+ module Server
4
+ class EngineConfig < org.apache.catalina.startup.EngineConfig
5
+ def initialize
6
+ end
7
+ end
8
+ class Noise; end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Trinidad
2
+ module Lifecycle
3
+ module WebApp
4
+ UserConfig = org.apache.catalina.startup.UserConfig.new
5
+ end
6
+ end
7
+ end
@@ -3,9 +3,18 @@ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
3
3
  describe 'trinidad lifecycle extension' do
4
4
 
5
5
  before :all do
6
- @options = { :path => File.expand_path('../fixtures', __FILE__) }
6
+ @options = { :path => File.expand_path('../lifecycle', __FILE__) }
7
7
  end
8
8
 
9
+ after do
10
+ Trinidad::Lifecycle::Server.listener_constants.each do |name|
11
+ Trinidad::Lifecycle::Server.send :remove_const, name
12
+ end
13
+ Trinidad::Lifecycle::WebApp.listener_constants.each do |name|
14
+ Trinidad::Lifecycle::WebApp.send :remove_const, name
15
+ end
16
+ end
17
+
9
18
  let(:tomcat) { org.apache.catalina.startup.Tomcat.new }
10
19
  let(:context) { Trinidad::Tomcat::StandardContext.new }
11
20
 
@@ -15,7 +24,16 @@ describe 'trinidad lifecycle extension' do
15
24
 
16
25
  it "adds the listener to the tomcat's server context" do
17
26
  subject.configure(tomcat)
18
- tomcat.server.findLifecycleListeners().should have(2).listener
27
+ tomcat.server.findLifecycleListeners.should have(2).listener
28
+ end
29
+
30
+ it "accepts a glob path" do
31
+ subject.options.replace :path => 'spec/listeners/ser*.rb'
32
+ subject.configure(tomcat)
33
+ tomcat.server.findLifecycleListeners.should have(2).listener
34
+ listeners = tomcat.server.findLifecycleListeners
35
+ listeners[0].should be_a org.apache.catalina.security.SecurityListener
36
+ listeners[1].should be_a org.apache.catalina.startup.EngineConfig
19
37
  end
20
38
 
21
39
  end
@@ -25,8 +43,15 @@ describe 'trinidad lifecycle extension' do
25
43
  subject { Trinidad::Extensions::LifecycleWebAppExtension.new(@options.dup) }
26
44
 
27
45
  it "adds the listener to the application context" do
28
- subject.configure(tomcat, context)
29
- context.findLifecycleListeners().should have(2).listener
46
+ subject.configure(context)
47
+ context.findLifecycleListeners.should have(2).listener
48
+ end
49
+
50
+ it "allows the path to point to a ruby file" do
51
+ subject.options.replace :listeners_path => 'spec/listeners/web_app.rb'
52
+ subject.configure(context)
53
+ context.findLifecycleListeners.should have(1).listener
54
+ context.findLifecycleListeners[0].should be_a org.apache.catalina.startup.UserConfig
30
55
  end
31
56
 
32
57
  end
@@ -7,8 +7,10 @@ Gem::Specification.new do |s|
7
7
  s.version = Trinidad::Extensions::Lifecycle::VERSION
8
8
  s.rubyforge_project = 'trinidad_lifecycle_extension'
9
9
 
10
- s.summary = "Add lifecycle listeners to Trinidad"
11
- s.description = "Add lifecycle listeners to Trinidad's server or the web applications that run on it."
10
+ s.summary = "Lifecycle Listeners for Trinidad"
11
+ s.description = "This extension allows you to add lifecycle listeners to " +
12
+ "Trinidad's server container as well as to deployed web application " +
13
+ "contexts running on top of it."
12
14
 
13
15
  s.authors = ["David Calavera"]
14
16
  s.email = 'calavera@apache.org'
@@ -21,7 +23,7 @@ Gem::Specification.new do |s|
21
23
  s.files = `git ls-files`.split("\n")
22
24
  s.test_files = s.files.select { |path| path =~ /^spec\/*_spec\.rb/ }
23
25
 
24
- s.add_dependency('trinidad', '>= 1.3.5')
26
+ s.add_dependency('trinidad', '>= 1.4.1')
25
27
  s.add_development_dependency('rake')
26
28
  s.add_development_dependency('rspec', '>= 2.8.0')
27
29
  s.add_development_dependency('mocha')
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: trinidad_lifecycle_extension
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.3.0
5
+ version: 0.4.0
6
6
  platform: ruby
7
7
  authors:
8
8
  - David Calavera
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-10-08 00:00:00 Z
13
+ date: 2012-10-09 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: trinidad
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 1.3.5
23
+ version: 1.4.1
24
24
  type: :runtime
25
25
  version_requirements: *id001
26
26
  - !ruby/object:Gem::Dependency
@@ -56,7 +56,7 @@ dependencies:
56
56
  version: "0"
57
57
  type: :development
58
58
  version_requirements: *id004
59
- description: Add lifecycle listeners to Trinidad's server or the web applications that run on it.
59
+ description: This extension allows you to add lifecycle listeners to Trinidad's server container as well as to deployed web application contexts running on top of it.
60
60
  email: calavera@apache.org
61
61
  executables: []
62
62
 
@@ -68,16 +68,18 @@ extra_rdoc_files:
68
68
  files:
69
69
  - .gitignore
70
70
  - Gemfile
71
- - History.txt
72
71
  - LICENSE
73
72
  - README.md
74
73
  - Rakefile
75
74
  - lib/trinidad_lifecycle_extension.rb
76
75
  - lib/trinidad_lifecycle_extension/version.rb
77
- - spec/fixtures/fake_listeners.rb
76
+ - spec/lifecycle/fake.rb
77
+ - spec/lifecycle/more.rb
78
+ - spec/listeners/server_1.rb
79
+ - spec/listeners/server_2.rb
80
+ - spec/listeners/web_app.rb
78
81
  - spec/spec_helper.rb
79
82
  - spec/trinidad_lifecycle_extension_spec.rb
80
- - trinidad-libs/tomcat-catalina-jmx-remote.jar
81
83
  - trinidad_lifecycle_extension.gemspec
82
84
  homepage: http://github.com/trinidad/trinidad_lifecycle_extension
83
85
  licenses: []
@@ -105,6 +107,6 @@ rubyforge_project: trinidad_lifecycle_extension
105
107
  rubygems_version: 1.8.15
106
108
  signing_key:
107
109
  specification_version: 3
108
- summary: Add lifecycle listeners to Trinidad
110
+ summary: Lifecycle Listeners for Trinidad
109
111
  test_files: []
110
112
 
@@ -1,5 +0,0 @@
1
- == 0.2.1 (2011-01-17)
2
-
3
- * Remote jmx configuration that doesn't work, just export JVM properties instead.
4
- * Use lib/lifecycle as default path.
5
- * Fix error when there arent listeners to load.