Class OpenWFE::DefaultWfidGenerator
In: lib/openwfe/expool/wfidgen.rb
Parent: Service

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"

Methods

Public Class methods

[Source]

    # File lib/openwfe/expool/wfidgen.rb, line 57
57:         def initialize (service_name, application_context)
58: 
59:             super
60: 
61:             @last = -1
62:             @mutex = Mutex.new
63: 
64:             @last_fn = get_work_directory + '/wfidgen.last'
65: 
66:             load_last()
67: 
68:             ensure_last_f
69:         end

This method is called by OpenWFE::split_wfid() when it has detected a wfid following this ‘defaut’ scheme.

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 111
111:         def self.split_wfid (wfid)
112: 
113:             r = []
114:             0.upto(wfid.length-1) do |i|
115:                 r << wfid[i, 1]
116:             end
117: 
118:             r
119:         end

Public Instance methods

Returns a new workflow instance id

The launchitem parameter is not used by this generator.

[Source]

    # File lib/openwfe/expool/wfidgen.rb, line 76
76:         def generate (launchitem=nil)
77: 
78:             wfid = nil
79: 
80:             @mutex.synchronize do
81:                 wfid = now
82:                 wfid = @last + 1 if wfid <= @last
83:                 @last = wfid
84:                 save_last
85:             end
86: 
87:             to_string(wfid)
88:         end

Is a simple call to OpenWFE::split_wfid()

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 102
102:         def split_wfid (wfid)
103: 
104:             OpenWFE.split_wfid(wfid)
105:         end

Stops this service. In this particular implementation, makes sure the "wfidgen.last" file is closed.

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 126
126:         def stop
127: 
128:             #linfo { "stop() stopping '#{@service_name}'" }
129:             @last_f.close if @last_f
130:         end

The actual job of turning the numeric result into a String. This method is overriden in extension of this class.

[Source]

    # File lib/openwfe/expool/wfidgen.rb, line 94
94:         def to_string (numeric_id)
95: 
96:             numeric_id.to_s
97:         end

Protected Instance methods

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 134
134:             def ensure_last_f
135:                 if (not @last_f) or @last_f.closed?
136:                     begin
137:                         @last_f = File.open(@last_fn, "w+")
138:                     rescue Exception => e
139:                         lwarn do
140:                             "new() failed to open #{@last_fn}, "+
141:                             "continuing anyway...\n"+
142:                             OpenWFE::exception_to_s(e)
143:                         end
144:                     end
145:                 end
146:             end

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 160
160:             def load_last
161:                 @mutex.synchronize do
162: 
163:                     if File.exist?(@last_fn)
164:                         begin
165:                             s = File.open(@last_fn, "r") do |f|
166:                                 f.readline
167:                             end
168:                             @last = Integer(s)
169:                             #puts @last
170:                         rescue Exception => e
171:                             #puts
172:                             #puts e.to_s
173:                         end
174:                     end
175: 
176:                     n = now
177: 
178:                     @last = n if (not @last) or (@last < n)
179:                 end
180:             end

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 148
148:             def now
149:                 wfid = Time.now.to_f * 1000 * 10
150:                 wfid.to_i
151:             end

[Source]

     # File lib/openwfe/expool/wfidgen.rb, line 153
153:             def save_last
154:                 return unless @last_f
155:                 ensure_last_f()
156:                 @last_f.pos = 0
157:                 @last_f.puts @last
158:             end

[Validate]