You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2013/04/23 17:05:12 UTC

svn commit: r1470997 - in /karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud: Activator.java BlobStoreDiscoveryService.java BlobStoreDiscoveryServiceFactory.java ServiceContainer.java

Author: jbonofre
Date: Tue Apr 23 15:05:11 2013
New Revision: 1470997

URL: http://svn.apache.org/r1470997
Log:
Code cleanup

Modified:
    karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/Activator.java
    karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java
    karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryServiceFactory.java
    karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/ServiceContainer.java

Modified: karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/Activator.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/Activator.java?rev=1470997&r1=1470996&r2=1470997&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/Activator.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/Activator.java Tue Apr 23 15:05:11 2013
@@ -20,8 +20,12 @@ import org.osgi.service.cm.ManagedServic
 
 import java.util.Hashtable;
 
+/**
+ * Cloud bundle activator.
+ */
 public class Activator implements BundleActivator {
 
+    @Override
     public void start(BundleContext context) throws Exception {
         Hashtable<String, Object> properties = new Hashtable<String, Object>();
         properties.put(Constants.SERVICE_PID, "org.apache.karaf.cellar.cloud");
@@ -29,7 +33,9 @@ public class Activator implements Bundle
         context.registerService(ManagedServiceFactory.class.getName(), blobStoreDiscoveryServiceFactory, properties);
     }
 
+    @Override
     public void stop(BundleContext context) throws Exception {
+        // nothing to do
     }
 
 }
\ No newline at end of file

Modified: karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java?rev=1470997&r1=1470996&r2=1470997&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryService.java Tue Apr 23 15:05:11 2013
@@ -37,6 +37,9 @@ import java.util.HashSet;
 import java.util.Map;
 import java.util.Set;
 
+/**
+ * Discovery service that use a cloud blob store.
+ */
 public class BlobStoreDiscoveryService implements DiscoveryService {
 
     private static final transient Logger LOGGER = LoggerFactory.getLogger(BlobStoreDiscoveryService.class);
@@ -51,9 +54,6 @@ public class BlobStoreDiscoveryService i
     BlobStoreContext context;
     private BlobStore blobStore;
 
-    /**
-     * Constructor
-     */
     public BlobStoreDiscoveryService() {
         LOGGER.debug("CELLAR CLOUD: blob store discovery service initialized");
     }
@@ -82,10 +82,11 @@ public class BlobStoreDiscoveryService i
     }
 
     /**
-     * Returns a {@link Set} of Ips.
+     * Return a {@link Set} of IPs.
      *
-     * @return
+     * @return a set of IPs.
      */
+    @Override
     public Set<String> discoverMembers() {
 
         refresh();
@@ -94,7 +95,7 @@ public class BlobStoreDiscoveryService i
         ListContainerOptions opt = new ListContainerOptions();
 
         PageSet<? extends StorageMetadata> pageSet = blobStore.list(container, opt);
-        LOGGER.debug("CELLAR CLOUD: storage contains a pageset of size {}", pageSet.size());
+        LOGGER.debug("CELLAR CLOUD: storage contains a page set of size {}", pageSet.size());
 		for (StorageMetadata md : pageSet) {
 			if (md.getType() != StorageType.BLOB) {
 				//skip everything that isn't of type BLOB ...
@@ -105,7 +106,7 @@ public class BlobStoreDiscoveryService i
             if (obj == null)
             	continue;
             
-            //Check if ip hasn't been updated recently.
+            // check if the IP hasn't been updated recently
             if (obj instanceof DateTime) {
             	LOGGER.debug("CELLAR CLOUD: retrieved a DateTime from blog store");
                 DateTime registeredTime = (DateTime) obj;
@@ -134,24 +135,27 @@ public class BlobStoreDiscoveryService i
     }
 
     /**
-     * Sign In member to the {@link DiscoveryService}.
+     * Sign in member to the {@link DiscoveryService}.
      */
+    @Override
     public void signIn() {
         DateTime now = new DateTime();
-        createBlob(container, ipAddress, new ServiceContainer(getHostAdress(), getIpAddress(), now));
+        createBlob(container, ipAddress, new ServiceContainer(getHostAddress(), getIpAddress(), now));
     }
 
     /**
      * Refresh member to the {@link DiscoveryService}.
      */
+    @Override
     public void refresh() {
         DateTime now = new DateTime();
-        createBlob(container, ipAddress, new ServiceContainer(getHostAdress(), getIpAddress(), now));
+        createBlob(container, ipAddress, new ServiceContainer(getHostAddress(), getIpAddress(), now));
     }
 
     /**
-     * Sing out member to the {@link DiscoveryService}.
+     * Sign out member to the {@link DiscoveryService}.
      */
+    @Override
     public void signOut() {
         if (blobStore.blobExists(container, ipAddress)) {
             blobStore.removeBlob(container, ipAddress);
@@ -161,11 +165,11 @@ public class BlobStoreDiscoveryService i
     }
 
     /**
-     * Reads from a {@link BlobStore}. It returns an Object.
+     * Reads from a {@link BlobStore}.
      *
-     * @param container
-     * @param blobName
-     * @return
+     * @param container the blob store container.
+     * @param blobName the blob store name.
+     * @return the Object read from the blob store.
      */
     protected Object readBlob(String container, String blobName) {
         Object result = null;
@@ -186,6 +190,7 @@ public class BlobStoreDiscoveryService i
                 try {
                     ois.close();
                 } catch (IOException e) {
+                    // nothing to do
                 }
             }
 
@@ -193,6 +198,7 @@ public class BlobStoreDiscoveryService i
                 try {
                     is.close();
                 } catch (IOException e) {
+                    // nothing to do
                 }
             }
         }
@@ -200,6 +206,13 @@ public class BlobStoreDiscoveryService i
         return result;
     }
 
+    /**
+     * Create a blob store.
+     *
+     * @param container the blob store container.
+     * @param name the blob store name.
+     * @param data the blob store data.
+     */
     public void createBlob(String container, String name, Object data) {
         Blob blob;
         if (blobStore != null) {
@@ -227,6 +240,7 @@ public class BlobStoreDiscoveryService i
                     try {
                         oos.close();
                     } catch (IOException e) {
+                        // nothing to do
                     }
                 }
 
@@ -234,6 +248,7 @@ public class BlobStoreDiscoveryService i
                     try {
                         baos.close();
                     } catch (IOException e) {
+                        // nothing to do
                     }
                 }
             }
@@ -241,23 +256,29 @@ public class BlobStoreDiscoveryService i
     }
 
     /**
-     * Get an instance of InetAddress for the local computer
-     * and return its string representation.
+     * Get the IP address of the local node.
+     *
+     * @return the IP address of the local node.
      */
     protected String getIpAddress() {
         try {
             return InetAddress.getLocalHost().getHostAddress();
         } catch (UnknownHostException ex) {
-            LOGGER.error("CELLAR CLOUD: unable to determine IP address for current node", ex);
+            LOGGER.error("CELLAR CLOUD: unable to determine IP address of the local node", ex);
             return null;
         }
     }
-    
-    protected String getHostAdress() {
+
+    /**
+     * Get the hostname of the local node.
+     *
+     * @return the hostname of the local node.
+     */
+    protected String getHostAddress() {
     	try {
 			return InetAddress.getLocalHost().getHostName();
 		} catch (UnknownHostException ex) {
-			LOGGER.error("CELLAR CLOUD: unable to determine host address for current node", ex);
+			LOGGER.error("CELLAR CLOUD: unable to determine host name of the local node", ex);
             return null;
 		}
     }

Modified: karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryServiceFactory.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryServiceFactory.java?rev=1470997&r1=1470996&r2=1470997&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryServiceFactory.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/BlobStoreDiscoveryServiceFactory.java Tue Apr 23 15:05:11 2013
@@ -26,6 +26,9 @@ import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ConcurrentHashMap;
 
+/**
+ * A factory for blob store discovery service.
+ */
 public class BlobStoreDiscoveryServiceFactory implements ManagedServiceFactory {
 
     private static final Logger LOGGER = LoggerFactory.getLogger(BlobStoreDiscoveryServiceFactory.class);
@@ -44,10 +47,12 @@ public class BlobStoreDiscoveryServiceFa
         this.bundleContext = bundleContext;
     }
 
+    @Override
     public String getName() {
         return "CELLAR CLOUD: blob store discovery service factory";
     }
 
+    @Override
     public void updated(String pid, Dictionary properties) throws ConfigurationException {
         ServiceRegistration newRegistration = null;
         try {
@@ -87,6 +92,7 @@ public class BlobStoreDiscoveryServiceFa
         }
     }
 
+    @Override
     public void deleted(String pid) {
         LOGGER.debug("CELLAR CLOUD: blob store discovery service deleted {}", pid);
         ServiceRegistration oldRegistration = registrations.remove(pid);

Modified: karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/ServiceContainer.java
URL: http://svn.apache.org/viewvc/karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/ServiceContainer.java?rev=1470997&r1=1470996&r2=1470997&view=diff
==============================================================================
--- karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/ServiceContainer.java (original)
+++ karaf/cellar/branches/cellar-2.3.x/cloud/src/main/java/org/apache/karaf/cellar/cloud/ServiceContainer.java Tue Apr 23 15:05:11 2013
@@ -17,12 +17,10 @@ import java.io.Serializable;
 
 import org.joda.time.DateTime;
 
+/**
+ * A cloud service container.
+ */
 public class ServiceContainer implements Serializable {
-
-	/**
-	 * 
-	 */
-	private static final long serialVersionUID = 1L;
 	
 	private DateTime registeredTime;
 	private String hostName;
@@ -56,4 +54,5 @@ public class ServiceContainer implements
 		this.hostIp = hostIp;
 		this.hostPort = hostPort;
 	}
+
 }