From dfc0d6d9f5f8313c8f8b9fb2c45cfa3bcb21b5ba Mon Sep 17 00:00:00 2001 From: Dave Hladky Date: Mon, 20 Jan 2014 16:48:58 -0600 Subject: [PATCH] Issue #2398 Fixed scheduling outside of active period/ expired window Change-Id: I6a07a597e84351d02cb1a0da29f796d86af28107 Former-commit-id: d5e3fdf7bd51177d24312d9daa6af7a2a4920f06 --- .../registry/RecurringSubscription.java | 27 +++++++++ .../bandwidth/EdexBandwidthManager.java | 56 ++++++++++++------- 2 files changed, 62 insertions(+), 21 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/RecurringSubscription.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/RecurringSubscription.java index 62e2fb2dfb..5283c360fd 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/RecurringSubscription.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/RecurringSubscription.java @@ -65,6 +65,7 @@ import com.raytheon.uf.common.time.util.TimeUtil; * Nov 14, 2013 2548 mpduff Add a subscription type slot. * Jan 08, 2014 2615 bgonzale Implement calculate start and calculate end methods. * Jan 14, 2014 2459 mpduff Add subscription state. + * Jan 20, 2013 2398 dhladky Fixed rescheduling beyond active period/expired window. * * * @@ -897,6 +898,19 @@ public abstract class RecurringSubscription return expired; } + + /** + * Check for expiration on date + * @param date + * @return + */ + private boolean isExpired(Date date) { + boolean expired = false; + if (subscriptionEnd != null && date.after(subscriptionEnd)) { + expired = true; + } + return expired; + } /** * Get the current subscription status. @@ -935,6 +949,19 @@ public abstract class RecurringSubscription return subscriptionState == SubscriptionState.ON && !checkAndSetExpiration(); } + + /** + * Should this be scheduled for this time. + * @param checkDate + * @return + */ + public boolean shouldScheduleForTime(Date checkDate) { + if (!isExpired(checkDate) && inWindow(checkDate)) { + return true; + } + + return false; + } private boolean inWindow(Date checkDate) { if (activePeriodStart == null && activePeriodEnd == null) { diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java index 3d28404308..c2f6bca0ef 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/EdexBandwidthManager.java @@ -49,6 +49,7 @@ import com.raytheon.uf.common.datadelivery.registry.DataSetMetaData; import com.raytheon.uf.common.datadelivery.registry.GriddedDataSetMetaData; import com.raytheon.uf.common.datadelivery.registry.PointDataSetMetaData; import com.raytheon.uf.common.datadelivery.registry.PointTime; +import com.raytheon.uf.common.datadelivery.registry.RecurringSubscription; import com.raytheon.uf.common.datadelivery.registry.SiteSubscription; import com.raytheon.uf.common.datadelivery.registry.Subscription; import com.raytheon.uf.common.datadelivery.registry.Time; @@ -112,7 +113,8 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * notifications. Republish dataset metadata registry * insert and update events as dataset metadata events. * Jan 13, 2014 2679 dhladky Small Point data updates. - * Jan 14, 2014 2692 dhladky AdhocSubscription handler + * Jan 14, 2014 2692 dhladky AdhocSubscription handler + * Jan 20, 2013 2398 dhladky Fixed rescheduling beyond active period/expired window. * * * @@ -306,28 +308,40 @@ public abstract class EdexBandwidthManager for (int day = 1; day <= days; day++) { next.add(Calendar.DAY_OF_YEAR, 1); - // Since subscriptions are based on cycles in a day, add one day - // to the - // completed BandwidthSubscription to get the next days - // retrieval. - // Now check if that BandwidthSubscription has already been - // scheduled. - BandwidthSubscription a = bandwidthDao - .getBandwidthSubscription(dao.getRegistryId(), next); - if (a == null) { - // Create the new BandwidthSubscription record with the next - // time.. - a = bandwidthDao.newBandwidthSubscription(subscription, - next); + // TODO Check if we need to set sub to "OFF" state and save to + // registry + if (((RecurringSubscription) subscription) + .shouldScheduleForTime(next.getTime())) { - schedule(subscription, a); - } else { - statusHandler - .info("Subscription [" - + subscription.getName() - + "] has already been scheduled for baseReferenceTime [" - + BandwidthUtil.format(next) + "]"); + // Since subscriptions are based on cycles in a day, add + // one + // day + // to the + // completed BandwidthSubscription to get the next days + // retrieval. + + // Now check if that BandwidthSubscription has already + // been + // scheduled. + BandwidthSubscription a = bandwidthDao + .getBandwidthSubscription(dao.getRegistryId(), next); + if (a == null) { + // Create the new BandwidthSubscription record with + // the + // next + // time.. + a = bandwidthDao.newBandwidthSubscription(subscription, + next); + + schedule(subscription, a); + } else { + statusHandler + .info("Subscription [" + + subscription.getName() + + "] has already been scheduled for baseReferenceTime [" + + BandwidthUtil.format(next) + "]"); + } } } }