Skip to content

Commit

Permalink
[Java] Do not use UnsafeAccess.
Browse files Browse the repository at this point in the history
  • Loading branch information
vyazelenko committed Dec 13, 2024
1 parent a430f6a commit 5b1b521
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions aeron-client/src/main/java/io/aeron/status/ReadableCounter.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
package io.aeron.status;

import io.aeron.Aeron;
import org.agrona.UnsafeAccess;
import org.agrona.concurrent.AtomicBuffer;
import org.agrona.concurrent.UnsafeBuffer;
import org.agrona.concurrent.status.CountersReader;

import static org.agrona.BitUtil.SIZE_OF_LONG;
Expand All @@ -27,15 +27,14 @@
* <p>
* <b>Note:</b>The user should call {@link #isClosed()} and ensure the result is false to avoid a race on reading a
* closed {@link io.aeron.Counter}.
* */
*/
public final class ReadableCounter implements AutoCloseable
{
private final long addressOffset;
private final CountersReader countersReader;
private final UnsafeBuffer valueBuffer;
private final long registrationId;
private final int counterId;
private volatile boolean isClosed = false;
private final byte[] buffer;
private final CountersReader countersReader;

/**
* Construct a view of an existing counter.
Expand All @@ -61,8 +60,7 @@ public ReadableCounter(final CountersReader countersReader, final long registrat
final int counterOffset = CountersReader.counterOffset(counterId);
valuesBuffer.boundsCheck(counterOffset, SIZE_OF_LONG);

this.buffer = valuesBuffer.byteArray();
this.addressOffset = valuesBuffer.addressOffset() + counterOffset;
valueBuffer = new UnsafeBuffer(valuesBuffer, counterOffset, SIZE_OF_LONG);
}

/**
Expand Down Expand Up @@ -100,11 +98,10 @@ public int counterId()
/**
* Return the state of the counter.
*
* @return state for the counter.
* @see CountersReader#RECORD_ALLOCATED
* @see CountersReader#RECORD_RECLAIMED
* @see CountersReader#RECORD_UNUSED
*
* @return state for the counter.
*/
public int state()
{
Expand All @@ -131,7 +128,7 @@ public String label()
*/
public long get()
{
return UnsafeAccess.UNSAFE.getLongVolatile(buffer, addressOffset);
return valueBuffer.getLongVolatile(0);
}

/**
Expand All @@ -141,7 +138,7 @@ public long get()
*/
public long getWeak()
{
return UnsafeAccess.UNSAFE.getLong(buffer, addressOffset);
return valueBuffer.getLong(0);
}

/**
Expand Down

0 comments on commit 5b1b521

Please sign in to comment.