Loading...
Searching...
No Matches
Logger.java
Go to the documentation of this file.
1package com.navigine.idl.java;
2
3import java.util.concurrent.atomic.AtomicBoolean;
4
9public abstract class Logger {
10 public abstract void subscribe(LogListener listener);
11
12 public abstract void unsubscribe(LogListener listener);
13
14 public static Logger getLogger()
15 {
16 return CppProxy.getLogger();
17 }
18
19 private static final class CppProxy extends Logger
20 {
21 private final long nativeRef;
22 private final AtomicBoolean destroyed = new AtomicBoolean(false);
23
24 private CppProxy(long nativeRef)
25 {
26 if (nativeRef == 0) throw new RuntimeException("nativeRef is zero");
27 this.nativeRef = nativeRef;
28 }
29
30 private native void nativeDestroy(long nativeRef);
31 public void _djinni_private_destroy()
32 {
33 boolean destroyed = this.destroyed.getAndSet(true);
34 if (!destroyed) nativeDestroy(this.nativeRef);
35 }
36 protected void finalize() throws java.lang.Throwable
37 {
38 _djinni_private_destroy();
39 super.finalize();
40 }
41
42 // Logger methods
43
44 @Override
45 public void subscribe(LogListener listener)
46 {
47 assert !this.destroyed.get() : "trying to use a destroyed object";
48 native_subscribe(this.nativeRef, listener);
49 }
50 private native void native_subscribe(long _nativeRef, LogListener listener);
51
52 @Override
53 public void unsubscribe(LogListener listener)
54 {
55 assert !this.destroyed.get() : "trying to use a destroyed object";
56 native_unsubscribe(this.nativeRef, listener);
57 }
58 private native void native_unsubscribe(long _nativeRef, LogListener listener);
59
60 public static native Logger getLogger();
61 }
62}