trinidad_lifecycle_extension 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,5 @@
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.
data/README CHANGED
@@ -5,6 +5,10 @@ This extension allows you to add lifecycle listeners written in ruby to the
5
5
  Trinidad's server context as well as each application context that runs on top
6
6
  of Trinidad.
7
7
 
8
+ This extension also allows to enable the jmx monitoring capabilities of Tomcat.
9
+ The configuration that Tomcat needs can be set as JAVA_OPTS properties or
10
+ through the Trinidad's configuration file.
11
+
8
12
 
9
13
  Configuration
10
14
  =============
@@ -14,31 +18,12 @@ to the directory where the listeners are. For instance:
14
18
 
15
19
  extensions:
16
20
  lifecycle:
17
- path: 'lib/lifecycle'
21
+ path: 'lib/lifecycle' # Path by default, not required
18
22
 
19
23
  Trinidad will try to load each class into that directory and add it to the
20
24
  approrpiated context regarding where the extension will be configured, into the
21
25
  server section or into the web_app section.
22
26
 
23
- This extension also allows to enable the jmx monitoring capabilities of Tomcat.
24
- The configuration that Tomcat needs can be set as JAVA_OPTS properties or
25
- through the Trinidad's configuration file:
26
-
27
- extensions:
28
- lifecycle:
29
- jmx:
30
- port: 9000 # not required, 8181 by default
31
- authenticate: true # not required, false by default
32
- ssl_enabled: #not required
33
- ssl_cypher_suites: #not required
34
- ssl_auth: # not required
35
- password_file: # not required
36
- access_file: #not required
37
-
38
- See the Tomcat's documention for a complete references of the options:
39
-
40
- http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html
41
-
42
27
  How to write a lifecycle listener
43
28
  =================================
44
29
 
@@ -51,14 +36,11 @@ example:
51
36
  module Trinidad
52
37
  module Lifecycle
53
38
  module WebApp
54
- import org.apache.catalina.LifecycleListener
55
- import org.apache.catalina.Lifecycle
56
-
57
39
  class WebAppListener
58
- include LifecycleListener
40
+ include Trinidad::Tomcat::LifecycleListener
59
41
 
60
42
  def lifecycleEvent(event)
61
- if Lifecycle::BEFORE_START_EVENT == event.type
43
+ if Trinidad::Tomcat::Lifecycle::BEFORE_START_EVENT == event.type
62
44
  # do something before start the web application context
63
45
  end
64
46
  end
@@ -78,4 +60,4 @@ http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Lifecycle.jav
78
60
 
79
61
  == Copyright
80
62
 
81
- Copyright (c) 2010 David Calavera<calavera@apache.org>. See LICENSE for details.
63
+ Copyright (c) 2011 David Calavera<calavera@apache.org>. See LICENSE for details.
@@ -1,23 +1,22 @@
1
1
  require 'rubygems'
2
2
  gem 'trinidad_jars'
3
3
  require 'trinidad/extensions'
4
+ require 'java'
4
5
 
5
6
  module Trinidad
6
7
  module Extensions
7
8
  module Lifecycle
8
- VERSION = '0.2.0'
9
-
10
- DEFAULT_JMX_OPTIONS = {
11
- :port => '8181',
12
- :authenticate => false
13
- }
9
+ VERSION = '0.2.1'
14
10
 
15
11
  def init_listeners(context, path, mod_name)
12
+ path ||= File.join('lib', 'lifecycle')
13
+
16
14
  Dir.glob("#{path}/*.rb").each do |listener|
17
15
  load listener
18
16
  end
19
17
 
20
18
  mod = constantize(mod_name)
19
+ return unless mod
21
20
 
22
21
  mod.constants.each do |listener|
23
22
  const_listener = mod.const_get(listener)
@@ -27,7 +26,7 @@ module Trinidad
27
26
 
28
27
  def constantize(mod)
29
28
  names = mod.split('::')
30
- names.inject(Object) {|constant, obj| constant.const_get(obj) }
29
+ names.inject(Object) {|constant, obj| constant.const_get(obj) } rescue nil
31
30
  end
32
31
  end
33
32
 
@@ -36,35 +35,7 @@ module Trinidad
36
35
  include Lifecycle
37
36
 
38
37
  def configure(tomcat)
39
- if @options.has_key?(:path)
40
- init_listeners(tomcat.server, @options[:path], 'Trinidad::Lifecycle::Server')
41
- end
42
- if @options.has_key?(:jmx)
43
- export_jmx_settings
44
-
45
- require File.expand_path('../../trinidad-libs/tomcat-catalina-jmx-remote', __FILE__)
46
- tomcat.server.add_lifecycle_listener(org.apache.catalina.mbeans.JmxRemoteLifecycleListener.new)
47
- end
48
- end
49
-
50
- def export_jmx_settings
51
- options = DEFAULT_JMX_OPTIONS.merge(@options[:jmx] || {})
52
-
53
- set_property("com.sun.management.jmxremote", "true")
54
- set_property("com.sun.management.jmxremote.port", options[:port])
55
-
56
- set_property("com.sun.management.jmxremote.ssl", options[:ssl_enabled])
57
- set_property("com.sun.management.jmxremote.ssl.enabled.protocols", options[:ssl_protocols])
58
- set_property("com.sun.management.jmxremote.ssl.enabled.cipher.suites", options[:ssl_cypher_suites])
59
- set_property("com.sun.management.jmxremote.ssl.need.client.auth", options[:ssl_auth])
60
- set_property("com.sun.management.jmxremote.authenticate", options[:authenticate])
61
- set_property("com.sun.management.jmxremote.password.file", options[:password_file])
62
- set_property("com.sun.management.jmxremote.access.file", options[:access_file])
63
- end
64
-
65
- private
66
- def set_property(name, option)
67
- java.lang.System.set_property(name, option) if option
38
+ init_listeners(tomcat.server, @options[:path], 'Trinidad::Lifecycle::Server')
68
39
  end
69
40
  end
70
41
 
@@ -1,11 +1,9 @@
1
1
  module Trinidad
2
2
  module Lifecycle
3
- import org.apache.catalina.LifecycleListener
4
- import org.apache.catalina.Lifecycle
5
3
 
6
4
  module Server
7
5
  class FakeServerListener
8
- include LifecycleListener
6
+ include Trinidad::Tomcat::LifecycleListener
9
7
 
10
8
  def lifecycleEvent(event)
11
9
  end
@@ -14,7 +12,7 @@ module Trinidad
14
12
 
15
13
  module WebApp
16
14
  class FakeWebAppListener
17
- include LifecycleListener
15
+ include Trinidad::Tomcat::LifecycleListener
18
16
 
19
17
  def lifecycleEvent(event)
20
18
  end
@@ -18,29 +18,6 @@ describe 'Trinidad lifecycle extension' do
18
18
  subject.configure(@tomcat)
19
19
  @tomcat.server.findLifecycleListeners().should have(1).listener
20
20
  end
21
-
22
- it "adds the jmx lifecycle listener when the jmx option is true" do
23
- ext = Trinidad::Extensions::LifecycleServerExtension.new({:jmx => nil})
24
- ext.configure(@tomcat)
25
- @tomcat.server.findLifecycleListeners().should have(1).listener
26
- end
27
-
28
- it "exports jmx option when is enabled" do
29
- ext = Trinidad::Extensions::LifecycleServerExtension.new({:jmx => nil})
30
- ext.configure(@tomcat)
31
-
32
- java.lang.System.get_property("com.sun.management.jmxremote").should == 'true'
33
- java.lang.System.get_property("com.sun.management.jmxremote.port").should == '8181'
34
- end
35
-
36
- it "exports custom jmx option when it exists" do
37
- ext = Trinidad::Extensions::LifecycleServerExtension.new({
38
- :jmx => {:ssl_enabled => 'true'}
39
- })
40
- ext.configure(@tomcat)
41
-
42
- java.lang.System.get_property("com.sun.management.jmxremote.ssl").should == 'true'
43
- end
44
21
  end
45
22
 
46
23
  context "when it's a webapp extension" do
@@ -13,8 +13,8 @@ Gem::Specification.new do |s|
13
13
  ## If your rubyforge_project name is different, then edit it and comment out
14
14
  ## the sub! line in the Rakefile
15
15
  s.name = 'trinidad_lifecycle_extension'
16
- s.version = '0.2.0'
17
- s.date = '2010-09-26'
16
+ s.version = '0.2.1'
17
+ s.date = '2011-01-17'
18
18
  s.rubyforge_project = 'trinidad_lifecycle_extension'
19
19
 
20
20
  ## Make sure your summary is short. The description may be as long
@@ -51,6 +51,7 @@ Gem::Specification.new do |s|
51
51
  ## THE MANIFEST COMMENTS, they are used as delimiters by the task.
52
52
  # = MANIFEST =
53
53
  s.files = %w[
54
+ History.txt
54
55
  LICENSE
55
56
  README
56
57
  Rakefile
metadata CHANGED
@@ -3,18 +3,18 @@ name: trinidad_lifecycle_extension
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
- - 0
7
- - 2
8
- - 0
9
- version: 0.2.0
6
+ - 0
7
+ - 2
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
- - David Calavera
12
+ - David Calavera
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-09-26 00:00:00 +02:00
17
+ date: 2011-01-17 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -25,48 +25,47 @@ executables: []
25
25
  extensions: []
26
26
 
27
27
  extra_rdoc_files:
28
- - README
29
- - LICENSE
28
+ - README
29
+ - LICENSE
30
30
  files:
31
- - LICENSE
32
- - README
33
- - Rakefile
34
- - lib/trinidad_lifecycle_extension.rb
35
- - spec/fixtures/fake_lifecycle_listener.rb
36
- - spec/spec.opts
37
- - spec/spec_helper.rb
38
- - spec/trinidad_lifecycle_extension_spec.rb
39
- - trinidad-libs/tomcat-catalina-jmx-remote.jar
40
- - trinidad_lifecycle_extension.gemspec
31
+ - History.txt
32
+ - LICENSE
33
+ - README
34
+ - Rakefile
35
+ - lib/trinidad_lifecycle_extension.rb
36
+ - spec/fixtures/fake_lifecycle_listener.rb
37
+ - spec/spec.opts
38
+ - spec/spec_helper.rb
39
+ - spec/trinidad_lifecycle_extension_spec.rb
40
+ - trinidad-libs/tomcat-catalina-jmx-remote.jar
41
+ - trinidad_lifecycle_extension.gemspec
41
42
  has_rdoc: true
42
43
  homepage: http://github.com/calavera/trinidad_lifecycle_extension
43
44
  licenses: []
44
45
 
45
46
  post_install_message:
46
47
  rdoc_options:
47
- - --charset=UTF-8
48
+ - --charset=UTF-8
48
49
  require_paths:
49
- - lib
50
+ - lib
50
51
  required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
52
  requirements:
53
- - - ">="
54
- - !ruby/object:Gem::Version
55
- segments:
56
- - 0
57
- version: "0"
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ segments:
56
+ - 0
57
+ version: "0"
58
58
  required_rubygems_version: !ruby/object:Gem::Requirement
59
- none: false
60
59
  requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- segments:
64
- - 0
65
- version: "0"
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ segments:
63
+ - 0
64
+ version: "0"
66
65
  requirements: []
67
66
 
68
67
  rubyforge_project: trinidad_lifecycle_extension
69
- rubygems_version: 1.3.7
68
+ rubygems_version: 1.3.6
70
69
  signing_key:
71
70
  specification_version: 2
72
71
  summary: Add lifecycle listeners to the trinidad's server or applications