juddi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ks...@apache.org
Subject svn commit: r1127255 - in /juddi/trunk: juddi-core/src/main/java/org/apache/juddi/subscription/ juddi-core/src/main/java/org/apache/juddi/subscription/notify/ uddi-tck-base/src/main/resources/uddi_data/subscriptionnotifier/ uddi-tck/src/test/java/org/a...
Date Tue, 24 May 2011 20:12:44 GMT
Author: kstam
Date: Tue May 24 20:12:43 2011
New Revision: 1127255

URL: http://svn.apache.org/viewvc?rev=1127255&view=rev
Log:
JUDDI-423 Making sure we only notify once on an asynchronous subscription. Now also supporting
endPoint types.

Added:
    juddi/trunk/uddi-tck-base/src/main/resources/uddi_data/subscriptionnotifier/subscription2.xml
Modified:
    juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java
    juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/notify/HTTPNotifier.java
    juddi/trunk/uddi-tck/src/test/java/org/apache/juddi/v3/tck/UDDI_090_SubscriptionListenerIntegrationTest.java

Modified: juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java?rev=1127255&r1=1127254&r2=1127255&view=diff
==============================================================================
--- juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java
(original)
+++ juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/SubscriptionNotifier.java
Tue May 24 20:12:43 2011
@@ -121,10 +121,13 @@ public class SubscriptionNotifier extend
 			
 			Collection<Subscription> subscriptions = getAllAsyncSubscriptions();
 			for (Subscription subscription : subscriptions) {
-				//expireCache after subscription.getExpiresAfter().getTime()
+				
 				if (subscription.getExpiresAfter()==null || subscription.getExpiresAfter().getTime()
> startTime) {
 					try {
-						GetSubscriptionResults getSubscriptionResults = buildGetSubscriptionResults(subscription,
new Date(scheduledExecutionTime()));
+						//build a query with a coverage period from the lastNotified time to 
+						//now (the scheduled Execution time)
+						GetSubscriptionResults getSubscriptionResults = 
+							buildGetSubscriptionResults(subscription, new Date(scheduledExecutionTime()));
 						if (getSubscriptionResults!=null) {
 							getSubscriptionResults.setSubscriptionKey(subscription.getSubscriptionKey());
 							UddiEntityPublisher publisher = new UddiEntityPublisher();
@@ -139,6 +142,11 @@ public class SubscriptionNotifier extend
 						log.error("Could not obtain subscriptionResult for subscriptionKey " 
 								+ subscription.getSubscriptionKey() + ". " + e.getMessage(),e);
 					}	
+				} else {
+					// the subscription expired, we should delete it
+					log.info("Subcription with key " + subscription.getSubscriptionKey() 
+							+ " expired " + subscription.getExpiresAfter());
+					deleteSubscription(subscription);
 				}
 			}
             long endTime   = System.currentTimeMillis();
@@ -152,7 +160,7 @@ public class SubscriptionNotifier extend
 		} else {
 			log.debug("Skipping current notification cycle because lagtime is too great.");
 		}
-	}
+ 	}
 	/**
 	 * Checks to see that the event are fired on time. If they are late this may indicate that
the server
 	 * is under load. The acceptableLagTime is configurable using the "juddi.notification.acceptable.lagtime"
@@ -167,7 +175,7 @@ public class SubscriptionNotifier extend
 		if (lagTime <= acceptableLagTime || acceptableLagTime < 0) {
 			return true;
 		} else {
-			log.warn("NotificationTimer is lagging " + lagTime + " milli seconds behind. A lag time
"
+			log.debug("NotificationTimer is lagging " + lagTime + " milli seconds behind. A lag time
"
 					+ "which exceeds an acceptable lagtime of " + acceptableLagTime + "ms indicates "
 					+ "that the registry server is under load or was in sleep mode. We are therefore skipping
this notification "
 					+ "cycle.");
@@ -184,7 +192,9 @@ public class SubscriptionNotifier extend
 		if (startPoint==null) startPoint = subscription.getCreateDate();
 		nextDesiredNotificationDate = new Date(startPoint.getTime());
 		duration.addTo(nextDesiredNotificationDate);
-
+		//nextDesiredNotificationDate = lastTime + the Interval Duration, which should be:
+		//AFTER the lastNotified time and BEFORE the endTime (current time). If it is
+		//after the endTime, then the user does not want a notification yet, so we accumulate.
 		if (subscription.getLastNotified()==null || nextDesiredNotificationDate.after(startPoint)
&& nextDesiredNotificationDate.before(endPoint)) {
 			getSubscriptionResults = new GetSubscriptionResults();
 			CoveragePeriod period = new CoveragePeriod();
@@ -234,34 +244,39 @@ public class SubscriptionNotifier extend
 	    return subscriptions;
 	}
 	/**
+	 * Deletes the subscription. i.e. when it is expired.
+	 * @param subscription
+	 */
+	protected void deleteSubscription(Subscription subscription) {
+		EntityManager em = PersistenceManager.getEntityManager();
+		EntityTransaction tx = em.getTransaction();
+		try {
+			tx.begin();
+			em.remove(subscription);
+		    tx.commit();
+		} finally {
+			if (tx.isActive()) {
+				tx.rollback();
+			}
+			em.close();
+		}
+	}
+	/**
 	 * Sends out the notifications.
 	 * @param resultList
 	 * @throws MalformedURLException 
 	 * @throws DispositionReportFaultMessage 
 	 */
-	protected synchronized void notify(GetSubscriptionResults getSubscriptionResults, SubscriptionResultsList
resultList) 
+	protected void notify(GetSubscriptionResults getSubscriptionResults, SubscriptionResultsList
resultList) 
 	{
 		EntityManager em = PersistenceManager.getEntityManager();
 		EntityTransaction tx = em.getTransaction();
 		try {
 			
-			org.apache.juddi.model.Subscription modelSubscription = em.find(org.apache.juddi.model.Subscription.class,
resultList.getSubscription().getSubscriptionKey());
-			//log.debug("Taking out a write lock on this subscription, and bail if we can't get it
since that would mean" 
-			// + " another jUDDI instance is in the process of sending out the notification.");
-			//em.lock(modelSubscription, LockModeType.WRITE);
+			org.apache.juddi.model.Subscription modelSubscription = 
+				em.find(org.apache.juddi.model.Subscription.class, resultList.getSubscription().getSubscriptionKey());
 			Date notificationDate = new Date();
-			Date startPoint = resultList.getCoveragePeriod().getStartPoint().toGregorianCalendar().getTime();
-			Date endPoint   = resultList.getCoveragePeriod().getEndPoint().toGregorianCalendar().getTime();
-			
-			
-			if (modelSubscription.getLastNotified()!=null 
-					&& startPoint.before(modelSubscription.getLastNotified()) 
-					&& endPoint.after(modelSubscription.getLastNotified())) {
-				 log.info("We already send out a notification within this coverage period, no need to
send another one.");
-				 return;
-			}
-			
-			//now log to the db that we completed sending the notification.
+			//now log to the db that we are sending the notification.
 			tx.begin();
 			modelSubscription.setLastNotified(notificationDate);
 			em.persist(modelSubscription);
@@ -269,10 +284,10 @@ public class SubscriptionNotifier extend
 			
 			org.apache.juddi.model.BindingTemplate bindingTemplate= em.find(org.apache.juddi.model.BindingTemplate.class,
modelSubscription.getBindingKey());
 			NotifySubscriptionListener body = new NotifySubscriptionListener();
-			if (resultList.getServiceList()!=null && resultList.getServiceList().getServiceInfos()!=null
&&
-					resultList.getServiceList().getServiceInfos().getServiceInfo().size() == 0) {
-				resultList.getServiceList().setServiceInfos(null);
-			}
+//			if (resultList.getServiceList()!=null && resultList.getServiceList().getServiceInfos()!=null
&&
+//					resultList.getServiceList().getServiceInfos().getServiceInfo().size() == 0) {
+//				resultList.getServiceList().setServiceInfos(null);
+//			}
 			body.setSubscriptionResultsList(resultList);
 			String authorizedName = modelSubscription.getAuthorizedName();
 			UDDISecurityImpl security = new UDDISecurityImpl();

Modified: juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/notify/HTTPNotifier.java
URL: http://svn.apache.org/viewvc/juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/notify/HTTPNotifier.java?rev=1127255&r1=1127254&r2=1127255&view=diff
==============================================================================
--- juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/notify/HTTPNotifier.java
(original)
+++ juddi/trunk/juddi-core/src/main/java/org/apache/juddi/subscription/notify/HTTPNotifier.java
Tue May 24 20:12:43 2011
@@ -21,7 +21,7 @@ import org.uddi.v3_service.UDDISubscript
 public class HTTPNotifier implements Notifier {
 	
 	private static String SUBR_V3_NAMESPACE = "urn:uddi-org:v3_service";
-	private static String SUBSCRIPTION_LISTENER_SERVICE = "UDDI_SubscriptionListener_Port";
+	private static String SUBSCRIPTION_LISTENER_SERVICE = "UDDISubscriptionListenerImplPort";
 	
 	Log log = LogFactory.getLog(this.getClass());
 	UDDISubscriptionListenerPortType subscriptionListenerPort = null;
@@ -34,7 +34,7 @@ public class HTTPNotifier implements Not
 					" should start with 'http' or 'https'");
 		}
 		if (AccessPointType.WSDL_DEPLOYMENT.toString().equalsIgnoreCase(bindingTemplate.getAccessPointType()))
{
-			//WSDL deployment types
+			//WSDL deployment type
 			//TODO, let user override the SUBSCRIPTION_LISTENER_SERVICE setting
 			QName qName = new QName(SUBR_V3_NAMESPACE, SUBSCRIPTION_LISTENER_SERVICE);
 			Service service = Service.create(new URL(bindingTemplate.getAccessPointUrl()), qName);

Added: juddi/trunk/uddi-tck-base/src/main/resources/uddi_data/subscriptionnotifier/subscription2.xml
URL: http://svn.apache.org/viewvc/juddi/trunk/uddi-tck-base/src/main/resources/uddi_data/subscriptionnotifier/subscription2.xml?rev=1127255&view=auto
==============================================================================
--- juddi/trunk/uddi-tck-base/src/main/resources/uddi_data/subscriptionnotifier/subscription2.xml
(added)
+++ juddi/trunk/uddi-tck-base/src/main/resources/uddi_data/subscriptionnotifier/subscription2.xml
Tue May 24 20:12:43 2011
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * Copyright 2001-2009 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.
+ *
+ */
+-->
+<subscription xmlns="urn:uddi-org:sub_v3">
+  <subscriptionKey>uddi:uddi.joepublisher.com:subscriptionone</subscriptionKey>
+  <subscriptionFilter>
+    <find_business xmlns="urn:uddi-org:api_v3" xmlns:xml="http://www.w3.org/XML/1998/namespace">
+      <findQualifiers>
+        <findQualifier>exactMatch</findQualifier>
+      </findQualifiers>
+      <name xml:lang="en">Listener One</name>
+    </find_business>
+  </subscriptionFilter>
+  <bindingKey xmlns="urn:uddi-org:api_v3">uddi:uddi.joepublisher.com:bindinglistener</bindingKey>
+  <notificationInterval>P5D</notificationInterval>
+  <maxEntities>1000</maxEntities>
+</subscription>

Modified: juddi/trunk/uddi-tck/src/test/java/org/apache/juddi/v3/tck/UDDI_090_SubscriptionListenerIntegrationTest.java
URL: http://svn.apache.org/viewvc/juddi/trunk/uddi-tck/src/test/java/org/apache/juddi/v3/tck/UDDI_090_SubscriptionListenerIntegrationTest.java?rev=1127255&r1=1127254&r2=1127255&view=diff
==============================================================================
--- juddi/trunk/uddi-tck/src/test/java/org/apache/juddi/v3/tck/UDDI_090_SubscriptionListenerIntegrationTest.java
(original)
+++ juddi/trunk/uddi-tck/src/test/java/org/apache/juddi/v3/tck/UDDI_090_SubscriptionListenerIntegrationTest.java
Tue May 24 20:12:43 2011
@@ -89,7 +89,7 @@ public class UDDI_090_SubscriptionListen
 	}
 	
 	@Test
-	public void joePublisher() {
+	public void joePublisherUpdateService() {
 		try {
 			tckTModel.saveJoePublisherTmodel(authInfoJoe);
 			tckBusiness.saveJoePublisherBusiness(authInfoJoe);
@@ -101,8 +101,7 @@ public class UDDI_090_SubscriptionListen
             //Changing the service we subscribed to "JoePublisherService"
 			Thread.sleep(1000);
 			logger.info("Updating Service ********** ");
-			tckBusinessService.updateJoePublisherService(authInfoJoe, "foo" + new Date());
-			//tckSubscriptionListener.changeSubscribedObject(authInfoJoe);
+			tckBusinessService.updateJoePublisherService(authInfoJoe, "foo");
 			
             //waiting up to 100 seconds for the listener to notice the change.
 			String test="";
@@ -134,6 +133,51 @@ public class UDDI_090_SubscriptionListen
 				tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
 				tckTModel.deleteJoePublisherTmodel(authInfoJoe);
 		}
+	}
+	
+	@Test
+	public void joePublisherUpdateBusiness() {
+		try {
+			tckTModel.saveJoePublisherTmodel(authInfoJoe);
+			tckBusiness.saveJoePublisherBusiness(authInfoJoe);
+			tckBusinessService.saveJoePublisherService(authInfoJoe);
+			//Saving the Listener Service
+			tckSubscriptionListener.saveService(authInfoJoe);
+			//Saving the Subscription
+			tckSubscriptionListener.saveNotifierSubscription(authInfoJoe);
+            //Changing the service we subscribed to "JoePublisherService"
+			Thread.sleep(1000);
+			logger.info("Deleting Business ********** ");
+			tckBusiness.deleteJoePublisherBusiness(authInfoJoe);
+			
+            //waiting up to 100 seconds for the listener to notice the change.
+			String test="";
+			for (int i=0; i<200; i++) {
+				Thread.sleep(500);
+				System.out.print(".");
+				if (UDDISubscriptionListenerImpl.notificationCount > 0) {
+					logger.info("Received Notification");
+					break;
+				} else {
+					System.out.print(test);
+				}
+			}
+			if (UDDISubscriptionListenerImpl.notificationCount == 0) {
+				Assert.fail("No Notification was sent");
+			}
+			if (!UDDISubscriptionListenerImpl.notifcationMap.get(0).contains("<name xml:lang=\"en\">Service
One</name>")) {
+				Assert.fail("Notification does not contain the correct service");
+			}
+			
+		} catch (Exception e) {
+			logger.error("No exceptions please.");
+			e.printStackTrace();
+
+			Assert.fail();
+		} finally {
+				tckSubscriptionListener.deleteNotifierSubscription(authInfoJoe);
+				tckTModel.deleteJoePublisherTmodel(authInfoJoe);
+		}
 	}	
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@juddi.apache.org
For additional commands, e-mail: commits-help@juddi.apache.org


Mime
View raw message