[vlma-devel] commit: Ensure to cancel orders that have been sent and do not seem to be streamed . (Adrien Grand )
git version control
git at videolan.org
Sun Aug 24 22:37:55 CEST 2008
vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sun Aug 24 22:39:19 2008 +0200| [95fb3d55e5b56dbb99ced409567dba3b1bd1bfbe] | committer: Adrien Grand
Ensure to cancel orders that have been sent and do not seem to be streamed.
> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=95fb3d55e5b56dbb99ced409567dba3b1bd1bfbe
---
.../main/java/org/videolan/vlma/VLMaService.java | 14 ++++++++
.../java/org/videolan/vlma/VLMaServiceImpl.java | 17 +++++++++-
.../org/videolan/vlma/monitor/OrderMonitor.java | 33 ++++++++++++++++++++
vlma-daemon/src/main/resources/daemon.xml | 1 +
4 files changed, 64 insertions(+), 1 deletions(-)
diff --git a/vlma-core/src/main/java/org/videolan/vlma/VLMaService.java b/vlma-core/src/main/java/org/videolan/vlma/VLMaService.java
index 2575595..c349f31 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/VLMaService.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/VLMaService.java
@@ -59,6 +59,20 @@ public interface VLMaService {
Set<Order> getOrders();
/**
+ * Returns the orders to cancel.
+ *
+ * @return the orders to cancel
+ */
+ Set<Order> getOrdersToCancel();
+
+ /**
+ * Cancel an order.
+ *
+ * @param order the order to cancel
+ */
+ void cancelOrder(Order order);
+
+ /**
* @see org.videolan.vlma.Data#giveOrders()
*/
void giveOrders();
diff --git a/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java b/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
index 470b8e5..4df65df 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
@@ -63,6 +63,7 @@ public class VLMaServiceImpl implements VLMaService {
private static final Logger logger = Logger.getLogger(VLMaServiceImpl.class);
private Set<Order> orders = new HashSet<Order>();
+ private Set<Order> ordersToCancel = new HashSet<Order>();
private Configuration configuration;
private DataRetriever dataRetriever;
@@ -87,13 +88,27 @@ public class VLMaServiceImpl implements VLMaService {
public Set<Order> getOrders() {
- return orders;
+ synchronized (orders) {
+ return orders;
+ }
+ }
+
+ public Set<Order> getOrdersToCancel() {
+ synchronized (ordersToCancel) {
+ return ordersToCancel;
+ }
}
public void giveOrders() {
orderGiver.giveOrders();
}
+ public void cancelOrder(Order order) {
+ synchronized (ordersToCancel) {
+ ordersToCancel.add(order);
+ }
+ }
+
public void sendNotification(String message) {
for (Notifier notifier : notifiers) {
synchronized (notifier) {
diff --git a/vlma-core/src/main/java/org/videolan/vlma/monitor/OrderMonitor.java b/vlma-core/src/main/java/org/videolan/vlma/monitor/OrderMonitor.java
index 85f6ce0..6f935d8 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/monitor/OrderMonitor.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/monitor/OrderMonitor.java
@@ -20,8 +20,10 @@
package org.videolan.vlma.monitor;
+import java.io.IOException;
import java.util.List;
import java.util.Iterator;
+import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.configuration.Configuration;
@@ -31,6 +33,7 @@ import org.videolan.vlma.VLMaService;
import org.videolan.vlma.model.Order;
import org.videolan.vlma.model.media.Media;
import org.videolan.vlma.model.media.Program;
+import org.videolan.vlma.order.OrderSender;
import org.videolan.vlma.watcher.StreamWatcher;
/**
@@ -49,6 +52,8 @@ public class OrderMonitor implements Monitor {
private OrderGiver orderGiver;
+ private OrderSender orderSender;
+
private Thread orderMonitorThread;
private Thread orderMonitorDaemonThread;
@@ -92,6 +97,7 @@ public class OrderMonitor implements Monitor {
while (it.hasNext()) {
Order o = it.next();
if(o.getMedias().contains(media)) {
+ vlmaService.cancelOrder(o);
it.remove();
break;
}
@@ -125,6 +131,24 @@ public class OrderMonitor implements Monitor {
}
/*
+ * Cancel orders that have been given but do not seem to be streamed
+ */
+ Set<Order> ordersToCancel = vlmaService.getOrdersToCancel();
+ Iterator<Order> orderIt = ordersToCancel.iterator();
+ while (orderIt.hasNext()) {
+ Order order = orderIt.next();
+ try {
+ orderSender.stop(order);
+ synchronized (ordersToCancel) {
+ orderIt.remove();
+ }
+ logger.debug("Order " + order + " cancelled");
+ } catch (IOException e) {
+ // The order could not be stopped, so keep it in the set
+ }
+ }
+
+ /*
* Something is wrong ! Ask for a new computation.
*/
if (shouldCompute) {
@@ -198,6 +222,15 @@ public class OrderMonitor implements Monitor {
}
/**
+ * Sets the orderSender.
+ *
+ * @param orderSender the orderSender to set
+ */
+ public void setOrderSender(OrderSender orderSender) {
+ this.orderSender = orderSender;
+ }
+
+ /**
* Sets the streamWatcher.
*
* @param streamWatcher the streamWatcher to set
diff --git a/vlma-daemon/src/main/resources/daemon.xml b/vlma-daemon/src/main/resources/daemon.xml
index eb4a6b1..91b31c6 100644
--- a/vlma-daemon/src/main/resources/daemon.xml
+++ b/vlma-daemon/src/main/resources/daemon.xml
@@ -134,6 +134,7 @@
<property name="configuration" ref="configuration" />
<property name="vlmaService" ref="vlmaService" />
<property name="orderGiver" ref="orderGiver" />
+ <property name="orderSender" ref="orderSender" />
<property name="streamWatcher" ref="streamWatcher" />
</bean>
More information about the vlma-devel
mailing list