github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

jmettraux / ruote

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 142
    • 17
  • Source
  • Commits
  • Network (17)
  • Issues (1)
  • Downloads (11)
  • Wiki (6)
  • Graphs
  • Tree: fc2d533

click here to add a description

click here to add a homepage

  • Branches (3)
    • ruote0.9
    • ruote2.0
    • ruote2.1
  • Tags (11)
    • v2.1.6
    • v2.1.5
    • v2.1.4
    • v2.1.3
    • v2.1.2
    • v2.1.1
    • v2.1.0
    • ruote_classical_0.9
    • r0.9.20
    • r0.9.19
    • r0.9.18
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

a ruby workflow engine — Read more

  cancel

http://ruote.rubyforge.org

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

making it easier to reach me 
jmettraux (author)
Thu Feb 26 19:28:25 -0800 2009
commit  fc2d533d7bc5cfbf42c4315f24d1bd0ffc35f96e
tree    be1384afae5d9697ae77341ce9d08c0d8a463dec
parent  fff7069e079e755795abcde2f5ad2ac8d241b943
ruote / lib / openwfe / expool / tc_expstorage.rb lib/openwfe/expool/tc_expstorage.rb
100644 240 lines (197 sloc) 6.392 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#
#--
# Copyright (c) 2009, John Mettraux, OpenWFE.org
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# . Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# . Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# . Neither the name of the "OpenWFE" nor the names of its contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#++
#
 
#
# "made in Japan"
#
# John Mettraux at openwfe.org
#
 
require 'base64'
 
require 'openwfe/flowexpressionid'
require 'openwfe/expool/expstorage'
 
require 'rufus/tokyo' # sudo gem install rufus-tokyo
 
begin
  require 'tokyocabinet' # attempting to load Hirabayashi-san's native bindings
  require 'rufus/edo'
rescue LoadError
end
 
 
module OpenWFE
 
  #
  # re-opening FlowExpression to add a method for determining
  # a 'Tokyo Cabinet key'
  #
  class FlowExpressionId
    def as_tc_key
      "#{@workflow_instance_id} #{@expression_name} #{@expression_id}"
    end
  end
 
  #
  # Tokyo Cabinet based expstorage.
  #
  # Places all the expressions under expstorage.tch in the work directory.
  #
  class TcExpressionStorage
    include ServiceMixin
    include OwfeServiceLocator
    include ExpressionStorageBase
 
    attr_reader :db
 
    def initialize (service_name, application_context)
 
      service_init(service_name, application_context)
 
      klass = (defined?(TokyoCabinet) &&
        ( ! application_context[:use_rufus_tokyo])) ?
        Rufus::Edo::Table : Rufus::Tokyo::Table
 
      linfo { "using #{klass} to access TokyoCabinet" }
 
      @db = klass.new(get_work_directory + '/expstorage.tct')
 
      set_indexes
 
      observe_expool
    end
 
    #
    # Takes care of closing the cabinet
    #
    def stop
 
      @db.close
      @db = nil
 
      super
    end
 
    #
    # Returns the count of stored expressions
    #
    def size
 
      @db.size
    end
    alias :length :size
 
    def [] (fei)
 
      v = @db[fei.as_tc_key]
 
      return nil unless v
 
      fexp = Marshal.load(Base64.decode64(v['fexp']))
 
      fexp.application_context = @application_context
      fexp
    end
 
    def []= (fei, fexp)
 
      @db[fei.as_tc_key] = {
        'wfid' => fexp.fei.wfid,
        'pwfid' => fexp.fei.parent_workflow_instance_id,
        'class' => fexp.class.name,
        'fexp' => Base64.encode64(Marshal.dump(fexp))
      }
    end
 
    def delete (fei)
 
      @db.delete(fei.as_tc_key)
    end
 
    def purge
 
      @db.clear
    end
 
    #
    # Finds expressions matching the given criteria (returns a list
    # of expressions).
    #
    # This methods is called by the expression pool, it's thus not
    # very "public" (not used directly by integrators, who should
    # just focus on the methods provided by the Engine).
    #
    # :wfid ::
    # will list only one process,
    # <tt>:wfid => '20071208-gipijiwozo'</tt>
    # :parent_wfid ::
    # will list only one process, and its subprocesses,
    # <tt>:parent_wfid => '20071208-gipijiwozo'</tt>
    # :consider_subprocesses ::
    # if true, "process-definition" expressions
    # of subprocesses will be returned as well.
    # :wfid_prefix ::
    # allows your to query for specific workflow instance
    # id prefixes. for example :
    # <tt>:wfid_prefix => "200712"</tt>
    # for the processes started in December.
    # :include_classes ::
    # excepts a class or an array of classes, only instances of these
    # classes will be returned. Parent classes or mixins can be
    # given.
    # <tt>:includes_classes => OpenWFE::SequenceExpression</tt>
    # :exclude_classes ::
    # works as expected.
    # :wfname ::
    # will return only the expressions who belongs to the given
    # workflow [name].
    # :wfrevision ::
    # usued in conjuction with :wfname, returns only the expressions
    # with a given workflow revision.
    # :applied ::
    # if this option is set to true, will only return the expressions
    # that have been applied (exp.apply_time != nil).
    #
    def find_expressions (options={})
 
      values = if wfid = options.delete(:wfid)
        @db.query { |q|
          q.add('wfid', :equals, wfid)
        }
      elsif pwfid = options.delete(:parent_wfid)
        @db.query { |q|
          q.add('pwfid', :equals, pwfid)
        }
      elsif wfidp = options.delete(:wfid_prefix)
        @db.query { |q|
          q.add('wfid', :starts_with, wfidp)
        }
      else
        @db.values # everything
      end
 
      values.inject([]) { |a, v|
        fexp = Marshal.load(Base64.decode64(v['fexp']))
        if does_match?(options, fexp)
          fexp.application_context = @application_context
          a << fexp
        end
        a
      }
    end
 
    #
    # Attempts at fetching the root expression of a given process
    # instance.
    #
    def fetch_root (wfid)
 
      find_expressions(
        :wfid => wfid,
        :consider_subprocesses => false,
        :include_classes => DefineExpression)[0]
    end
 
    protected
 
    #
    # Sets the indexes for the Tokyo Cabinet/Tyrant table.
    #
    def set_indexes
 
      @db.set_index(:pk, :lexical)
      @db.set_index('wfid', :lexical)
      @db.set_index('pwfid', :lexical)
    end
  end
 
end
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server