support for caller constructed Sigar object

This commit is contained in:
Doug MacEachern 2009-07-08 15:28:49 -07:00
parent 22e9e06b9d
commit ce39c1ad1e
1 changed files with 9 additions and 2 deletions

View File

@ -36,9 +36,14 @@ public class Humidor {
private Object LOCK = new Object(); private Object LOCK = new Object();
private InvocationHandler _handler; private InvocationHandler _handler;
private SigarProxy _sigar; private SigarProxy _sigar;
private Sigar _impl;
private Humidor() {} private Humidor() {}
public Humidor(Sigar sigar) {
_impl = sigar;
}
private static class MyHandler implements InvocationHandler { private static class MyHandler implements InvocationHandler {
private SigarProxy _sigar; private SigarProxy _sigar;
private Object _lock = new Object(); private Object _lock = new Object();
@ -63,8 +68,10 @@ public class Humidor {
public SigarProxy getSigar() { public SigarProxy getSigar() {
synchronized(LOCK) { synchronized(LOCK) {
if (_sigar == null) { if (_sigar == null) {
Sigar s = new Sigar(); if (_impl == null) {
_handler = new MyHandler(s); _impl = new Sigar();
}
_handler = new MyHandler(_impl);
_sigar = (SigarProxy) _sigar = (SigarProxy)
Proxy.newProxyInstance(Humidor.class.getClassLoader(), Proxy.newProxyInstance(Humidor.class.getClassLoader(),
new Class[] { SigarProxy.class }, new Class[] { SigarProxy.class },