Permalink
Browse files

initial commit

  • Loading branch information...
0 parents commit 72d0f9b657cba8dd9ca17fd64ede631accebdce0 @jmettraux committed May 11, 2009
@@ -0,0 +1,7 @@
+
+= ruota
+
+== license
+
+MIT
+
@@ -0,0 +1,3 @@
+
+#require ''
+
@@ -0,0 +1,3 @@
+
+require 'ruote/engine/engine'
+
@@ -0,0 +1,55 @@
+#--
+# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# Made in Japan.
+#++
+
+
+module Ruote
+
+ module EngineContext
+
+ attr_accessor :context
+
+ alias :ac :context
+ alias :application_context :context
+
+ def engine
+ @context[:s_engine]
+ end
+ def get_expression_pool
+ @context[:expression_pool]
+ end
+ def expstorage
+ @context[:s_expression_storage]
+ end
+ def workqueue
+ @context[:s_wqueue]
+ end
+ def parser
+ @context[:s_parser]
+ end
+ def scheduler
+ @context[:s_scheduler]
+ end
+ end
+end
+
@@ -0,0 +1,108 @@
+#--
+# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# Made in Japan.
+#++
+
+
+#require 'rufus/scheduler' # sudo gem install rufus-scheduler
+
+require 'ruote/engine/context'
+require 'ruote/parser'
+require 'ruote/expressions/expression_map'
+require 'ruote/expool/wfid_generator'
+require 'ruote/expool/expression_pool'
+require 'ruote/wqueue/work_queue'
+
+
+module Ruote
+
+ class Engine
+
+ include EngineContext
+
+ def initialize (context={})
+
+ @context = context
+
+ build_scheduler
+ build_parser
+ build_expression_map
+ build_expression_storage
+ build_expression_pool
+ build_work_queue
+ build_wfid_generator
+
+ build_tree_checker
+ build_parser
+ end
+
+ def launch (definition, workitem)
+
+ tree = parser.parse(definition)
+
+ expool.apply(tree, nil, workitem)
+ end
+
+ protected
+
+ def build_service (name, o)
+
+ service = o.is_a?(Class) ? o.new : o
+ service.context = @context if o.respond_to?(:context=)
+ @context[name] = service
+ #service
+ end
+
+ def build_scheduler
+ #build_service(:s_scheduler, Rufus::Scheduler.start_new)
+ end
+
+ def build_expression_map
+ build_service(:s_expression_map, Ruote::ExpressionMap)
+ end
+
+ def build_expression_storage
+ build_service(:s_expression_storage, Hash)
+ end
+
+ def build_expression_pool
+ build_service(:s_expression_pool, Ruote::ExpressionPool)
+ end
+
+ def build_work_queue
+ build_service(:s_work_queue, Ruote::PlainWorkQueue)
+ end
+
+ def build_wfid_generator
+ build_service(:s_wfid_generator, Ruote::PlainWfidGenerator)
+ end
+
+ def build_tree_checker
+ #build_service(:s_tree_checker, ...
+ end
+
+ def build_parser
+ build_service(:s_parser, Ruote::Parser)
+ end
+ end
+end
+
@@ -0,0 +1,37 @@
+#--
+# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# Made in Japan.
+#++
+
+require 'ruote/engine/context'
+
+
+module Ruote
+
+ class ExpressionPool
+
+ include EngineContext
+
+ #def initialize
+ #end
+ end
+end
@@ -0,0 +1,45 @@
+#--
+# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# Made in Japan.
+#++
+
+require 'thread'
+
+
+module Ruote
+
+ class PlainWfidGenerator
+
+ def initialize
+ @counter = -1
+ @mutex = Mutex.new
+ end
+
+ def generate
+
+ @mutex.synchronize do
+ @counter += 1
+ @counter
+ end
+ end
+ end
+end
@@ -0,0 +1,57 @@
+#--
+# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# Made in Japan.
+#++
+
+exppath = File.dirname(__FILE__)
+
+Dir.new(exppath).entries.select { |p|
+ p.match(/^fe_.*\.rb$/)
+}.each { |p|
+ require exppath + '/' + p
+}
+
+
+module Ruote
+
+ class ExpressionMap
+
+ def initialize
+
+ @map = {}
+
+ add(Ruote::SequenceExpression)
+ add(Ruote::EchoExpression)
+ end
+
+ def exp_class (exp_name)
+ @map[exp_name]
+ end
+
+ protected
+
+ def add (exp_class)
+ exp_class.names.each { |n| @map[n] = exp_class }
+ end
+ end
+end
+
@@ -0,0 +1,47 @@
+#--
+# Copyright (c) 2009, John Mettraux, jmettraux@gmail.com
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# Made in Japan.
+#++
+
+require 'ruote/expressions/flowexpression'
+
+
+module Ruote
+
+ class EchoExpression < FlowExpression
+
+ def self.names; %w[ echo ]; end
+
+ def apply (workitem)
+
+ reply(workitem)
+ end
+
+ def reply (workitem)
+
+ puts @children.inspect
+
+ reply_to_parent(workitem)
+ end
+ end
+end
+
Oops, something went wrong.

0 comments on commit 72d0f9b

Please sign in to comment.