jjbridge.engine.utils.NativeReference Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jjbridge-engine-v8 Show documentation
Show all versions of jjbridge-engine-v8 Show documentation
A JJBridge library bundled with the V8 JavaScript Engine
package jjbridge.engine.utils;
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
/**
* This class associates a {@link CleanUpAction} to a {@link PhantomReference}.
* This allows to perform additional clean up operation before the reference is cleared by the garbage collector.
*
* @see ReferenceMonitor
* */
public class NativeReference extends PhantomReference
{
private final CleanUpAction cleanUpAction;
public final long id;
NativeReference(long id, T referent, ReferenceQueue super T> q, CleanUpAction cleanUpAction)
{
super(referent, q);
this.id = id;
this.cleanUpAction = cleanUpAction;
}
/**
* Performs the {@link CleanUpAction} passed in
* {@link #NativeReference(long, Object, ReferenceQueue, CleanUpAction)}.
* */
public void cleanUp()
{
this.cleanUpAction.cleanUp();
}
}