torquebox-scheduling 4.0.0.alpha1-java

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 796ce74cdf3f9b5e3eeae0e71c87a0db5189785c
4
+ data.tar.gz: 90bac3951e73cab6c0a50614d4e08b1818e21b4f
5
+ SHA512:
6
+ metadata.gz: 512e06854638257d5962ad619432042e89d0332d333e295e4adb2ffb0329bd9adace8e583ed3b5b92bf53e3dc22e369a6824a71b1329caf594b6f8d1d6439319
7
+ data.tar.gz: 4ceb64201f9ffde95b3e368ef565aa101e4fa7c44c64c8f043c8fdfaa579de8f51e46addd87de62d69881add2bc87510b5388cab11d980088caae1b96ab55318
@@ -0,0 +1,21 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'torquebox-core'
16
+
17
+ Dir.glob("#{File.dirname(__FILE__)}/wunderboss-jars/*.jar") do |jar|
18
+ TorqueBox::Jars.register_and_require(jar)
19
+ end
20
+
21
+ require 'torquebox/scheduling'
@@ -0,0 +1,16 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ require 'torquebox/scheduling/scheduler'
16
+ require 'torquebox/scheduling/job'
@@ -0,0 +1,50 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module TorqueBox
17
+ module Scheduling
18
+ # Represents a scheduled job.
19
+ #
20
+ # (see {Scheduler#schedule})
21
+ class Job
22
+
23
+ # The id of this job
24
+ attr_reader :id
25
+
26
+ # Returns true if this job replaced an existing job with the
27
+ # same id.
28
+ def replacement?
29
+ @replacement
30
+ end
31
+
32
+ # Unschedules this job.
33
+ #
34
+ # (see {Scheduler#unschedule})
35
+ # @return true if a job was unscheduled, false otherwise
36
+ def unschedule
37
+ @scheduler.unschedule(@id)
38
+ end
39
+
40
+ protected
41
+
42
+ def initialize(scheduler, id, replacement)
43
+ @scheduler = scheduler
44
+ @id = id
45
+ @replacement = replacement
46
+ end
47
+
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,161 @@
1
+ # Copyright 2014 Red Hat, Inc, and individual contributors.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module TorqueBox
17
+ module Scheduling
18
+ # Provides an interface to a job scheduler.
19
+ #
20
+ # You can get access to the default or a custom configured
21
+ # scheduler via {.find_or_create}, and schedule against that
22
+ # instance, or use {.schedule} and {.unschedule} to interact with
23
+ # the default scheduler.
24
+ class Scheduler
25
+ include TorqueBox::OptionUtils
26
+
27
+ # @return The raw java scheduler object.
28
+ attr_reader :internal_scheduler
29
+
30
+ # Schedules a job to fire at some point(s) in the future.
31
+ #
32
+ # If called with the id of an already scheduled job, that job
33
+ # will be replaced.
34
+ #
35
+ # Time options (`:at`, `:until`) can be specified as `Time`
36
+ # objects or millis-since-epoch.
37
+ #
38
+ # Period options (`:in`, `:every`) are milliseconds, but can be
39
+ # generated with ActiveSupport's numeric additions (if your
40
+ # application uses ActiveSupport):
41
+ #
42
+ # s.schedule(:foo, in: 5.minutes, every: 10.seconds) {
43
+ # puts "Called!"
44
+ # }
45
+ #
46
+ # @param id [String, Symbol] The identifier for the job.
47
+ # @param spec [Hash] Options specifying the firing schedule for the job.
48
+ # @option spec :in [Fixnum] a period (in millis) after which the job will fire
49
+ # @option spec :at [Time, Fixnum] a time after which the job will fire
50
+ # @option spec :every [Fixnum] the period (in millis) between firings
51
+ # @option spec :until [Time, Fixnum] a specific time for the job to stop firing
52
+ # @option spec :limit [Fixnum] limits the firings to a specific count
53
+ # @option spec :cron [String] fires according to a
54
+ # {http://quartz-scheduler.org/documentation/quartz-2.2.x/tutorials/tutorial-lesson-06 Quartz-style}
55
+ # cron spec
56
+ # @option spec :singleton [true, false] (true) denotes the job's behavior in a cluster
57
+ # @param block [Proc] A zero-arity block or proc that will be
58
+ # called on each job execution.
59
+ # @return [Job] An object that allows you to unschedule the job.
60
+ def schedule(id, spec, &block)
61
+ validate_options(spec, opts_to_set(WBScheduling::ScheduleOption))
62
+ spec = coerce_schedule_options(spec)
63
+ replacement = internal_scheduler.schedule(id.to_s, block,
64
+ extract_options(spec, WBScheduling::ScheduleOption))
65
+ Job.new(self, id, replacement)
66
+ end
67
+
68
+ # Unschedules the job with the given id.
69
+ #
70
+ # @param id [String, Symbol] The id of the job to unschedule
71
+ # @return true if a job was unscheduled, false otherwise
72
+ def unschedule(id)
73
+ internal_scheduler.unschedule(id.to_s)
74
+ end
75
+
76
+ # Starts the scheduler.
77
+ #
78
+ # The scheduler will automatically be started when a job is
79
+ # scheduled, so you may never need to call this.
80
+ def start
81
+ @internal_scheduler.start
82
+ end
83
+
84
+ # Stops the scheduler after unscheduling all of its jobs.
85
+ def stop
86
+ @internal_scheduler.stop
87
+ end
88
+
89
+ # Looks up the scheduler with the given name.
90
+ #
91
+ # If a scheduler with that name doesn't exist, it is created
92
+ # with the given options. The options are ignored when
93
+ # retrieving an existing scheduler.
94
+ #
95
+ # @param name [String, Symbol] The name of the scheduler. The
96
+ # default scheduler is named 'default'.
97
+ # @param options [Hash] Options for scheduler creation.
98
+ # @option options num_threads [Fixnum] (5) The size of the thread
99
+ # pool for firing jobs
100
+ def self.find_or_create(name, options = {})
101
+ Scheduler.new(name, options)
102
+ end
103
+
104
+ # (see #schedule)
105
+ # This method schedules via the default scheduler.
106
+ def self.schedule(id, spec, &block)
107
+ default_scheduler.schedule(id, spec, &block)
108
+ end
109
+
110
+ # (see #unschedule)
111
+ # This method unschedules via the default scheduler.
112
+ def self.unschedule(id)
113
+ default_scheduler.unschedule(id)
114
+ end
115
+
116
+ protected
117
+
118
+ WB = org.projectodd.wunderboss.WunderBoss
119
+ WBScheduling = org.projectodd.wunderboss.scheduling.Scheduling
120
+
121
+ def self.default_scheduler
122
+ @scheduler ||= find_or_create("default")
123
+ end
124
+
125
+ def initialize(name, options = {})
126
+ @logger = WB.logger('TorqueBox::Scheduling::Scheduler')
127
+ validate_options(options, opts_to_set(WBScheduling::CreateOption))
128
+ create_options = extract_options(options, WBScheduling::CreateOption)
129
+ comp = WB.find_or_create_component(WBScheduling.java_class, name,
130
+ create_options)
131
+ @logger.debug("TorqueBox::Scheduling::Scheduler '{}' has component {}",
132
+ name, comp)
133
+ @internal_scheduler = comp
134
+ at_exit { stop }
135
+ end
136
+
137
+ def coerce_schedule_options(options)
138
+ options.clone.merge(options) do |k, v|
139
+ # ActiveSupport's durations use seconds as the base unit, so
140
+ # we have to detect that and convert to ms
141
+ v = v.in_milliseconds if defined?(ActiveSupport::Duration) && v.is_a?(ActiveSupport::Duration)
142
+
143
+ v = as_date(v) if [:at, :until].include?(k)
144
+
145
+ v = !!v if k == :singleton
146
+
147
+ v.to_java
148
+ end
149
+ end
150
+
151
+ def as_date(val)
152
+ if val.is_a?(Integer)
153
+ Time.at(val)
154
+ else
155
+ val
156
+ end
157
+ end
158
+
159
+ end
160
+ end
161
+ end
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: torquebox-scheduling
3
+ version: !ruby/object:Gem::Version
4
+ version: 4.0.0.alpha1
5
+ platform: java
6
+ authors:
7
+ - The TorqueBox Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: torquebox-core
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0.alpha1
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - '='
23
+ - !ruby/object:Gem::Version
24
+ version: 4.0.0.alpha1
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: jbundler
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0'
39
+ prerelease: false
40
+ type: :development
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ prerelease: false
54
+ type: :development
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake-compiler
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ prerelease: false
68
+ type: :development
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.14'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: '2.14'
81
+ prerelease: false
82
+ type: :development
83
+ description:
84
+ email: torquebox-dev@torquebox.org
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - lib/torquebox-scheduling.rb
90
+ - lib/wunderboss-jars/wunderboss-scheduling-1.x.incremental.174.jar
91
+ - lib/wunderboss-jars/quartz-2.2.1.jar
92
+ - lib/torquebox/scheduling.rb
93
+ - lib/torquebox/scheduling/scheduler.rb
94
+ - lib/torquebox/scheduling/job.rb
95
+ homepage: http://torquebox.org/torqbox
96
+ licenses:
97
+ - Apache-2.0
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - '>='
106
+ - !ruby/object:Gem::Version
107
+ version: 1.9.3
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - '>'
111
+ - !ruby/object:Gem::Version
112
+ version: 1.3.1
113
+ requirements:
114
+ - jar org.projectodd.wunderboss:wunderboss-ruby, 1.x.incremental.174
115
+ - jar org.projectodd.wunderboss:wunderboss-scheduling, 1.x.incremental.174
116
+ rubyforge_project:
117
+ rubygems_version: 2.1.9
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: TorqueBox Next Generation
121
+ test_files: []
122
+ has_rdoc: