Class: PRuby::ProcNode
Overview
Classe atomique de base, donc non composite, donc celle a qui sera associe un Thread actif.
Instance Attribute Summary collapse
-
#input_channel ⇒ Channel
(also: #input)
Le canal d'entree.
-
#output_channel ⇒ Channel
(also: #output)
Le canal de sortie.
Instance Method Summary collapse
-
#add_stage(other) ⇒ Pipeline
Cree un pipeline avec self comme 1er etage et other comme 2e etage.
-
#get ⇒ Object
Obtient le prochain element du canal d'entree (simple proxy).
-
#initialize(body, source_ou_sink = nil) ⇒ Pipeline
constructor
Constructeur pour un noeud atomique (non composite).
-
#join ⇒ self
Bloque jusqu'a ce que l'execution de la tache soit terminee.
-
#peek ⇒ Object
Lit le prochain element du canal d'entree (simple proxy), mais le retirer.
-
#put(c) ⇒ self
Ecrit un element sur le canal de sortie.
-
#run(no_wait = nil) ⇒ self
Lance un thread pour executer la tache associee au noeud.
- #to_s ⇒ String
-
#value ⇒ Object
La valeur finale produite par le thread associe au noeud.
Methods inherited from Pipeline
#>>, create, #input_channel_connected?, #output_channel_connected?, sink, #sink?, source, #source?, #terminated?, #wrap_around!, #|
Constructor Details
#initialize(body, source_ou_sink = nil) ⇒ Pipeline
Constructeur pour un noeud atomique (non composite).
249 250 251 252 253 254 255 256 257 258 259 260 261 262 |
# File 'lib/pruby/pipeline.rb', line 249 def initialize( body, source_ou_sink = nil ) DBC.check_type( body, Proc, "*** Dans creation d'un pipeline, l'argument n'est pas un lambda (class = #{body.class}" ) DBC.assert( body.arity.abs >= 2, "*** Dans creation d'un pipeline, le lambda n'a pas deux arguments:\n" << " body.arity = #{body.arity}\n" << " body.parameters = #{body.parameters}\n" ) @body = body @input_channel = nil @output_channel = nil @source_ou_sink = source_ou_sink end |
Instance Attribute Details
#input_channel ⇒ Channel Also known as: input
Le canal d'entree.
234 235 236 |
# File 'lib/pruby/pipeline.rb', line 234 def input_channel @input_channel end |
#output_channel ⇒ Channel Also known as: output
Le canal de sortie.
239 240 241 |
# File 'lib/pruby/pipeline.rb', line 239 def output_channel @output_channel end |
Instance Method Details
#add_stage(other) ⇒ Pipeline
Cree un pipeline avec self comme 1er etage et other comme 2e etage
313 314 315 |
# File 'lib/pruby/pipeline.rb', line 313 def add_stage( other ) PipelineFactory.pipeline self, other end |
#get ⇒ Object
Obtient le prochain element du canal d'entree (simple proxy).
282 283 284 285 |
# File 'lib/pruby/pipeline.rb', line 282 def get DBC.require input_channel_connected?, "*** Le canal input_channel n'est pas connecte" @input_channel.get end |
#join ⇒ self
Bloque jusqu'a ce que l'execution de la tache soit terminee. Si deja termine, alors NOOP.
340 341 342 343 344 345 346 347 |
# File 'lib/pruby/pipeline.rb', line 340 def join return if terminated? @thread.join @terminated = true self end |
#peek ⇒ Object
Lit le prochain element du canal d'entree (simple proxy), mais le retirer
293 294 295 296 |
# File 'lib/pruby/pipeline.rb', line 293 def peek DBC.require input_channel_connected?, "*** Le canal input_channel n'est pas connecte" @input_channel.peek end |
#put(c) ⇒ self
Ecrit un element sur le canal de sortie.
305 306 307 308 |
# File 'lib/pruby/pipeline.rb', line 305 def put( c ) DBC.require output_channel_connected?, "*** Le canal output_channel n'est pas connecte" @output_channel.put c end |
#run(no_wait = nil) ⇒ self
Lance un thread pour executer la tache associee au noeud.
325 326 327 328 329 330 331 332 |
# File 'lib/pruby/pipeline.rb', line 325 def run( no_wait = nil ) @terminated = false @thread = Thread.new { @value = @body.call(input_channel, output_channel) } @thread.join unless no_wait == :NO_WAIT self end |
#to_s ⇒ String
358 359 360 361 362 363 364 365 366 |
# File 'lib/pruby/pipeline.rb', line 358 def to_s if source? "Source(#{output_channel})" elsif sink? "Sink(#{input_channel})" else "ProcNode(#{input_channel}, #{output_channel})" end end |
#value ⇒ Object
Returns La valeur finale produite par le thread associe au noeud.
352 353 354 355 |
# File 'lib/pruby/pipeline.rb', line 352 def value join @value end |