Ruby 1.9.3 リファレンスマニュアル > ライブラリ一覧 > rinda/tuplespaceライブラリ > Rinda::TupleSpaceクラス

class Rinda::TupleSpace + MonitorMixin + DRb::DRbUndumped

クラスの継承リスト: Rinda::TupleSpace < MonitorMixin < DRb::DRbUndumped < Object < Kernel < BasicObject

要約

Tuple Space のためのクラスです。 普通は Rinda::TupleSpaceProxy を介して使います。

特異メソッド

new(period = 60)

[TODO]

Rinda::TupleSpace オブジェクトを生成します。

インスタンスメソッド

mon_enter -> ()

モニターをロックします。

一度に一つのスレッドだけがモニターをロックできます。 既にモニターがロックされている場合は、ロックが開放されるまで そのスレッドは待ちます。

Mutex#lock に相当します。 Mutex#lock と違うのは現在のモニターの所有者が現在実行されているスレッドである場合、 何度でもロックできる点です。ロックした回数だけ mon_exit を呼ばなければモニターは 解放されません。

例:

require 'monitor'
buf = []
buf.extend(MonitorMixin)
buf.mon_enter
buf.mon_enter

Mutex#lock ではデッドロックが起きます。

例:

require 'thread'
m = Mutex.new
m.lock
m.lock # => deadlock; recursive locking (ThreadError)
mon_exit -> ()

モニターのロックを解放します。

mon_enter でロックした回数だけ mon_exit を 呼ばなければモニターは解放されません。

モニターが解放されればモニターのロック待ちになっていた スレッドが一つ実行を再開します。

[EXCEPTION] ThreadError:
ロックを持っていないスレッドが呼びだした場合に発生します
mon_synchronize { ... } -> object
synchronize { ... } -> object

モニターをロックし、ブロックを実行します。実行後に必ずモニターのロックを解放します。

ブロックの評価値を返り値として返します。

[SEE_ALSO] MonitorMixin#mon_enter

mon_try_enter -> bool
try_mon_enter -> bool

モニターのロックを取得しようと試みます。 ロックに成功した(ロックが開放状態だった、もしくは ロックを取得していたスレッドが自分自身であった)場合には 真を返します。

ロックができなかった場合は偽を返し、実行を継続します。この場合には スレッドはブロックしません。

move(port, tuple, sec = nil)

[TODO]

Moves +tuple+ to +port+.

new_cond -> MonitorMixin::ConditionVariable

モニタに関連付けられた、新しい MonitorMixin::ConditionVariable を生成して返します。

notify(event, tuple, sec = nil)

[TODO]

Registers for notifications of +event+. Returns a NotifyTemplateEntry. See NotifyTemplateEntry for examples of how to listen for notifications.

+event+ can be:

'write': A tuple was added

'take': A tuple was taken or moved

'delete': A tuple was lost after being overwritten or expiring

The TupleSpace will also notify you of the 'close' event when the NotifyTemplateEntry has expired.

read(tuple, sec=nil)

[TODO]

Reads +tuple+, but does not remove it.

read_all(tuple)

[TODO]

Returns all tuples matching +tuple+. Does not remove the found tuples.

take(tuple, sec = nil)
take(tuple, sec = nil) {|template| ... }

[TODO]

tuple にマッチするタプルをタプルスペースから取り出して返します。 マッチするタプルが存在しない場合は、マッチするタプルがタプルスペースに 投入されるまで待ちます。

待ち時間が sec 秒を過ぎた時には take をあきらめ 例外 Rinda::RequestExpiredError を投げます。

write(tuple, sec = nil)

[TODO]

Rinda::Tuple オブジェクト tuple をタプルスペースに加えます。 tuple を管理するための Rinda::TupleEntry オブジェクトを返します。

class Rinda::TupleSpace