Class: Aikido::Zen::IPC::Client
- Inherits:
-
Object
- Object
- Aikido::Zen::IPC::Client
- Includes:
- Handshake::Client
- Defined in:
- lib/aikido/zen/ipc/ipc.rb
Instance Attribute Summary collapse
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Class Method Summary collapse
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(secret, host = "127.0.0.1", port = 0, connect_timeout: IPC::CONNECT_TIMEOUT, handshake_timeout: IPC::HANDSHAKE_TIMEOUT, reconnect: false, reconnect_delay: IPC::RECONNECT_DELAY) ⇒ Client
constructor
A new instance of Client.
- #start(&block) ⇒ Object
- #stop(&block) ⇒ Object
Constructor Details
#initialize(secret, host = "127.0.0.1", port = 0, connect_timeout: IPC::CONNECT_TIMEOUT, handshake_timeout: IPC::HANDSHAKE_TIMEOUT, reconnect: false, reconnect_delay: IPC::RECONNECT_DELAY) ⇒ Client
Returns a new instance of Client.
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/aikido/zen/ipc/ipc.rb', line 419 def initialize( secret, host = "127.0.0.1", port = 0, connect_timeout: IPC::CONNECT_TIMEOUT, handshake_timeout: IPC::HANDSHAKE_TIMEOUT, reconnect: false, reconnect_delay: IPC::RECONNECT_DELAY ) @secret = secret @host = host @port = port @connect_timeout = connect_timeout @handshake_timeout = handshake_timeout @reconnect = reconnect @reconnect_delay = reconnect_delay @running = Concurrent::AtomicBoolean.new(false) connect end |
Instance Attribute Details
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
394 395 396 |
# File 'lib/aikido/zen/ipc/ipc.rb', line 394 def socket @socket end |
Class Method Details
.start(secret, host = "127.0.0.1", port = 0, connect_timeout: IPC::CONNECT_TIMEOUT, handshake_timeout: IPC::HANDSHAKE_TIMEOUT, reconnect: false, reconnect_delay: IPC::RECONNECT_DELAY, &block) ⇒ Object
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/aikido/zen/ipc/ipc.rb', line 396 def self.start( secret, host = "127.0.0.1", port = 0, connect_timeout: IPC::CONNECT_TIMEOUT, handshake_timeout: IPC::HANDSHAKE_TIMEOUT, reconnect: false, reconnect_delay: IPC::RECONNECT_DELAY, &block ) client = new( secret, host, port, connect_timeout: connect_timeout, handshake_timeout: handshake_timeout, reconnect: reconnect, reconnect_delay: reconnect_delay ) client.start(&block) client end |
Instance Method Details
#close ⇒ Object
441 442 443 |
# File 'lib/aikido/zen/ipc/ipc.rb', line 441 def close @socket.close end |
#start(&block) ⇒ Object
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 |
# File 'lib/aikido/zen/ipc/ipc.rb', line 445 def start(&block) raise ArgumentError, "block required" unless block return false unless @running.make_true Thread.new do loop do block.call(@socket) break rescue break unless @reconnect && reconnect end ensure @running.make_false close end true end |
#stop(&block) ⇒ Object
466 467 468 469 470 471 472 473 474 |
# File 'lib/aikido/zen/ipc/ipc.rb', line 466 def stop(&block) return false unless @running.make_false block&.call close true end |