diff --git a/edexOsgi/com.raytheon.uf.common.registry.event/.classpath b/edexOsgi/com.raytheon.uf.common.registry.event/.classpath
index ad32c83a78..31db9a9117 100644
--- a/edexOsgi/com.raytheon.uf.common.registry.event/.classpath
+++ b/edexOsgi/com.raytheon.uf.common.registry.event/.classpath
@@ -3,5 +3,6 @@
+ * + * SOFTWARE HISTORY + * + * Date Ticket# Engineer Description + * ------------ ---------- ----------- -------------------------- + * June 25, 2014 2760 dhladky Initial creation + * + *+ * + * @author dhladky + * @version 1.0 + */ + +public class PublishRegistryEvent { + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(PublishRegistryEvent.class); + + /** static instance **/ + public static PublishRegistryEvent instance = null; + + /** allow external publish of registry events **/ + private final boolean externalPublish; + + /** URI to send events to, this could be another queue, topic, etc **/ + public final String externalUri; + + private PublishRegistryEvent() { + + externalPublish = Boolean.parseBoolean(System.getProperty("registry.event.external.publish")); + externalUri = System.getProperty("registry.event.external.publish.uri"); + + statusHandler.info("Registry configured to publish events externally: "+externalPublish); + + if (externalPublish) { + statusHandler.info("External URI: "+externalUri); + } + } + + /** + * Static for speed + * @return + */ + public static PublishRegistryEvent getInstance() { + + if (instance == null) { + instance = new PublishRegistryEvent(); + } + return instance; + } + + /** + * Publish registry event, general method. + * + * @param event + */ + public void publish(Event event) { + + if (instance.externalPublish) { + try { + // filter out internal audit trail, statistics, etc + if (event instanceof RegistryEvent) { + publishExternal(event); + } + } catch (Exception e) { + statusHandler.error("Can't send event to external URI!: " + + instance.externalUri, e); + } + } + + // local publish as usual + EventBus.publish(event); + } + + /** + * Publish registry events to an external route + * + * @param event + * @throws EdexException + * @throws SerializationException + */ + private void publishExternal(Event event) throws Exception { + + if (event != null) { + byte[] bytes = SerializationUtil.transformToThrift(event); + EDEXUtil.getMessageProducer().sendAsyncUri(instance.externalUri, bytes); + } + } + + +} diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/publish/SampleExternalMessageHandler.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/publish/SampleExternalMessageHandler.java new file mode 100644 index 0000000000..52deda8455 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/publish/SampleExternalMessageHandler.java @@ -0,0 +1,69 @@ +package com.raytheon.uf.edex.registry.ebxml.publish; + +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ + +import com.raytheon.uf.common.registry.event.RegistryEvent; +import com.raytheon.uf.common.status.IUFStatusHandler; +import com.raytheon.uf.common.status.UFStatus; + +/** + * + * Sample External Registry Event Handler + * + * This is a sample class only here to prove external delivery of registry messages. + * When an actual handler is created this can go away along with it's supporting spring. + * + *
+ * + * SOFTWARE HISTORY + * + * Date Ticket# Engineer Description + * ------------ ---------- ----------- -------------------------- + * June 25, 2014 2760 dhladky Initial creation + * + *+ * + * @author dhladky + * @version 1.0 + */ + +public class SampleExternalMessageHandler { + + private static final IUFStatusHandler statusHandler = UFStatus + .getHandler(SampleExternalMessageHandler.class); + + // default pub constuctor + public SampleExternalMessageHandler() { + + } + + /** + * Notify of arrival on the JMS route specified in spring + * @param RegistryEvent + */ + public void notify(RegistryEvent event) { + + if (event != null) { + statusHandler.info("Received Registry event externally: "+event.toString()); + } + } + +} diff --git a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/lifecycle/LifecycleManagerImpl.java b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/lifecycle/LifecycleManagerImpl.java index aec58708a4..7894a27073 100644 --- a/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/lifecycle/LifecycleManagerImpl.java +++ b/edexOsgi/com.raytheon.uf.edex.registry.ebxml/src/com/raytheon/uf/edex/registry/ebxml/services/lifecycle/LifecycleManagerImpl.java @@ -52,7 +52,6 @@ import oasis.names.tc.ebxml.regrep.xsd.rs.v4.RegistryResponseType; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; -import com.raytheon.uf.common.event.EventBus; import com.raytheon.uf.common.registry.constants.ActionTypes; import com.raytheon.uf.common.registry.constants.AssociationTypes; import com.raytheon.uf.common.registry.constants.DeletionScope; @@ -73,6 +72,7 @@ import com.raytheon.uf.common.util.CollectionUtil; import com.raytheon.uf.edex.database.DataAccessLayerException; import com.raytheon.uf.edex.registry.ebxml.dao.RegistryObjectDao; import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException; +import com.raytheon.uf.edex.registry.ebxml.publish.PublishRegistryEvent; import com.raytheon.uf.edex.registry.ebxml.services.cataloger.CatalogerImpl; import com.raytheon.uf.edex.registry.ebxml.services.query.QueryManagerImpl; import com.raytheon.uf.edex.registry.ebxml.services.validator.ValidatorImpl; @@ -113,6 +113,7 @@ import com.raytheon.uf.edex.registry.events.DeleteSlotEvent; * Mar 31, 2014 2889 dhladky Added username for notification center tracking. * 4/11/2014 3011 bphillip Modified merge behavior * 4/17/2014 3011 bphillip Delete slot events now contain strings + * June 25, 2014 2760 dhladky Added external delivery of registry events * * * @@ -153,6 +154,9 @@ public class LifecycleManagerImpl implements LifecycleManager { private RegistryObjectDao registryObjectDao; private RegistryXPathProcessor xpathProcessor; + + /** publishes registry events **/ + private PublishRegistryEvent publisher = PublishRegistryEvent.getInstance(); /** * The Remove Objects protocol allows a client to remove or delete one or @@ -300,15 +304,15 @@ public class LifecycleManagerImpl implements LifecycleManager { event.setAction(Action.DELETE); event.setLid(obj.getLid()); event.setObjectType(objectType); - EventBus.publish(event); + publisher.publish(event); } DeleteSlotEvent deleteEvent = new DeleteSlotEvent(obj.getSlot()); - EventBus.publish(deleteEvent); - EventBus.publish(new RegistryStatisticsEvent(obj.getObjectType(), + publisher.publish(deleteEvent); + publisher.publish(new RegistryStatisticsEvent(obj.getObjectType(), obj.getStatus(), obj.getOwner(), avTimePerRecord)); } - EventBus.publish(new CreateAuditTrailEvent(request.getId(), request, + publisher.publish(new CreateAuditTrailEvent(request.getId(), request, ActionTypes.delete, objectsToRemove, TimeUtil .currentTimeMillis())); @@ -474,24 +478,24 @@ public class LifecycleManagerImpl implements LifecycleManager { long currentTime = TimeUtil.currentTimeMillis(); if (!objsCreated.isEmpty()) { for (RegistryObjectType obj : objsCreated) { - EventBus.publish(new InsertRegistryEvent(obj.getId(), obj + publisher.publish(new InsertRegistryEvent(obj.getId(), obj .getLid(), request.getUsername(), obj.getObjectType())); - EventBus.publish(new RegistryStatisticsEvent(obj + publisher.publish(new RegistryStatisticsEvent(obj .getObjectType(), obj.getStatus(), obj.getOwner(), avTimePerRecord)); } - EventBus.publish(new CreateAuditTrailEvent(request.getId(), + publisher.publish(new CreateAuditTrailEvent(request.getId(), request, ActionTypes.create, objsCreated, currentTime)); } if (!objsUpdated.isEmpty()) { for (RegistryObjectType obj : objsUpdated) { - EventBus.publish(new UpdateRegistryEvent(obj.getId(), obj + publisher.publish(new UpdateRegistryEvent(obj.getId(), obj .getLid(), request.getUsername(), obj.getObjectType())); - EventBus.publish(new RegistryStatisticsEvent(obj + publisher.publish(new RegistryStatisticsEvent(obj .getObjectType(), obj.getStatus(), obj.getOwner(), avTimePerRecord)); } - EventBus.publish(new CreateAuditTrailEvent(request.getId(), + publisher.publish(new CreateAuditTrailEvent(request.getId(), request, ActionTypes.update, objsUpdated, currentTime)); } @@ -746,7 +750,7 @@ public class LifecycleManagerImpl implements LifecycleManager { mergeObjects(updatedObject, objToUpdate); } if (!objectsToUpdate.isEmpty()) { - EventBus.publish(new CreateAuditTrailEvent(request.getId(), + publisher.publish(new CreateAuditTrailEvent(request.getId(), request, ActionTypes.update, objectsToUpdate, TimeUtil .currentTimeMillis())); } @@ -762,7 +766,7 @@ public class LifecycleManagerImpl implements LifecycleManager { RegistryObjectType existingObject) { DeleteSlotEvent deleteSlotEvent = new DeleteSlotEvent(existingObject.getSlot()); registryObjectDao.merge(newObject, existingObject); - EventBus.publish(deleteSlotEvent); + publisher.publish(deleteSlotEvent); } private RegistryObjectType applyUpdates(RegistryObjectType objectToUpdate, @@ -858,5 +862,5 @@ public class LifecycleManagerImpl implements LifecycleManager { public void setXpathProcessor(RegistryXPathProcessor xpathProcessor) { this.xpathProcessor = xpathProcessor; } - + }