Loading...
Searching...
No Matches
StorageManager.java
Go to the documentation of this file.
1package com.navigine.idl.java;
2
3import java.util.ArrayList;
4import java.util.concurrent.atomic.AtomicBoolean;
5
17public abstract class StorageManager {
31 public abstract ArrayList<String> getStorageList();
32
47 public abstract KeyValueStorage getStorage(String name);
48
63 public abstract void removeStorage(String name);
64
65 private static final class CppProxy extends StorageManager
66 {
67 private final long nativeRef;
68 private final AtomicBoolean destroyed = new AtomicBoolean(false);
69
70 private CppProxy(long nativeRef)
71 {
72 if (nativeRef == 0) throw new RuntimeException("nativeRef is zero");
73 this.nativeRef = nativeRef;
74 }
75
76 private native void nativeDestroy(long nativeRef);
77 public void _djinni_private_destroy()
78 {
79 boolean destroyed = this.destroyed.getAndSet(true);
80 if (!destroyed) nativeDestroy(this.nativeRef);
81 }
82 protected void finalize() throws java.lang.Throwable
83 {
84 _djinni_private_destroy();
85 super.finalize();
86 }
87
88 // StorageManager methods
89
90 @Override
91 public ArrayList<String> getStorageList()
92 {
93 assert !this.destroyed.get() : "trying to use a destroyed object";
94 return native_getStorageList(this.nativeRef);
95 }
96 private native ArrayList<String> native_getStorageList(long _nativeRef);
97
98 @Override
99 public KeyValueStorage getStorage(String name)
100 {
101 assert !this.destroyed.get() : "trying to use a destroyed object";
102 return native_getStorage(this.nativeRef, name);
103 }
104 private native KeyValueStorage native_getStorage(long _nativeRef, String name);
105
106 @Override
107 public void removeStorage(String name)
108 {
109 assert !this.destroyed.get() : "trying to use a destroyed object";
110 native_removeStorage(this.nativeRef, name);
111 }
112 private native void native_removeStorage(long _nativeRef, String name);
113 }
114}