Repository: logging-log4j2 Updated Branches: refs/heads/LOG4J2-1883-instant-field 2b15f88b3 -> 4354f5193
LOG4J2-1883 created new package core.time.internal and moved internal class FixedPreciseClock into it Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/4354f519 Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/4354f519 Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/4354f519 Branch: refs/heads/LOG4J2-1883-instant-field Commit: 4354f519335f73f55101e11dc9aa8a50d7397e21 Parents: 2b15f88 Author: rpopma <[email protected]> Authored: Sat Jan 27 19:46:07 2018 +0900 Committer: rpopma <[email protected]> Committed: Sat Jan 27 19:46:07 2018 +0900 ---------------------------------------------------------------------- .../log4j/core/time/FixedPreciseClock.java | 62 ------------------- .../core/time/internal/FixedPreciseClock.java | 65 ++++++++++++++++++++ .../core/async/RingBufferLogEventTest.java | 2 +- .../log4j/core/time/MutableInstantTest.java | 1 + 4 files changed, 67 insertions(+), 63 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4354f519/log4j-core/src/main/java/org/apache/logging/log4j/core/time/FixedPreciseClock.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/time/FixedPreciseClock.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/FixedPreciseClock.java deleted file mode 100644 index 21edc80..0000000 --- a/log4j-core/src/main/java/org/apache/logging/log4j/core/time/FixedPreciseClock.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache license, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the license for the specific language governing permissions and - * limitations under the license. - */ -package org.apache.logging.log4j.core.time; - -/** - * Implementation of the {@code PreciseClock} interface that always returns a fixed time value. - * @since 2.11 - */ -public class FixedPreciseClock implements PreciseClock { - private final long currentTimeMillis; - private final int nanosOfMillisecond; - - /** - * Constructs a {@code FixedPreciseClock} that always returns the epoch. - */ - public FixedPreciseClock() { - this(0); - } - - /** - * Constructs a {@code FixedPreciseClock} that always returns the specified time in milliseconds since the epoch. - * @param currentTimeMillis milliseconds since the epoch - */ - public FixedPreciseClock(final long currentTimeMillis) { - this(currentTimeMillis, 0); - } - - /** - * Constructs a {@code FixedPreciseClock} that always returns the specified time in milliseconds since the epoch - * and nanosecond of the millisecond. - * @param currentTimeMillis milliseconds since the epoch - * @param nanosOfMillisecond nanosecond of the specified millisecond - */ - public FixedPreciseClock(final long currentTimeMillis, final int nanosOfMillisecond) { - this.currentTimeMillis = currentTimeMillis; - this.nanosOfMillisecond = nanosOfMillisecond; - } - - @Override - public void init(final MutableInstant instant) { - instant.initFromEpochMilli(currentTimeMillis, nanosOfMillisecond); - } - - @Override - public long currentTimeMillis() { - return currentTimeMillis; - } -} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4354f519/log4j-core/src/main/java/org/apache/logging/log4j/core/time/internal/FixedPreciseClock.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/main/java/org/apache/logging/log4j/core/time/internal/FixedPreciseClock.java b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/internal/FixedPreciseClock.java new file mode 100644 index 0000000..868cdbe --- /dev/null +++ b/log4j-core/src/main/java/org/apache/logging/log4j/core/time/internal/FixedPreciseClock.java @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache license, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the license for the specific language governing permissions and + * limitations under the license. + */ +package org.apache.logging.log4j.core.time.internal; + +import org.apache.logging.log4j.core.time.MutableInstant; +import org.apache.logging.log4j.core.time.PreciseClock; + +/** + * Implementation of the {@code PreciseClock} interface that always returns a fixed time value. + * @since 2.11 + */ +public class FixedPreciseClock implements PreciseClock { + private final long currentTimeMillis; + private final int nanosOfMillisecond; + + /** + * Constructs a {@code FixedPreciseClock} that always returns the epoch. + */ + public FixedPreciseClock() { + this(0); + } + + /** + * Constructs a {@code FixedPreciseClock} that always returns the specified time in milliseconds since the epoch. + * @param currentTimeMillis milliseconds since the epoch + */ + public FixedPreciseClock(final long currentTimeMillis) { + this(currentTimeMillis, 0); + } + + /** + * Constructs a {@code FixedPreciseClock} that always returns the specified time in milliseconds since the epoch + * and nanosecond of the millisecond. + * @param currentTimeMillis milliseconds since the epoch + * @param nanosOfMillisecond nanosecond of the specified millisecond + */ + public FixedPreciseClock(final long currentTimeMillis, final int nanosOfMillisecond) { + this.currentTimeMillis = currentTimeMillis; + this.nanosOfMillisecond = nanosOfMillisecond; + } + + @Override + public void init(final MutableInstant instant) { + instant.initFromEpochMilli(currentTimeMillis, nanosOfMillisecond); + } + + @Override + public long currentTimeMillis() { + return currentTimeMillis; + } +} http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4354f519/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java index dfb0a35..e3920f7 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/async/RingBufferLogEventTest.java @@ -31,7 +31,7 @@ import org.apache.logging.log4j.ThreadContext.ContextStack; import org.apache.logging.log4j.categories.AsyncLoggers; import org.apache.logging.log4j.core.LogEvent; import org.apache.logging.log4j.core.util.DummyNanoClock; -import org.apache.logging.log4j.core.time.FixedPreciseClock; +import org.apache.logging.log4j.core.time.internal.FixedPreciseClock; import org.apache.logging.log4j.util.FilteredObjectInputStream; import org.apache.logging.log4j.util.StringMap; import org.apache.logging.log4j.core.impl.ThrowableProxy; http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/4354f519/log4j-core/src/test/java/org/apache/logging/log4j/core/time/MutableInstantTest.java ---------------------------------------------------------------------- diff --git a/log4j-core/src/test/java/org/apache/logging/log4j/core/time/MutableInstantTest.java b/log4j-core/src/test/java/org/apache/logging/log4j/core/time/MutableInstantTest.java index e18c35f..63d3138 100644 --- a/log4j-core/src/test/java/org/apache/logging/log4j/core/time/MutableInstantTest.java +++ b/log4j-core/src/test/java/org/apache/logging/log4j/core/time/MutableInstantTest.java @@ -16,6 +16,7 @@ */ package org.apache.logging.log4j.core.time; +import org.apache.logging.log4j.core.time.internal.FixedPreciseClock; import org.junit.Test; import static org.junit.Assert.assertEquals;
