[vlma-devel] commit: Fix parallelization when sending orders. (Adrien Grand )

git version control git at videolan.org
Sun Sep 7 22:32:33 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sun Sep  7 22:29:33 2008 +0200| [e959a9d4d5dcab6933058859eee95131fee0fed2] | committer: Adrien Grand 

Fix parallelization when sending orders.

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

 .../main/java/org/videolan/vlma/OrderGiver.java    |   37 +++++++++++++------
 .../videolan/vlma/order/OrderSenderDispatcher.java |    1 -
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java b/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java
index 1aa8643..30006a0 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java
@@ -305,17 +305,24 @@ public class OrderGiver {
                 newOrders.removeAll(orders);
                 if (logger.isDebugEnabled())
                     logger.debug(newOrders.size() + " new orders to send");
-                List<Thread> sendThreads = new ArrayList<Thread>();
+                Map<Server, SendOrder> sendThreads = new HashMap<Server, SendOrder>();
                 for (Order order : newOrders) {
                     for(Media media : order.getMedias()) {
                         media.getProgram().setPlayer(order.getAdapter().getServer().getIp());
                     }
-                    Thread sendThread = new SendOrder(order);
-                    sendThreads.add(sendThread);
-                    sendThread.start();
+                    SendOrder sendThread = sendThreads.get(order.getAdapter().getServer());
+                    if(sendThread == null) {
+                        sendThread = new SendOrder();
+                        sendThreads.put(order.getAdapter().getServer(), sendThread);
+                    }
+                    sendThread.addOrder(order);
+                }
+                // Start threads, one per server
+                for(Thread thread : sendThreads.values()) {
+                    thread.start();
                 }
                 // Wait for all threads to finish
-                for(Thread thread : sendThreads) {
+                for(Thread thread : sendThreads.values()) {
                     try {
                         thread.join();
                     } catch (InterruptedException e) { }
@@ -345,17 +352,23 @@ public class OrderGiver {
     }
 
     private class SendOrder extends Thread {
-        private Order order;
+        private List<Order> orders;
 
-        public SendOrder(Order order) {
-            this.order = order;
+        public SendOrder() {
+            orders = new ArrayList<Order>();
+        }
+
+        public void addOrder(Order order) {
+            this.orders.add(order);
         }
 
         public void run() {
-            try {
-                orderSender.start(order);
-            } catch (IOException e) {
-                logger.error("Error while trying to send an order to " + order.getAdapter().getServer(), e);
+            for(Order order : orders) {
+                try {
+                    orderSender.start(order);
+                } catch (IOException e) {
+                    logger.error("Error while trying to send an order to " + order.getAdapter().getServer(), e);
+                }
             }
         }
     }
diff --git a/vlma-core/src/main/java/org/videolan/vlma/order/OrderSenderDispatcher.java b/vlma-core/src/main/java/org/videolan/vlma/order/OrderSenderDispatcher.java
index a10c712..a3c4039 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/order/OrderSenderDispatcher.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/order/OrderSenderDispatcher.java
@@ -22,7 +22,6 @@ package org.videolan.vlma.order;
 
 import java.io.IOException;
 
-import org.apache.commons.configuration.Configuration;
 import org.apache.log4j.Logger;
 import org.videolan.vlma.exception.NoAvailableOrderSenderException;
 import org.videolan.vlma.model.FilesChannel;



More information about the vlma-devel mailing list