[vlma-devel] commit: Send orders in separate threads. (Adrien Grand )
git version control
git at videolan.org
Sun Aug 24 01:34:44 CEST 2008
vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sun Aug 24 00:55:05 2008 +0200| [e38c500c9274e7d5a6eee0fce53ddaec562ef07a] | committer: Adrien Grand
Send orders in separate threads.
Since sending an order to a server takes at least 1s, this makes gain much
time to send them in parallel.
> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=e38c500c9274e7d5a6eee0fce53ddaec562ef07a
---
.../main/java/org/videolan/vlma/OrderGiver.java | 33 +++++++++++++++++---
1 files changed, 28 insertions(+), 5 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 955838c..1abffc1 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/OrderGiver.java
@@ -314,19 +314,25 @@ public class OrderGiver {
}
}
- // Send newly computed orders
+ // Send newly computed orders, each one in a separate thread
newOrders.removeAll(oldOrders);
if (logger.isDebugEnabled())
logger.debug(newOrders.size() + " new orders to send");
+ List<Thread> sendThreads = new ArrayList<Thread>();
for (Order order : newOrders) {
for(Media media : order.getMedias()) {
media.getProgram().setPlayer(order.getAdapter().getServer().getIp());
}
+ Runnable r = new SendOrder(order);
+ Thread sendThread = new Thread(r);
+ sendThreads.add(sendThread);
+ sendThread.start();
+ }
+ // Wait for all threads to finish
+ for(Thread thread : sendThreads) {
try {
- orderSender.start(order);
- } catch (IOException e) {
- logger.error("Error while trying to send an order to " + order.getAdapter().getServer(), e);
- }
+ thread.join();
+ } catch (InterruptedException e) { }
}
vlmaService.getOrders().removeAll(oldOrders);
@@ -347,4 +353,21 @@ public class OrderGiver {
computingThread.start();
}
}
+
+ private class SendOrder implements Runnable {
+
+ private Order order;
+
+ public SendOrder(Order order) {
+ this.order = 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);
+ }
+ }
+ }
}
More information about the vlma-devel
mailing list