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 {
32 public abstract ArrayList<String> getStorageList();
33
49 public abstract KeyValueStorage getStorage(String name);
50
66 public abstract void removeStorage(String name);
67
68 private static final class CppProxy extends StorageManager
69 {
70 private final long nativeRef;
71 private final AtomicBoolean destroyed = new AtomicBoolean(false);
72
73 private CppProxy(long nativeRef)
74 {
75 if (nativeRef == 0) throw new RuntimeException("nativeRef is zero");
76 this.nativeRef = nativeRef;
77 }
78
79 private native void nativeDestroy(long nativeRef);
80 public void _djinni_private_destroy()
81 {
82 boolean destroyed = this.destroyed.getAndSet(true);
83 if (!destroyed) nativeDestroy(this.nativeRef);
84 }
85 protected void finalize() throws java.lang.Throwable
86 {
87 _djinni_private_destroy();
88 super.finalize();
89 }
90
91 // StorageManager methods
92
93 @Override
94 public ArrayList<String> getStorageList()
95 {
96 assert !this.destroyed.get() : "trying to use a destroyed object";
97 return native_getStorageList(this.nativeRef);
98 }
99 private native ArrayList<String> native_getStorageList(long _nativeRef);
100
101 @Override
102 public KeyValueStorage getStorage(String name)
103 {
104 assert !this.destroyed.get() : "trying to use a destroyed object";
105 return native_getStorage(this.nativeRef, name);
106 }
107 private native KeyValueStorage native_getStorage(long _nativeRef, String name);
108
109 @Override
110 public void removeStorage(String name)
111 {
112 assert !this.destroyed.get() : "trying to use a destroyed object";
113 native_removeStorage(this.nativeRef, name);
114 }
115 private native void native_removeStorage(long _nativeRef, String name);
116 }
117}