Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2018-05-21 03:04:27 -0400
committerEike Stepper2018-05-21 03:04:27 -0400
commit669e8e9176c90c7e68751a0018b7d9e6435d50a9 (patch)
tree5862aa4c56a6d5b5354321843352cae4c59bda3d
parent58168ee30078b21e11cb1e11267c2b1dfa3787c1 (diff)
downloadcdo-669e8e9176c90c7e68751a0018b7d9e6435d50a9.tar.gz
cdo-669e8e9176c90c7e68751a0018b7d9e6435d50a9.tar.xz
cdo-669e8e9176c90c7e68751a0018b7d9e6435d50a9.zip
[534898] Provide a repository activity log
https://bugs.eclipse.org/bugs/show_bug.cgi?id=534898
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml1
-rw-r--r--plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml1
-rw-r--r--plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml1
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java51
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/Log.java2
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/RollingLog.java123
6 files changed, 145 insertions, 34 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
index e00f297083..a4e2f4282d 100644
--- a/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
+++ b/plugins/org.eclipse.emf.cdo.examples.installer/examples/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
@@ -46,6 +46,7 @@
<activityLog type="rolling">
<property name="file" value="/develop/cdo-master/repo1-activities"/>
<property name="size" value="100000000"/>
+ <property name="append" value="true"/>
</activityLog>
-->
diff --git a/plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml b/plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
index e00f297083..a4e2f4282d 100644
--- a/plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
+++ b/plugins/org.eclipse.emf.cdo.examples.master/config/cdo-server.xml
@@ -46,6 +46,7 @@
<activityLog type="rolling">
<property name="file" value="/develop/cdo-master/repo1-activities"/>
<property name="size" value="100000000"/>
+ <property name="append" value="true"/>
</activityLog>
-->
diff --git a/plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml b/plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml
index 9b8209e539..3419ffa6c7 100644
--- a/plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml
+++ b/plugins/org.eclipse.emf.cdo.server.product/config/cdo-server.xml
@@ -46,6 +46,7 @@
<activityLog type="rolling">
<property name="file" value="/develop/cdo-master/repo1-activities"/>
<property name="size" value="100000000"/>
+ <property name="append" value="true"/>
</activityLog>
-->
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java
index 48c7594136..1571190132 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/StringUtil.java
@@ -291,6 +291,57 @@ public final class StringUtil
return count;
}
+ /**
+ * @since 3.8
+ */
+ public static String translate(String str, String from, String to)
+ {
+ int length = str == null ? 0 : str.length();
+ if (length == 0)
+ {
+ return str;
+ }
+
+ int fromLength = from.length();
+ int toLength = to.length();
+
+ if (fromLength == 0)
+ {
+ return str;
+ }
+
+ if (fromLength > toLength)
+ {
+ throw new IllegalArgumentException("'from' is longer than 'to'");
+ }
+
+ StringBuilder builder = null;
+ for (int i = 0; i < length; i++)
+ {
+ char c = str.charAt(i);
+
+ int pos = from.indexOf(c);
+ if (pos != -1)
+ {
+ c = to.charAt(pos);
+
+ if (builder == null)
+ {
+ builder = new StringBuilder(str);
+ }
+
+ builder.setCharAt(i, c);
+ }
+ }
+
+ if (builder == null)
+ {
+ return str;
+ }
+
+ return builder.toString();
+ }
+
public static boolean isEmpty(String str)
{
return ObjectUtil.isEmpty(str);
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/Log.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/Log.java
index ec858c7fe6..ef3fb414ec 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/Log.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/Log.java
@@ -16,5 +16,5 @@ package org.eclipse.net4j.util.om.log;
*/
public interface Log
{
- public void log(String line);
+ public void log(String message);
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/RollingLog.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/RollingLog.java
index 011f1e59c7..7d93a9475e 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/RollingLog.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/om/log/RollingLog.java
@@ -11,6 +11,7 @@
package org.eclipse.net4j.util.om.log;
import org.eclipse.net4j.internal.util.bundle.OM;
+import org.eclipse.net4j.util.StringUtil;
import org.eclipse.net4j.util.collection.AbstractIterator;
import org.eclipse.net4j.util.collection.CloseableIterator;
import org.eclipse.net4j.util.concurrent.Worker;
@@ -47,10 +48,11 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
private List<LogLine> queue = new ArrayList<LogLine>();
- public RollingLog(String logFile, long logSize)
+ public RollingLog(String logFile, long logSize, boolean append)
{
this.logFile = logFile;
this.logSize = logSize;
+ fileAppend = append;
setDaemon(true);
}
@@ -65,9 +67,9 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
return logSize;
}
- public final void log(String line)
+ public final void log(String message)
{
- LogLine logLine = createLogLine(line);
+ LogLine logLine = createLogLine(message);
synchronized (this)
{
@@ -104,12 +106,12 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
writeLogLines(logLines);
}
- protected LogLine createLogLine(String line)
+ protected LogLine createLogLine(String message)
{
long millis = System.currentTimeMillis();
String thread = getThreadInfo();
- return new LogLine(millis, thread, line);
+ return new LogLine(millis, thread, message);
}
protected void writeLogLines(List<LogLine> logLines)
@@ -120,21 +122,7 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
try
{
- File file;
-
- for (;;)
- {
- file = getFile(logFile, fileNumber);
-
- if (fileAppend && file.length() > logSize)
- {
- fileNumber++;
- fileAppend = false;
- continue;
- }
-
- break;
- }
+ File file = getFile();
out = new PrintStream(new FileOutputStream(file, fileAppend));
writeLogLines(logLines, out);
@@ -174,14 +162,68 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
return Thread.currentThread().getName();
}
- public final CloseableIterator<LogLine> iterator()
+ @Override
+ protected void doActivate() throws Exception
{
- return iterator(logFile);
+ if (fileAppend)
+ {
+ int number = getLastFileNumber();
+ if (number == -1)
+ {
+ fileAppend = false;
+ }
+ else
+ {
+ long lastID = 0;
+
+ for (LogIterator iterator = new LogIterator(logFile, number); iterator.hasNext();)
+ {
+ LogLine logLine = iterator.next();
+ lastID = logLine.getID();
+ }
+
+ logLineCounter.set(lastID);
+ }
+ }
+
+ super.doActivate();
}
- public static CloseableIterator<LogLine> iterator(String logFile)
+ private int getLastFileNumber()
{
- return new LogIterator(logFile);
+ int lastFileNumber = -1;
+ for (int i = 0; i < Integer.MAX_VALUE; i++)
+ {
+ File file = getFile(logFile, i);
+ if (!file.isFile())
+ {
+ break;
+ }
+
+ lastFileNumber = i;
+ }
+
+ return lastFileNumber;
+ }
+
+ private File getFile()
+ {
+ File file;
+
+ for (;;)
+ {
+ file = getFile(logFile, fileNumber);
+
+ if (fileAppend && file.length() > logSize)
+ {
+ fileNumber++;
+ fileAppend = false;
+ continue;
+ }
+
+ break;
+ }
+ return file;
}
private static File getFile(String logFile, int fileNumber)
@@ -189,6 +231,16 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
return new File(logFile + String.format("-%04d", fileNumber) + ".txt");
}
+ public final CloseableIterator<LogLine> iterator()
+ {
+ return iterator(logFile);
+ }
+
+ public static CloseableIterator<LogLine> iterator(String logFile)
+ {
+ return new LogIterator(logFile, 0);
+ }
+
/**
* @author Eike Stepper
*/
@@ -202,9 +254,10 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
private BufferedReader reader;
- public LogIterator(String logFile)
+ public LogIterator(String logFile, int fileNumber)
{
this.logFile = logFile;
+ this.fileNumber = fileNumber;
}
@Override
@@ -273,21 +326,25 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
*/
public static final class LogLine
{
+ private static final String NL = "\n\r";
+
private static final String TAB = "\t";
+ private static final String TABNL = TAB + NL;
+
private long id;
private final long millis;
private final String thread;
- private final String line;
+ private final String message;
- public LogLine(long millis, String thread, String line)
+ public LogLine(long millis, String thread, String message)
{
this.millis = millis;
- this.thread = thread;
- this.line = line;
+ this.thread = StringUtil.translate(thread, TABNL, " ");
+ this.message = StringUtil.translate(message, NL, " ");
}
public LogLine(String string)
@@ -296,7 +353,7 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
id = Long.parseLong(tokenizer.nextToken());
millis = Long.parseLong(tokenizer.nextToken());
thread = tokenizer.nextToken();
- line = tokenizer.nextToken("").substring(1);
+ message = tokenizer.nextToken("").substring(1);
}
public long getID()
@@ -314,15 +371,15 @@ public class RollingLog extends Worker implements Log, Iterable<LogLine>
return thread;
}
- public String getLine()
+ public String getMessage()
{
- return line;
+ return message;
}
@Override
public String toString()
{
- return id + TAB + millis + TAB + thread + TAB + line;
+ return id + TAB + millis + TAB + thread + TAB + message;
}
}
}

Back to the top