[vlma-devel] commit: Throw an exception when no free IP can be found. (Adrien Grand )

git version control git at videolan.org
Sat Sep 20 13:34:37 CEST 2008


vlma | branch: master | Adrien Grand <jpountz at videolan.org> | Sat Sep 20 13:37:04 2008 +0200| [73174402db9f360223ae52371fcebe8a679c117a] | committer: Adrien Grand 

Throw an exception when no free IP can be found.

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

 .../src/main/java/org/videolan/vlma/DataImpl.java  |    3 +--
 .../src/main/java/org/videolan/vlma/IpBank.java    |    9 ++++-----
 2 files changed, 5 insertions(+), 7 deletions(-)

diff --git a/vlma-core/src/main/java/org/videolan/vlma/DataImpl.java b/vlma-core/src/main/java/org/videolan/vlma/DataImpl.java
index 0788e43..7c93995 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/DataImpl.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/DataImpl.java
@@ -21,7 +21,6 @@
 package org.videolan.vlma;
 
 import java.io.IOException;
-
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashSet;
@@ -42,6 +41,7 @@ import org.htmlparser.util.ParserException;
 import org.videolan.vlma.daemon.Daemon;
 import org.videolan.vlma.dao.VLMaDao;
 import org.videolan.vlma.model.Command;
+import org.videolan.vlma.model.DTTChannel;
 import org.videolan.vlma.model.FilesChannel;
 import org.videolan.vlma.model.Media;
 import org.videolan.vlma.model.Program;
@@ -50,7 +50,6 @@ import org.videolan.vlma.model.Satellite;
 import org.videolan.vlma.model.Server;
 import org.videolan.vlma.model.StreamChannel;
 import org.videolan.vlma.model.StreamingStrategy;
-import org.videolan.vlma.model.DTTChannel;
 import org.videolan.vlma.order.CommandLogger;
 
 /**
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 3bed857..31a5a63 100644
--- a/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
+++ b/vlma-core/src/main/java/org/videolan/vlma/IpBank.java
@@ -27,8 +27,8 @@ import java.util.HashMap;
 import java.util.Map;
 
 import org.apache.commons.configuration.Configuration;
-import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
+import org.videolan.vlma.exception.NotFoundException;
 import org.videolan.vlma.model.Media;
 import org.videolan.vlma.model.Program;
 import org.videolan.vlma.model.StreamingStrategy;
@@ -71,8 +71,7 @@ public class IpBank {
             if (p == null || !p.getStreamingStrategy().getProtocol().equals(StreamingStrategy.Protocol.UDP_MULTICAST)) {
                 continue;
             }
-            logger.log(Level.DEBUG, "The media " + m.getName()
-                    + " has a program");
+            logger.debug("The media " + m.getName() + " has a program");
             if (usedIps.containsKey(p.getIp())) {
                 usedIps.put(p.getIp(), Boolean.TRUE);
             }
@@ -95,8 +94,7 @@ public class IpBank {
                 return entry.getKey();
             }
         }
-        logger.error("No free IP found.");
-        return null;
+        throw new NotFoundException("No free IP found in the IP bank");
     }
 
     /**
@@ -105,6 +103,7 @@ public class IpBank {
      * @param ip
      */
     synchronized public void releaseIp(InetAddress ip) {
+        if(ip == null) return;
         if (usedIps.containsKey(ip)) {
             usedIps.put(ip, Boolean.FALSE);
         } else {



More information about the vlma-devel mailing list