public void Monitor(QueryOffsetCommand cmd) { if (cmd != null) { cmds[cmd.Header.CorrelationId] = cmd; } }
public void Remove(QueryOffsetCommand cmd) { QueryOffsetCommand removedCmd = null; if (cmd != null) { cmds.TryRemove(cmd.Header.CorrelationId, out removedCmd); } }
private void QueryLatestOffset(ConsumerLeaseKey key, long correlationId) { while (!IsClosed() && !leaseRef.ReadFullFence().Expired) { Endpoint endpoint = EndpointManager.GetEndpoint(Context.Topic.Name, PartitionId); if (endpoint == null) { log.Warn(string.Format("No endpoint found for topic {0} partition {1}, will retry later", Context.Topic.Name, PartitionId)); noEndpointSchedulePolicy.Fail(true); continue; } else { noEndpointSchedulePolicy.Succeess(); } SettableFuture<QueryOffsetResultCommand> future = SettableFuture<QueryOffsetResultCommand>.Create(); QueryOffsetCommand cmd = new QueryOffsetCommand(Context.Topic.Name, PartitionId, Context.GroupId); cmd.Header.CorrelationId = correlationId; cmd.Future = future; QueryOffsetResultCommand offsetRes = null; int timeout = Config.QueryOffsetTimeoutMillis; queryOffsetResultMonitor.Monitor(cmd); EndpointClient.WriteCommand(endpoint, cmd, timeout); try { offsetRes = future.Get(timeout); } catch (Exception e) { } finally { queryOffsetResultMonitor.Remove(cmd); } if (offsetRes != null && offsetRes.Offset != null) { offset.WriteFullFence(offsetRes.Offset); return; } else { noEndpointSchedulePolicy.Fail(true); } } }