Class: Riser::LocalServiceServerClient
- Inherits:
-
Object
- Object
- Riser::LocalServiceServerClient
- Defined in:
- lib/riser/services.rb
Class Method Summary collapse
Instance Method Summary collapse
- #[](name, *optional, &block) ⇒ Object
- #add_any_process_service(name, callable = false) ⇒ Object
- #add_any_process_service_with_type(name, type_or_object) ⇒ Object
- #add_service(name, front) ⇒ Object
- #add_single_process_service(name, callable = false) ⇒ Object
- #add_single_process_service_with_type(name, type_or_object) ⇒ Object
- #add_sticky_process_service(name, callable = false) ⇒ Object
- #add_sticky_process_service_with_type(name, type_or_object) ⇒ Object
- #call_service(name, *optional, &block) ⇒ Object
- #get_client ⇒ Object
- #get_server ⇒ Object
- #get_service(name, *optional) ⇒ Object
-
#initialize ⇒ LocalServiceServerClient
constructor
A new instance of LocalServiceServerClient.
-
#postprocess(name, &block) ⇒ Object
:yields: service_front.
-
#preprocess(name, &block) ⇒ Object
:yields: service_front.
- #start_client ⇒ Object
- #start_server ⇒ Object
- #stop_server ⇒ Object
Constructor Details
#initialize ⇒ LocalServiceServerClient
Returns a new instance of LocalServiceServerClient.
326 327 328 329 330 331 332 333 334 |
# File 'lib/riser/services.rb', line 326 def initialize @services = {} @hook_thread = nil @mutex = Thread::Mutex.new @state = nil @state_cond = Thread::ConditionVariable.new @stop = false @stop_cond = Thread::ConditionVariable.new end |
Class Method Details
.make_pair ⇒ Object
546 547 548 549 |
# File 'lib/riser/services.rb', line 546 def self.make_pair server_client = new return server_client.get_server, server_client.get_client end |
Instance Method Details
#[](name, *optional, &block) ⇒ Object
473 474 475 476 477 478 479 480 481 482 483 |
# File 'lib/riser/services.rb', line 473 def [](name, *optional, &block) if (@services.key? name) then if (@services[name].callable) then call_service(name, *optional, &block) else get_service(name, *optional) end else raise KeyError, "not found a service: #{name}" end end |
#add_any_process_service(name, callable = false) ⇒ Object
376 377 378 379 380 |
# File 'lib/riser/services.rb', line 376 def add_any_process_service(name, callable=false) @services[name].process_type = :any @services[name].callable = callable nil end |
#add_any_process_service_with_type(name, type_or_object) ⇒ Object
394 395 396 397 |
# File 'lib/riser/services.rb', line 394 def add_any_process_service_with_type(name, type_or_object) add_any_process_service(name, DRbServiceCall.is_callable(type_or_object)) nil end |
#add_service(name, front) ⇒ Object
336 337 338 339 |
# File 'lib/riser/services.rb', line 336 def add_service(name, front) @services[name] = LocalService.new(front, DRbService::NO_CALL, DRbService::NO_CALL) nil end |
#add_single_process_service(name, callable = false) ⇒ Object
382 383 384 385 386 |
# File 'lib/riser/services.rb', line 382 def add_single_process_service(name, callable=false) @services[name].process_type = :single @services[name].callable = callable nil end |
#add_single_process_service_with_type(name, type_or_object) ⇒ Object
399 400 401 402 |
# File 'lib/riser/services.rb', line 399 def add_single_process_service_with_type(name, type_or_object) add_single_process_service(name, DRbServiceCall.is_callable(type_or_object)) nil end |
#add_sticky_process_service(name, callable = false) ⇒ Object
388 389 390 391 392 |
# File 'lib/riser/services.rb', line 388 def add_sticky_process_service(name, callable=false) @services[name].process_type = :sticky @services[name].callable = callable nil end |
#add_sticky_process_service_with_type(name, type_or_object) ⇒ Object
404 405 406 407 |
# File 'lib/riser/services.rb', line 404 def add_sticky_process_service_with_type(name, type_or_object) add_sticky_process_service(name, DRbServiceCall.is_callable(type_or_object)) nil end |
#call_service(name, *optional, &block) ⇒ Object
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 |
# File 'lib/riser/services.rb', line 456 def call_service(name, *optional, &block) if (@services.key? name) then case (@services[name].process_type) when :any call_any_process_service(name, *optional, &block) when :single call_single_process_service(name, *optional, &block) when :sticky call_sticky_process_service(name, *optional, &block) else raise "internal error: (service_name,process_type)=(#{name},#{@services[name].process_type})" end else raise KeyError, "not found a service: #{name}" end end |
#get_client ⇒ Object
542 543 544 |
# File 'lib/riser/services.rb', line 542 def get_client LocalServiceCall.new(self) end |
#get_server ⇒ Object
538 539 540 |
# File 'lib/riser/services.rb', line 538 def get_server LocalServiceServer.new(self) end |
#get_service(name, *optional) ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/riser/services.rb', line 424 def get_service(name, *optional) if (@services.key? name) then case (@services[name].process_type) when :any get_any_process_service(name, *optional) when :single get_single_process_service(name, *optional) when :sticky get_sticky_process_service(name, *optional) else raise "internal error: (service_name,process_type)=(#{name},#{@services[name].process_type})" end else raise KeyError, "not found a service: #{name}" end end |
#postprocess(name, &block) ⇒ Object
:yields: service_front
346 347 348 349 |
# File 'lib/riser/services.rb', line 346 def postprocess(name, &block) # :yields: service_front @services[name].postprocess = block nil end |
#preprocess(name, &block) ⇒ Object
:yields: service_front
341 342 343 344 |
# File 'lib/riser/services.rb', line 341 def preprocess(name, &block) # :yields: service_front @services[name].preprocess = block nil end |
#start_client ⇒ Object
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/riser/services.rb', line 510 def start_client @mutex.synchronize{ while (@state.nil?) @state_cond.wait(@mutex) end } # If the `do' state is skipped, propagate the error because an # error occurred. if (@mutex.synchronize{ @state } == :done) then @hook_thread.join end nil end |
#start_server ⇒ Object
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 |
# File 'lib/riser/services.rb', line 485 def start_server @hook_thread = Thread.new{ begin apply_service_hooks{ @mutex.synchronize{ @state = :do @state_cond.signal } @mutex.synchronize{ until (@stop) @stop_cond.wait(@mutex) end } } ensure @mutex.synchronize{ @state = :done @state_cond.signal } end } nil end |
#stop_server ⇒ Object
526 527 528 529 530 531 532 533 534 535 536 |
# File 'lib/riser/services.rb', line 526 def stop_server if (@mutex.synchronize{ @state } == :do) then @mutex.synchronize{ @stop = true @stop_cond.signal } @hook_thread.join end nil end |