This repository has been archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
ClientRequestRound.java
70 lines (60 loc) · 2.04 KB
/
ClientRequestRound.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2017, Xiaomi, Inc. All rights reserved.
// This source code is licensed under the Apache License Version 2.0, which
// can be found in the LICENSE file in the root directory of this source tree.
package com.xiaomi.infra.pegasus.rpc.async;
import com.xiaomi.infra.pegasus.metrics.MetricsManager;
import com.xiaomi.infra.pegasus.operator.client_operator;
import com.xiaomi.infra.pegasus.rpc.Table;
import java.util.concurrent.ScheduledFuture;
import org.slf4j.Logger;
/** Created by weijiesun on 16-11-25. */
public final class ClientRequestRound {
private static final Logger logger = org.slf4j.LoggerFactory.getLogger(TableHandler.class);
client_operator operator;
Table.ClientOPCallback callback;
long timeoutMs;
boolean enableCounter;
long createNanoTime;
long expireNanoTime;
boolean isCompleted;
ScheduledFuture<?> backupRequestTask;
/**
* Constructor.
*
* @param op
* @param enableCounter whether enable counter.
*/
public ClientRequestRound(
client_operator op,
Table.ClientOPCallback cb,
boolean enableCounter,
long timeoutInMilliseconds) {
operator = op;
callback = cb;
timeoutMs = timeoutInMilliseconds;
this.enableCounter = enableCounter;
createNanoTime = System.nanoTime();
expireNanoTime = createNanoTime + timeoutMs * 1000000L;
isCompleted = false;
backupRequestTask = null;
}
public com.xiaomi.infra.pegasus.operator.client_operator getOperator() {
return operator;
}
public void setOperator(client_operator op) {
operator = op;
}
public void thisRoundCompletion() {
try {
callback.onCompletion(operator);
} catch (Throwable ex) {
// The exception is generated by the user's callback logic, so we don't do much things on it
logger.debug("{} got exception", operator.toString(), ex);
}
if (enableCounter) {
MetricsManager.updateCount(operator.getQPSCounter(), 1L);
MetricsManager.setHistogramValue(
operator.getLatencyCounter(), System.nanoTime() - createNanoTime);
}
}
}