26 package jau.direct_bt;
28 import java.util.concurrent.atomic.AtomicBoolean;
34 private long nativeInstance;
35 private final AtomicBoolean isValid =
new AtomicBoolean(
false);
36 private final Object nativeLock =
new Object();
44 this.nativeInstance = nativeInstance;
46 initNativeJavaObject(nativeInstance);
49 protected boolean isValid() {
return isValid.get(); }
65 public final void delete() {
66 synchronized (nativeLock) {
67 if( !isValid.compareAndSet(
true,
false) ) {
69 System.err.println(
"JAVA: delete: !valid -> bail: "+getClass().getSimpleName());
74 System.err.println(
"JAVA: delete.0: "+getClass().getSimpleName()+
": valid, handle 0x"+Long.toHexString(nativeInstance));
76 final long _nativeInstance = nativeInstance;
78 deleteNativeJavaObject(_nativeInstance);
81 System.err.println(
"JAVA: delete.X: "+getClass().getSimpleName()+
": handle 0x"+Long.toHexString(nativeInstance));
90 private final void notifyDeleted() {
91 synchronized (nativeLock) {
92 final boolean _isValid = isValid.get();
93 final long _nativeInstance = nativeInstance;
97 System.err.println(
"JAVA: delete.notifyDeleted: "+getClass().getSimpleName()+
", was: valid "+_isValid+
", handle 0x"+Long.toHexString(_nativeInstance)+
": "+toString());
115 private native
void initNativeJavaObject(
final long nativeInstance);
116 private native
void deleteNativeJavaObject(
final long nativeInstance);