forked from I2P_Developers/i2p.i2p
2004-11-01 jrandom
* Increase the tunnel test timeout rapidly if our tunnels are failing.
* Honor message expirations for some tunnel jobs that were prematurely
expired.
* Streamline memory usage with temporary object caches and more efficient
serialization for SHA256 calculation, logging, and both I2CP and I2NP
message handling.
* Fix some situations where we forward messages too eagerly. For a
request at the tunnel endpoint, if the tunnel is inbound and the target
is remote, honor the message by tunnel routing the data rather than
sending it directly to the requested location.
This commit is contained in:
@@ -25,6 +25,7 @@ import net.i2p.data.DataHelper;
|
||||
*/
|
||||
public class Log {
|
||||
private Class _class;
|
||||
private String _className;
|
||||
private String _name;
|
||||
private int _minPriority;
|
||||
private LogScope _scope;
|
||||
@@ -90,6 +91,7 @@ public class Log {
|
||||
Log(LogManager manager, Class cls, String name) {
|
||||
_manager = manager;
|
||||
_class = cls;
|
||||
_className = cls != null ? cls.getName() : null;
|
||||
_name = name;
|
||||
_minPriority = DEBUG;
|
||||
_scope = new LogScope(name, cls);
|
||||
@@ -161,33 +163,37 @@ public class Log {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
if (_class != null) return _class.getName();
|
||||
if (_className != null) return _className;
|
||||
|
||||
return _name;
|
||||
}
|
||||
|
||||
public Object getScope() { return _scope; }
|
||||
static String getScope(String name, Class cls) {
|
||||
if ( (name == null) && (cls == null) ) return "f00";
|
||||
if (cls == null) return name;
|
||||
if (name == null) return cls.getName();
|
||||
return name + "" + cls.getName();
|
||||
}
|
||||
private static final class LogScope {
|
||||
private String _scopeName;
|
||||
private Class _scopeClass;
|
||||
private String _scopeCache;
|
||||
public LogScope(String name, Class cls) {
|
||||
_scopeName = name;
|
||||
_scopeClass = cls;
|
||||
_scopeCache = getScope(name, cls);
|
||||
}
|
||||
public int hashCode() {
|
||||
if (_scopeClass != null)
|
||||
return _scopeClass.hashCode();
|
||||
else if (_scopeName != null)
|
||||
return _scopeName.hashCode();
|
||||
else
|
||||
return 42;
|
||||
return _scopeCache.hashCode();
|
||||
}
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null) throw new NullPointerException("Null object scope?");
|
||||
if (obj instanceof LogScope) {
|
||||
LogScope s = (LogScope)obj;
|
||||
return DataHelper.eq(s._scopeName, _scopeName) &&
|
||||
DataHelper.eq(s._scopeClass, _scopeClass);
|
||||
return s._scopeCache.equals(_scopeCache);
|
||||
} else if (obj instanceof String) {
|
||||
return obj.equals(_scopeCache);
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -141,14 +141,11 @@ public class LogManager {
|
||||
public Log getLog(Class cls, String name) {
|
||||
Log rv = null;
|
||||
synchronized (_logs) {
|
||||
Log newLog = new Log(this, cls, name);
|
||||
if (_logs.containsKey(newLog.getScope())) {
|
||||
Log oldLog = (Log)_logs.get(newLog.getScope());
|
||||
rv = oldLog;
|
||||
//_log.error("Duplicate log creation for " + cls);
|
||||
} else {
|
||||
_logs.put(newLog.getScope(), newLog);
|
||||
rv = newLog;
|
||||
String scope = Log.getScope(name, cls);
|
||||
rv = (Log)_logs.get(scope);
|
||||
if (rv == null) {
|
||||
rv = new Log(this, cls, name);
|
||||
_logs.put(scope, rv);
|
||||
}
|
||||
}
|
||||
updateLimit(rv);
|
||||
@@ -483,14 +480,16 @@ public class LogManager {
|
||||
List limits = getLimits(log);
|
||||
LogLimit max = null;
|
||||
LogLimit notMax = null;
|
||||
for (int i = 0; i < limits.size(); i++) {
|
||||
LogLimit cur = (LogLimit) limits.get(i);
|
||||
if (max == null)
|
||||
max = cur;
|
||||
else {
|
||||
if (cur.getRootName().length() > max.getRootName().length()) {
|
||||
notMax = max;
|
||||
if (limits != null) {
|
||||
for (int i = 0; i < limits.size(); i++) {
|
||||
LogLimit cur = (LogLimit) limits.get(i);
|
||||
if (max == null)
|
||||
max = cur;
|
||||
else {
|
||||
if (cur.getRootName().length() > max.getRootName().length()) {
|
||||
notMax = max;
|
||||
max = cur;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -504,11 +503,15 @@ public class LogManager {
|
||||
}
|
||||
|
||||
private List getLimits(Log log) {
|
||||
ArrayList limits = new ArrayList(4);
|
||||
ArrayList limits = null; // new ArrayList(4);
|
||||
synchronized (_limits) {
|
||||
for (int i = 0; i < _limits.size(); i++) {
|
||||
LogLimit limit = (LogLimit)_limits.get(i);
|
||||
if (limit.matches(log)) limits.add(limit);
|
||||
if (limit.matches(log)) {
|
||||
if (limits == null)
|
||||
limits = new ArrayList(4);
|
||||
limits.add(limit);
|
||||
}
|
||||
}
|
||||
}
|
||||
return limits;
|
||||
|
||||
Reference in New Issue
Block a user