📄 transportbindingmetric.java
字号:
public int getAverageSendProcessingTime() { return (int) ( ((initiatorMessagesSent + acceptorMessagesSent) != 0) ? ((initiatorSendProcessingTime + acceptorSendProcessingTime) / (initiatorMessagesSent + acceptorMessagesSent)) : 0); } public int getAverageTimeToConnect() { return (int) ( ((initiatorConnections + acceptorConnections) != 0) ? ((initiatorTimeToConnect + acceptorTimeToConnect) / (initiatorConnections + acceptorConnections)) : 0); } public int getAverageTimeToFail() { return (int) ( ((initiatorConnectionsFailed + acceptorConnectionsFailed) != 0) ? ((initiatorTimeToFail + acceptorTimeToFail) / (initiatorConnectionsFailed + acceptorConnectionsFailed)) : 0); } /** Get the total time this intiated connection has been connected. * <BR><BR> * <B>Note:</B> This does not include the current time connected (if it is currently connected) * @see #getTotalTimeConnected() * @return time in ms (see note above) **/ public long getInitiatorTotalTimeConnected() { return initiatorTotalTimeConnected; } /** Get the total time this initiating connection has been connected. If it is currently * connected, then the total time is adjusted to include the time since the transition time * to become connected until the provided time * @param adjustmentTime The time of this metric will be adjusted to * @see #getTotalTimeConnected() * @return time in ms (see note above) **/ public long getInitiatorTotalTimeConnected(long adjustmentTime) { long result = initiatorTotalTimeConnected; if(isInitiatorConnected()) result += (adjustmentTime - this.initiatorTransitionTime); return result; } /** Get the duration of current connection relative to local clock (from transition time) * <BR><BR> * <B>Note:</B> This assumes the clocks are in sync with the reporting peer * @see #getTotalTimeConnected() * @return time in ms (see note above) or 0 if not connected **/ public long getInitiatorTimeConnected() { return getInitiatorTimeConnected(System.currentTimeMillis()); } /** Get the duration of current connection until the specified time * @param adjustmentTime The time of this metric will be computed until * @see #getTimeConnected() * @return time in ms (see note above) or 0 if not connected **/ public long getInitiatorTimeConnected(long adjustmentTime) { if(isInitiatorConnected()) return (adjustmentTime - this.initiatorTransitionTime); else return 0; } /** Get the total time this intiated connection has been connected. * <BR><BR> * <B>Note:</B> This does not include the current time connected (if it is currently connected) * @see #getTotalTimeConnected() * @return time in ms (see note above) **/ public long getAcceptorTotalTimeConnected() { return acceptorTotalTimeConnected; } /** Get the total time this initiating connection has been connected. If it is currently * connected, then the total time is adjusted to include the time since the transition time * to become connected until the provided time * @param adjustmentTime The time of this metric will be adjusted to * @see #getTotalTimeConnected() * @return time in ms (see note above) **/ public long getAcceptorTotalTimeConnected(long adjustmentTime) { long result = acceptorTotalTimeConnected; if(isAcceptorConnected()) result += (adjustmentTime - this.acceptorTransitionTime); return result; } /** Get the duration of current connection relative to local clock (from transition time) * <BR><BR> * <B>Note:</B> This assumes the clocks are in sync with the reporting peer * @see #getTotalTimeConnected() * @return time in ms (see note above) or 0 if not connected **/ public long getAcceptorTimeConnected() { return getAcceptorTimeConnected(System.currentTimeMillis()); } /** Get the duration of current connection until the specified time * @param adjustmentTime The time of this metric will be computed until * @see #getTimeConnected() * @return time in ms (see note above) or 0 if not connected **/ public long getAcceptorTimeConnected(long adjustmentTime) { if(isAcceptorConnected()) return (adjustmentTime - this.acceptorTransitionTime); else return 0; } void resetInitiatorState(String state, long transitionTime) { if (isInitiatorConnected()) acceptorTotalTimeConnected += (System.currentTimeMillis() - this.initiatorTransitionTime); this.initiatorState = state; this.initiatorTransitionTime = transitionTime;//System.out.println("initiatorState: " + initiatorState + " " + endpointAddress); } void resetAcceptorState(String state, long transitionTime) { if (isAcceptorConnected()) initiatorTotalTimeConnected += (System.currentTimeMillis() - this.acceptorTransitionTime); this.acceptorState = state; this.acceptorTransitionTime = transitionTime;//System.out.println("acceptorState: " + acceptorState + " " + endpointAddress); } void connectionEstablished(boolean initiator, long timeToConnect, long transitionTime) { if (initiator) { resetInitiatorState(CONNECTED, transitionTime); initiatorConnections++; initiatorTimeToConnect += timeToConnect; } else { resetAcceptorState(CONNECTED, transitionTime); acceptorConnections++; acceptorTimeToConnect += timeToConnect; } } void connectionFailed(boolean initiator, long timeToConnect, long transitionTime) { if (initiator) { resetInitiatorState(FAILED, transitionTime); initiatorConnectionsFailed++; initiatorTimeToFail += timeToConnect; } else { resetAcceptorState(FAILED, transitionTime); acceptorConnectionsFailed++; acceptorTimeToFail += timeToConnect; } } void connectionClosed(boolean initiator, long transitionTime) { if (initiator) { resetInitiatorState(CLOSED, transitionTime); initiatorConnectionsClosed++; } else { resetAcceptorState(CLOSED, transitionTime); acceptorConnectionsClosed++; } } void connectionDropped(boolean initiator, long transitionTime) { if (initiator) { resetInitiatorState(DROPPED, transitionTime); initiatorConnectionsDropped++; } else { resetAcceptorState(DROPPED, transitionTime); acceptorConnectionsDropped++; } } void pingReceived() { numPingsReceived++; } void ping(long time) { numPings++; pingTime += time; } void pingFailed(long time) { numFailedPings++; pingFailedTime += time; } void dataReceived(boolean initiator, int size) { if (initiator) initiatorBytesReceived += size; else acceptorBytesReceived += size; } void messageReceived(boolean initiator, Message message, long time, long size) { if (initiator) { initiatorMessagesReceived++; initiatorReceiveProcessingTime += time; initiatorBytesReceived += size; } else { acceptorMessagesReceived++; acceptorReceiveProcessingTime += time; acceptorBytesReceived += size; } } void receiveFailure(boolean initiator, long time, long size) { if (initiator) { initiatorReceiveFailures++; initiatorReceiveFailureProcessingTime += time; initiatorBytesReceived += size; } else { acceptorReceiveFailures++; acceptorReceiveFailureProcessingTime += time; acceptorBytesReceived += size; } } void dataSent(boolean initiator, long size) { if (initiator) initiatorBytesSent += size; else acceptorBytesSent += size; } void sendFailure(boolean initiator, Message message, long time, long size) { if (initiator) { initiatorSendFailures++; initiatorSendFailureProcessingTime += time; initiatorBytesSent += size; } else { acceptorSendFailures++; acceptorSendFailureProcessingTime += time; acceptorBytesSent += size; } } void messageSent(boolean initiator, Message message, long time, long size) { if (initiator) { initiatorMessagesSent++; initiatorSendProcessingTime += time; initiatorBytesSent += size; } else { acceptorMessagesSent++; acceptorSendProcessingTime += time; acceptorBytesSent += size; } } public void mergeMetrics(TransportBindingMetric other) { peerID = other.peerID; if (other.initiatorState != null) initiatorState = other.initiatorState; if (other.initiatorTransitionTime != 0) initiatorTransitionTime = other.initiatorTransitionTime; if (other.acceptorState != null) acceptorState = other.acceptorState; if (other.initiatorTransitionTime != 0) acceptorTransitionTime = other.acceptorTransitionTime; acceptorBytesReceived += other.acceptorBytesReceived; acceptorBytesSent += other.acceptorBytesSent; acceptorConnections += other.acceptorConnections; acceptorConnectionsClosed += other.acceptorConnectionsClosed; acceptorConnectionsDropped += other.acceptorConnectionsDropped; acceptorConnectionsFailed += other.acceptorConnectionsFailed; acceptorMessagesReceived += other.acceptorMessagesReceived; acceptorMessagesSent += other.acceptorMessagesSent;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -