river-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sijs...@apache.org
Subject svn commit: r1400681 - in /river/jtsk/trunk/src/org/apache/river/config: LocalHostLookup.java LocalHostLookupProvider.java
Date Sun, 21 Oct 2012 17:21:36 GMT
Author: sijskes
Date: Sun Oct 21 17:21:36 2012
New Revision: 1400681

URL: http://svn.apache.org/viewvc?rev=1400681&view=rev
Log:
RIVER-413

Added:
    river/jtsk/trunk/src/org/apache/river/config/LocalHostLookupProvider.java
Modified:
    river/jtsk/trunk/src/org/apache/river/config/LocalHostLookup.java

Modified: river/jtsk/trunk/src/org/apache/river/config/LocalHostLookup.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/org/apache/river/config/LocalHostLookup.java?rev=1400681&r1=1400680&r2=1400681&view=diff
==============================================================================
--- river/jtsk/trunk/src/org/apache/river/config/LocalHostLookup.java (original)
+++ river/jtsk/trunk/src/org/apache/river/config/LocalHostLookup.java Sun Oct 21 17:21:36
2012
@@ -20,6 +20,7 @@ package org.apache.river.config;
 
 import java.net.InetAddress;
 import java.net.UnknownHostException;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 import org.apache.river.common.Beta;
 
@@ -29,31 +30,51 @@ import org.apache.river.common.Beta;
 public class LocalHostLookup
 {
     private final static Logger logger = Logger.getLogger(LocalHostLookup.class.getName());
+    
+    private static LocalHostLookupProvider provider;
 
     public static InetAddress getLocalHost() throws UnknownHostException
     {
-        return InetAddress.getLocalHost();
+        return getProvider().getLocalHost();
     }
 
+    private static synchronized LocalHostLookupProvider getProvider()
+    {
+        if( provider == null ) {
+            setProvider( new DefaultLocalHostLookupProvider() );
+        }
+        return provider ;
+    }
 
-//    private static InetAddress localHost ;
-//
-//    public static InetAddress getLocalHost() throws UnknownHostException
-//    {
-//        if( localHost == null ) {
-//            setLocalHost( InetAddress.getLocalHost() );
-//        }
-//        return localHost ;
-//    }
-//
-//    private static void setLocalHost(InetAddress localHost)
-//    {
-//        if( localHost.isLoopbackAddress() ) {
-//            logger.warning( "local host is loopback" );
-//        }
-//        LocalHostLookup.localHost = localHost ;
-//    }
+    public static synchronized void setProvider(LocalHostLookupProvider prvdr )
+    {
+        if( LocalHostLookup.provider != null ) {
+            throw new RuntimeException( "provider already set" );
+        }
+        
+        LocalHostLookup.provider = prvdr ;
+
+        try {
+            if (getLocalHost().isLoopbackAddress()) {
+                logger.warning("local host is loopback");
+            }
+        } catch (UnknownHostException ex) {
+            logger.log(Level.WARNING,"",ex);
+        }
+    }
 
+    static class DefaultLocalHostLookupProvider 
+        implements LocalHostLookupProvider
+    {
+
+        @Override
+        public InetAddress getLocalHost() throws UnknownHostException
+        {
+            return InetAddress.getLocalHost();
+        }
+        
+    }
+    
     private LocalHostLookup()
     {
     }

Added: river/jtsk/trunk/src/org/apache/river/config/LocalHostLookupProvider.java
URL: http://svn.apache.org/viewvc/river/jtsk/trunk/src/org/apache/river/config/LocalHostLookupProvider.java?rev=1400681&view=auto
==============================================================================
--- river/jtsk/trunk/src/org/apache/river/config/LocalHostLookupProvider.java (added)
+++ river/jtsk/trunk/src/org/apache/river/config/LocalHostLookupProvider.java Sun Oct 21 17:21:36
2012
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.river.config;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import org.apache.river.common.Beta;
+
+/**
+ */
+@Beta
+public interface LocalHostLookupProvider
+{
+    public InetAddress getLocalHost() throws UnknownHostException ;    
+}



Mime
View raw message