[vlma-devel] commit: Give scores to adapters. (Adrien Grand )

git version control git at videolan.org
Wed Feb 4 02:03:13 CET 2009


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Wed Feb  4 01:57:24 2009 +0100| [6e3d196691a05538841056ec7be772ac9e052b89] | committer: Adrien Grand 

Give scores to adapters.

The score of an adapter should reflect the probability it has to work,
so as to be able to assign an adapter which is knwon to work to
high priority channels.

> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=6e3d196691a05538841056ec7be772ac9e052b89
---

 .../main/java/org/videolan/vlma/model/Adapter.java |   39 ++++++++++++++++++++
 .../java/org/videolan/vlma/dao/VLMaDaoImpl.java    |    1 +
 .../vlma/order/management/OrderComputer.java       |    8 ++++
 .../vlma/order/management/OrderManager.java        |    6 +++
 4 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/vlma-api/src/main/java/org/videolan/vlma/model/Adapter.java b/vlma-api/src/main/java/org/videolan/vlma/model/Adapter.java
index c5295db..a34185f 100644
--- a/vlma-api/src/main/java/org/videolan/vlma/model/Adapter.java
+++ b/vlma-api/src/main/java/org/videolan/vlma/model/Adapter.java
@@ -37,6 +37,13 @@ public abstract class Adapter implements Serializable {
 
     private Server server;
 
+    /**
+     * The score of an adapter can be understood as the probability this adapter
+     * has to work. An adapter with a high score is proven to work whereas an
+     * adapter with a low score probably doesn't.
+     */
+    private volatile transient int score;
+
     public Adapter() {
         name = "";
         setUp(true);
@@ -107,6 +114,15 @@ public abstract class Adapter implements Serializable {
     }
 
     /**
+     * Returns the adapter's score.
+     *
+     * @return the score
+     */
+    public int getScore() {
+        return score;
+    }
+
+    /**
      * Returns the state of the adapter (up or not).
      *
      * @return the state of the adapter (true if up, false otherwise)
@@ -160,6 +176,29 @@ public abstract class Adapter implements Serializable {
     }
 
     /**
+     * Sets the adapter's score.
+     *
+     * @param score the score to set
+     */
+    public void setScore(int score) {
+        this.score = score;
+    }
+
+    /**
+     * Increments the adapter's score.
+     */
+    public void incrementScore() {
+        ++this.score;
+    }
+
+    /**
+     * Decrements the adapter's score.
+     */
+    public void decrementScore() {
+        --this.score;
+    }
+
+    /**
      * Capacity of the adapter: how many orders can reference this adapter.
      *
      * @return the capacity of the adapter
diff --git a/vlma-core/src/main/java/org/videolan/vlma/dao/VLMaDaoImpl.java b/vlma-core/src/main/java/org/videolan/vlma/dao/VLMaDaoImpl.java
index 7442726..0e4387e 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/dao/VLMaDaoImpl.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/dao/VLMaDaoImpl.java
@@ -384,6 +384,7 @@ public class VLMaDaoImpl implements VLMaDao {
                 for(Server server : servers.values()) {
                     for(Adapter adapter : server.getAdapters()) {
                         adapter.setUp(true);
+                        adapter.setScore(0);
                     }
                 }
             }
diff --git a/vlma-core/src/main/java/org/videolan/vlma/order/management/OrderComputer.java b/vlma-core/src/main/java/org/videolan/vlma/order/management/OrderComputer.java
index 05bfd40..35f3974 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/order/management/OrderComputer.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/order/management/OrderComputer.java
@@ -228,9 +228,17 @@ public class OrderComputer {
         return family instanceof AdapterFamily.Sat || family instanceof AdapterFamily.DTT;
     }
 
+    static Comparator<Adapter> higherScoreFirst = new Comparator<Adapter>() {
+        public int compare(Adapter a0, Adapter a1) {
+            return a1.getScore() - a0.getScore();
+        }
+    };
+
     private void computeOrdersAvailableAdapters(List<ProgramGroup> groups, List<Adapter> adapters, SortedSet<Order> orders, final Map<Server, Integer> load) {
         // Handle groups with higher priority first
         Collections.sort(groups);
+        // Give adapters with the highest score to groups with the highest score
+        Collections.sort(adapters, higherScoreFirst);
         Iterator<ProgramGroup> groupIt = groups.iterator();
         Iterator<Adapter> adapterIt = adapters.iterator();
         while(groupIt.hasNext() && adapterIt.hasNext()) {
diff --git a/vlma-core/src/main/java/org/videolan/vlma/order/management/OrderManager.java b/vlma-core/src/main/java/org/videolan/vlma/order/management/OrderManager.java
index df782cf..524acd4 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/order/management/OrderManager.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/order/management/OrderManager.java
@@ -86,6 +86,12 @@ public class OrderManager {
                 }
             }
             entry.getValue().setValue(broadcasted ? State.STARTED : State.TO_START);
+            // Update the adapter's score
+            if (broadcasted) {
+                entry.getValue().getKey().getAdapter().incrementScore();
+            } else {
+                entry.getValue().getKey().getAdapter().decrementScore();
+            }
         }
         return result;
     }



More information about the vlma-devel mailing list