trinidad_lifecycle_extension 0.2.2 → 0.3.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/.gitignore +2 -0
- data/Gemfile +2 -0
- data/LICENSE +1 -3
- data/README.md +140 -0
- data/Rakefile +9 -142
- data/lib/trinidad_lifecycle_extension.rb +43 -31
- data/lib/trinidad_lifecycle_extension/version.rb +7 -0
- data/spec/fixtures/fake_listeners.rb +35 -0
- data/spec/spec_helper.rb +11 -8
- data/spec/trinidad_lifecycle_extension_spec.rb +18 -16
- data/trinidad_lifecycle_extension.gemspec +18 -61
- metadata +58 -15
- data/README +0 -63
- data/spec/fixtures/fake_lifecycle_listener.rb +0 -22
- data/spec/spec.opts +0 -2
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
Copyright (c) 2010 David Calavera
|
1
|
+
Copyright (c) 2012 Team Trinidad and contributors http://github.com/trinidad
|
4
2
|
|
5
3
|
Permission is hereby granted, free of charge, to any person obtaining
|
6
4
|
a copy of this software and associated documentation files (the
|
data/README.md
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
# Trinidad Lifecycle Extension
|
2
|
+
|
3
|
+
This extension allows you to add lifecycle listeners (written in ruby) to the
|
4
|
+
[Trinidad](https://github.com/trinidad/trinidad/) server container as well as to
|
5
|
+
each deployed web application context running on top of Trinidad.
|
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.
|
10
|
+
|
11
|
+
## Install
|
12
|
+
|
13
|
+
Install the gem or simply add it to you *Gemfile* along with Trinidad :
|
14
|
+
|
15
|
+
```
|
16
|
+
group :server do
|
17
|
+
platform :jruby do
|
18
|
+
gem 'trinidad', :require => false
|
19
|
+
gem 'trinidad_lifecycle_extension', :require => false
|
20
|
+
end
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
## Configuration
|
25
|
+
|
26
|
+
Add this extension into the Trinidad's configuration file and (optionally) set
|
27
|
+
the path to the directory where the listener .rb files are located e.g. :
|
28
|
+
|
29
|
+
```
|
30
|
+
---
|
31
|
+
# ...
|
32
|
+
extensions:
|
33
|
+
lifecycle:
|
34
|
+
path: 'lib/lifecycle' # defaults to lib/lifecycle
|
35
|
+
```
|
36
|
+
|
37
|
+
Trinidad will try to require the *.rb files from the lifecycle directory and
|
38
|
+
will instantiate listener classes while adding them to the appropriate lifecycle
|
39
|
+
container based on whether the class is defined under the `Lifecycle::Server` or
|
40
|
+
the `Lifecycle::WebApp` module.
|
41
|
+
|
42
|
+
## How to write a Listener
|
43
|
+
|
44
|
+
### Server Lifecycle Listener
|
45
|
+
|
46
|
+
If the listener is for the server the class must be exported under the module
|
47
|
+
`Trinidad::Lifecycle::Server` the class is expected to "implement" the interface
|
48
|
+
[LifecycleListener](http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/LifecycleListener.html)
|
49
|
+
you do not need to worry about that if you extend from `Trinidad::Lifecycle::Base`
|
50
|
+
class. All [Lifecycle](http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/Lifecycle.html)
|
51
|
+
events are mapped to methods e.g. on an `AFTER_INIT_EVENT` `#after_init(event)`
|
52
|
+
gets invoked, it accepts a single argument the event object.
|
53
|
+
Example :
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
module Trinidad
|
57
|
+
module Lifecycle
|
58
|
+
module Server
|
59
|
+
# for Trinidad::Lifecycle::Base
|
60
|
+
# @see trinidad/lifecycle/base.rb
|
61
|
+
class StartStop < Base
|
62
|
+
|
63
|
+
def start(event)
|
64
|
+
puts "starting server"
|
65
|
+
end
|
66
|
+
|
67
|
+
def stop(event)
|
68
|
+
puts "stopping server"
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
```
|
76
|
+
|
77
|
+
You can as well export existing (Java classes) as nested module constants and
|
78
|
+
they will be instantiated and configured as listeners e.g. :
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
module Trinidad
|
82
|
+
module Lifecycle
|
83
|
+
module Server
|
84
|
+
SIMPLE_CLUSTER = org.apache.catalina.ha.tcp.SimpleTcpCluster
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
90
|
+
### WebApp Lifecycle Listener
|
91
|
+
|
92
|
+
The very same rulez apply as for the Server Listener above except that we add
|
93
|
+
listener classes under the `Trinidad::Lifecycle::WebApp` module e.g. :
|
94
|
+
|
95
|
+
```ruby
|
96
|
+
module Trinidad
|
97
|
+
module Lifecycle
|
98
|
+
module WebApp
|
99
|
+
# not using Trinidad::Lifecycle::Base base class ...
|
100
|
+
# but implementing Tomcat:LifecycleListener by hand
|
101
|
+
class TheOldWayListener
|
102
|
+
include Trinidad::Tomcat::LifecycleListener
|
103
|
+
|
104
|
+
def lifecycleEvent(event)
|
105
|
+
case event.type
|
106
|
+
when Trinidad::Tomcat::Lifecycle::BEFORE_START_EVENT
|
107
|
+
# do something before start the web application context
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
```
|
116
|
+
|
117
|
+
Lifecycle listeners might be exported as configured instances as well e.g. :
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
module Trinidad
|
121
|
+
module Lifecycle
|
122
|
+
module Server
|
123
|
+
|
124
|
+
def self.configure_cluster
|
125
|
+
cluster = org.apache.catalina.ha.tcp.SimpleTcpCluster.new
|
126
|
+
cluster.setClusterName('Trinidad')
|
127
|
+
cluster
|
128
|
+
end
|
129
|
+
|
130
|
+
CONFIGURED_CLUSTER = self.configure_cluster
|
131
|
+
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
```
|
136
|
+
|
137
|
+
## Copyright
|
138
|
+
|
139
|
+
Copyright (c) 2012 [Team Trinidad](https://github.com/trinidad).
|
140
|
+
See LICENSE (http://en.wikipedia.org/wiki/MIT_License) for details.
|
data/Rakefile
CHANGED
@@ -1,147 +1,14 @@
|
|
1
|
-
|
2
|
-
require '
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
#
|
7
|
-
# Helper functions
|
8
|
-
#
|
9
|
-
#############################################################################
|
10
|
-
|
11
|
-
def name
|
12
|
-
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
-
end
|
14
|
-
|
15
|
-
def version
|
16
|
-
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
17
|
-
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
18
|
-
end
|
19
|
-
|
20
|
-
def date
|
21
|
-
Date.today.to_s
|
22
|
-
end
|
23
|
-
|
24
|
-
def rubyforge_project
|
25
|
-
name
|
26
|
-
end
|
27
|
-
|
28
|
-
def gemspec_file
|
29
|
-
"#{name}.gemspec"
|
1
|
+
begin
|
2
|
+
require 'bundler/gem_helper'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'bundler/gem_helper'
|
30
6
|
end
|
7
|
+
Bundler::GemHelper.install_tasks
|
31
8
|
|
32
|
-
|
33
|
-
|
9
|
+
require 'rspec/core/rake_task'
|
10
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
11
|
+
spec.rspec_opts = ['--color', "--format documentation"]
|
34
12
|
end
|
35
13
|
|
36
|
-
def replace_header(head, header_name)
|
37
|
-
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
38
|
-
end
|
39
|
-
|
40
|
-
#############################################################################
|
41
|
-
#
|
42
|
-
# Standard tasks
|
43
|
-
#
|
44
|
-
#############################################################################
|
45
|
-
|
46
14
|
task :default => :spec
|
47
|
-
|
48
|
-
require 'spec/rake/spectask'
|
49
|
-
Spec::Rake::SpecTask.new(:spec) do |spec|
|
50
|
-
spec.libs << 'lib' << 'spec'
|
51
|
-
spec.spec_opts = ['--options', 'spec/spec.opts']
|
52
|
-
spec.spec_files = FileList['spec/**/*_spec.rb']
|
53
|
-
end
|
54
|
-
|
55
|
-
|
56
|
-
desc "Generate RCov test coverage and open in your browser"
|
57
|
-
task :coverage do
|
58
|
-
require 'rcov'
|
59
|
-
sh "rm -fr coverage"
|
60
|
-
sh "rcov test/test_*.rb"
|
61
|
-
sh "open coverage/index.html"
|
62
|
-
end
|
63
|
-
|
64
|
-
require 'rake/rdoctask'
|
65
|
-
Rake::RDocTask.new do |rdoc|
|
66
|
-
rdoc.rdoc_dir = 'rdoc'
|
67
|
-
rdoc.title = "#{name} #{version}"
|
68
|
-
rdoc.rdoc_files.include('README*')
|
69
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
70
|
-
end
|
71
|
-
|
72
|
-
desc "Open an irb session preloaded with this library"
|
73
|
-
task :console do
|
74
|
-
sh "irb -rubygems -r ./lib/#{name}.rb"
|
75
|
-
end
|
76
|
-
|
77
|
-
#############################################################################
|
78
|
-
#
|
79
|
-
# Custom tasks (add your own tasks here)
|
80
|
-
#
|
81
|
-
#############################################################################
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
#############################################################################
|
86
|
-
#
|
87
|
-
# Packaging tasks
|
88
|
-
#
|
89
|
-
#############################################################################
|
90
|
-
|
91
|
-
task :release => :build do
|
92
|
-
unless `git branch` =~ /^\* master$/
|
93
|
-
puts "You must be on the master branch to release!"
|
94
|
-
exit!
|
95
|
-
end
|
96
|
-
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
97
|
-
sh "git tag v#{version}"
|
98
|
-
sh "git push origin master"
|
99
|
-
sh "git push --tags"
|
100
|
-
sh "gem push pkg/#{name}-#{version}.gem"
|
101
|
-
end
|
102
|
-
|
103
|
-
task :build => :gemspec do
|
104
|
-
sh "mkdir -p pkg"
|
105
|
-
sh "gem build #{gemspec_file}"
|
106
|
-
sh "mv #{gem_file} pkg"
|
107
|
-
end
|
108
|
-
|
109
|
-
task :gemspec => :validate do
|
110
|
-
# read spec file and split out manifest section
|
111
|
-
spec = File.read(gemspec_file)
|
112
|
-
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
113
|
-
|
114
|
-
# replace name version and date
|
115
|
-
replace_header(head, :name)
|
116
|
-
replace_header(head, :version)
|
117
|
-
replace_header(head, :date)
|
118
|
-
#comment this out if your rubyforge_project has a different name
|
119
|
-
replace_header(head, :rubyforge_project)
|
120
|
-
|
121
|
-
# determine file list from git ls-files
|
122
|
-
files = `git ls-files`.
|
123
|
-
split("\n").
|
124
|
-
sort.
|
125
|
-
reject { |file| file =~ /^\./ }.
|
126
|
-
reject { |file| file =~ /^(rdoc|pkg|src)/ }.
|
127
|
-
map { |file| " #{file}" }.
|
128
|
-
join("\n")
|
129
|
-
|
130
|
-
# piece file back together and write
|
131
|
-
manifest = " s.files = %w[\n#{files}\n ]\n"
|
132
|
-
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
133
|
-
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
134
|
-
puts "Updated #{gemspec_file}"
|
135
|
-
end
|
136
|
-
|
137
|
-
task :validate do
|
138
|
-
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
139
|
-
unless libfiles.empty?
|
140
|
-
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
141
|
-
exit!
|
142
|
-
end
|
143
|
-
unless Dir['VERSION*'].empty?
|
144
|
-
puts "A `VERSION` file at root level violates Gem best practices."
|
145
|
-
exit!
|
146
|
-
end
|
147
|
-
end
|
@@ -1,57 +1,68 @@
|
|
1
|
-
require '
|
2
|
-
|
3
|
-
require 'trinidad/extensions'
|
4
|
-
require 'java'
|
1
|
+
require 'trinidad'
|
2
|
+
require 'trinidad_lifecycle_extension/version'
|
5
3
|
|
6
4
|
module Trinidad
|
5
|
+
module Lifecycle
|
6
|
+
|
7
|
+
Listener = Trinidad::Tomcat::LifecycleListener
|
8
|
+
|
9
|
+
module Server; end
|
10
|
+
module WebApp; end
|
11
|
+
|
12
|
+
[ Server, WebApp ].each do |mod|
|
13
|
+
mod.module_eval do
|
14
|
+
@@_constants = self.constants.dup
|
15
|
+
|
16
|
+
def self.listeners
|
17
|
+
listeners = self.constants - @@_constants
|
18
|
+
listeners.map! do |name|
|
19
|
+
const = self.const_get(name)
|
20
|
+
if const.is_a?(Class) && const.included_modules.include?(Listener)
|
21
|
+
const.new
|
22
|
+
elsif const.is_a?(Listener)
|
23
|
+
const
|
24
|
+
end
|
25
|
+
end
|
26
|
+
listeners.compact
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
7
33
|
module Extensions
|
8
34
|
module Lifecycle
|
9
|
-
VERSION = '0.2.2'
|
10
35
|
|
11
|
-
|
36
|
+
private
|
37
|
+
|
38
|
+
def init_listeners(container, path, base_mod)
|
12
39
|
path ||= File.join('lib', 'lifecycle')
|
13
40
|
|
14
|
-
Dir.glob("#{path}/*.rb").each
|
15
|
-
load listener
|
16
|
-
end
|
17
|
-
|
18
|
-
mod = constantize(mod_name)
|
19
|
-
return unless mod
|
41
|
+
Dir.glob("#{path}/*.rb").each { |rb| require rb }
|
20
42
|
|
21
|
-
|
22
|
-
|
23
|
-
context.add_lifecycle_listener(const_listener.new)
|
43
|
+
base_mod.listeners.each do |listener|
|
44
|
+
container.add_lifecycle_listener listener
|
24
45
|
end
|
25
46
|
end
|
26
|
-
|
27
|
-
def constantize(mod)
|
28
|
-
names = mod.split('::')
|
29
|
-
names.inject(Object) {|constant, obj| constant.const_get(obj) } rescue nil
|
30
|
-
end
|
31
|
-
|
32
|
-
def trap_signals(tomcat)
|
33
|
-
trap('INT') { tomcat.stop }
|
34
|
-
trap('TERM') { tomcat.stop }
|
35
|
-
end
|
47
|
+
|
36
48
|
end
|
37
49
|
|
38
|
-
|
39
50
|
class LifecycleServerExtension < ServerExtension
|
40
51
|
include Lifecycle
|
41
52
|
|
42
53
|
def configure(tomcat)
|
43
|
-
|
44
|
-
init_listeners(tomcat.server, @options[:path], 'Trinidad::Lifecycle::Server')
|
54
|
+
init_listeners(tomcat.server, @options[:path], Trinidad::Lifecycle::Server)
|
45
55
|
end
|
56
|
+
|
46
57
|
end
|
47
58
|
|
48
59
|
class LifecycleWebAppExtension < WebAppExtension
|
49
60
|
include Lifecycle
|
50
61
|
|
51
|
-
def configure(tomcat,
|
52
|
-
|
53
|
-
init_listeners(app_context, @options[:path], 'Trinidad::Lifecycle::WebApp')
|
62
|
+
def configure(tomcat, context)
|
63
|
+
init_listeners(context, @options[:path], Trinidad::Lifecycle::WebApp)
|
54
64
|
end
|
65
|
+
|
55
66
|
end
|
56
67
|
|
57
68
|
class LifecycleOptionsExtension < OptionsExtension
|
@@ -60,5 +71,6 @@ module Trinidad
|
|
60
71
|
default_options[:extensions][:lifecycle] = {}
|
61
72
|
end
|
62
73
|
end
|
74
|
+
|
63
75
|
end
|
64
76
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Trinidad
|
2
|
+
module Lifecycle
|
3
|
+
module Server
|
4
|
+
|
5
|
+
CONSTANT = 42
|
6
|
+
|
7
|
+
class FakeStart < Base
|
8
|
+
|
9
|
+
def start
|
10
|
+
put "#{self.inspect} start"
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
USER_CONFIG = org.apache.catalina.startup.UserConfig
|
16
|
+
|
17
|
+
end
|
18
|
+
module WebApp
|
19
|
+
|
20
|
+
class HelperClass; end
|
21
|
+
|
22
|
+
class FakeListener
|
23
|
+
include Trinidad::Tomcat::LifecycleListener
|
24
|
+
|
25
|
+
def lifecycleEvent(event)
|
26
|
+
put "#{self.inspect} lifecycle event: #{event}"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
SECURITY = org.apache.catalina.security.SecurityListener.new
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
require '
|
1
|
+
begin
|
2
|
+
require 'trinidad'
|
3
|
+
rescue LoadError
|
4
|
+
require 'rubygems'
|
5
|
+
require 'trinidad'
|
6
|
+
end
|
5
7
|
|
6
|
-
require '
|
7
|
-
require 'trinidad'
|
8
|
-
require 'spec'
|
8
|
+
require 'rspec'
|
9
9
|
|
10
|
-
|
10
|
+
RSpec.configure do |config|
|
11
11
|
config.mock_with :mocha
|
12
12
|
end
|
13
|
+
|
14
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
15
|
+
require 'trinidad_lifecycle_extension'
|
@@ -1,32 +1,34 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
2
|
|
3
|
-
describe '
|
4
|
-
|
3
|
+
describe 'trinidad lifecycle extension' do
|
4
|
+
|
5
|
+
before :all do
|
5
6
|
@options = { :path => File.expand_path('../fixtures', __FILE__) }
|
6
7
|
end
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
@tomcat = mock
|
11
|
-
@tomcat.stubs(:server).returns(@context)
|
12
|
-
end
|
9
|
+
let(:tomcat) { org.apache.catalina.startup.Tomcat.new }
|
10
|
+
let(:context) { Trinidad::Tomcat::StandardContext.new }
|
13
11
|
|
14
|
-
context "
|
15
|
-
|
12
|
+
context "server" do
|
13
|
+
|
14
|
+
subject { Trinidad::Extensions::LifecycleServerExtension.new(@options.dup) }
|
16
15
|
|
17
16
|
it "adds the listener to the tomcat's server context" do
|
18
|
-
subject.configure(
|
19
|
-
|
17
|
+
subject.configure(tomcat)
|
18
|
+
tomcat.server.findLifecycleListeners().should have(2).listener
|
20
19
|
end
|
20
|
+
|
21
21
|
end
|
22
22
|
|
23
|
-
context "
|
24
|
-
|
23
|
+
context "webapp" do
|
24
|
+
|
25
|
+
subject { Trinidad::Extensions::LifecycleWebAppExtension.new(@options.dup) }
|
25
26
|
|
26
27
|
it "adds the listener to the application context" do
|
27
|
-
|
28
|
-
|
29
|
-
app_context.findLifecycleListeners().should have(1).listener
|
28
|
+
subject.configure(tomcat, context)
|
29
|
+
context.findLifecycleListeners().should have(2).listener
|
30
30
|
end
|
31
|
+
|
31
32
|
end
|
33
|
+
|
32
34
|
end
|
@@ -1,71 +1,28 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
## this file, feel free to delete any comments that begin with two hash marks.
|
5
|
-
## You can find comprehensive Gem::Specification documentation, at
|
6
|
-
## http://docs.rubygems.org/read/chapter/20
|
7
|
-
Gem::Specification.new do |s|
|
8
|
-
s.specification_version = 2 if s.respond_to? :specification_version=
|
9
|
-
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
10
|
-
s.rubygems_version = '1.3.5'
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "trinidad_lifecycle_extension/version"
|
11
4
|
|
12
|
-
|
13
|
-
## If your rubyforge_project name is different, then edit it and comment out
|
14
|
-
## the sub! line in the Rakefile
|
5
|
+
Gem::Specification.new do |s|
|
15
6
|
s.name = 'trinidad_lifecycle_extension'
|
16
|
-
s.version =
|
17
|
-
s.date = '2011-03-30'
|
7
|
+
s.version = Trinidad::Extensions::Lifecycle::VERSION
|
18
8
|
s.rubyforge_project = 'trinidad_lifecycle_extension'
|
19
9
|
|
20
|
-
|
21
|
-
|
22
|
-
s.summary = "Add lifecycle listeners to the trinidad's server or applications"
|
23
|
-
s.description = "Add lifecycle listeners to the trinidad's server or the applications that run on it"
|
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."
|
24
12
|
|
25
|
-
## List the primary authors. If there are a bunch of authors, it's probably
|
26
|
-
## better to set the email to an email list or something. If you don't have
|
27
|
-
## a custom homepage, consider using your GitHub URL or the like.
|
28
13
|
s.authors = ["David Calavera"]
|
29
14
|
s.email = 'calavera@apache.org'
|
30
|
-
s.homepage = 'http://github.com/
|
15
|
+
s.homepage = 'http://github.com/trinidad/trinidad_lifecycle_extension'
|
31
16
|
|
32
|
-
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
33
|
-
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
34
|
-
s.require_paths = %w[lib]
|
35
|
-
|
36
|
-
## Specify any RDoc options here. You'll want to add your README and
|
37
|
-
## LICENSE files to the extra_rdoc_files list.
|
38
17
|
s.rdoc_options = ["--charset=UTF-8"]
|
39
|
-
s.extra_rdoc_files = %w[README LICENSE]
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
# s.add_dependency('DEPNAME', [">= 1.1.0", "< 2.0.0"])
|
44
|
-
|
45
|
-
## List your development dependencies here. Development dependencies are
|
46
|
-
## those that are only needed during development
|
47
|
-
# s.add_development_dependency('DEVDEPNAME', [">= 1.1.0", "< 2.0.0"])
|
48
|
-
|
49
|
-
## Leave this section as-is. It will be automatically generated from the
|
50
|
-
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
51
|
-
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
52
|
-
# = MANIFEST =
|
53
|
-
s.files = %w[
|
54
|
-
History.txt
|
55
|
-
LICENSE
|
56
|
-
README
|
57
|
-
Rakefile
|
58
|
-
lib/trinidad_lifecycle_extension.rb
|
59
|
-
spec/fixtures/fake_lifecycle_listener.rb
|
60
|
-
spec/spec.opts
|
61
|
-
spec/spec_helper.rb
|
62
|
-
spec/trinidad_lifecycle_extension_spec.rb
|
63
|
-
trinidad-libs/tomcat-catalina-jmx-remote.jar
|
64
|
-
trinidad_lifecycle_extension.gemspec
|
65
|
-
]
|
66
|
-
# = MANIFEST =
|
67
|
-
|
68
|
-
## Test files will be grabbed from the file list. Make sure the path glob
|
69
|
-
## matches what you actually use.
|
18
|
+
s.extra_rdoc_files = %w[ README.md LICENSE ]
|
19
|
+
|
20
|
+
s.require_paths = %w[lib]
|
21
|
+
s.files = `git ls-files`.split("\n")
|
70
22
|
s.test_files = s.files.select { |path| path =~ /^spec\/*_spec\.rb/ }
|
71
|
-
|
23
|
+
|
24
|
+
s.add_dependency('trinidad', '>= 1.3.5')
|
25
|
+
s.add_development_dependency('rake')
|
26
|
+
s.add_development_dependency('rspec', '>= 2.8.0')
|
27
|
+
s.add_development_dependency('mocha')
|
28
|
+
end
|
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.
|
5
|
+
version: 0.3.0
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- David Calavera
|
@@ -10,33 +10,76 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date:
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
date: 2012-10-08 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: trinidad
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 1.3.5
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rake
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rspec
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.8.0
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: mocha
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
description: Add lifecycle listeners to Trinidad's server or the web applications that run on it.
|
18
60
|
email: calavera@apache.org
|
19
61
|
executables: []
|
20
62
|
|
21
63
|
extensions: []
|
22
64
|
|
23
65
|
extra_rdoc_files:
|
24
|
-
- README
|
66
|
+
- README.md
|
25
67
|
- LICENSE
|
26
68
|
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
27
71
|
- History.txt
|
28
72
|
- LICENSE
|
29
|
-
- README
|
73
|
+
- README.md
|
30
74
|
- Rakefile
|
31
75
|
- lib/trinidad_lifecycle_extension.rb
|
32
|
-
-
|
33
|
-
- spec/
|
76
|
+
- lib/trinidad_lifecycle_extension/version.rb
|
77
|
+
- spec/fixtures/fake_listeners.rb
|
34
78
|
- spec/spec_helper.rb
|
35
79
|
- spec/trinidad_lifecycle_extension_spec.rb
|
36
80
|
- trinidad-libs/tomcat-catalina-jmx-remote.jar
|
37
81
|
- trinidad_lifecycle_extension.gemspec
|
38
|
-
|
39
|
-
homepage: http://github.com/calavera/trinidad_lifecycle_extension
|
82
|
+
homepage: http://github.com/trinidad/trinidad_lifecycle_extension
|
40
83
|
licenses: []
|
41
84
|
|
42
85
|
post_install_message:
|
@@ -59,9 +102,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
102
|
requirements: []
|
60
103
|
|
61
104
|
rubyforge_project: trinidad_lifecycle_extension
|
62
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.8.15
|
63
106
|
signing_key:
|
64
|
-
specification_version:
|
65
|
-
summary: Add lifecycle listeners to
|
107
|
+
specification_version: 3
|
108
|
+
summary: Add lifecycle listeners to Trinidad
|
66
109
|
test_files: []
|
67
110
|
|
data/README
DELETED
@@ -1,63 +0,0 @@
|
|
1
|
-
Trinidad lifecycle extension
|
2
|
-
============================
|
3
|
-
|
4
|
-
This extension allows you to add lifecycle listeners written in ruby to the
|
5
|
-
Trinidad's server context as well as each application context that runs on top
|
6
|
-
of Trinidad.
|
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
|
-
|
12
|
-
|
13
|
-
Configuration
|
14
|
-
=============
|
15
|
-
|
16
|
-
Add this extension into the Trinidad's configuration file and include the path
|
17
|
-
to the directory where the listeners are. For instance:
|
18
|
-
|
19
|
-
extensions:
|
20
|
-
lifecycle:
|
21
|
-
path: 'lib/lifecycle' # Path by default, not required
|
22
|
-
|
23
|
-
Trinidad will try to load each class into that directory and add it to the
|
24
|
-
approrpiated context regarding where the extension will be configured, into the
|
25
|
-
server section or into the web_app section.
|
26
|
-
|
27
|
-
How to write a lifecycle listener
|
28
|
-
=================================
|
29
|
-
|
30
|
-
If the listener is for the server the class must be into the module
|
31
|
-
Trinidad::Lifecycle::Server but if it's for the web application it must be into
|
32
|
-
the module Trinidad::Lifecycle::WebApp. The class must include the java class
|
33
|
-
LifecycleListener and must contain the method `lifecycleEvent(event)`. For
|
34
|
-
example:
|
35
|
-
|
36
|
-
module Trinidad
|
37
|
-
module Lifecycle
|
38
|
-
module WebApp
|
39
|
-
class WebAppListener
|
40
|
-
include Trinidad::Tomcat::LifecycleListener
|
41
|
-
|
42
|
-
def lifecycleEvent(event)
|
43
|
-
if Trinidad::Tomcat::Lifecycle::BEFORE_START_EVENT == event.type
|
44
|
-
# do something before start the web application context
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
As a reference, Trinidad is configured with a lifecycle listener, here is the
|
53
|
-
code:
|
54
|
-
|
55
|
-
http://github.com/calavera/trinidad/blob/master/lib/trinidad/web_app_lifecycle_listener.rb
|
56
|
-
|
57
|
-
You should also be familiar with the Tomcat's life cycle:
|
58
|
-
|
59
|
-
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/Lifecycle.java?view=markup
|
60
|
-
|
61
|
-
== Copyright
|
62
|
-
|
63
|
-
Copyright (c) 2011 David Calavera<calavera@apache.org>. See LICENSE for details.
|
@@ -1,22 +0,0 @@
|
|
1
|
-
module Trinidad
|
2
|
-
module Lifecycle
|
3
|
-
|
4
|
-
module Server
|
5
|
-
class FakeServerListener
|
6
|
-
include Trinidad::Tomcat::LifecycleListener
|
7
|
-
|
8
|
-
def lifecycleEvent(event)
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
module WebApp
|
14
|
-
class FakeWebAppListener
|
15
|
-
include Trinidad::Tomcat::LifecycleListener
|
16
|
-
|
17
|
-
def lifecycleEvent(event)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
data/spec/spec.opts
DELETED