Class: AlWorker::Ipc
- Inherits:
-
Object
- Object
- AlWorker::Ipc
- Defined in:
- lib/al_worker_ipc.rb
Overview
IPCサーバ
Instance Attribute Summary collapse
-
#banner ⇒ String
接続後のバナー表示.
-
#cb_prefix ⇒ String
コールバックメソッドのプレフィックス.
-
#chmod ⇒ Integer
IPCソケットのread/writeモード (chmodの値).
-
#socketfile ⇒ String
readonly
IPCソケットファイル.
Class Method Summary collapse
-
.finalizer(socketfile) ⇒ Object
object finalizer.
-
.open(socketfile = nil, &block) ⇒ Object
クライアント接続ソケットの作成.
Instance Method Summary collapse
-
#initialize(socketfile = nil) ⇒ Ipc
constructor
constructor.
-
#run(obj) ⇒ Object
実行開始.
Constructor Details
#initialize(socketfile = nil) ⇒ Ipc
constructor
58 59 60 61 |
# File 'lib/al_worker_ipc.rb', line 58 def initialize( socketfile = nil ) @socketfile = socketfile @cb_prefix = "ipc" end |
Instance Attribute Details
#banner ⇒ String
Returns 接続後のバナー表示.
50 51 52 |
# File 'lib/al_worker_ipc.rb', line 50 def @banner end |
#cb_prefix ⇒ String
Returns コールバックメソッドのプレフィックス.
47 48 49 |
# File 'lib/al_worker_ipc.rb', line 47 def cb_prefix @cb_prefix end |
#chmod ⇒ Integer
Returns IPCソケットのread/writeモード (chmodの値).
44 45 46 |
# File 'lib/al_worker_ipc.rb', line 44 def chmod @chmod end |
#socketfile ⇒ String (readonly)
Returns IPCソケットファイル.
41 42 43 |
# File 'lib/al_worker_ipc.rb', line 41 def socketfile @socketfile end |
Class Method Details
.finalizer(socketfile) ⇒ Object
object finalizer
20 21 22 23 24 |
# File 'lib/al_worker_ipc.rb', line 20 def self.finalizer( socketfile ) proc { File.unlink( socketfile ) rescue 0 } end |
.open(socketfile = nil, &block) ⇒ Object
クライアント接続ソケットの作成
32 33 34 35 36 |
# File 'lib/al_worker_ipc.rb', line 32 def self.open( socketfile = nil, &block ) # ソケットファイル、デフォルト値を使う socketfile ||= File.join( AlWorker::DEFAULT_WORKDIR, AlWorker::DEFAULT_NAME ) AlWorker::IpcClient.open( socketfile, &block ) end |
Instance Method Details
#run(obj) ⇒ Object
実行開始
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/al_worker_ipc.rb', line 69 def run( obj ) @me = obj @socketfile ||= File.join( @me.workdir, @me.name ) # ソケットオープン begin UNIXSocket.open( @socketfile ) {} raise "IPC socket file '#{@socketfile}' was already in use." rescue Errno::ENOENT # ok continue. rescue Errno::ECONNREFUSED # file exist but not use. File.unlink( @socketfile ) rescue 0 end server = UNIXServer.new( @socketfile ) File.chmod( @chmod, @socketfile ) if @chmod ObjectSpace.define_finalizer( self, self.class.finalizer( @socketfile ) ) # サービス開始 Thread.start { loop do Thread.start( server.accept ) { |sock| _start_service( sock ) } end } end |