Skip to content

Commit

Permalink
reintroduction of the 'listener' concept : lib/ruote/part/listener.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
jmettraux committed Apr 20, 2010
1 parent 31ff672 commit 5c0789a
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.txt
Expand Up @@ -4,6 +4,7 @@

== ruote - 2.1.10 not yet released

- reintroduction of the 'listener' concept : lib/ruote/part/listener.rb
- LocalParticpant : added a reject(workitem) method
- participant exp : dispatched = true set right after dispatch

Expand Down
71 changes: 71 additions & 0 deletions lib/ruote/part/listener.rb
@@ -0,0 +1,71 @@
#--
# Copyright (c) 2005-2010, 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

#
# Listening to workitems coming [back] to the engine.
#
# This module contains the base methods necessary for a Listener
# implementation.
#
# This module is included in the LocalParticipant one. The reply_to_engine
# method is present in both concepts.
#
# Hypothetically, a listener implementation might look like :
#
# require 'ruote/part/listener'
#
# class MyMqListener
# include Ruote::Listener
# def initialize (queue)
# @queue = queue
# end
# def start_pooling
# while workitem = @queue.blocking_pop
# reply_to_engine(workitem)
# end
# end
# end
#
module Listener

attr_accessor :context

# Sends back the workitem to the ruote engine.
#
def reply_to_engine (workitem)

# the local participant knows how to deal with the storage directly

@context.storage.put_msg(
'receive',
'fei' => workitem.h.fei,
'workitem' => workitem.h,
'participant_name' => workitem.participant_name)
end
end
end

18 changes: 4 additions & 14 deletions lib/ruote/part/local_participant.rb
Expand Up @@ -22,6 +22,8 @@
# Made in Japan.
#++

require 'ruote/part/listener'


module Ruote

Expand All @@ -35,20 +37,8 @@ module Ruote
#
module LocalParticipant

attr_accessor :context

# Sends back the workitem to the ruote engine.
#
def reply_to_engine (workitem)

# the local participant knows how to deal with the storage directly

@context.storage.put_msg(
'receive',
'fei' => workitem.h.fei,
'workitem' => workitem.h,
'participant_name' => workitem.participant_name)
end
include Listener
# the reply_to_engine method is there

# WARNING : this method is only for 'stateless' participants, ie
# participants that are registered in the engine by passing their class
Expand Down

0 comments on commit 5c0789a

Please sign in to comment.