Coverage Report - org.kuali.rice.ksb.impl.bus.InstanceIdFactoryBean
 
Classes in this File Line Coverage Branch Coverage Complexity
InstanceIdFactoryBean
0%
0/12
0%
0/4
1.5
 
 1  
 /*
 2  
  * Copyright 2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 1.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl1.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.ksb.impl.bus;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.config.CoreConfigHelper;
 20  
 import org.kuali.rice.core.api.config.property.ConfigContext;
 21  
 import org.kuali.rice.core.api.util.RiceUtilities;
 22  
 import org.kuali.rice.ksb.util.KSBConstants;
 23  
 import org.springframework.beans.factory.config.AbstractFactoryBean;
 24  
 
 25  
 /**
 26  
  * A factory bean which is used to produce an instance id for the service bus.
 27  
  * 
 28  
  * <p>The value for the instance id is determined in the following order of preference:
 29  
  * 
 30  
  * <ol>
 31  
  *   <li>If {@code instanceId} is set on this factory bean, that value will be used.</li> 
 32  
  *   <li>If {@link KSBConstants.Config#INSTANCE_ID} has been set in the configuration context, that value will be used.</li>
 33  
  *   <li>If none of the above, the instance id will be a combination of this application's namespace plus ip address.</li>
 34  
  * </ol>
 35  
  * 
 36  
  * <p>In the case that the instance id is generated, the application id will be pulled
 37  
  * from the configuration context using the {@link KSBConstants.Config#INSTANCE_ID} configuration parameter which
 38  
  * should always have a value.
 39  
  * 
 40  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 41  
  *
 42  
  */
 43  0
 public class InstanceIdFactoryBean extends AbstractFactoryBean<String> {
 44  
 
 45  
         private String instanceId;
 46  
         
 47  
         public void setInstanceId(String instanceId) {
 48  0
                 this.instanceId = instanceId;
 49  0
         }
 50  
         
 51  
         @Override
 52  
         protected String createInstance() throws Exception {
 53  0
                 if (StringUtils.isBlank(instanceId)) {
 54  0
                         this.instanceId = loadInstanceIdFromConfig();
 55  
                 }
 56  0
                 if (StringUtils.isBlank(instanceId)) {
 57  0
                         String applicationId = CoreConfigHelper.getApplicationId();
 58  0
                         String ipNumber = RiceUtilities.getIpNumber();
 59  0
                         this.instanceId = applicationId + "-" + ipNumber;
 60  
                 }
 61  0
                 return this.instanceId;
 62  
         }
 63  
         
 64  
         protected String loadInstanceIdFromConfig() {
 65  0
                 return ConfigContext.getCurrentContextConfig().getProperty(KSBConstants.Config.INSTANCE_ID);
 66  
         }
 67  
 
 68  
         @Override
 69  
         public Class<String> getObjectType() {
 70  0
                 return String.class;
 71  
         }
 72  
 
 73  
         
 74  
         
 75  
 }