20
20
import io .aeron .logbuffer .LogBufferDescriptor ;
21
21
import io .aeron .logbuffer .LogBufferUnblocker ;
22
22
import org .agrona .collections .ArrayUtil ;
23
+ import org .agrona .concurrent .NanoClock ;
23
24
import org .agrona .concurrent .UnsafeBuffer ;
24
25
import org .agrona .concurrent .status .AtomicCounter ;
25
26
import org .agrona .concurrent .status .Position ;
@@ -50,12 +51,12 @@ enum Status
50
51
private final int termWindowLength ;
51
52
private final int positionBitsToShift ;
52
53
private final int initialTermId ;
53
- private long tripLimit = 0 ;
54
- private long consumerPosition = 0 ;
55
- private long lastConsumerPosition = 0 ;
56
- private long timeOfLastConsumerPositionChange = 0 ;
57
- private long cleanPosition = 0 ;
58
- private long timeOfLastStatusChange = 0 ;
54
+ private long tripLimit ;
55
+ private long consumerPosition ;
56
+ private long lastConsumerPosition ;
57
+ private long timeOfLastConsumerPositionChangeNs ;
58
+ private long cleanPosition ;
59
+ private long timeOfLastStatusChangeNs ;
59
60
private int refCount = 0 ;
60
61
private boolean reachedEndOfLife = false ;
61
62
private final boolean isExclusive ;
@@ -64,6 +65,7 @@ enum Status
64
65
private ReadablePosition [] subscriberPositions = EMPTY_POSITIONS ;
65
66
private final Position publisherLimit ;
66
67
private final UnsafeBuffer metaDataBuffer ;
68
+ private final NanoClock nanoClock ;
67
69
private final RawLog rawLog ;
68
70
private final AtomicCounter unblockedPublications ;
69
71
@@ -75,6 +77,7 @@ public IpcPublication(
75
77
final RawLog rawLog ,
76
78
final long unblockTimeoutNs ,
77
79
final SystemCounters systemCounters ,
80
+ final NanoClock nanoClock ,
78
81
final boolean isExclusive )
79
82
{
80
83
this .registrationId = registrationId ;
@@ -83,6 +86,7 @@ public IpcPublication(
83
86
this .isExclusive = isExclusive ;
84
87
this .termBuffers = rawLog .termBuffers ();
85
88
this .initialTermId = initialTermId (rawLog .metaData ());
89
+ this .nanoClock = nanoClock ;
86
90
87
91
final int termLength = rawLog .termLength ();
88
92
this .termBufferLength = termLength ;
@@ -98,6 +102,7 @@ public IpcPublication(
98
102
consumerPosition = producerPosition ();
99
103
lastConsumerPosition = consumerPosition ;
100
104
cleanPosition = consumerPosition ;
105
+ timeOfLastConsumerPositionChangeNs = nanoClock .nanoTime ();
101
106
}
102
107
103
108
public int sessionId ()
@@ -143,6 +148,11 @@ public void close()
143
148
144
149
public void addSubscriber (final ReadablePosition subscriberPosition )
145
150
{
151
+ if (subscriberPositions .length == 0 )
152
+ {
153
+ timeOfLastConsumerPositionChangeNs = nanoClock .nanoTime ();
154
+ }
155
+
146
156
subscriberPositions = ArrayUtil .add (subscriberPositions , subscriberPosition );
147
157
}
148
158
@@ -236,13 +246,13 @@ public void onTimeEvent(final long timeNs, final long timeMs, final DriverConduc
236
246
if (isDrained ())
237
247
{
238
248
status = Status .LINGER ;
239
- timeOfLastStatusChange = timeNs ;
249
+ timeOfLastStatusChangeNs = timeNs ;
240
250
conductor .transitionToLinger (this );
241
251
}
242
252
break ;
243
253
244
254
case LINGER :
245
- if (timeNs > (timeOfLastStatusChange + PUBLICATION_LINGER_NS ))
255
+ if (timeNs > (timeOfLastStatusChangeNs + PUBLICATION_LINGER_NS ))
246
256
{
247
257
reachedEndOfLife = true ;
248
258
conductor .cleanupIpcPublication (this );
@@ -256,14 +266,14 @@ public boolean hasReachedEndOfLife()
256
266
return reachedEndOfLife ;
257
267
}
258
268
259
- public void timeOfLastStateChange (final long time )
269
+ public void timeOfLastStateChange (final long timeNs )
260
270
{
261
- timeOfLastStatusChange = time ;
271
+ timeOfLastStatusChangeNs = timeNs ;
262
272
}
263
273
264
274
public long timeOfLastStateChange ()
265
275
{
266
- return timeOfLastStatusChange ;
276
+ return timeOfLastStatusChangeNs ;
267
277
}
268
278
269
279
public void delete ()
@@ -318,8 +328,8 @@ private void checkForBlockedPublisher(final long timeNs)
318
328
{
319
329
if (consumerPosition == lastConsumerPosition )
320
330
{
321
- if (producerPosition () > consumerPosition &&
322
- timeNs > ( timeOfLastConsumerPositionChange + unblockTimeoutNs ) )
331
+ if (timeNs > ( timeOfLastConsumerPositionChangeNs + unblockTimeoutNs ) &&
332
+ producerPosition () > consumerPosition )
323
333
{
324
334
if (LogBufferUnblocker .unblock (termBuffers , metaDataBuffer , consumerPosition ))
325
335
{
@@ -329,7 +339,7 @@ private void checkForBlockedPublisher(final long timeNs)
329
339
}
330
340
else
331
341
{
332
- timeOfLastConsumerPositionChange = timeNs ;
342
+ timeOfLastConsumerPositionChangeNs = timeNs ;
333
343
lastConsumerPosition = consumerPosition ;
334
344
}
335
345
}
0 commit comments