Author: zothar
Date: 2006-07-23 15:50:59 +0000 (Sun, 23 Jul 2006)
New Revision: 9735
Modified:
trunk/freenet/src/freenet/support/DoubleTokenBucket.java
trunk/freenet/src/freenet/support/FileLoggerHook.java
trunk/freenet/src/freenet/support/LimitedRangeIntByteArrayMap.java
trunk/freenet/src/freenet/support/Logger.java
trunk/freenet/src/freenet/support/LoggerHookChain.java
trunk/freenet/src/freenet/support/MultiValueTable.java
trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
trunk/freenet/src/freenet/support/RandomAccessFileBucket.java
trunk/freenet/src/freenet/support/RandomGrabArray.java
trunk/freenet/src/freenet/support/ReceivedPacketNumbers.java
trunk/freenet/src/freenet/support/SortedLongSet.java
trunk/freenet/src/freenet/support/SortedVectorByNumber.java
Log:
Locking consistency in support/
Modified: trunk/freenet/src/freenet/support/DoubleTokenBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/DoubleTokenBucket.java 2006-07-23
15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/DoubleTokenBucket.java 2006-07-23
15:50:59 UTC (rev 9735)
@@ -85,7 +85,7 @@
return max;
}
- protected long offset() {
+ protected synchronized long offset() {
return curForced;
}
Modified: trunk/freenet/src/freenet/support/FileLoggerHook.java
===================================================================
--- trunk/freenet/src/freenet/support/FileLoggerHook.java 2006-07-23
15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/FileLoggerHook.java 2006-07-23
15:50:59 UTC (rev 9735)
@@ -114,11 +114,15 @@
}
public void setMaxListLength(int len) {
- MAX_LIST_SIZE = len;
+ synchronized(list) {
+ MAX_LIST_SIZE = len;
+ }
}
public void setMaxListBytes(long len) {
- MAX_LIST_BYTES = len;
+ synchronized(list) {
+ MAX_LIST_BYTES = len;
+ }
}
public void setInterval(String intervalName) throws
IntervalParseException {
@@ -458,7 +462,7 @@
synchronized(trimOldLogFilesLock) {
while(oldLogFilesDiskSpaceUsage >
maxOldLogfilesDiskUsage) {
OldLogFile olf;
- synchronized(logFiles) {
+ synchronized(logFiles) { // **FIXME**/TODO:
creates a double lock situation, but only here
if(logFiles.isEmpty()) {
System.err.println("ERROR:
INCONSISTENT LOGGER TOTALS: Log file list is empty but still used
"+oldLogFilesDiskSpaceUsage+" bytes!");
}
@@ -551,7 +555,9 @@
synchronized(logFiles) {
logFiles.addLast(olf);
}
- oldLogFilesDiskSpaceUsage += l;
+ synchronized(trimOldLogFilesLock) {
+ oldLogFilesDiskSpaceUsage += l;
+ }
}
lastStartTime = startTime;
oldFile = f;
@@ -566,7 +572,9 @@
synchronized(logFiles) {
logFiles.addLast(olf);
}
- oldLogFilesDiskSpaceUsage += l;
+ synchronized(trimOldLogFilesLock) {
+ oldLogFilesDiskSpaceUsage += l;
+ }
}
trimOldLogFiles();
}
@@ -757,8 +765,9 @@
sb.append(str[sctr++]);
break;
case DATE :
+ long now = System.currentTimeMillis();
synchronized (this) {
-
myDate.setTime(System.currentTimeMillis());
+ myDate.setTime(now);
sb.append(df.format(myDate));
}
break;
@@ -835,7 +844,9 @@
}
public long listBytes() {
- return listBytes;
+ synchronized (list) {
+ return listBytes;
+ }
}
public static int numberOf(char c) {
@@ -937,7 +948,9 @@
* by the time the function returns as it is run off-thread.
*/
public void setMaxOldLogsSize(long val) {
- maxOldLogfilesDiskUsage = val;
+ synchronized(trimOldLogFilesLock) {
+ maxOldLogfilesDiskUsage = val;
+ }
Runnable r = new Runnable() {
public void run() {
trimOldLogFiles();
@@ -958,11 +971,11 @@
}
public void waitForSwitch() {
+ long now = System.currentTimeMillis();
synchronized(this) {
if(!switchedBaseFilename) return;
- long startTime = System.currentTimeMillis();
+ long startTime = now;
long endTime = startTime + 10000;
- long now;
while(((now = System.currentTimeMillis()) < endTime) &&
!switchedBaseFilename) {
try {
wait(Math.max(1, endTime-now));
Modified: trunk/freenet/src/freenet/support/LimitedRangeIntByteArrayMap.java
===================================================================
--- trunk/freenet/src/freenet/support/LimitedRangeIntByteArrayMap.java
2006-07-23 15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/LimitedRangeIntByteArrayMap.java
2006-07-23 15:50:59 UTC (rev 9735)
@@ -32,11 +32,11 @@
flag = false;
}
- public int minValue() {
+ public synchronized int minValue() {
return minValue;
}
- public int maxValue() {
+ public synchronized int maxValue() {
return maxValue;
}
@@ -208,7 +208,7 @@
/**
* Empty the structure.
*/
- private void clear() {
+ private synchronized void clear() {
contents.clear();
minValue = maxValue = -1;
}
Modified: trunk/freenet/src/freenet/support/Logger.java
===================================================================
--- trunk/freenet/src/freenet/support/Logger.java 2006-07-23 15:50:39 UTC
(rev 9734)
+++ trunk/freenet/src/freenet/support/Logger.java 2006-07-23 15:50:59 UTC
(rev 9735)
@@ -30,7 +30,7 @@
*/
static Logger logger = new VoidLogger();
- public static FileLoggerHook setupStdoutLogging(int level, String
detail) throws InvalidThresholdException {
+ public synchronized static FileLoggerHook setupStdoutLogging(int level,
String detail) throws InvalidThresholdException {
setupChain();
logger.setThreshold(level);
logger.setDetailedThresholds(detail);
@@ -43,55 +43,55 @@
return fh;
}
- public static void setupChain() {
+ public synchronized static void setupChain() {
logger = new LoggerHookChain();
}
- public static void debug(Object o, String s) {
+ public synchronized static void debug(Object o, String s) {
logger.log(o, s, DEBUG);
}
- public static void debug(Object o, String s, Throwable t) {
+ public synchronized static void debug(Object o, String s, Throwable t) {
logger.log(o, s, t, DEBUG);
}
- public static void error(Class c, String s) {
+ public synchronized static void error(Class c, String s) {
logger.log(c, s, ERROR);
}
- public static void error(Object o, String s) {
+ public synchronized static void error(Object o, String s) {
logger.log(o, s, ERROR);
}
- public static void error(Object o, String s, Throwable e) {
+ public synchronized static void error(Object o, String s, Throwable e) {
logger.log(o, s, e, ERROR);
}
- public static void minor(Object o, String s) {
+ public synchronized static void minor(Object o, String s) {
logger.log(o, s, MINOR);
}
- public static void minor(Object o, String s, Throwable t) {
+ public synchronized static void minor(Object o, String s, Throwable t) {
logger.log(o, s, t, MINOR);
}
- public static void minor(Class class1, String string, Throwable t) {
+ public synchronized static void minor(Class class1, String string,
Throwable t) {
logger.log(class1, string, t, MINOR);
}
- public static void normal(Object o, String s) {
+ public synchronized static void normal(Object o, String s) {
logger.log(o, s, NORMAL);
}
- public static void normal(Object o, String s, Throwable t) {
+ public synchronized static void normal(Object o, String s, Throwable t)
{
logger.log(o, s, t, NORMAL);
}
- public static void normal(Class c, String s) {
+ public synchronized static void normal(Class c, String s) {
logger.log(c, s, NORMAL);
}
- public static void logStatic(Object o, String s, int prio) {
+ public synchronized static void logStatic(Object o, String s, int prio)
{
logger.log(o, s, prio);
}
@@ -159,7 +159,7 @@
public abstract boolean instanceShouldLog(int priority, Class c);
- public static boolean shouldLog(int priority, Class c) {
+ public synchronized static boolean shouldLog(int priority, Class c) {
return logger.instanceShouldLog(priority, c);
}
@@ -210,11 +210,11 @@
((LoggerHookChain)logger).addHook(logger2);
}
- public static void globalSetThreshold(int i) {
+ public synchronized static void globalSetThreshold(int i) {
logger.setThreshold(i);
}
- public static int globalGetThreshold() {
+ public synchronized static int globalGetThreshold() {
return logger.getThreshold();
}
@@ -232,7 +232,7 @@
}
}
- public static LoggerHookChain getChain() {
+ public synchronized static LoggerHookChain getChain() {
if(logger instanceof LoggerHookChain)
return (LoggerHookChain) logger;
else {
Modified: trunk/freenet/src/freenet/support/LoggerHookChain.java
===================================================================
--- trunk/freenet/src/freenet/support/LoggerHookChain.java 2006-07-23
15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/LoggerHookChain.java 2006-07-23
15:50:59 UTC (rev 9735)
@@ -38,7 +38,7 @@
* one logger receive events from another.
* @implements LoggerHook.log()
*/
- public void log(Object o, Class c, String msg, Throwable e, int priority){
+ public synchronized void log(Object o, Class c, String msg, Throwable e,
int priority){
LoggerHook[] myHooks = hooks;
for(int i=0;i<myHooks.length;i++) {
myHooks[i].log(o,c,msg,e,priority);
@@ -82,7 +82,7 @@
/**
* Returns all the current hooks.
*/
- public LoggerHook[] getHooks() {
+ public synchronized LoggerHook[] getHooks() {
return hooks;
}
Modified: trunk/freenet/src/freenet/support/MultiValueTable.java
===================================================================
--- trunk/freenet/src/freenet/support/MultiValueTable.java 2006-07-23
15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/MultiValueTable.java 2006-07-23
15:50:59 UTC (rev 9735)
@@ -48,7 +48,9 @@
}
public boolean containsKey(Object key) {
- return table.containsKey(key);
+ synchronized (table) {
+ return table.containsKey(key);
+ }
}
public boolean containsElement(Object key, Object value) {
@@ -62,14 +64,20 @@
* Users will have to handle synchronizing.
*/
public Enumeration getAll(Object key) {
- Vector v = (Vector) table.get(key);
+ Vector v;
+ synchronized (table) {
+ v = (Vector) table.get(key);
+ }
return (v == null ?
new LimitedEnumeration(null) :
v.elements());
}
public int countAll(Object key) {
- Vector v = (Vector)table.get(key);
+ Vector v;
+ synchronized (table) {
+ v = (Vector)table.get(key);
+ }
if(v != null)
return v.size();
else
@@ -77,7 +85,9 @@
}
public Object getSync(Object key) {
- return table.get(key);
+ synchronized (table) {
+ return table.get(key);
+ }
}
public Object[] getArray(Object key) {
@@ -94,15 +104,21 @@
}
public void remove(Object key) {
- table.remove(key);
+ synchronized (table) {
+ table.remove(key);
+ }
}
public boolean isEmpty() {
- return table.isEmpty();
+ synchronized (table) {
+ return table.isEmpty();
+ }
}
public void clear() {
- table.clear();
+ synchronized (table) {
+ table.clear();
+ }
}
public boolean removeElement(Object key, Object value) {
@@ -120,21 +136,27 @@
}
public Enumeration keys() {
- return table.keys();
+ synchronized (table) {
+ return table.keys();
+ }
}
public Enumeration elements() {
- if (table.isEmpty())
- return new LimitedEnumeration(null);
- else
- return new MultiValueEnumeration();
+ synchronized (table) {
+ if (table.isEmpty())
+ return new LimitedEnumeration(null);
+ else
+ return new MultiValueEnumeration();
+ }
}
private class MultiValueEnumeration implements Enumeration {
private Enumeration current;
private Enumeration global;
public MultiValueEnumeration() {
- global = table.elements();
+ synchronized (table) {
+ global = table.elements();
+ }
current = ((Vector) global.nextElement()).elements();
step();
}
Modified:
trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
2006-07-23 15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/PaddedEphemerallyEncryptedBucket.java
2006-07-23 15:50:59 UTC (rev 9735)
@@ -134,7 +134,9 @@
public OutputStream getOutputStream() throws IOException {
if(readOnly) throw new IOException("Read only");
OutputStream os = bucket.getOutputStream();
- dataLength = 0;
+ synchronized(this) {
+ dataLength = 0;
+ }
return new PaddedEphemerallyEncryptedOutputStream(os,
++lastOutputStream);
}
@@ -307,7 +309,7 @@
return super.toString()+":"+bucket.toString();
}
- public long size() {
+ public synchronized long size() {
return dataLength;
}
@@ -340,7 +342,9 @@
public SimpleFieldSet toFieldSet() {
SimpleFieldSet fs = new SimpleFieldSet(true);
fs.put("Type", "PaddedEphemerallyEncryptedBucket");
- fs.put("DataLength", dataLength);
+ synchronized(this) {
+ fs.put("DataLength", dataLength);
+ }
if(key != null) {
fs.put("DecryptKey", HexUtil.bytesToHex(key));
} else {
Modified: trunk/freenet/src/freenet/support/RandomAccessFileBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/RandomAccessFileBucket.java
2006-07-23 15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/RandomAccessFileBucket.java
2006-07-23 15:50:59 UTC (rev 9735)
@@ -124,7 +124,7 @@
return newOut;
}
- public String getName() {
+ public synchronized String getName() {
return file.getAbsolutePath() + " [" + offset + ", " +
(offset + len - 1) + "]";
}
@@ -140,7 +140,7 @@
localOffset = 0;
}
- public long size() { return len; }
+ public synchronized long size() { return len; }
public synchronized boolean release() {
if (released) {
@@ -176,7 +176,7 @@
public synchronized final boolean isReleased() { return released; }
- public void finalize() throws Throwable {
+ public synchronized void finalize() throws Throwable {
if (!released) {
release();
}
@@ -246,7 +246,9 @@
// FilterInput implementation
private final int bytesLeft() throws IOException {
- return (int)(rafb.offset + rafb.len - raf.getFilePointer());
+ synchronized (rafb) {
+ return (int)(rafb.offset + rafb.len -
raf.getFilePointer());
+ }
}
public int read() throws java.io.IOException {
@@ -346,9 +348,11 @@
}
private final void checkValid() throws IOException {
- if (rafb.released) {
- throw new IOException("Attempt to use a released
RandomAccessFileBucket: " + prefix);
- }
+ synchronized(rafb) {
+ if (rafb.released) {
+ throw new IOException("Attempt to use a
released RandomAccessFileBucket: " + prefix);
+ }
+ }
}
////////////////////////////////////////////////////////////
@@ -439,12 +443,16 @@
}
private final void checkValid() throws IOException {
- if (rafb.isReleased()) {
- throw new IOException("Attempt to use a released
RandomAccessFileBucket: " + prefix);
- }
+ synchronized (rafb) {
+ if (rafb.isReleased()) {
+ throw new IOException("Attempt to use a
released RandomAccessFileBucket: " + prefix);
+ }
+ }
}
private final int bytesLeft() throws IOException {
- return (int)(rafb.offset + rafb.len - raf.getFilePointer());
+ synchronized (rafb) {
+ return (int)(rafb.offset + rafb.len -
raf.getFilePointer());
+ }
}
private RandomAccessFileBucket rafb = null;
@@ -454,19 +462,19 @@
}
////////////////////////////////////////////////////////////
- public boolean isReadOnly() {
+ public synchronized boolean isReadOnly() {
return readOnly;
}
- public void setReadOnly() {
+ public synchronized void setReadOnly() {
readOnly = true;
}
- public void free() {
+ public synchronized void free() {
release();
}
- public SimpleFieldSet toFieldSet() {
+ public synchronized SimpleFieldSet toFieldSet() {
SimpleFieldSet fs = new SimpleFieldSet(true);
fs.put("Type", "RandomAccessFileBucket");
fs.put("Filename", file.toString());
Modified: trunk/freenet/src/freenet/support/RandomGrabArray.java
===================================================================
--- trunk/freenet/src/freenet/support/RandomGrabArray.java 2006-07-23
15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/RandomGrabArray.java 2006-07-23
15:50:59 UTC (rev 9735)
@@ -77,7 +77,7 @@
}
}
- public boolean isEmpty() {
+ public synchronized boolean isEmpty() {
return index == 0;
}
}
Modified: trunk/freenet/src/freenet/support/ReceivedPacketNumbers.java
===================================================================
--- trunk/freenet/src/freenet/support/ReceivedPacketNumbers.java
2006-07-23 15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/ReceivedPacketNumbers.java
2006-07-23 15:50:59 UTC (rev 9735)
@@ -164,11 +164,11 @@
StringBuffer sb = new StringBuffer();
sb.append(super.toString());
sb.append(": max=");
- sb.append(highestSeqNumber);
- sb.append(", min=");
- sb.append(lowestSeqNumber);
- sb.append(", ranges=");
synchronized(this) {
+ sb.append(highestSeqNumber);
+ sb.append(", min=");
+ sb.append(lowestSeqNumber);
+ sb.append(", ranges=");
Iterator i = ranges.iterator();
while(i.hasNext()) {
Range r = (Range) i.next();
Modified: trunk/freenet/src/freenet/support/SortedLongSet.java
===================================================================
--- trunk/freenet/src/freenet/support/SortedLongSet.java 2006-07-23
15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/SortedLongSet.java 2006-07-23
15:50:59 UTC (rev 9735)
@@ -88,7 +88,7 @@
push(num, x);
}
- private void push(long num, int x) {
+ private synchronized void push(long num, int x) {
Logger.minor(this, "Insertion point: "+x+" length "+length+"
data.length "+data.length);
// Move the data
if(length == data.length) {
Modified: trunk/freenet/src/freenet/support/SortedVectorByNumber.java
===================================================================
--- trunk/freenet/src/freenet/support/SortedVectorByNumber.java 2006-07-23
15:50:39 UTC (rev 9734)
+++ trunk/freenet/src/freenet/support/SortedVectorByNumber.java 2006-07-23
15:50:59 UTC (rev 9735)
@@ -86,7 +86,7 @@
push(grabber, x);
}
- private void push(IntNumberedItem grabber, int x) {
+ private synchronized void push(IntNumberedItem grabber, int x) {
Logger.minor(this, "Insertion point: "+x);
// Move the data
if(length == data.length) {