@@ -3,12 +3,18 @@ module ChannelIdAllocator
3
3
4
4
MAX_CHANNELS_PER_CONNECTION = ( 2 **16 ) - 1
5
5
6
+ def initialize ( *args , &block )
7
+ super
8
+
9
+ @channel_id_mutex = Mutex . new
10
+ end
11
+
6
12
# Resets channel allocator. This method is thread safe.
7
13
# @api public
8
14
# @see Channel.next_channel_id
9
15
# @see Channel.release_channel_id
10
16
def reset_channel_id_allocator
11
- channel_id_mutex . synchronize do
17
+ @ channel_id_mutex. synchronize do
12
18
int_allocator . reset
13
19
end
14
20
end
@@ -20,7 +26,7 @@ def reset_channel_id_allocator
20
26
# @see Channel.next_channel_id
21
27
# @see Channel.reset_channel_id_allocator
22
28
def release_channel_id ( i )
23
- channel_id_mutex . synchronize do
29
+ @ channel_id_mutex. synchronize do
24
30
int_allocator . release ( i )
25
31
end
26
32
end
@@ -32,7 +38,7 @@ def release_channel_id(i)
32
38
# @see Channel.release_channel_id
33
39
# @see Channel.reset_channel_id_allocator
34
40
def next_channel_id
35
- channel_id_mutex . synchronize do
41
+ @ channel_id_mutex. synchronize do
36
42
result = int_allocator . allocate
37
43
raise "No further channels available. Please open a new connection." if result < 0
38
44
result
@@ -41,12 +47,6 @@ def next_channel_id
41
47
42
48
private
43
49
44
- # @private
45
- # @api private
46
- def channel_id_mutex
47
- @channel_id_mutex ||= Mutex . new
48
- end
49
-
50
50
# @private
51
51
def int_allocator
52
52
# TODO: ideally, this should be in agreement with agreed max number of channels of the connection,
0 commit comments