Coverage Report - org.kuali.rice.ksb.messaging.service.impl.ServiceRegistryImpl
 
Classes in this File Line Coverage Branch Coverage Complexity
ServiceRegistryImpl
0%
0/45
0%
0/16
1.765
 
 1  
 /*
 2  
  * Copyright 2007 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.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/ecl2.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.messaging.service.impl;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.List;
 20  
 
 21  
 import javax.xml.namespace.QName;
 22  
 
 23  
 import org.kuali.rice.core.config.ConfigContext;
 24  
 import org.kuali.rice.core.exception.RiceRuntimeException;
 25  
 import org.kuali.rice.core.util.DataAccessUtils;
 26  
 import org.kuali.rice.kns.util.ObjectUtils;
 27  
 import org.kuali.rice.ksb.messaging.FlattenedServiceDefinition;
 28  
 import org.kuali.rice.ksb.messaging.ServiceInfo;
 29  
 import org.kuali.rice.ksb.messaging.dao.ServiceInfoDAO;
 30  
 import org.kuali.rice.ksb.messaging.service.ServiceRegistry;
 31  
 import org.kuali.rice.ksb.service.KSBContextServiceLocator;
 32  
 import org.kuali.rice.ksb.service.KSBServiceLocator;
 33  
 
 34  
 
 35  0
 public class ServiceRegistryImpl implements ServiceRegistry {
 36  
 
 37  
         private ServiceInfoDAO dao;
 38  
         protected KSBContextServiceLocator serviceLocator;
 39  
         
 40  
         /**
 41  
          * @return the serviceLocator
 42  
          */
 43  
         public KSBContextServiceLocator getServiceLocator() {
 44  0
                 return this.serviceLocator;
 45  
         }
 46  
 
 47  
         /**
 48  
          * @param serviceLocator the serviceLocator to set
 49  
          */
 50  
         public void setServiceLocator(KSBContextServiceLocator serviceLocator) {
 51  0
                 this.serviceLocator = serviceLocator;
 52  0
         }
 53  
 
 54  
         public void saveEntry(ServiceInfo entry) {
 55  
                 try {
 56  0
                         if (ObjectUtils.isNull(entry.getSerializedServiceNamespace())) {
 57  0
                                 entry.setSerializedServiceNamespace(new FlattenedServiceDefinition(serviceLocator==null ?
 58  
                                                 KSBServiceLocator.getMessageHelper().serializeObject(entry.getServiceDefinition()) :
 59  
                                                                 serviceLocator.getMessageHelper().serializeObject(entry.getServiceDefinition())));
 60  
                         } else {
 61  0
                                 entry.getSerializedServiceNamespace().setFlattenedServiceDefinitionData(serviceLocator==null ?
 62  
                                                 KSBServiceLocator.getMessageHelper().serializeObject(entry.getServiceDefinition()) :
 63  
                                                                 serviceLocator.getMessageHelper().serializeObject(entry.getServiceDefinition()));
 64  
                         }
 65  0
                 } catch (Exception e) {
 66  0
                         throw new RiceRuntimeException(e);
 67  0
                 }
 68  0
                 getDao().addEntry(entry);
 69  0
         }
 70  
 
 71  
         public List<ServiceInfo> fetchAll() {
 72  0
                 return getDao().fetchAll();
 73  
         }
 74  
 
 75  
         public List<ServiceInfo> fetchAllActive() {
 76  0
             return dao.fetchAllActive();
 77  
         }
 78  
 
 79  
         public List<ServiceInfo> fetchActiveByNameLocalPart(String localPart) {
 80  0
                 return getDao().fetchActiveByNameLocalPart(localPart);
 81  
         }
 82  
         
 83  
         public List<ServiceInfo> fetchActiveByName(QName serviceName) {
 84  0
                 return getDao().fetchActiveByName(serviceName);                
 85  
         }
 86  
         
 87  
         public List<ServiceInfo> fetchActiveByNamespace(String serviceNamespace) {
 88  0
                 return getDao().fetchActiveByNamespace(serviceNamespace);
 89  
         }
 90  
         
 91  
         public List<ServiceInfo> findLocallyPublishedServices(String ipNumber, String serviceNamespace) {
 92  0
                 if (ConfigContext.getCurrentContextConfig().getDevMode()) {
 93  0
                         return new ArrayList<ServiceInfo>();
 94  
                 }
 95  0
                 return getDao().findLocallyPublishedServices(ipNumber, serviceNamespace);
 96  
         }
 97  
 
 98  
         public void removeEntry(ServiceInfo entry) {
 99  0
                 getDao().removeEntry(entry);
 100  0
         }
 101  
 
 102  
         public void removeLocallyPublishedServices(String ipNumber, String serviceNamespace) {
 103  0
                 getDao().removeLocallyPublishedServices(ipNumber, serviceNamespace);
 104  0
         }
 105  
 
 106  
         public ServiceInfoDAO getDao() {
 107  0
                 return this.dao;
 108  
         }
 109  
 
 110  
         public void setDao(ServiceInfoDAO dao) {
 111  0
                 this.dao = dao;
 112  0
         }
 113  
 
 114  
         public void removeEntries(List<ServiceInfo> serviceEntries) {
 115  0
                 for (ServiceInfo info : serviceEntries) {
 116  0
                         removeEntry(info);
 117  
                 }
 118  0
         }
 119  
 
 120  
         public void saveEntries(List<ServiceInfo> serviceEntries) {
 121  0
                 for (ServiceInfo info : serviceEntries) {
 122  0
                         saveEntry(info);
 123  
                 }
 124  0
         }
 125  
 
 126  
         public void markServicesDead(List<ServiceInfo> serviceEntries) {
 127  0
                 for (ServiceInfo info : serviceEntries) {
 128  
                         // there is contention on these records from multiple nodes and odds
 129  
                         // are the
 130  
                         // one we have in memory is stale. refetch and mork dead.
 131  0
                         ServiceInfo currentInfo = getDao().findServiceInfo(info.getMessageEntryId());
 132  0
                         currentInfo.setAlive(false);
 133  
                         try {
 134  0
                                 saveEntry(currentInfo);
 135  0
                         } catch (Exception e) {
 136  0
                                 boolean isOptimisticLockExp = DataAccessUtils.isOptimisticLockFailure(e);
 137  
                                 // suppress optimistic lock exceptions, it's collision with
 138  
                                 // other nodes
 139  0
                                 if (!isOptimisticLockExp) {
 140  0
                                         throw (RuntimeException) e;
 141  
                                 }
 142  0
                         }
 143  
 
 144  0
                 }
 145  0
         }
 146  
 
 147  
         public FlattenedServiceDefinition getFlattenedServiceDefinition(Long flattenedServiceDefinitionId) {
 148  0
                 return getDao().findFlattenedServiceDefinition(flattenedServiceDefinitionId);
 149  
         }
 150  
 }