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(timeout_seconds = nil, local_druby_uri: nil, config: nil) ⇒ Object
- #start_server ⇒ Object
- #stop_server ⇒ Object
Constructor Details
#initialize ⇒ LocalServiceServerClient
Returns a new instance of LocalServiceServerClient.
325 326 327 328 329 330 331 332 333 |
# File 'lib/riser/services.rb', line 325 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
545 546 547 548 |
# File 'lib/riser/services.rb', line 545 def self.make_pair server_client = new return server_client.get_server, server_client.get_client end |
Instance Method Details
#[](name, *optional, &block) ⇒ Object
472 473 474 475 476 477 478 479 480 481 482 |
# File 'lib/riser/services.rb', line 472 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
375 376 377 378 379 |
# File 'lib/riser/services.rb', line 375 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
393 394 395 396 |
# File 'lib/riser/services.rb', line 393 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
335 336 337 338 |
# File 'lib/riser/services.rb', line 335 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
381 382 383 384 385 |
# File 'lib/riser/services.rb', line 381 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
398 399 400 401 |
# File 'lib/riser/services.rb', line 398 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
387 388 389 390 391 |
# File 'lib/riser/services.rb', line 387 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
403 404 405 406 |
# File 'lib/riser/services.rb', line 403 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
455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/riser/services.rb', line 455 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
541 542 543 |
# File 'lib/riser/services.rb', line 541 def get_client LocalServiceCall.new(self) end |
#get_server ⇒ Object
537 538 539 |
# File 'lib/riser/services.rb', line 537 def get_server LocalServiceServer.new(self) end |
#get_service(name, *optional) ⇒ Object
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/riser/services.rb', line 423 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
345 346 347 348 |
# File 'lib/riser/services.rb', line 345 def postprocess(name, &block) # :yields: service_front @services[name].postprocess = block nil end |
#preprocess(name, &block) ⇒ Object
:yields: service_front
340 341 342 343 |
# File 'lib/riser/services.rb', line 340 def preprocess(name, &block) # :yields: service_front @services[name].preprocess = block nil end |
#start_client(timeout_seconds = nil, local_druby_uri: nil, config: nil) ⇒ Object
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 |
# File 'lib/riser/services.rb', line 509 def start_client(timeout_seconds=nil, local_druby_uri: nil, config: nil) @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
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 |
# File 'lib/riser/services.rb', line 484 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
525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/riser/services.rb', line 525 def stop_server if (@mutex.synchronize{ @state } == :do) then @mutex.synchronize{ @stop = true @stop_cond.signal } @hook_thread.join end nil end |