Class: OpenWFE::DefaultWfidGenerator
- Defined in:
- lib/openwfe/expool/wfidgen.rb
Overview
This default wfid generator outputs a long integer as a String. The last given id (in order to prevent clocks being put back) is stored in the work directory in the file “wfidgen.last”
Direct Known Subclasses
Instance Attribute Summary
Attributes included from ServiceMixin
Attributes included from Contextual
Class Method Summary collapse
-
.split_wfid(wfid) ⇒ Object
This method is called by OpenWFE::split_wfid() when it has detected a wfid following this ‘defaut’ scheme.
Instance Method Summary collapse
-
#generate(launchitem = nil) ⇒ Object
Returns a new workflow instance id.
-
#initialize(service_name, application_context) ⇒ DefaultWfidGenerator
constructor
A new instance of DefaultWfidGenerator.
-
#split_wfid(wfid) ⇒ Object
Is a simple call to OpenWFE::split_wfid().
-
#stop ⇒ Object
Stops this service.
-
#to_string(numeric_id) ⇒ Object
The actual job of turning the numeric result into a String.
Methods included from ServiceMixin
Methods included from Contextual
#get_work_directory, #init_service, #lookup
Methods included from Logging
#ldebug, #ldebug_callstack, #lerror, #lfatal, #linfo, #llog, #lunknown, #lwarn
Constructor Details
#initialize(service_name, application_context) ⇒ DefaultWfidGenerator
Returns a new instance of DefaultWfidGenerator.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/openwfe/expool/wfidgen.rb', line 57 def initialize (service_name, application_context) super @last = -1 @mutex = Mutex.new @last_fn = get_work_directory + '/wfidgen.last' load_last() ensure_last_f end |
Class Method Details
.split_wfid(wfid) ⇒ Object
This method is called by OpenWFE::split_wfid() when it has detected a wfid following this ‘defaut’ scheme.
111 112 113 114 115 116 117 118 119 |
# File 'lib/openwfe/expool/wfidgen.rb', line 111 def self.split_wfid (wfid) r = [] 0.upto(wfid.length-1) do |i| r << wfid[i, 1] end r end |
Instance Method Details
#generate(launchitem = nil) ⇒ Object
Returns a new workflow instance id
The launchitem parameter is not used by this generator.
76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/openwfe/expool/wfidgen.rb', line 76 def generate (launchitem=nil) wfid = nil @mutex.synchronize do wfid = now wfid = @last + 1 if wfid <= @last @last = wfid save_last end to_string(wfid) end |
#split_wfid(wfid) ⇒ Object
Is a simple call to OpenWFE::split_wfid()
102 103 104 105 |
# File 'lib/openwfe/expool/wfidgen.rb', line 102 def split_wfid (wfid) OpenWFE.split_wfid(wfid) end |
#stop ⇒ Object
Stops this service. In this particular implementation, makes sure the “wfidgen.last” file is closed.
126 127 128 129 130 |
# File 'lib/openwfe/expool/wfidgen.rb', line 126 def stop #linfo { "stop() stopping '#{@service_name}'" } @last_f.close if @last_f end |
#to_string(numeric_id) ⇒ Object
The actual job of turning the numeric result into a String. This method is overriden in extension of this class.
94 95 96 97 |
# File 'lib/openwfe/expool/wfidgen.rb', line 94 def to_string (numeric_id) numeric_id.to_s end |