Coverage Summary for Class: MessageRoundtrip (org.ethereum.net)

Class Class, % Method, % Line, %
MessageRoundtrip 0% (0/1) 0% (0/8) 0% (0/13)


1 /* 2  * This file is part of RskJ 3  * Copyright (C) 2017 RSK Labs Ltd. 4  * (derived from ethereumJ library, Copyright (c) 2016 <ether.camp>) 5  * 6  * This program is free software: you can redistribute it and/or modify 7  * it under the terms of the GNU Lesser General Public License as published by 8  * the Free Software Foundation, either version 3 of the License, or 9  * (at your option) any later version. 10  * 11  * This program is distributed in the hope that it will be useful, 12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14  * GNU Lesser General Public License for more details. 15  * 16  * You should have received a copy of the GNU Lesser General Public License 17  * along with this program. If not, see <http://www.gnu.org/licenses/>. 18  */ 19  20 package org.ethereum.net; 21  22 import org.ethereum.net.message.Message; 23  24 /** 25  * Utility wraps around a message to keep track of the number of times it has 26  * been offered This class also contains the last time a message was offered and 27  * is updated when an answer has been received to it can be removed from the 28  * queue. 29  * 30  * @author Roman Mandeleil 31  */ 32 public class MessageRoundtrip { 33  34  private final Message msg; 35  long lastTimestamp = 0; 36  long retryTimes = 0; 37  boolean answered = false; 38  39  public MessageRoundtrip(Message msg) { 40  this.msg = msg; 41  saveTime(); 42  } 43  44  public boolean isAnswered() { 45  return answered; 46  } 47  48  public void answer() { 49  answered = true; 50  } 51  52  public long getRetryTimes() { 53  return retryTimes; 54  } 55  56  public void incRetryTimes() { 57  ++retryTimes; 58  } 59  60  public void saveTime() { 61  lastTimestamp = System.currentTimeMillis(); 62  } 63  64  public boolean hasToRetry() { 65  return 20000 < System.currentTimeMillis() - lastTimestamp; 66  } 67  68  public Message getMsg() { 69  return msg; 70  } 71 }