mirror of
https://github.com/ceph/ceph
synced 2025-01-31 15:32:38 +00:00
java: clean-up in finalize()
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
This commit is contained in:
parent
d88c60c61e
commit
16a4c92d20
@ -89,6 +89,30 @@ public class CephMount {
|
||||
*/
|
||||
static native void native_initialize();
|
||||
|
||||
/*
|
||||
* Controls clean-up synchronization between the constructor and finalize().
|
||||
* If native_ceph_create fails, then we want a call to finalize() to not
|
||||
* attempt to clean-up native context, because there is none.
|
||||
*/
|
||||
private boolean initialized = false;
|
||||
|
||||
/*
|
||||
* Try to clean-up. First, unmount() will catch users who forget to do the
|
||||
* unmount manually. Second, release() will destroy the entire context. It
|
||||
* is safe to call release after a failure in unmount.
|
||||
*/
|
||||
protected void finalize() throws Throwable {
|
||||
if (initialized) {
|
||||
try {
|
||||
unmount();
|
||||
} catch (Exception e) {}
|
||||
try {
|
||||
native_ceph_release(instance_ptr);
|
||||
} catch (Exception e) {}
|
||||
}
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new CephMount with specific client id.
|
||||
*
|
||||
@ -96,6 +120,7 @@ public class CephMount {
|
||||
*/
|
||||
public CephMount(String id) {
|
||||
native_ceph_create(this, id);
|
||||
initialized = true;
|
||||
}
|
||||
|
||||
private static synchronized native int native_ceph_create(CephMount mount, String id);
|
||||
|
Loading…
Reference in New Issue
Block a user