support for caller constructed Sigar object
This commit is contained in:
parent
22e9e06b9d
commit
ce39c1ad1e
|
@ -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 },
|
||||||
|
|
Loading…
Reference in New Issue