Class/Module Index [+]

Quicksearch

Ruote::ReceiverMixin

The core methods for the Receiver class (sometimes a Mixin is easier to integrate).

(The engine itself includes this mixin, the LocalParticipant module includes it as well).

Public Instance Methods

launch(process_definition, fields={}, variables={}) click to toggle source

Given a process definitions and optional initial fields and variables, launches a new process instance.

This method is mostly used from the Ruote::Engine class (which includes this mixin).

process_definition must be a result of Ruote.process_definition call or XML or JSON serialized process definition, as accepted by Ruote::Parser#parse.

fields are workflow parameters that will be placed in workitem.fields.

variables contain engine variables.

# File lib/ruote/receiver/base.rb, line 66
def launch (process_definition, fields={}, variables={})

  wfid = @context.wfidgen.generate

  @context.storage.put_msg(
    'launch',
    'wfid' => wfid,
    'tree' => @context.parser.parse(process_definition),
    'workitem' => { 'fields' => fields },
    'variables' => variables)

  wfid
end
receive(workitem) click to toggle source

This method pipes back a workitem into the engine, letting it resume in its flow, hopefully.

# File lib/ruote/receiver/base.rb, line 40
def receive (workitem)

  workitem = workitem.to_h if workitem.respond_to?(:to_h)

  @context.storage.put_msg(
    'receive',
    'fei' => workitem['fei'],
    'workitem' => workitem,
    'participant_name' => workitem['participant_name'],
    'receiver' => sign)
end
reply(workitem) click to toggle source

Wraps a call to receive(workitem)

Not aliasing so that if someone changes the receive implementation, reply is affected as well.

# File lib/ruote/receiver/base.rb, line 85
def reply (workitem)

  receive (workitem)
end
reply_to_engine(workitem) click to toggle source

Wraps a call to receive(workitem)

Not aliasing so that if someone changes the receive implementation, reply_to_engine is affected as well.

# File lib/ruote/receiver/base.rb, line 95
def reply_to_engine (workitem)

  receive (workitem)
end
sign() click to toggle source

A receiver signs a workitem when it comes back.

Not used much as of now.

# File lib/ruote/receiver/base.rb, line 104
def sign

  self.class.to_s
end

Protected Instance Methods

fetch_flow_expression(workitem) click to toggle source

Convenience method, fetches the flow expression (ParticipantExpression) that emitted that workitem.

# File lib/ruote/receiver/base.rb, line 114
def fetch_flow_expression (workitem)

  Ruote::Exp::FlowExpression.fetch(@context, workitem.fei.to_h)
end
get(fei, key=nil) click to toggle source

Fetches back a stashed value.

get(fei, 'colour')
  # => 'blue'

To return the whole stash

get(fei)
  # => { 'colour' => 'blue' }

put & get are useful for a participant that needs to communicate between its consume and its cancel.

# File lib/ruote/receiver/base.rb, line 154
def get (fei, key=nil)

  fexp = Ruote::Exp::FlowExpression.fetch(@context, fei.to_h)

  stash = fexp.h['stash'] rescue {}

  key ? stash[key] : stash
end
put(fei, hash) click to toggle source

Stashes values in the participant expression (in the storage).

put(workitem.fei, 'key' => 'value', 'colour' => 'blue')

Remember that keys/values must be serializable in JSON.

put & get are useful for a participant that needs to communicate between its consume and its cancel.

See the thread at groups.google.com/group/openwferu-users/t/2e6a95708c10847b for the justification.

# File lib/ruote/receiver/base.rb, line 132
def put (fei, hash)

  fexp = Ruote::Exp::FlowExpression.fetch(@context, fei.to_h)

  (fexp.h['stash'] ||= {}).merge!(hash)

  fexp.persist_or_raise
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.