Author: nextgens
Date: 2009-01-29 17:44:54 +0000 (Thu, 29 Jan 2009)
New Revision: 25373
Modified:
trunk/freenet/src/freenet/io/comm/Message.java
trunk/freenet/src/freenet/io/comm/MessageCore.java
Log:
same thing on Message* classes
Modified: trunk/freenet/src/freenet/io/comm/Message.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/Message.java 2009-01-29 17:39:53 UTC
(rev 25372)
+++ trunk/freenet/src/freenet/io/comm/Message.java 2009-01-29 17:44:54 UTC
(rev 25373)
@@ -32,6 +32,7 @@
import freenet.support.ByteBufferInputStream;
import freenet.support.Fields;
import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
import freenet.support.Serializer;
import freenet.support.ShortBuffer;
@@ -43,7 +44,18 @@
public class Message {
public static final String VERSION = "$Id: Message.java,v 1.11 2005/09/15
18:16:04 amphibian Exp $";
+ private static volatile boolean logMINOR;
+ private static volatile boolean logDEBUG;
+ static {
+ Logger.registerLogThresholdCallback(new LogThresholdCallback(){
+ public void shouldUpdate(){
+ logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
+ }
+ });
+ }
+
private final MessageType _spec;
private final WeakReference<? extends PeerContext> _sourceRef;
private final boolean _internal;
@@ -59,12 +71,11 @@
private static Message decodeMessage(ByteBufferInputStream bb,
PeerContext peer, int recvByteCount,
boolean mayHaveSubMessages, boolean inSubMessage) {
- boolean logMINOR = Logger.shouldLog(Logger.MINOR,
Message.class);
MessageType mspec;
try {
mspec = MessageType.getSpec(Integer.valueOf(bb.readInt()));
} catch (IOException e1) {
- if(Logger.shouldLog(Logger.DEBUG, Message.class))
+ if(logDEBUG)
Logger.minor(Message.class,"Failed to read message
type: "+e1, e1);
return null;
}
@@ -214,7 +225,7 @@
// if (this.getSpec() != MessageTypes.ping && this.getSpec() !=
MessageTypes.pong)
// Logger.logMinor("<<<<< Send message : " + this);
- if(Logger.shouldLog(Logger.DEBUG, Message.class))
+ if(logDEBUG)
Logger.minor(this, "My spec code:
"+_spec.getName().hashCode()+" for "+_spec.getName());
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dos = new DataOutputStream(baos);
@@ -243,7 +254,7 @@
}
byte[] buf = baos.toByteArray();
- if(Logger.shouldLog(Logger.DEBUG, Message.class))
+ if(logDEBUG)
Logger.minor(this, "Length: "+buf.length+", hash:
"+Fields.hashCode(buf));
return buf;
}
@@ -339,4 +350,4 @@
return System.currentTimeMillis() - localInstantiationTime;
}
-}
\ No newline at end of file
+}
Modified: trunk/freenet/src/freenet/io/comm/MessageCore.java
===================================================================
--- trunk/freenet/src/freenet/io/comm/MessageCore.java 2009-01-29 17:39:53 UTC
(rev 25372)
+++ trunk/freenet/src/freenet/io/comm/MessageCore.java 2009-01-29 17:44:54 UTC
(rev 25373)
@@ -28,12 +28,24 @@
import freenet.node.PeerNode;
import freenet.node.Ticker;
import freenet.support.Logger;
+import freenet.support.LogThresholdCallback;
import freenet.support.TimeUtil;
public class MessageCore {
public static final String VERSION = "$Id: MessageCore.java,v 1.22
2005/08/25 17:28:19 amphibian Exp $";
- private static boolean logMINOR;
+ private static volatile boolean logMINOR;
+ private static volatile boolean logDEBUG;
+
+ static {
+ Logger.registerLogThresholdCallback(new LogThresholdCallback(){
+ public void shouldUpdate(){
+ logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
+ }
+ });
+ }
+
private Dispatcher _dispatcher;
/** _filters serves as lock for both */
private final LinkedList<MessageFilter> _filters = new
LinkedList<MessageFilter>();
@@ -50,7 +62,6 @@
public MessageCore() {
_timedOutFilters = new Vector<MessageFilter>(32);
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
}
/**
@@ -97,7 +108,6 @@
* Remove timed out filters.
*/
void removeTimedOutFilters() {
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
long tStart = System.currentTimeMillis() + 1;
// Extra millisecond to give waitFor() a chance to remove the
filter.
// Avoids exhaustive and unsuccessful search in waitFor()
removal of a timed out filter.
@@ -292,7 +302,6 @@
}
public void addAsyncFilter(MessageFilter filter,
AsyncMessageFilterCallback callback) throws DisconnectedException {
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
filter.setAsyncCallback(callback);
if(filter.matched()) {
Logger.error(this, "addAsyncFilter() on a filter which
is already matched: "+filter, new Exception("error"));
@@ -372,9 +381,7 @@
* @throws DisconnectedException If the single peer being waited for
disconnects.
*/
public Message waitFor(MessageFilter filter, ByteCounter ctr) throws
DisconnectedException {
- boolean logDEBUG = Logger.shouldLog(Logger.DEBUG, this);
if(logDEBUG) Logger.debug(this, "Waiting for "+filter);
- logMINOR = Logger.shouldLog(Logger.MINOR, this);
long startTime = System.currentTimeMillis();
if(filter.matched()) {
Logger.error(this, "waitFor() on a filter which is
already matched: "+filter, new Exception("error"));
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs