Router: OutNetMessage cleanup (ticket #2386)

This commit is contained in:
zzz
2019-02-05 15:19:29 +00:00
parent 6f75680a7e
commit beb0879f24

View File

@ -29,7 +29,6 @@ import net.i2p.util.Log;
* *
*/ */
public class OutNetMessage implements CDPQEntry { public class OutNetMessage implements CDPQEntry {
private final Log _log;
private final RouterContext _context; private final RouterContext _context;
private final RouterInfo _target; private final RouterInfo _target;
private final I2NPMessage _message; private final I2NPMessage _message;
@ -50,6 +49,7 @@ public class OutNetMessage implements CDPQEntry {
private final long _created; private final long _created;
private long _enqueueTime; private long _enqueueTime;
private long _seqNum; private long _seqNum;
private final boolean _shouldTimestamp;
/** for debugging, contains a mapping of even name to Long (e.g. "begin sending", "handleOutbound", etc) */ /** for debugging, contains a mapping of even name to Long (e.g. "begin sending", "handleOutbound", etc) */
private HashMap<String, Long> _timestamps; private HashMap<String, Long> _timestamps;
/** /**
@ -96,7 +96,6 @@ public class OutNetMessage implements CDPQEntry {
*/ */
public OutNetMessage(RouterContext context, I2NPMessage msg, long expiration, int priority, RouterInfo target) { public OutNetMessage(RouterContext context, I2NPMessage msg, long expiration, int priority, RouterInfo target) {
_context = context; _context = context;
_log = context.logManager().getLog(OutNetMessage.class);
_message = msg; _message = msg;
if (msg != null) { if (msg != null) {
_messageTypeId = msg.getType(); _messageTypeId = msg.getType();
@ -113,7 +112,9 @@ public class OutNetMessage implements CDPQEntry {
//_createdBy = new Exception("Created by"); //_createdBy = new Exception("Created by");
_created = context.clock().now(); _created = context.clock().now();
if (_log.shouldLog(Log.INFO)) Log log = context.logManager().getLog(OutNetMessage.class);
_shouldTimestamp = log.shouldLog(Log.INFO);
if (_shouldTimestamp)
timestamp("Created"); timestamp("Created");
//_context.messageStateMonitor().outboundMessageAdded(); //_context.messageStateMonitor().outboundMessageAdded();
//_context.statManager().createRateStat("outNetMessage.timeToDiscard", //_context.statManager().createRateStat("outNetMessage.timeToDiscard",
@ -128,10 +129,10 @@ public class OutNetMessage implements CDPQEntry {
* @param eventName what occurred * @param eventName what occurred
* @return how long this message has been 'in flight' * @return how long this message has been 'in flight'
*/ */
public long timestamp(String eventName) { public void timestamp(String eventName) {
long now = _context.clock().now(); if (_shouldTimestamp) {
if (_log.shouldLog(Log.INFO)) {
// only timestamp if we are debugging // only timestamp if we are debugging
long now = _context.clock().now();
synchronized (this) { synchronized (this) {
locked_initTimestamps(); locked_initTimestamps();
// ??? // ???
@ -142,13 +143,12 @@ public class OutNetMessage implements CDPQEntry {
_timestampOrder.add(eventName); _timestampOrder.add(eventName);
} }
} }
return now - _created;
} }
/** @deprecated unused */ /** @deprecated unused */
@Deprecated @Deprecated
public Map<String, Long> getTimestamps() { public Map<String, Long> getTimestamps() {
if (_log.shouldLog(Log.INFO)) { if (_shouldTimestamp) {
synchronized (this) { synchronized (this) {
locked_initTimestamps(); locked_initTimestamps();
return new HashMap<String, Long>(_timestamps); return new HashMap<String, Long>(_timestamps);
@ -160,7 +160,7 @@ public class OutNetMessage implements CDPQEntry {
/** @deprecated unused */ /** @deprecated unused */
@Deprecated @Deprecated
public Long getTimestamp(String eventName) { public Long getTimestamp(String eventName) {
if (_log.shouldLog(Log.INFO)) { if (_shouldTimestamp) {
synchronized (this) { synchronized (this) {
locked_initTimestamps(); locked_initTimestamps();
return _timestamps.get(eventName); return _timestamps.get(eventName);
@ -390,7 +390,7 @@ public class OutNetMessage implements CDPQEntry {
buf.append(" with onFailedReply job: ").append(_onFailedReply); buf.append(" with onFailedReply job: ").append(_onFailedReply);
if (_onFailedSend != null) if (_onFailedSend != null)
buf.append(" with onFailedSend job: ").append(_onFailedSend); buf.append(" with onFailedSend job: ").append(_onFailedSend);
if (_timestamps != null && _timestampOrder != null && _log.shouldLog(Log.INFO)) { if (_timestamps != null && _timestampOrder != null) {
buf.append(" {timestamps: \n"); buf.append(" {timestamps: \n");
renderTimestamps(buf); renderTimestamps(buf);
buf.append("}"); buf.append("}");