001: /*
002: * Copyright 2007 The Kuali Foundation
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package edu.iu.uis.eden.messaging;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.kuali.bus.services.KSBServiceLocator;
022: import org.kuali.rice.core.Core;
023: import org.kuali.rice.exceptions.RiceRuntimeException;
024:
025: import edu.iu.uis.eden.messaging.dao.ServiceInfoDAO;
026:
027: public class ServiceRegistryImpl implements ServiceRegistry {
028:
029: private ServiceInfoDAO dao;
030:
031: public void saveEntry(ServiceInfo entry) {
032: try {
033: Object service = entry.getServiceDefinition().getService();
034: entry.getServiceDefinition().setService(null);
035: entry.setSerializedMessageEntity(KSBServiceLocator
036: .getMessageHelper().serializeObject(
037: entry.getServiceDefinition()));
038: entry.getServiceDefinition().setService(service);
039: } catch (Exception e) {
040: throw new RiceRuntimeException(e);
041: }
042: getDao().addEntry(entry);
043: }
044:
045: public List<ServiceInfo> fetchAll() {
046: return getDao().fetchAll();
047: }
048:
049: public List<ServiceInfo> fetchAllActive() {
050: return dao.fetchAllActive();
051: }
052:
053: public List<ServiceInfo> findLocallyPublishedServices(
054: String ipNumber, String messageEntity) {
055: if (Core.getCurrentContextConfig().getDevMode()) {
056: return new ArrayList<ServiceInfo>();
057: }
058: return getDao().findLocallyPublishedServices(ipNumber,
059: messageEntity);
060: }
061:
062: public void removeEntry(ServiceInfo entry) {
063: getDao().removeEntry(entry);
064: }
065:
066: public void removeLocallyPublishedServices(String ipNumber,
067: String messageEntity) {
068: getDao()
069: .removeLocallyPublishedServices(ipNumber, messageEntity);
070: }
071:
072: public ServiceInfoDAO getDao() {
073: return this .dao;
074: }
075:
076: public void setDao(ServiceInfoDAO dao) {
077: this .dao = dao;
078: }
079:
080: public void remove(List<ServiceInfo> serviceEntries) {
081: for (ServiceInfo info : serviceEntries) {
082: removeEntry(info);
083: }
084: }
085:
086: public void save(List<ServiceInfo> serviceEntries) {
087: for (ServiceInfo info : serviceEntries) {
088: saveEntry(info);
089: }
090: }
091:
092: public void markServicesDead(List<ServiceInfo> serviceEntries) {
093: for (ServiceInfo info : serviceEntries) {
094: // there is contention on these records from multiple nodes and odds
095: // are the
096: // one we have in memory is stale. refetch and mork dead.
097: ServiceInfo currentInfo = getDao().findServiceInfo(
098: info.getMessageEntryId());
099: currentInfo.setAlive(false);
100: try {
101: saveEntry(currentInfo);
102: } catch (Exception e) {
103: boolean isOptimisticLockExp = KSBServiceLocator
104: .getOptimisticLockFailureService()
105: .checkForOptimisticLockFailure(e);
106: // suppress optimistic lock exceptions, it's collision with
107: // other nodes
108: if (!isOptimisticLockExp) {
109: throw (RuntimeException) e;
110: }
111: }
112:
113: }
114: }
115: }
|