1 17 18 package org.apache.geronimo.gbean.runtime; 19 20 import org.apache.commons.logging.Log; 21 import org.apache.commons.logging.LogFactory; 22 import org.apache.geronimo.gbean.AbstractName; 23 import org.apache.geronimo.gbean.GReferenceInfo; 24 import org.apache.geronimo.gbean.InvalidConfigurationException; 25 import org.apache.geronimo.gbean.ReferencePatterns; 26 import org.apache.geronimo.kernel.Kernel; 27 import org.apache.geronimo.kernel.GBeanNotFoundException; 28 29 32 public class GBeanSingleReference extends AbstractGBeanReference { 33 private static final Log log = LogFactory.getLog(GBeanSingleReference.class); 34 35 38 private final AbstractName targetName; 39 40 public GBeanSingleReference(GBeanInstance gbeanInstance, GReferenceInfo referenceInfo, Kernel kernel, ReferencePatterns referencePatterns) throws InvalidConfigurationException { 41 super(gbeanInstance, referenceInfo, kernel, referencePatterns != null && referencePatterns.getAbstractName() != null); 42 targetName = referencePatterns != null? referencePatterns.getAbstractName(): null; 43 } 44 45 public AbstractName getTargetName() { 46 return targetName; 47 } 48 49 public final synchronized void online() { 50 } 51 52 public final synchronized void offline() { 53 stop(); 54 } 55 56 57 public synchronized boolean start() { 58 if (targetName == null) { 60 return true; 61 } 62 63 AbstractName abstractName = getGBeanInstance().getAbstractName(); 65 if (!isRunning(getKernel(), targetName)) { 66 log.debug("Waiting to start " + abstractName + " because no targets are running for reference " + getName() +" matching the patterns " + targetName); 67 return false; 68 } 69 70 if (getProxy() != null) { 71 return true; 72 } 73 74 if (NO_PROXY) { 75 try { 76 setProxy(getKernel().getGBean(targetName)); 77 } catch (GBeanNotFoundException e) { 78 log.debug("Waiting to start " + abstractName + " because no targets are running for reference " + getName() +" matching the patterns " + targetName); 80 return false; 81 } 82 } else { 83 setProxy(getKernel().getProxyManager().createProxy(targetName, getReferenceType())); 84 } 85 log.debug("Started " + abstractName); 86 return true; 87 } 88 89 public synchronized void stop() { 90 Object proxy = getProxy(); 91 if (proxy != null) { 92 getKernel().getProxyManager().destroyProxy(proxy); 93 setProxy(null); 94 } 95 } 96 97 98 } 99 | Popular Tags |