[vlma-devel] commit: Try to fix synchronization. (Adrien Grand )

git version control git at videolan.org
Sat Aug 2 18:53:24 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sat Aug  2 18:38:52 2008 +0200| [122060f3d810a9ba8f458dc9de9219d736b5e0dd] | committer: Adrien Grand 

Try to fix synchronization.

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

 .../src/main/java/org/videolan/vlma/IpBank.java    |    8 +++---
 .../java/org/videolan/vlma/OrderGiverImpl.java     |    2 +-
 .../java/org/videolan/vlma/VLMaServiceImpl.java    |   24 ++++++----------
 .../main/java/org/videolan/vlma/daemon/Daemon.java |    6 ++--
 .../java/org/videolan/vlma/order/OrderSender.java  |   28 ++++++++++---------
 5 files changed, 32 insertions(+), 36 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/IpBank.java b/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
index 0ed8379..76cf2df 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
@@ -55,7 +55,7 @@ public class IpBank {
      * @throws UnknownHostException
      *             address is invalid
      */
-    public void initIps() throws UnknownHostException {
+    synchronized public void initIps() throws UnknownHostException {
         Inet4Address min = (Inet4Address) InetAddress.getByName(configuration.getString("vlma.streaming.udp.ipbank.min"));
         Inet4Address max = (Inet4Address) InetAddress.getByName(configuration.getString("vlma.streaming.udp.ipbank.max"));
 
@@ -79,7 +79,7 @@ public class IpBank {
         }
     }
 
-    public boolean isUsed(InetAddress ip) {
+    synchronized public boolean isUsed(InetAddress ip) {
         return usedIps.containsKey(ip) && usedIps.get(ip);
     }
 
@@ -88,7 +88,7 @@ public class IpBank {
      *
      * @return the IP address
      */
-    public InetAddress getIp() {
+    synchronized public InetAddress getIp() {
         for (Map.Entry<InetAddress, Boolean> entry : usedIps.entrySet()) {
             if (!entry.getValue().booleanValue()) {
                 entry.setValue(Boolean.TRUE);
@@ -104,7 +104,7 @@ public class IpBank {
      *
      * @param ip
      */
-    public void releaseIp(InetAddress ip) {
+    synchronized public void releaseIp(InetAddress ip) {
         if (usedIps.containsKey(ip)) {
             usedIps.put(ip, Boolean.FALSE);
         } else {
diff --git a/vlma-core/src/main/java/org/videolan/vlma/OrderGiverImpl.java b/vlma-core/src/main/java/org/videolan/vlma/OrderGiverImpl.java
index 49b9669..4fe02f9 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/OrderGiverImpl.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/OrderGiverImpl.java
@@ -76,7 +76,7 @@ public class OrderGiverImpl implements OrderGiver {
      * @return true only and only if the object is computing the orders. ordres
      */
     public boolean isComputing() {
-        return (computingThread != null) && (computingThread.isAlive());
+        return (computingThread != null && computingThread.isAlive());
     }
 
     /**
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 912fd91..4ed5150 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/VLMaServiceImpl.java
@@ -206,7 +206,7 @@ public class VLMaServiceImpl implements VLMaService {
         return s.getCoverages();
     }
 
-    public void removeSatellite(int satellite)
+    synchronized public void removeSatellite(int satellite)
       throws SatelliteDoesNotExistException {
         Satellite s = getSatellite(satellite);
         satellites.remove(s);
@@ -373,7 +373,7 @@ public class VLMaServiceImpl implements VLMaService {
         throw new MediaDoesNotExistException("Media " + media + " doesn't exist");
     }
 
-    public String getUrlOfProgram(Program program) {
+    synchronized public String getUrlOfProgram(Program program) {
         if (program != null) {
             if (program.getStreamingStrategy().getProtocol().equals(StreamingStrategy.Protocol.HTTP)) {
                 return "http://" + program.getPlayer().getHostAddress() + ":" + configuration.getInt("vlma.streaming.http.port") + "/" + program.hashCode();
@@ -641,7 +641,9 @@ public class VLMaServiceImpl implements VLMaService {
 
     public void sendNotification(String message) {
         for (Notifier notifier : notifiers) {
-            notifier.sendNotification(message);
+            synchronized (notifier) {
+                notifier.sendNotification(message);
+            }
         }
     }
 
@@ -694,15 +696,7 @@ public class VLMaServiceImpl implements VLMaService {
         }
     }
 
-    public void setServers(List<Server> servers) {
-        this.servers = servers;
-    }
-
-    public void setMedias(List<Media> medias) {
-        this.medias = medias;
-    }
-
-    public void sortMedias()
+    synchronized public void sortMedias()
     {
         Collections.sort(medias);
     }
@@ -762,7 +756,7 @@ public class VLMaServiceImpl implements VLMaService {
         return rrdR.getPath();
     }
 
-    public void updateSnmpData(Server server) {
+    synchronized public void updateSnmpData(Server server) {
         String rrdFile;
         try {
             rrdFile = createRrdFileIfNecessary(server);
@@ -818,7 +812,7 @@ public class VLMaServiceImpl implements VLMaService {
         }
     }
 
-    public void updateRrdGraph(Server server) {
+    synchronized public void updateRrdGraph(Server server) {
         RrdGraph rrdGraph;
         long startTime, endTime = Util.getTime();
         startTime = endTime - 3600 * 24;
@@ -866,7 +860,7 @@ public class VLMaServiceImpl implements VLMaService {
         }
     }
 
-    public boolean checkVLC(Server server) {
+    synchronized public boolean checkVLC(Server server) {
         boolean formerState = server.isUp();
         try {
             Socket socket = new Socket(server.getIp(), configuration.getInt("vlc.telnet.port"));
diff --git a/vlma-core/src/main/java/org/videolan/vlma/daemon/Daemon.java b/vlma-core/src/main/java/org/videolan/vlma/daemon/Daemon.java
index 9f93b9f..857a18f 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/daemon/Daemon.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/daemon/Daemon.java
@@ -92,7 +92,7 @@ public class Daemon {
     /**
      * Starts the daemon.
      */
-    public void start() {
+    synchronized public void start() {
 
         // First, load data from disk
         vlmaService.loadFromDisk();
@@ -116,11 +116,11 @@ public class Daemon {
         }
     }
 
-    public void reload() {
+    synchronized public void reload() {
         vlmaService.loadFromDisk();
     }
 
-    public void stop() {
+    synchronized public void stop() {
 
         // Destroy the RMI exporter
         try {
diff --git a/vlma-core/src/main/java/org/videolan/vlma/order/OrderSender.java b/vlma-core/src/main/java/org/videolan/vlma/order/OrderSender.java
index b329dfb..07f38bf 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/order/OrderSender.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/order/OrderSender.java
@@ -98,21 +98,23 @@ public abstract class OrderSender {
      * @throws IOException Operation aborted.
      */
     protected void telnetCommand(String command, Adapter adapter) throws IOException {
-        logger.debug("Send command " + command + " to " + adapter.getServer().getName());
-        telnetOut.println(command);
-        int d = configuration.getInt("vlc.telnet.delay");
-        while (!telnetIn.ready() && (d -= DEFAULT_TELNET_WAIT) > 0) {
-            try {
-                Thread.sleep(DEFAULT_TELNET_WAIT);
-            } catch (InterruptedException e) {
+        synchronized (adapter.getServer()) {
+            logger.debug("Send command " + command + " to " + adapter.getServer().getName());
+            telnetOut.println(command);
+            int d = configuration.getInt("vlc.telnet.delay");
+            while (!telnetIn.ready() && (d -= DEFAULT_TELNET_WAIT) > 0) {
+                try {
+                    Thread.sleep(DEFAULT_TELNET_WAIT);
+                } catch (InterruptedException e) {
+                }
             }
+            StringBuffer response = new StringBuffer();
+            while (telnetIn.ready()) {
+                response.append((char) telnetIn.read());
+            }
+            commandLogger.add(adapter.getServer(), command, response.toString());
+            logger.debug("Command result: " + response);
         }
-        StringBuffer response = new StringBuffer();
-        while (telnetIn.ready()) {
-            response.append((char) telnetIn.read());
-        }
-        commandLogger.add(adapter.getServer(), command, response.toString());
-        logger.debug("Command result: " + response);
     }
 
     /**



More information about the vlma-devel mailing list