Home » geronimo-2.2-source-release » org.apache.geronimo.gbean.runtime » [javadoc | source]

    1   /**
    2    *  Licensed to the Apache Software Foundation (ASF) under one or more
    3    *  contributor license agreements.  See the NOTICE file distributed with
    4    *  this work for additional information regarding copyright ownership.
    5    *  The ASF licenses this file to You under the Apache License, Version 2.0
    6    *  (the "License"); you may not use this file except in compliance with
    7    *  the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    *  Unless required by applicable law or agreed to in writing, software
   12    *  distributed under the License is distributed on an "AS IS" BASIS,
   13    *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    *  See the License for the specific language governing permissions and
   15    *  limitations under the License.
   16    */
   17   
   18   package org.apache.geronimo.gbean.runtime;
   19   
   20   import org.slf4j.Logger;
   21   import org.slf4j.LoggerFactory;
   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   /**
   30    * @version $Rev: 653588 $ $Date: 2008-05-05 13:34:06 -0700 (Mon, 05 May 2008) $
   31    */
   32   public class GBeanSingleReference extends AbstractGBeanReference
   33   {
   34       private static final Logger log = LoggerFactory.getLogger(GBeanSingleReference.class);
   35   
   36       /**
   37        * The object to which the proxy is bound
   38        */
   39       private final AbstractName targetName;
   40   
   41       public GBeanSingleReference(GBeanInstance gbeanInstance, GReferenceInfo referenceInfo, Kernel kernel, ReferencePatterns referencePatterns) throws InvalidConfigurationException {
   42           super(gbeanInstance, referenceInfo, kernel, referencePatterns != null && referencePatterns.getAbstractName() != null);
   43           targetName = referencePatterns != null? referencePatterns.getAbstractName(): null;
   44       }
   45   
   46       public AbstractName getTargetName() {
   47           return targetName;
   48       }
   49   
   50       public final synchronized void online() {
   51       }
   52   
   53       public final synchronized void offline() {
   54           stop();
   55       }
   56   
   57   
   58       public synchronized boolean start() {
   59           // We only need to start if there are patterns and we don't already have a proxy
   60           if (targetName == null) {
   61               return true;
   62           }
   63   
   64           // assure the gbean is running
   65           AbstractName abstractName = getGBeanInstance().getAbstractName();
   66           if (!isRunning(getKernel(), targetName)) {
   67               log.debug("Waiting to start " + abstractName + " because no targets are running for reference " + getName() +" matching the patterns " + targetName);
   68               return false;
   69           }
   70   
   71           if (getProxy() != null) {
   72               return true;
   73           }
   74   
   75           if (NO_PROXY) {
   76               try {
   77                   setProxy(getKernel().getGBean(targetName));
   78               } catch (GBeanNotFoundException e) {
   79                   // gbean disappeard on us
   80                   log.debug("Waiting to start " + abstractName + " because no targets are running for reference " + getName() +" matching the patterns " + targetName);
   81                   return false;
   82               }
   83           } else {
   84               setProxy(getKernel().getProxyManager().createProxy(targetName, getReferenceType()));
   85           }
   86           log.debug("Started {}", abstractName);
   87           return true;
   88       }
   89   
   90       public synchronized void stop() {
   91           Object proxy = getProxy();
   92           if (proxy != null) {
   93               getKernel().getProxyManager().destroyProxy(proxy);
   94               setProxy(null);
   95           }
   96       }
   97   
   98   
   99   }

Home » geronimo-2.2-source-release » org.apache.geronimo.gbean.runtime » [javadoc | source]