1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */1819package org.apache.giraph.comm.netty.handler;
2021import org.apache.giraph.comm.requests.WritableRequest;
22import org.apache.giraph.time.SystemTime;
23import org.apache.giraph.time.Time;
24import io.netty.channel.ChannelFuture;
2526import java.net.InetSocketAddress;
27import java.util.Date;
2829/**30 * Help track requests throughout the system31 */32publicclassRequestInfo {
33/**Time class to use */34privatestaticfinalTime TIME = SystemTime.get();
35/** Destination of the request */36privatefinal InetSocketAddress destinationAddress;
37/** When the request was started */38privatefinallong startedNanos;
39/** Request */40privatefinalWritableRequest request;
41/** Future of the write of this request*/42privatevolatile ChannelFuture writeFuture;
4344/**45 * Constructor.46 *47 * @param destinationAddress Destination of the request48 * @param request Request that is sent49 */50publicRequestInfo(InetSocketAddress destinationAddress,
51WritableRequest request) {
52this.destinationAddress = destinationAddress;
53this.request = request;
54this.startedNanos = TIME.getNanoseconds();
55 }
5657public InetSocketAddress getDestinationAddress() {
58return destinationAddress;
59 }
6061/**62 * Get the started msecs.63 *64 * @return Started msecs65 */66publiclong getStartedMsecs() {
67return startedNanos / Time.NS_PER_MS;
68 }
6970/**71 * Get the elapsed nanoseconds since the request started.72 *73 * @return Nanoseconds since the request was started74 */75publiclong getElapsedNanos() {
76return TIME.getNanoseconds() - startedNanos;
77 }
7879/**80 * Get the elapsed millseconds since the request started.81 *82 * @return Milliseconds since the request was started83 */84publiclong getElapsedMsecs() {
85return getElapsedNanos() / Time.NS_PER_MS;
86 }
878889publicWritableRequest getRequest() {
90return request;
91 }
9293publicvoid setWriteFuture(ChannelFuture writeFuture) {
94this.writeFuture = writeFuture;
95 }
9697public ChannelFuture getWriteFuture() {
98return writeFuture;
99 }
100101 @Override
102public String toString() {
103return"(reqId=" + request.getRequestId() +
104",destAddr=" + destinationAddress.getHostName() + ":" +
105 destinationAddress.getPort() +
106",elapsedNanos=" +
107 getElapsedNanos() +
108",started=" + new Date(getStartedMsecs()) +
109 ((writeFuture == null) ? ")" :
110",writeDone=" + writeFuture.isDone() +
111",writeSuccess=" + writeFuture.isSuccess() + ")");
112 }
113 }