Class: Fairy::ChunkedSizedPoolQueue

Inherits:
ChunkedPoolQueue show all
Defined in:
lib/fairy/share/port.rb

Instance Attribute Summary

Attributes inherited from ChunkedPoolQueue

#fib_cv

Instance Method Summary collapse

Constructor Details

#initialize(policy, queues_mon = Monitor.new, queues_cv = queues_mon.new_cond) ⇒ ChunkedSizedPoolQueue

Returns a new instance of ChunkedSizedPoolQueue.



1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
# File 'lib/fairy/share/port.rb', line 1084

def initialize(policy, queues_mon = Monitor.new, queues_cv = queues_mon.new_cond)
  super
  @max_size = policy[:size]
  @max_size ||= CONF.ONMEMORY_SIZEDQUEUE_SIZE

  @queue_size = 0

  @pop_cv = @queues_cv
  @push_cv = @queues_mon.new_cond
end

Instance Method Details

#popObject



1111
1112
1113
1114
1115
1116
1117
1118
# File 'lib/fairy/share/port.rb', line 1111

def pop
  e = super
  @queues_mon.synchronize do
	@queue_size -= 1
	@push_cv.broadcast if @queue_size <= @max_size
  end
  e
end

#pop_allObject



1120
1121
1122
1123
1124
1125
1126
1127
# File 'lib/fairy/share/port.rb', line 1120

def pop_all
  buf = super
  @queues_mon.synchronize do
	@queue_size -= buf.size
	@push_cv.broadcast if @queue_size <= @max_size
  end
  buf
end

#push(e) ⇒ Object



1095
1096
1097
1098
1099
1100
1101
# File 'lib/fairy/share/port.rb', line 1095

def push(e)
  @queues_mon.synchronize do
	@push_cv.wait_while{@queue_size > @max_size}
	@queue_size += 1
  end
  super
end

#push_all(buf) ⇒ Object



1103
1104
1105
1106
1107
1108
1109
# File 'lib/fairy/share/port.rb', line 1103

def push_all(buf)
  @queues_mon.synchronize do
	@push_cv.wait_while{@queue_size > @max_size}
	@queue_size += buf.size
  end
  super
end