Permalink
Browse files

Merge remote-tracking branch 'neo4j/master' into cookbook

  • Loading branch information...
2 parents 6c87de5 + 4cdecf6 commit 6e14f9b7f65b5c4ddd909aff7c6f90787c422e38 @peterneubauer committed Feb 17, 2012
@@ -22,39 +22,70 @@
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.TimeZone;
public class Format
{
public static String date()
{
- return date( new Date() );
+ return date( DEFAULT_TIME_ZONE );
}
+ public static String date( TimeZone timeZone )
+ {
+ return date( new Date(), timeZone );
+ }
+
public static String date( long millis )
{
- return date( new Date( millis ) );
+ return date( millis, DEFAULT_TIME_ZONE );
}
+ public static String date( long millis, TimeZone timeZone )
+ {
+ return date( new Date( millis ), timeZone );
+ }
+
public static String date( Date date )
{
- return DATE.format( date );
+ return date( date, DEFAULT_TIME_ZONE );
}
+ public static String date( Date date, TimeZone timeZone )
+ {
+ return DATE.format( date, timeZone );
+ }
+
public static String time()
{
- return time( new Date() );
+ return time( DEFAULT_TIME_ZONE );
}
+ public static String time( TimeZone timeZone )
+ {
+ return time( new Date() );
+ }
+
public static String time( long millis )
{
- return time( new Date( millis ) );
+ return time( millis, DEFAULT_TIME_ZONE );
}
+ public static String time( long millis, TimeZone timeZone )
+ {
+ return time( new Date( millis ), timeZone );
+ }
+
public static String time( Date date )
{
- return TIME.format( date );
+ return time( date, DEFAULT_TIME_ZONE );
}
+ public static String time( Date date, TimeZone timeZone )
+ {
+ return TIME.format( date, timeZone );
+ }
+
public static String bytes( long bytes )
{
double size = bytes;
@@ -73,8 +104,17 @@ private Format()
private static final String[] BYTE_SIZES = { "B", "kB", "MB", "GB" };
- private static final ThreadLocalFormat DATE = new ThreadLocalFormat( "yyyy-MM-dd HH:mm:ss.SSSZ" ),
- TIME = new ThreadLocalFormat( "HH:mm:ss.SSS" );
+ public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss.SSSZ";
+ public static final String TIME_FORMAT = "HH:mm:ss.SSS";
+
+ /**
+ * Default time zone is UTC (+00:00) so that comparing timestamped logs from different
+ * sources is an easier task.
+ */
+ public static final TimeZone DEFAULT_TIME_ZONE = TimeZone.getTimeZone( "UTC" );
+
+ private static final ThreadLocalFormat DATE = new ThreadLocalFormat( DATE_FORMAT ),
+ TIME = new ThreadLocalFormat( TIME_FORMAT );
private static class ThreadLocalFormat extends ThreadLocal<DateFormat>
{
@@ -85,9 +125,11 @@ private Format()
this.format = format;
}
- String format( Date date )
+ String format( Date date, TimeZone timeZone )
{
- return get().format( date );
+ DateFormat dateFormat = get();
+ dateFormat.setTimeZone( timeZone );
+ return dateFormat.format( date );
}
@Override
@@ -19,6 +19,8 @@
*/
package org.neo4j.kernel.impl.transaction.xaframework;
+import java.util.TimeZone;
+
import javax.transaction.xa.Xid;
import org.neo4j.helpers.Format;
@@ -49,6 +51,11 @@ public int getIdentifier()
{
return identifier;
}
+
+ public String toString( TimeZone timeZone )
+ {
+ return toString();
+ }
public static class Start extends LogEntry
{
@@ -112,7 +119,13 @@ public long getChecksum()
@Override
public String toString()
{
- return "Start[" + getIdentifier() + ",xid=" + xid + ",master=" + masterId + ",me=" + myId + ",time=" + timestamp( timeWritten ) + "]";
+ return toString( Format.DEFAULT_TIME_ZONE );
+ }
+
+ @Override
+ public String toString( TimeZone timeZone )
+ {
+ return "Start[" + getIdentifier() + ",xid=" + xid + ",master=" + masterId + ",me=" + myId + ",time=" + timestamp( timeWritten, timeZone ) + "]";
}
}
@@ -134,20 +147,28 @@ public long getTimeWritten()
@Override
public String toString()
{
- return "Prepare[" + getIdentifier() + ", " + timestamp( timeWritten ) + "]";
+ return toString( Format.DEFAULT_TIME_ZONE );
+ }
+
+ @Override
+ public String toString( TimeZone timeZone )
+ {
+ return "Prepare[" + getIdentifier() + ", " + timestamp( timeWritten, timeZone ) + "]";
}
}
public static abstract class Commit extends LogEntry
{
private final long txId;
private final long timeWritten;
+ protected final String name;
- Commit( int identifier, long txId, long timeWritten )
+ Commit( int identifier, long txId, long timeWritten, String name )
{
super( identifier );
this.txId = txId;
this.timeWritten = timeWritten;
+ this.name = name;
}
public long getTxId()
@@ -159,19 +180,33 @@ public long getTimeWritten()
{
return timeWritten;
}
+
+ @Override
+ public String toString()
+ {
+ return toString( Format.DEFAULT_TIME_ZONE );
+ }
+
+ @Override
+ public String toString( TimeZone timeZone )
+ {
+ return name + "[" + getIdentifier() + ", txId=" + getTxId() + ", " + timestamp( getTimeWritten(), timeZone ) + "]";
+ }
}
public static class OnePhaseCommit extends Commit
{
OnePhaseCommit( int identifier, long txId, long timeWritten )
{
- super( identifier, txId, timeWritten );
+ super( identifier, txId, timeWritten, "1PC" );
}
+ }
- @Override
- public String toString()
+ public static class TwoPhaseCommit extends Commit
+ {
+ TwoPhaseCommit( int identifier, long txId, long timeWritten )
{
- return "1PC[" + getIdentifier() + ", txId=" + getTxId() + ", " + timestamp( getTimeWritten() ) + "]";
+ super( identifier, txId, timeWritten, "2PC" );
}
}
@@ -188,21 +223,7 @@ public String toString()
return "Done[" + getIdentifier() + "]";
}
}
-
- public static class TwoPhaseCommit extends Commit
- {
- TwoPhaseCommit( int identifier, long txId, long timeWritten )
- {
- super( identifier, txId, timeWritten );
- }
-
- @Override
- public String toString()
- {
- return "2PC[" + getIdentifier() + ", txId=" + getTxId() + ", " + timestamp( getTimeWritten() ) + "]";
- }
- }
-
+
public static class Command extends LogEntry
{
private final XaCommand command;
@@ -230,8 +251,8 @@ public void setIdentifier( int newXidIdentifier )
identifier = newXidIdentifier;
}
- public String timestamp( long timeWritten )
+ public String timestamp( long timeWritten, TimeZone timeZone )
{
- return Format.date( timeWritten ) + "/" + timeWritten;
+ return Format.date( timeWritten, timeZone ) + "/" + timeWritten;
}
}
@@ -28,10 +28,14 @@
import java.nio.channels.ReadableByteChannel;
import java.util.Collection;
import java.util.Comparator;
+import java.util.TimeZone;
import java.util.TreeSet;
import javax.transaction.xa.Xid;
+import org.neo4j.helpers.Args;
+import org.neo4j.helpers.Format;
+import org.neo4j.helpers.Pair;
import org.neo4j.kernel.impl.nioneo.store.NeoStore;
import org.neo4j.kernel.impl.nioneo.xa.Command;
import org.neo4j.kernel.impl.transaction.xaframework.LogEntry;
@@ -41,7 +45,7 @@
public class DumpLogicalLog
{
- public int dump( String filenameOrDirectory ) throws IOException
+ public int dump( String filenameOrDirectory, TimeZone timeZone ) throws IOException
{
int logsFound = 0;
for ( String fileName : filenamesOf( filenameOrDirectory, getLogPrefix() ) )
@@ -70,7 +74,7 @@ public int dump( String filenameOrDirectory ) throws IOException
prevLastCommittedTx + "]" );
long logEntriesFound = 0;
XaCommandFactory cf = instantiateCommandFactory();
- while ( readAndPrintEntry( fileChannel, buffer, cf ) )
+ while ( readAndPrintEntry( fileChannel, buffer, cf, timeZone ) )
{
logEntriesFound++;
}
@@ -85,13 +89,13 @@ protected static boolean isAGraphDatabaseDirectory( String fileName )
return file.isDirectory() && new File( file, NeoStore.DEFAULT_NAME ).exists();
}
- protected boolean readAndPrintEntry( FileChannel fileChannel, ByteBuffer buffer, XaCommandFactory cf )
+ protected boolean readAndPrintEntry( FileChannel fileChannel, ByteBuffer buffer, XaCommandFactory cf, TimeZone timeZone )
throws IOException
{
LogEntry entry = LogIoUtils.readEntry( buffer, fileChannel, cf );
if ( entry != null )
{
- System.out.println( entry.toString() );
+ System.out.println( entry.toString( timeZone ) );
return true;
}
return false;
@@ -109,10 +113,17 @@ protected String getLogPrefix()
public static void main( String args[] ) throws IOException
{
- for ( String arg : args )
- {
- new DumpLogicalLog().dump( arg );
- }
+ Pair<Iterable<String>, TimeZone> config = parseConfig( args );
+ for ( String file : config.first() ) new DumpLogicalLog().dump( file, config.other() );
+ }
+
+ public static Pair<Iterable<String>, TimeZone> parseConfig( String[] args )
+ {
+ Args arguments = new Args( args );
+ TimeZone timeZone = Format.DEFAULT_TIME_ZONE;
+ String timeZoneString = arguments.get( "timezone", null );
+ if ( timeZoneString != null ) timeZone = TimeZone.getTimeZone( timeZoneString );
+ return Pair.<Iterable<String>,TimeZone>of( arguments.orphans(), timeZone );
}
protected static String[] filenamesOf( String filenameOrDirectory, final String prefix )
Oops, something went wrong.

0 comments on commit 6e14f9b

Please sign in to comment.