| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.kuali.rice.ksb.messaging.service.impl; |
| 18 | |
|
| 19 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
| 20 | |
import org.kuali.rice.core.api.exception.RiceRuntimeException; |
| 21 | |
import org.kuali.rice.core.framework.persistence.ojb.DataAccessUtils; |
| 22 | |
import org.kuali.rice.kns.util.ObjectUtils; |
| 23 | |
import org.kuali.rice.ksb.messaging.FlattenedServiceDefinition; |
| 24 | |
import org.kuali.rice.ksb.messaging.ServiceInfo; |
| 25 | |
import org.kuali.rice.ksb.messaging.dao.ServiceInfoDAO; |
| 26 | |
import org.kuali.rice.ksb.messaging.service.ServiceRegistry; |
| 27 | |
import org.kuali.rice.ksb.service.KSBContextServiceLocator; |
| 28 | |
import org.kuali.rice.ksb.service.KSBServiceLocator; |
| 29 | |
|
| 30 | |
import javax.xml.namespace.QName; |
| 31 | |
import java.util.ArrayList; |
| 32 | |
import java.util.List; |
| 33 | |
|
| 34 | |
|
| 35 | 0 | public class ServiceRegistryImpl implements ServiceRegistry { |
| 36 | |
|
| 37 | |
private ServiceInfoDAO dao; |
| 38 | |
protected KSBContextServiceLocator serviceLocator; |
| 39 | |
|
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
public KSBContextServiceLocator getServiceLocator() { |
| 44 | 0 | return this.serviceLocator; |
| 45 | |
} |
| 46 | |
|
| 47 | |
|
| 48 | |
|
| 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 | |
|
| 129 | |
|
| 130 | |
|
| 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 | |
|
| 138 | |
|
| 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 | |
} |