[vlma-devel] commit: Simplify management of the commands queue. (Adrien Grand )
git version control
git at videolan.org
Sun Apr 27 19:42:32 CEST 2008
vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sun Apr 27 19:13:17 2008 +0200| [f1ce42def61695622912d06bde2d3f7b0eda720b]
Simplify management of the commands queue.
> http://git.videolan.org/gitweb.cgi/vlma.git/?a=commit;h=f1ce42def61695622912d06bde2d3f7b0eda720b
---
.../java/org/videolan/vlma/common/IVlData.java | 3 +-
.../org/videolan/vlma/common/orders/VlCommand.java | 24 ++++++++++
.../org/videolan/vlma/common/orders/VlOrder.java | 2 +-
.../main/java/org/videolan/vlma/daemon/VLMad.java | 2 -
.../main/java/org/videolan/vlma/daemon/VlData.java | 8 +---
.../videolan/vlma/daemon/VlOrderMonitoring.java | 46 +------------------
6 files changed, 31 insertions(+), 54 deletions(-)
diff --git a/core/src/main/java/org/videolan/vlma/common/IVlData.java b/core/src/main/java/org/videolan/vlma/common/IVlData.java
index 43b3fab..e253dc9 100644
--- a/core/src/main/java/org/videolan/vlma/common/IVlData.java
+++ b/core/src/main/java/org/videolan/vlma/common/IVlData.java
@@ -25,7 +25,6 @@ import java.io.IOException;
import java.net.InetAddress;
import java.net.URL;
import java.util.HashMap;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
@@ -398,7 +397,7 @@ public interface IVlData {
*
* @return the list of commands sent to servers
*/
- public LinkedList<VlCommand> getCommands();
+ public List<VlCommand> getCommands();
// Sauvegarde et restauration des paramètres
/**
diff --git a/core/src/main/java/org/videolan/vlma/common/orders/VlCommand.java b/core/src/main/java/org/videolan/vlma/common/orders/VlCommand.java
index 9bec7e8..8d03f51 100644
--- a/core/src/main/java/org/videolan/vlma/common/orders/VlCommand.java
+++ b/core/src/main/java/org/videolan/vlma/common/orders/VlCommand.java
@@ -22,11 +22,20 @@ package org.videolan.vlma.common.orders;
import java.io.Serializable;
import java.util.Date;
+import java.util.LinkedList;
+import java.util.List;
import org.videolan.vlma.common.VlServer;
public class VlCommand implements Serializable {
+ /**
+ * Max size allowed for the command list.
+ */
+ private static final int COMMANDS_SIZE = 500;
+
+ private static LinkedList<VlCommand> commands = new LinkedList<VlCommand>();
+
private Date date;
private VlServer server;
private String command;
@@ -43,6 +52,21 @@ public class VlCommand implements Serializable {
this.response = response;
}
+ public static void add(VlCommand command) {
+ commands.addFirst(command);
+ if (commands.size() > COMMANDS_SIZE) {
+ commands.removeLast();
+ }
+ }
+
+ public static void add(VlServer server, String command, String response) {
+ VlCommand.add(new VlCommand(server, command, response));
+ }
+
+ public static List<VlCommand> getCommands() {
+ return commands;
+ }
+
public String getCommand() {
return command;
}
diff --git a/core/src/main/java/org/videolan/vlma/common/orders/VlOrder.java b/core/src/main/java/org/videolan/vlma/common/orders/VlOrder.java
index ecef478..f183ea1 100644
--- a/core/src/main/java/org/videolan/vlma/common/orders/VlOrder.java
+++ b/core/src/main/java/org/videolan/vlma/common/orders/VlOrder.java
@@ -207,7 +207,7 @@ public class VlOrder {
while (telnetIn.ready()) {
response += (char) telnetIn.read();
}
- commands.addFirst(new VlCommand(server, command, response));
+ VlCommand.add(server, command, response);
logger.log(Level.DEBUG, "Command result: " + response);
}
diff --git a/daemon/src/main/java/org/videolan/vlma/daemon/VLMad.java b/daemon/src/main/java/org/videolan/vlma/daemon/VLMad.java
index 38b89c9..d3ca92f 100644
--- a/daemon/src/main/java/org/videolan/vlma/daemon/VLMad.java
+++ b/daemon/src/main/java/org/videolan/vlma/daemon/VLMad.java
@@ -72,7 +72,5 @@ public class VLMad {
data.startServerMonitoringDaemon();
logger.log(Level.DEBUG, "Launching the thread which monitores streaming.");
data.startOrderMonitoringDaemon();
- logger.log(Level.DEBUG, "Launching the thread which cleans the command list.");
- data.startCommandCleanerDaemon();
}
}
diff --git a/daemon/src/main/java/org/videolan/vlma/daemon/VlData.java b/daemon/src/main/java/org/videolan/vlma/daemon/VlData.java
index 8a2aa39..1951de2 100644
--- a/daemon/src/main/java/org/videolan/vlma/daemon/VlData.java
+++ b/daemon/src/main/java/org/videolan/vlma/daemon/VlData.java
@@ -587,8 +587,8 @@ public class VlData implements IVlData {
return orderGiver;
}
- public LinkedList<VlCommand> getCommands() {
- return VlOrder.getCommands();
+ public List<VlCommand> getCommands() {
+ return VlCommand.getCommands();
}
synchronized public void saveToDisk() throws FileNotFoundException,
@@ -694,10 +694,6 @@ public class VlData implements IVlData {
orderMonitoring.startOrderMonitoringThread();
}
- public void startCommandCleanerDaemon() {
- orderMonitoring.startCommandCleanerDaemon();
- }
-
public void startCheckAllVLCs() {
serverMonitoring.startCheckVLCThread();
}
diff --git a/daemon/src/main/java/org/videolan/vlma/daemon/VlOrderMonitoring.java b/daemon/src/main/java/org/videolan/vlma/daemon/VlOrderMonitoring.java
index 3554f2b..69767a2 100644
--- a/daemon/src/main/java/org/videolan/vlma/daemon/VlOrderMonitoring.java
+++ b/daemon/src/main/java/org/videolan/vlma/daemon/VlOrderMonitoring.java
@@ -49,20 +49,14 @@ public class VlOrderMonitoring {
private Thread orderMonitorThread;
private Thread orderMonitorDaemonThread;
-
- private Thread commandsCleanerDaemonThread;
-
+
public boolean isMonitoring() {
return (orderMonitorThread != null) && (orderMonitorThread.isAlive());
};
-
+
public boolean isDaemonMonitoring() {
return (orderMonitorDaemonThread != null) && (orderMonitorDaemonThread.isAlive());
};
-
- public boolean isCommandsCleaning() {
- return (commandsCleanerDaemonThread != null) && (commandsCleanerDaemonThread.isAlive());
- };
/**
* The constructor need a data interface which he will monitore the orders.
@@ -80,17 +74,7 @@ public class VlOrderMonitoring {
* Time interval between two RRD interrogations.
*/
private static final int RRD_INTERVAL = 60;
-
- /**
- * Time interval between two commands cleanings.
- */
- private static final int COMMANDS_INTERVAL = 600;
-
- /**
- * Max size allowed for the command list.
- */
- private static final int COMMANDS_SIZE = 500;
-
+
/**
* The object which will give the multicast streams list.
*/
@@ -202,30 +186,6 @@ public class VlOrderMonitoring {
}
}
-
- private Runnable commandCleanerDaemon = new Runnable() {
- public void run() {
- while(true) {
- VlOrder.cleanCommands(COMMANDS_SIZE);
- try {
- Thread.sleep(1000 * (COMMANDS_INTERVAL - (Util.getTime() % COMMANDS_INTERVAL)));
- } catch (InterruptedException e) {
- // Do nothing
- logger.debug(e.getStackTrace());
- }
- }
- }
- };
-
-
- public synchronized void startCommandCleanerDaemon() {
- if (!isCommandsCleaning()) {
- commandsCleanerDaemonThread = new Thread(commandCleanerDaemon);
- commandsCleanerDaemonThread.setName("commandsCleanerDaemonThread");
- commandsCleanerDaemonThread.start();
- }
- }
-
public void setStreamWatcher(IVlStreamWatcher streamWatcher) {
this.streamWatcher = streamWatcher;
More information about the vlma-devel
mailing list