Skip to content

Commit

Permalink
Merge branch 'raipc-timestamp-performance-incr'
Browse files Browse the repository at this point in the history
  • Loading branch information
chrjohn committed Jul 1, 2024
2 parents eb7dcfd + b5c283f commit 6a68735
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
12 changes: 8 additions & 4 deletions quickfixj-base/src/main/java/quickfix/SystemTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

package quickfix;

import java.time.Clock;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.Calendar;
Expand All @@ -30,20 +32,22 @@
*/
public class SystemTime {
public static final TimeZone UTC_TIMEZONE = TimeZone.getTimeZone("UTC");
private static final Clock UTC_CLOCK = Clock.systemUTC();

private static final SystemTimeSource DEFAULT_TIME_SOURCE = new SystemTimeSource() {
static final SystemTimeSource UTC = new SystemTimeSource() {
@Override
public long getTime() {
return System.currentTimeMillis();
}

@Override
public LocalDateTime getNow() {
return LocalDateTime.now(ZoneOffset.UTC);
final Instant instant = UTC_CLOCK.instant();
return LocalDateTime.ofEpochSecond(instant.getEpochSecond(), instant.getNano(), ZoneOffset.UTC);
}
};

private static volatile SystemTimeSource systemTimeSource = DEFAULT_TIME_SOURCE;
private static volatile SystemTimeSource systemTimeSource = UTC;

public static long currentTimeMillis() {
return systemTimeSource.getTime();
Expand All @@ -63,7 +67,7 @@ public static LocalDateTime getLocalDateTime() {

public static void setTimeSource(SystemTimeSource systemTimeSource) {
SystemTime.systemTimeSource = systemTimeSource != null ? systemTimeSource
: DEFAULT_TIME_SOURCE;
: UTC;
}

public static Calendar getUtcCalendar() {
Expand Down
14 changes: 6 additions & 8 deletions quickfixj-base/src/main/java/quickfix/UtcTimeStampField.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@
*/
public class UtcTimeStampField extends Field<LocalDateTime> {

private UtcTimestampPrecision precision = getDefaultUtcTimestampPrecision();
private final UtcTimestampPrecision precision;

public UtcTimeStampField(int field) {
super(field, LocalDateTime.now(ZoneOffset.UTC));
this(field, SystemTime.UTC.getNow());
}

protected UtcTimeStampField(int field, LocalDateTime data) {
super(field, data);
this.precision = getDefaultUtcTimestampPrecision();
}

protected UtcTimeStampField(int field, LocalDateTime data, UtcTimestampPrecision precision) {
Expand All @@ -43,18 +44,15 @@ protected UtcTimeStampField(int field, LocalDateTime data, UtcTimestampPrecision
}

public UtcTimeStampField(int field, boolean includeMilliseconds) {
super(field, LocalDateTime.now(ZoneOffset.UTC));
this.precision = includeMilliseconds ? UtcTimestampPrecision.MILLIS : UtcTimestampPrecision.SECONDS;
this(field, includeMilliseconds ? UtcTimestampPrecision.MILLIS : UtcTimestampPrecision.SECONDS);
}

public UtcTimeStampField(int field, UtcTimestampPrecision precision) {
super(field, LocalDateTime.now(ZoneOffset.UTC));
this.precision = precision;
this(field, SystemTime.UTC.getNow(), precision);
}

protected UtcTimeStampField(int field, LocalDateTime data, boolean includeMilliseconds) {
super(field, data);
this.precision = includeMilliseconds ? UtcTimestampPrecision.MILLIS : UtcTimestampPrecision.SECONDS;
this(field, data, includeMilliseconds ? UtcTimestampPrecision.MILLIS : UtcTimestampPrecision.SECONDS);
}

public UtcTimestampPrecision getPrecision() {
Expand Down

0 comments on commit 6a68735

Please sign in to comment.