You are viewing a plain text version of this content. The canonical link for it is here.
Posted to muse-commits@ws.apache.org by da...@apache.org on 2006/08/18 17:52:58 UTC
svn commit: r432622 - in
/webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl:
AbstractAdvertisement.java BroadcastAdvertisement.java
ServiceGroupEntryAdvertisement.java SimpleAdvertisement.java
Author: danj
Date: Fri Aug 18 08:52:56 2006
New Revision: 432622
URL: http://svn.apache.org/viewvc?rev=432622&view=rev
Log:
Fix for MUSE-64, using code submitted to JIRA by Joel H. I modified the original SimpleAdvertisement a bit
so that it could be an abstract class reused by the different adveritsement types. The concrete advertisement
classes just provide the logic to determine whether or not a given resource meets their "filter" for creating
a notification.
Added:
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/AbstractAdvertisement.java
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/BroadcastAdvertisement.java
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/ServiceGroupEntryAdvertisement.java
Modified:
webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java
Added: webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/AbstractAdvertisement.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/AbstractAdvertisement.java?rev=432622&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/AbstractAdvertisement.java (added)
+++ webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/AbstractAdvertisement.java Fri Aug 18 08:52:56 2006
@@ -0,0 +1,179 @@
+/*=============================================================================*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.ws.dm.muws.adv.impl;
+
+import javax.xml.namespace.QName;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.AbstractCapability;
+import org.apache.muse.core.Environment;
+import org.apache.muse.core.Resource;
+import org.apache.muse.core.ResourceManager;
+import org.apache.muse.core.ResourceManagerListener;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.dm.muws.MuwsConstants;
+import org.apache.muse.ws.dm.muws.adv.Advertisement;
+import org.apache.muse.ws.dm.muws.events.Component;
+import org.apache.muse.ws.dm.muws.events.ComponentAddress;
+import org.apache.muse.ws.dm.muws.events.ManagementEvent;
+import org.apache.muse.ws.dm.muws.events.Situation;
+import org.apache.muse.ws.dm.muws.events.WefFactory;
+import org.apache.muse.ws.dm.muws.events.WefConstants;
+import org.apache.muse.ws.dm.muws.events.impl.SimpleWefFactory;
+import org.apache.muse.ws.notification.NotificationProducer;
+import org.apache.muse.ws.notification.WsnConstants;
+import org.apache.muse.ws.notification.impl.TopicFilter;
+
+/**
+ *
+ * @author Dan Jemiolo (danj)
+ *
+ */
+
+public abstract class AbstractAdvertisement
+ extends AbstractCapability implements Advertisement, ResourceManagerListener
+{
+ private static final String _CONSUMER_EPR_PARAM = "initial-consumer-reference";
+
+ protected WefFactory createWefFactory()
+ {
+ return new SimpleWefFactory();
+ }
+
+ public void initializeCompleted()
+ throws SoapFault
+ {
+ super.initializeCompleted();
+
+ Resource resource = getResource();
+
+ //
+ // this allows the advertisement capability to hear about
+ // all resource lifecycle events that happen in the application
+ //
+ ResourceManager manager = resource.getResourceManager();
+ manager.addListener(this);
+
+ //
+ // initialize the advertisement topics
+ //
+ NotificationProducer wsn =
+ (NotificationProducer)resource.getCapability(WsnConstants.PRODUCER_URI);
+
+ wsn.addTopic(MuwsConstants.ADV_ME_CREATION_TOPIC);
+ wsn.addTopic(MuwsConstants.ADV_ME_DESTRUCTION_TOPIC);
+
+ //
+ // create subscriptions for all event consumer that are going to
+ // receive notifications from the above topics
+ //
+ subscribeInitialConsumer();
+ }
+
+ protected abstract boolean isAdvertised(EndpointReference epr);
+
+ public void resourceAdded(EndpointReference epr, Resource resource)
+ throws SoapFault
+ {
+ if (!isAdvertised(epr))
+ return;
+
+ Element payload = XmlUtils.createElement(MuwsConstants.MANAGEABILITY_EPR_QNAME, epr.toXML());
+ sendMessage(epr, MuwsConstants.ADV_ME_CREATION_TOPIC, WefConstants.CREATE_SITUATION_QNAME, payload);
+ }
+
+ public void resourceRemoved(EndpointReference epr)
+ throws SoapFault
+ {
+ if (!isAdvertised(epr))
+ return;
+
+ Element payload = XmlUtils.createElement(MuwsConstants.DESTROY_NOTIFICATION_QNAME);
+ sendMessage(epr, MuwsConstants.ADV_ME_DESTRUCTION_TOPIC, WefConstants.DESTROY_SITUATION_QNAME, payload);
+
+ Resource advertiser = getResource();
+
+ if (advertiser.hasBeenShutdown())
+ advertiser.getResourceManager().removeListener(this);
+ }
+
+ protected void sendMessage(EndpointReference sourceEPR,
+ QName topicName,
+ QName situationCategory,
+ Element payload)
+ throws SoapFault
+ {
+ Resource advertiser = getResource();
+
+ WefFactory factory = createWefFactory();
+ ManagementEvent event = factory.createEvent();
+
+ event.addExtendedElement(payload);
+
+ Component source = factory.createComponent();
+ source.setName(WefConstants.SOURCE_COMP_QNAME);
+
+ ComponentAddress address = factory.createComponentAddress(sourceEPR);
+ source.setAddress(address);
+
+ event.setSource(source);
+
+ Component reporter = factory.createComponent();
+ reporter.setName(WefConstants.REPORTER_COMP_QNAME);
+
+ address = factory.createComponentAddress(advertiser.getEndpointReference());
+ reporter.setAddress(address);
+
+ event.setReporter(reporter);
+
+ Situation situation = factory.createSituation();
+ situation.setCategoryType(situationCategory);
+ event.setSituation(situation);
+
+ NotificationProducer wsn = (NotificationProducer)advertiser.getCapability(WsnConstants.PRODUCER_URI);
+ wsn.publish(topicName, event.toXML());
+ }
+
+ protected void subscribeInitialConsumer()
+ throws SoapFault
+ {
+ String fileName = getInitializationParameter(_CONSUMER_EPR_PARAM);
+
+ //
+ // pre-existing consumer is optional - other consumers can
+ // still subscribe using WS-N
+ //
+ if (fileName != null)
+ {
+ Environment env = getResource().getEnvironment();
+ Document eprDoc = env.getDocument(fileName);
+ Element eprXML = XmlUtils.getFirstElement(eprDoc);
+
+ EndpointReference epr = new EndpointReference(eprXML);
+
+ NotificationProducer wsn =
+ (NotificationProducer)getResource().getCapability(WsnConstants.PRODUCER_URI);
+
+ wsn.subscribe(epr, new TopicFilter(MuwsConstants.ADV_ME_CREATION_TOPIC), null, null);
+ wsn.subscribe(epr, new TopicFilter(MuwsConstants.ADV_ME_DESTRUCTION_TOPIC), null, null);
+ }
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/BroadcastAdvertisement.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/BroadcastAdvertisement.java?rev=432622&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/BroadcastAdvertisement.java (added)
+++ webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/BroadcastAdvertisement.java Fri Aug 18 08:52:56 2006
@@ -0,0 +1,34 @@
+/*=============================================================================*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.ws.dm.muws.adv.impl;
+
+import org.apache.muse.ws.addressing.EndpointReference;
+
+/**
+ *
+ * @author Dan Jemiolo (danj)
+ * @author Joel Hawkins
+ *
+ */
+
+public class BroadcastAdvertisement extends AbstractAdvertisement
+{
+ protected boolean isAdvertised(EndpointReference epr)
+ {
+ return true;
+ }
+}
Added: webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/ServiceGroupEntryAdvertisement.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/ServiceGroupEntryAdvertisement.java?rev=432622&view=auto
==============================================================================
--- webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/ServiceGroupEntryAdvertisement.java (added)
+++ webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/ServiceGroupEntryAdvertisement.java Fri Aug 18 08:52:56 2006
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * =============================================================================
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ * =============================================================================
+ */
+
+package org.apache.muse.ws.dm.muws.adv.impl;
+
+import org.w3c.dom.Element;
+
+import org.apache.muse.core.Resource;
+import org.apache.muse.util.xml.XmlUtils;
+import org.apache.muse.ws.addressing.EndpointReference;
+import org.apache.muse.ws.addressing.soap.SoapFault;
+import org.apache.muse.ws.dm.muws.MuwsConstants;
+import org.apache.muse.ws.dm.muws.events.WefConstants;
+import org.apache.muse.ws.resource.sg.Entry;
+import org.apache.muse.ws.resource.sg.ServiceGroup;
+import org.apache.muse.ws.resource.sg.WssgConstants;
+
+/**
+ *
+ * @author Dan Jemiolo (danj)
+ * @author Joel Hawkins
+ *
+ */
+
+public class ServiceGroupEntryAdvertisement extends SimpleAdvertisement
+{
+ public void resourceAdded(EndpointReference epr, Resource resource) throws SoapFault
+ {
+ Entry entry = (Entry)resource.getCapability(WssgConstants.ENTRY_URI);
+
+ //
+ // resource is not a service group entry
+ //
+ if (entry == null)
+ return;
+
+ //
+ // if the resource the service group that owns the entry, send a message
+ //
+ if (isAdvertised(entry.getServiceGroupEPR()))
+ {
+ Element payload = XmlUtils.createElement(MuwsConstants.MANAGEABILITY_EPR_QNAME, epr.toXML());
+ sendMessage(epr, MuwsConstants.ADV_ME_CREATION_TOPIC, WefConstants.CREATE_SITUATION_QNAME, payload);
+ }
+ }
+
+ public void resourceRemoved(EndpointReference epr) throws SoapFault
+ {
+ ServiceGroup serviceGroup = (ServiceGroup)getResource().getCapability(WssgConstants.SERVICE_GROUP_URI);
+
+ //
+ // resource may be a SG, but its not necessarily the SG that owns
+ // the entry resource
+ //
+ if (serviceGroup.getEntry(epr) != null)
+ {
+ Element payload = XmlUtils.createElement(MuwsConstants.DESTROY_NOTIFICATION_QNAME);
+ sendMessage(epr, MuwsConstants.ADV_ME_DESTRUCTION_TOPIC, WefConstants.DESTROY_SITUATION_QNAME, payload);
+ }
+ }
+}
Modified: webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java
URL: http://svn.apache.org/viewvc/webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java?rev=432622&r1=432621&r2=432622&view=diff
==============================================================================
--- webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java (original)
+++ webservices/muse/trunk/modules/muse-wsdm-muws-adv-impl/src/org/apache/muse/ws/dm/muws/adv/impl/SimpleAdvertisement.java Fri Aug 18 08:52:56 2006
@@ -1,171 +1,34 @@
-/*=============================================================================*
- * Copyright 2006 The Apache Software Foundation
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *=============================================================================*/
-
-package org.apache.muse.ws.dm.muws.adv.impl;
-
-import javax.xml.namespace.QName;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import org.apache.muse.core.AbstractCapability;
-import org.apache.muse.core.Environment;
-import org.apache.muse.core.Resource;
-import org.apache.muse.core.ResourceManager;
-import org.apache.muse.core.ResourceManagerListener;
-import org.apache.muse.util.xml.XmlUtils;
-import org.apache.muse.ws.addressing.EndpointReference;
-import org.apache.muse.ws.addressing.soap.SoapFault;
-import org.apache.muse.ws.dm.muws.MuwsConstants;
-import org.apache.muse.ws.dm.muws.adv.Advertisement;
-import org.apache.muse.ws.dm.muws.events.Component;
-import org.apache.muse.ws.dm.muws.events.ComponentAddress;
-import org.apache.muse.ws.dm.muws.events.ManagementEvent;
-import org.apache.muse.ws.dm.muws.events.Situation;
-import org.apache.muse.ws.dm.muws.events.WefFactory;
-import org.apache.muse.ws.dm.muws.events.WefConstants;
-import org.apache.muse.ws.dm.muws.events.impl.SimpleWefFactory;
-import org.apache.muse.ws.notification.NotificationProducer;
-import org.apache.muse.ws.notification.WsnConstants;
-import org.apache.muse.ws.notification.impl.TopicFilter;
-
-/**
- *
- * @author Dan Jemiolo (danj)
- *
- */
-
-public class SimpleAdvertisement
- extends AbstractCapability implements Advertisement, ResourceManagerListener
-{
- private static final String _CONSUMER_EPR_PARAM = "initial-consumer-reference";
-
- protected WefFactory createWefFactory()
- {
- return new SimpleWefFactory();
- }
-
- public void initializeCompleted()
- throws SoapFault
- {
- super.initializeCompleted();
-
- Resource resource = getResource();
-
- //
- // this allows the advertisement capability to hear about
- // all resource lifecycle events that happen in the touchpoint
- //
- ResourceManager manager = resource.getResourceManager();
- manager.addListener(this);
-
- //
- // initialize the advertisement topics
- //
- NotificationProducer wsn =
- (NotificationProducer)resource.getCapability(WsnConstants.PRODUCER_URI);
-
- wsn.addTopic(MuwsConstants.ADV_ME_CREATION_TOPIC);
- wsn.addTopic(MuwsConstants.ADV_ME_DESTRUCTION_TOPIC);
-
- //
- // create subscriptions for all event consumer that are going to
- // receive notifications from the above topics
- //
- subscribeInitialConsumer();
- }
-
- public void resourceAdded(EndpointReference epr, Resource resource)
- throws SoapFault
- {
- Element payload = XmlUtils.createElement(MuwsConstants.MANAGEABILITY_EPR_QNAME, epr.toXML());
- sendMessage(epr, MuwsConstants.ADV_ME_CREATION_TOPIC, MuwsConstants.CREATE_NOTIFICATION_QNAME, payload);
- }
-
- public void resourceRemoved(EndpointReference epr)
- throws SoapFault
- {
- Element payload = XmlUtils.createElement(MuwsConstants.DESTROY_NOTIFICATION_QNAME);
- sendMessage(epr, MuwsConstants.ADV_ME_DESTRUCTION_TOPIC, WefConstants.DESTROY_SITUATION_QNAME, payload);
-
- Resource advertiser = getResource();
-
- if (advertiser.hasBeenShutdown())
- advertiser.getResourceManager().removeListener(this);
- }
-
- protected void sendMessage(EndpointReference sourceEPR,
- QName topicName,
- QName situationCategory,
- Element payload)
- throws SoapFault
- {
- Resource advertiser = getResource();
-
- WefFactory factory = createWefFactory();
- ManagementEvent event = factory.createEvent();
-
- event.addExtendedElement(payload);
-
- Component source = factory.createComponent();
- source.setName(WefConstants.SOURCE_COMP_QNAME);
-
- ComponentAddress address = factory.createComponentAddress(sourceEPR);
- source.setAddress(address);
-
- event.setSource(source);
-
- Component reporter = factory.createComponent();
- reporter.setName(WefConstants.REPORTER_COMP_QNAME);
-
- address = factory.createComponentAddress(advertiser.getEndpointReference());
- reporter.setAddress(address);
-
- event.setReporter(reporter);
-
- Situation situation = factory.createSituation();
- situation.setCategoryType(situationCategory);
- event.setSituation(situation);
-
- NotificationProducer wsn = (NotificationProducer)advertiser.getCapability(WsnConstants.PRODUCER_URI);
- wsn.publish(topicName, event.toXML());
- }
-
- protected void subscribeInitialConsumer()
- throws SoapFault
- {
- String fileName = getInitializationParameter(_CONSUMER_EPR_PARAM);
-
- //
- // pre-existing consumer is optional - other consumers can
- // still subscribe using WS-N
- //
- if (fileName != null)
- {
- Environment env = getResource().getEnvironment();
- Document eprDoc = env.getDocument(fileName);
- Element eprXML = XmlUtils.getFirstElement(eprDoc);
-
- EndpointReference epr = new EndpointReference(eprXML);
-
- NotificationProducer wsn =
- (NotificationProducer)getResource().getCapability(WsnConstants.PRODUCER_URI);
-
- wsn.subscribe(epr, new TopicFilter(MuwsConstants.ADV_ME_CREATION_TOPIC), null, null);
- wsn.subscribe(epr, new TopicFilter(MuwsConstants.ADV_ME_DESTRUCTION_TOPIC), null, null);
- }
- }
-}
+/*=============================================================================*
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *=============================================================================*/
+
+package org.apache.muse.ws.dm.muws.adv.impl;
+
+import org.apache.muse.ws.addressing.EndpointReference;
+
+/**
+ *
+ * @author Dan Jemiolo (danj)
+ * @author Joel Hawkins
+ *
+ */
+
+public class SimpleAdvertisement extends AbstractAdvertisement
+{
+ protected boolean isAdvertised(EndpointReference epr)
+ {
+ return getResource().getEndpointReference().equals(epr);
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: muse-commits-unsubscribe@ws.apache.org
For additional commands, e-mail: muse-commits-help@ws.apache.org