add close() method

This commit is contained in:
Doug MacEachern 2010-04-21 13:47:06 -07:00
parent aa2cbaa89b
commit c9ef9f4bb6
1 changed files with 11 additions and 2 deletions

View File

@ -36,7 +36,7 @@ public class Humidor {
private Object LOCK = new Object();
private InvocationHandler _handler;
private SigarProxy _sigar;
private Sigar _impl;
private Sigar _impl, _inst;
private Humidor() {}
@ -69,7 +69,7 @@ public class Humidor {
synchronized(LOCK) {
if (_sigar == null) {
if (_impl == null) {
_impl = new Sigar();
_inst = _impl = new Sigar();
}
_handler = new MyHandler(_impl);
_sigar = (SigarProxy)
@ -84,4 +84,13 @@ public class Humidor {
public static Humidor getInstance() {
return INSTANCE;
}
//close the Sigar instance if getSigar() created it
public void close() {
if (_inst != null) {
_inst.close();
_impl = _inst = null;
}
_sigar = null;
}
}