Author: j16sdiz
Date: 2008-09-01 08:40:47 +0000 (Mon, 01 Sep 2008)
New Revision: 22295
Modified:
trunk/freenet/src/freenet/support/FileLoggerHook.java
trunk/freenet/src/freenet/support/Logger.java
trunk/freenet/src/freenet/support/LoggerHook.java
Log:
use ArrayList, fix generic warnings
Modified: trunk/freenet/src/freenet/support/FileLoggerHook.java
===================================================================
--- trunk/freenet/src/freenet/support/FileLoggerHook.java 2008-09-01
08:40:24 UTC (rev 22294)
+++ trunk/freenet/src/freenet/support/FileLoggerHook.java 2008-09-01
08:40:47 UTC (rev 22295)
@@ -13,6 +13,7 @@
import java.net.InetAddress;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -22,7 +23,6 @@
import java.util.NoSuchElementException;
import java.util.StringTokenizer;
import java.util.TimeZone;
-import java.util.Vector;
import java.util.zip.GZIPOutputStream;
import freenet.node.Version;
@@ -95,7 +95,7 @@
* Something wierd happens when the disk gets full, also we don't want
to
* block So run the actual write on another thread
*/
- protected final LinkedList list = new LinkedList();
+ protected final LinkedList<byte[]> list = new LinkedList<byte[]>();
protected long listBytes = 0;
protected int MAX_LIST_SIZE = 100000;
@@ -103,7 +103,7 @@
// FIXME: should reimplement LinkedList with minimal locking
long maxOldLogfilesDiskUsage;
- protected final LinkedList logFiles = new LinkedList();
+ protected final LinkedList<OldLogFile> logFiles = new
LinkedList<OldLogFile>();
private long oldLogFilesDiskSpaceUsage = 0;
private static class OldLogFile {
@@ -208,9 +208,10 @@
super("Log File Writer Thread");
}
+ @SuppressWarnings("fallthrough")
public void run() {
File currentFilename = null;
- Object o = null;
+ byte[] o = null;
long thisTime;
long lastTime = -1;
long startTime;
@@ -245,7 +246,7 @@
filename = getHourLogName(gc, true);
currentFilename = new File(filename);
synchronized(logFiles) {
- if((!logFiles.isEmpty()) &&
((OldLogFile)logFiles.getLast()).filename.equals(currentFilename)) {
+ if ((!logFiles.isEmpty()) &&
logFiles.getLast().filename.equals(currentFilename)) {
logFiles.removeLast();
}
}
@@ -334,11 +335,11 @@
}
}
o = list.removeFirst();
- listBytes -= (((byte[])
o).length + LINE_OVERHEAD);
+ listBytes -= o.length +
LINE_OVERHEAD;
}
- myWrite(logStream, ((byte[]) o));
+ myWrite(logStream, o);
if(altLogStream != null)
- myWrite(altLogStream, (byte[]) o);
+ myWrite(altLogStream, o);
} catch (OutOfMemoryError e) {
System.err.println(e.getClass());
System.err.println(e.getMessage());
@@ -473,7 +474,7 @@
if(logFiles.isEmpty()) {
System.err.println("ERROR:
INCONSISTENT LOGGER TOTALS: Log file list is empty but still used
"+oldLogFilesDiskSpaceUsage+" bytes!");
}
- olf = (OldLogFile)
logFiles.removeFirst();
+ olf = logFiles.removeFirst();
}
olf.filename.delete();
oldLogFilesDiskSpaceUsage -= olf.size;
@@ -719,7 +720,8 @@
fmt = "d:c:h:t:p:m";
char[] f = fmt.toCharArray();
- Vector fmtVec = new Vector(), strVec = new Vector();
+ ArrayList<Integer> fmtVec = new ArrayList<Integer>();
+ ArrayList<String> strVec = new ArrayList<String>();
StringBuilder sb = new StringBuilder();
@@ -730,11 +732,11 @@
getUName();
if (!comment && (type != 0)) {
if (sb.length() > 0) {
- strVec.addElement(sb.toString());
- fmtVec.addElement((int) 0);
+ strVec.add(sb.toString());
+ fmtVec.add(0);
sb = new StringBuilder();
}
- fmtVec.addElement(new Integer(type));
+ fmtVec.add(type);
} else if (f[i] == '\\') {
comment = true;
} else {
@@ -743,17 +745,17 @@
}
}
if (sb.length() > 0) {
- strVec.addElement(sb.toString());
- fmtVec.addElement(new Integer(0));
+ strVec.add(sb.toString());
+ fmtVec.add(0);
}
this.fmt = new int[fmtVec.size()];
int size = fmtVec.size();
for (int i = 0; i < size; ++i)
- this.fmt[i] = ((Integer)
fmtVec.elementAt(i)).intValue();
+ this.fmt[i] = fmtVec.get(i);
this.str = new String[strVec.size()];
- str = (String[]) strVec.toArray(str);
+ str = strVec.toArray(str);
}
private void setDateFormat(String dfmt) {
@@ -769,7 +771,7 @@
df.setTimeZone(TimeZone.getTimeZone("UTC"));
}
- public void log(Object o, Class c, String msg, Throwable e, int
priority) {
+ public void log(Object o, Class<?> c, String msg, Throwable e, int
priority) {
if (!instanceShouldLog(priority, c))
return;
@@ -858,7 +860,7 @@
|| (listBytes > (MAX_LIST_BYTES *
0.9F))) {
byte[] ss;
try {
- ss = (byte[])
(list.removeFirst());
+ ss = list.removeFirst();
} catch (NoSuchElementException e) {
// Yes I know this is
impossible but it happens with 1.6 with heap profiling enabled
noElementCount++;
@@ -943,7 +945,7 @@
public void listAvailableLogs(OutputStreamWriter writer) throws
IOException {
OldLogFile[] oldLogFiles;
synchronized(logFiles) {
- oldLogFiles = (OldLogFile[]) logFiles.toArray(new
OldLogFile[logFiles.size()]);
+ oldLogFiles = logFiles.toArray(new
OldLogFile[logFiles.size()]);
}
DateFormat tempDF =
DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT,
Locale.ENGLISH);
tempDF.setTimeZone(TimeZone.getTimeZone("GMT"));
@@ -956,9 +958,9 @@
public void sendLogByContainedDate(long time, OutputStream os) throws
IOException {
OldLogFile toReturn = null;
synchronized(logFiles) {
- Iterator i = logFiles.iterator();
+ Iterator<OldLogFile> i = logFiles.iterator();
while(i.hasNext()) {
- OldLogFile olf = (OldLogFile) i.next();
+ OldLogFile olf = i.next();
boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
if(logMINOR)
Logger.minor(this, "Checking "+time+" against
"+olf.filename+" : start="+olf.start+", end="+olf.end);
@@ -1040,7 +1042,7 @@
OldLogFile olf;
synchronized(logFiles) {
if(logFiles.isEmpty()) return;
- olf = (OldLogFile)
logFiles.removeFirst();
+ olf = logFiles.removeFirst();
}
olf.filename.delete();
oldLogFilesDiskSpaceUsage -= olf.size;
Modified: trunk/freenet/src/freenet/support/Logger.java
===================================================================
--- trunk/freenet/src/freenet/support/Logger.java 2008-09-01 08:40:24 UTC
(rev 22294)
+++ trunk/freenet/src/freenet/support/Logger.java 2008-09-01 08:40:47 UTC
(rev 22295)
@@ -242,7 +242,7 @@
logger.log(o, s, t, DEBUG);
}
- public synchronized static void error(Class c, String s) {
+ public synchronized static void error(Class<?> c, String s) {
logger.log(c, s, ERROR);
}
@@ -254,7 +254,7 @@
logger.log(o, s, e, ERROR);
}
- public synchronized static void minor(Class c, String s) {
+ public synchronized static void minor(Class<?> c, String s) {
logger.log(c, s, MINOR);
}
@@ -266,7 +266,7 @@
logger.log(o, s, t, MINOR);
}
- public synchronized 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);
}
@@ -278,7 +278,7 @@
logger.log(o, s, t, NORMAL);
}
- public synchronized static void normal(Class c, String s) {
+ public synchronized static void normal(Class<?> c, String s) {
logger.log(c, s, NORMAL);
}
@@ -303,7 +303,7 @@
*/
public abstract void log(
Object o,
- Class source,
+ Class<?> source,
String message,
Throwable e,
int priority);
@@ -335,7 +335,7 @@
* @param priority The priority of the mesage, one of Logger.ERROR,
* Logger.NORMAL, Logger.MINOR, or Logger.DEBUG.
*/
- public abstract void log(Class c, String message, int priority);
+ public abstract void log(Class<?> c, String message, int priority);
/**
* Log a message from static code.
@@ -345,12 +345,12 @@
* @param priority The priority of the mesage, one of Logger.ERROR,
* Logger.NORMAL, Logger.MINOR, or Logger.DEBUG.
*/
- public abstract void log(Class c, String message, Throwable e,
+ public abstract void log(Class<?> c, String message, Throwable e,
int priority);
- public abstract boolean instanceShouldLog(int priority, Class c);
+ public abstract boolean instanceShouldLog(int priority, Class<?> c);
- public static boolean shouldLog(int priority, Class c) {
+ public static boolean shouldLog(int priority, Class<?> c) {
return logger.instanceShouldLog(priority, c);
}
Modified: trunk/freenet/src/freenet/support/LoggerHook.java
===================================================================
--- trunk/freenet/src/freenet/support/LoggerHook.java 2008-09-01 08:40:24 UTC
(rev 22294)
+++ trunk/freenet/src/freenet/support/LoggerHook.java 2008-09-01 08:40:47 UTC
(rev 22295)
@@ -1,10 +1,10 @@
package freenet.support;
+import java.util.Iterator;
import java.util.StringTokenizer;
import java.util.Vector;
import freenet.l10n.L10n;
-import java.util.Iterator;
public abstract class LoggerHook extends Logger {
@@ -46,7 +46,7 @@
*/
public abstract void log(
Object o,
- Class source,
+ Class<?> source,
String message,
Throwable e,
int priority);
@@ -86,13 +86,13 @@
* @param priority The priority of the mesage, one of Logger.ERROR,
* Logger.NORMAL, Logger.MINOR, or Logger.DEBUG.
*/
- public void log(Class c, String message, int priority) {
+ public void log(Class<?> c, String message, int priority) {
if (!instanceShouldLog(priority,c)) return;
log(null, c, message, null, priority);
}
- public void log(Class c, String message, Throwable e, int priority) {
+ public void log(Class<?> c, String message, Throwable e, int priority) {
if (!instanceShouldLog(priority, c))
return;
log(null, c, message, e, priority);
@@ -196,7 +196,7 @@
}
}
- public boolean instanceShouldLog(int priority, Class c) {
+ public boolean instanceShouldLog(int priority, Class<?> c) {
int thresh = threshold;
if ((c != null) && (detailedThresholds.size() > 0)) {
String cname = c.getName();