Skip to content

Commit

Permalink
Using reflection to unmonitor a reference results in errors in Java 17
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-lawrey authored and JerryShea committed May 20, 2024
1 parent f0e0018 commit f29fe71
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
* The class uses a file-based mechanism to ensure that timestamps are not only unique across restarts
* but also across different JVM instances.
*/
public class DistributedUniqueTimeProvider extends SimpleCloseable implements TimeProvider {
public class DistributedUniqueTimeProvider extends SimpleCloseable implements TimeProvider, Monitorable {

static final int HOST_IDS = 100;
private static final int LAST_TIME = 128;
Expand All @@ -65,17 +65,17 @@ private DistributedUniqueTimeProvider(@NonNegative int hostId, boolean unmonitor
hostId(hostId);
try {
file = MappedFile.ofSingle(new File(BytesUtil.TIME_STAMP_PATH), OS.pageSize(), false);
if (unmonitor) IOTools.unmonitor(file);
bytes = file.acquireBytesForWrite(this, 0);
if (unmonitor) IOTools.unmonitor(bytes);
bytes.append8bit("&TSF\nTime stamp file used for sharing a unique id\n");
values = new BinaryLongArrayReference(HOST_IDS);
if (unmonitor) IOTools.unmonitor(values);
values.bytesStore(bytes, DEDUPLICATOR, HOST_IDS * 8L + 16L);
deduplicator = new VanillaDistributedUniqueTimeDeduplicator(values);

} catch (Exception ioe) {
throw new IORuntimeException(ioe);
} finally {
if (unmonitor)
unmonitor();
}
}

Expand Down Expand Up @@ -283,6 +283,13 @@ private long currentTimeNanosLoop() {
}
}

@Override
public void unmonitor() {
Monitorable.unmonitor(file);
Monitorable.unmonitor(bytes);
Monitorable.unmonitor(values);
}

/**
* A deduplicator to help recognise duplicate timestamps for a hostId
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import net.openhft.chronicle.core.Jvm;
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.io.IORuntimeException;
import net.openhft.chronicle.core.io.IOTools;
import net.openhft.chronicle.core.io.Monitorable;
import net.openhft.chronicle.core.io.ReferenceOwner;
import net.openhft.chronicle.core.time.SystemTimeProvider;
import net.openhft.chronicle.core.time.TimeProvider;
Expand Down Expand Up @@ -53,8 +53,8 @@ public enum MappedUniqueTimeProvider implements TimeProvider, ReferenceOwner {
final Bytes<?> bytes = file.acquireBytesForWrite(this, 0);
bytes.append8bit("&TSF\nTime stamp file used for sharing a unique id\n");
this.bytesStore = bytes.bytesStore();
IOTools.unmonitor(file);
IOTools.unmonitor(bytes);
Monitorable.unmonitor(file);
Monitorable.unmonitor(bytes);
} catch (Exception ioe) {
throw new IORuntimeException(ioe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@
import net.openhft.chronicle.core.OS;
import net.openhft.chronicle.core.annotation.NonNegative;
import net.openhft.chronicle.core.annotation.Positive;
import net.openhft.chronicle.core.io.ClosedIllegalStateException;
import net.openhft.chronicle.core.io.IORuntimeException;
import net.openhft.chronicle.core.io.ReferenceOwner;
import net.openhft.chronicle.core.io.ThreadingIllegalStateException;
import net.openhft.chronicle.core.io.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -404,4 +401,10 @@ public void chunkCount(long[] chunkCount) {
public MappedBytes createBytesFor() {
return new SingleMappedBytes(this);
}

@Override
public void unmonitor() {
super.unmonitor();
Monitorable.unmonitor(store);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
import net.openhft.chronicle.bytes.BytesStore;
import net.openhft.chronicle.bytes.MappedBytesStore;
import net.openhft.chronicle.core.annotation.NonNegative;
import net.openhft.chronicle.core.io.AbstractCloseable;
import net.openhft.chronicle.core.io.Closeable;
import net.openhft.chronicle.core.io.ClosedIllegalStateException;
import net.openhft.chronicle.core.io.ThreadingIllegalStateException;
import net.openhft.chronicle.core.io.*;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -188,4 +185,10 @@ public FileLock tryLock(boolean shared) throws IOException {
}
throw new UnsupportedOperationException();
}

@Override
public void unmonitor() {
super.unmonitor();
Monitorable.unmonitor(bytes);
}
}

0 comments on commit f29fe71

Please sign in to comment.