From 49d2b31fab4ef9e7dbec35db49eb1c64f664450d Mon Sep 17 00:00:00 2001 From: Dave Hladky Date: Wed, 2 Apr 2014 13:48:54 -0500 Subject: [PATCH] Issue #2810 Added comparator to BandwidthAllocations Change-Id: I4320d1d5b00bdf69c0969a349ae249090a389b85 Former-commit-id: fb642de1095bce1aa84b8641784754b965b8a190 [formerly f36998ca1d3bf606bb34cc8747fb17620ee78681] Former-commit-id: 78bae7e97ba01e2b3eaf637c4321bd1c63b641f1 --- .../registry/RecurringSubscription.java | 12 +++++++++- .../datadelivery/registry/Subscription.java | 13 +++++++++-- .../bandwidth/BandwidthManager.java | 12 +++++++--- .../bandwidth/dao/BandwidthAllocation.java | 23 +++++++++---------- .../retrieval/PriorityRetrievalScheduler.java | 10 ++++---- .../bandwidth/retrieval/RetrievalManager.java | 8 ++++++- 6 files changed, 53 insertions(+), 25 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 eb38210751..a931bd840c 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 @@ -70,6 +70,7 @@ import com.raytheon.uf.common.time.util.TimeUtil; * to check day of year. removed now unused active period methods. * Jan 28, 2014 2636 mpduff Changed to use GMT calendar. * Feb 12, 2014 2636 mpduff Return new instance of calculated start and end. + * Apr 02, 2014 2810 dhladky Priority sorting of subscriptions. * * * @@ -81,7 +82,7 @@ import com.raytheon.uf.common.time.util.TimeUtil; AdhocSubscription.class, SiteSubscription.class, SharedSubscription.class }) public abstract class RecurringSubscription - implements Serializable, Subscription { + implements Serializable, Subscription, Comparable> { private static final long serialVersionUID = -6422673887457060034L; @@ -1111,4 +1112,13 @@ public abstract class RecurringSubscription public boolean shouldUpdate() { return shouldUpdate; } + + @Override + public int compareTo(Subscription o) { + + SubscriptionPriority oPriority = o.getPriority(); + SubscriptionPriority myPriority = this.getPriority(); + + return myPriority.compareTo(oPriority); + } } \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/Subscription.java b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/Subscription.java index aafaf50254..04df1eca63 100644 --- a/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/Subscription.java +++ b/edexOsgi/com.raytheon.uf.common.datadelivery.registry/src/com/raytheon/uf/common/datadelivery/registry/Subscription.java @@ -49,6 +49,7 @@ import com.raytheon.uf.common.datadelivery.registry.Utils.SubscriptionStatus; * Jan 14, 2014 2459 mpduff Change Subscription status code * Jan 24, 2013 2709 bgonzale Added method inActivePeriodWindow. * Feb 05, 2014 2677 mpduff Add subscription state getter/setter. + * Apr 02, 2014 2810 dhladky Priority sorting of subscriptions. * * * @@ -56,7 +57,7 @@ import com.raytheon.uf.common.datadelivery.registry.Utils.SubscriptionStatus; * @version 1.0 */ -public interface Subscription { +public interface Subscription extends Comparable> { @XmlEnum public enum SubscriptionType { @@ -78,7 +79,15 @@ public interface Subscription { /** Enumeration to use for subscription priorities */ @XmlEnum - public static enum SubscriptionPriority { + public static enum SubscriptionPriority implements Comparable{ + + /* + These are in the order in which priorities would + appear for comparator purposes. BE SURE that + if you add any new state enum it is inserted in the order + you wish it to be in for logical ordering in comparison to others. + */ + /** High Priority */ @XmlEnumValue("High") HIGH("High", 1), diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java index 4ddca51a63..9a66c98561 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/BandwidthManager.java @@ -147,6 +147,7 @@ import com.raytheon.uf.edex.registry.ebxml.exception.EbxmlRegistryException; * of already scheduled BandwidthAllocations. * Feb 11, 2014 2771 bgonzale Added handler for GET_DATADELIVERY_ID request. * Feb 10, 2014 2636 mpduff Changed how retrieval plan is updated over time. + * Apr 02, 2014 2810 dhladky Priority sorting of subscriptions. * * * @@ -1132,13 +1133,18 @@ public abstract class BandwidthManager * @throws SerializationException */ protected Set scheduleSubscriptions( - List> subscriptions) + List> insubscriptions) throws SerializationException { + Set unscheduledSubscriptions = new TreeSet(); - Set unscheduledAllocations = new HashSet(); - Map subscriptionEventsMap = new HashMap(); + + // Order list by Subscription Priority + // We want highest priority subscriptions scheduled first. + List> subscriptions = new ArrayList>(insubscriptions.size()); + subscriptions.addAll(insubscriptions); + Collections.sort(subscriptions); for (Subscription subscription : subscriptions) { List unscheduled = subscriptionUpdated(subscription); diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthAllocation.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthAllocation.java index b10ba0b8d0..0d2de56c01 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthAllocation.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/dao/BandwidthAllocation.java @@ -42,6 +42,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Jun 24, 2013 2106 djohnson Add copy constructor. * Jul 11, 2013 2106 djohnson Use SubscriptionPriority enum. * Oct 30, 2013 2448 dhladky Moved methods to TimeUtil. + * Apr 02, 2014 2810 dhladky Priority sorting of allocations. * * * @@ -56,7 +57,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; @DynamicSerialize @SequenceGenerator(name = "BANDWIDTH_SEQ", sequenceName = "bandwidth_seq", allocationSize = 1, initialValue = 1) public class BandwidthAllocation implements IPersistableDataObject, - Serializable, IDeepCopyable { + Serializable, IDeepCopyable, Comparable { private static final long serialVersionUID = 743702044231376839L; @@ -337,17 +338,6 @@ public class BandwidthAllocation implements IPersistableDataObject, return sb.toString(); } - /** - * Check whether this allocation is higher priority than another. - * - * @param other - * the other - * @return true if this allocation is higher priority than the other one - */ - public boolean isHigherPriorityThan(BandwidthAllocation other) { - return this.getPriority().isHigherPriorityThan(other.getPriority()); - } - /** * @return */ @@ -356,4 +346,13 @@ public class BandwidthAllocation implements IPersistableDataObject, return new BandwidthAllocation(this); } + @Override + public int compareTo(BandwidthAllocation o) { + + SubscriptionPriority oPriority = o.priority; + SubscriptionPriority myPriority = this.priority; + + return myPriority.compareTo(oPriority); + } + } \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/PriorityRetrievalScheduler.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/PriorityRetrievalScheduler.java index fea640da4f..a4b4a767b5 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/PriorityRetrievalScheduler.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/PriorityRetrievalScheduler.java @@ -32,6 +32,7 @@ import com.raytheon.uf.edex.datadelivery.bandwidth.util.BandwidthUtil; * Jun 25, 2013 2106 djohnson Access bandwidth bucket contents through RetrievalPlan. * Dec 17, 2013 2636 bgonzale When adding to buckets, call the constrained method. * Feb 14, 2014 2636 mpduff Clean up logging. + * Apr 02, 2014 2810 dhladky Priority sorting of allocations. * * * @version 1.0 @@ -184,14 +185,11 @@ public class PriorityRetrievalScheduler implements IRetrievalScheduler { for (BandwidthAllocation o : plan .getBandwidthAllocationsForBucket(bucket)) { long estimatedSizeInBytes = o.getEstimatedSizeInBytes(); - // This was bad... we just about released giving lower - // priority requests the ability to unschedule higher priority - // requests.... - if (request.isHigherPriorityThan(o)) { + + if (request.compareTo(o) == 1) { total += estimatedSizeInBytes; lowerPriorityRequests.add(o); - } - + } // See if we have found enough room if (total >= estimatedSizeInBytes) { enoughBandwidth = true; diff --git a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalManager.java b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalManager.java index 7171a97d91..8dbfc15582 100644 --- a/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalManager.java +++ b/edexOsgi/com.raytheon.uf.edex.datadelivery.bandwidth/src/com/raytheon/uf/edex/datadelivery/bandwidth/retrieval/RetrievalManager.java @@ -9,6 +9,7 @@ import java.util.TreeMap; import com.google.common.eventbus.Subscribe; import com.raytheon.uf.common.datadelivery.registry.Network; +import com.raytheon.uf.common.datadelivery.registry.Subscription; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.time.util.TimeUtil; @@ -41,6 +42,7 @@ import com.raytheon.uf.edex.datadelivery.retrieval.RetrievalManagerNotifyEvent; * Oct 03, 2013 2267 bgonzale Added check for no retrieval plan matching in the proposed retrieval plans. * Jan 30, 2014 2686 dhladky refactor of retrieval. * Feb 10, 2014 2678 dhladky Prevent duplicate allocations. + * Apr 02, 2014 2810 dhladky Priority sorting of allocations. * * * @@ -87,8 +89,12 @@ public class RetrievalManager { * scheduled */ public List schedule( - List bandwidthAllocations) { + List inallocations) { List unscheduled = new ArrayList(); + // Arrange allocations in priority order + List bandwidthAllocations = new ArrayList(inallocations.size()); + bandwidthAllocations.addAll(inallocations); + Collections.sort(bandwidthAllocations); for (BandwidthAllocation bandwidthAllocation : bandwidthAllocations) { Network network = bandwidthAllocation.getNetwork();