You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by ri...@apache.org on 2014/06/07 00:05:26 UTC

[08/10] git commit: Updated PortForwardManager Javadoc

Updated PortForwardManager Javadoc


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/a5f7b4c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/a5f7b4c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/a5f7b4c7

Branch: refs/heads/master
Commit: a5f7b4c71d7e626408b36005ed217dab1de77c13
Parents: 11e381c
Author: Andrew Donald Kennedy <gr...@apache.org>
Authored: Fri Jun 6 21:07:56 2014 +0100
Committer: Andrew Donald Kennedy <gr...@apache.org>
Committed: Fri Jun 6 21:17:01 2014 +0100

----------------------------------------------------------------------
 .../location/access/PortForwardManager.java     | 102 ++++++++++++-------
 .../access/PortForwardManagerAuthority.java     |  60 +++++------
 2 files changed, 89 insertions(+), 73 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a5f7b4c7/core/src/main/java/brooklyn/location/access/PortForwardManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/access/PortForwardManager.java b/core/src/main/java/brooklyn/location/access/PortForwardManager.java
index 4657b26..71edc4b 100644
--- a/core/src/main/java/brooklyn/location/access/PortForwardManager.java
+++ b/core/src/main/java/brooklyn/location/access/PortForwardManager.java
@@ -7,93 +7,117 @@ import brooklyn.location.Location;
 import com.google.common.annotations.Beta;
 import com.google.common.net.HostAndPort;
 
-/** Records port mappings against public IP addresses with given identifiers 
+/**
+ * Records port mappings against public IP addresses with given identifiers.
  * <p>
  * To use, create a new authoritative instance (e.g. {@link PortForwardManagerAuthority}) which will live in one
  * canonical place, then set config to be a client (e.g. {@link PortForwardManagerClient} which delegates to the
  * primary instance) so the authority is shared among all communicating parties but only persisted in one place.
  * <p>
  * One Location side (e.g. a software process in a VM) can request ({@link #acquirePublicPort(String, Location, int)})
- * an unused port on a firewall / public IP address.
- * He may then go on actually to talk to that firewall/IP to provision the forwarding rule.
+ * an unused port on a firewall / public IP address. It may then go on actually to talk to that firewall/IP to
+ * provision the forwarding rule.
  * <p>
  * Subseequently the other side can use this class {@link #lookup(Location, int)} if it knows the
  * location and private port it wishes to talk to.
  * <p>
- * Implementations typically not know anything about what the firewall/IP actually is; 
- * it just handles a unique identifier for it.
- * It is recommended, however, to {@link #recordPublicIpHostname(String, String)} an accessible hostname with the identifier 
- * (this is required in order to use {@link #lookup(Location, int)}).
- **/
+ * Implementations typically will not know anything about what the firewall/IP actually is, they just handle a
+ * unique identifier for it. It is recommended, however, to {@link #recordPublicIpHostname(String, String)} an
+ * accessible hostname with the identifier. This is required in order to use {@link #lookup(Location, int)}.
+ */
 @Beta
 public interface PortForwardManager {
 
-    /** reserves a unique public port on the given publicIpId
-     * (often followed by {@link #associate(String, int, Location, int)}
-     * to enable {@link #lookup(Location, int)}) */
+    /**
+     * Reserves a unique public port on the given publicIpId.
+     * <p>
+     * Often followed by {@link #associate(String, int, Location, int)}
+     * to enable {@link #lookup(Location, int)}.
+     */
     public int acquirePublicPort(String publicIpId);
 
-    /** returns old mapping if it existed, null if it is new */
+    /** Returns old mapping if it existed, null if it is new. */
     public PortMapping acquirePublicPortExplicit(String publicIpId, int port);
 
-    /** returns the port mapping for a given publicIpId and public port */
+    /** Returns the port mapping for a given publicIpId and public port. */
     public PortMapping getPortMappingWithPublicSide(String publicIpId, int publicPort);
 
-    /** returns the subset of port mappings associated with a given public IP ID */
+    /** Returns the subset of port mappings associated with a given public IP ID. */
     public Collection<PortMapping> getPortMappingWithPublicIpId(String publicIpId);
 
-    /** clears the given port mapping, returning the mapping if there was one */
+    /** Clears the given port mapping, returning the mapping if there was one. */
     public PortMapping forgetPortMapping(String publicIpId, int publicPort);
     
+    /** @see #forgetPortMapping(String, int) */
     public boolean forgetPortMapping(PortMapping m);
 
     // -----------------
     
-    /** records a public hostname or address to be associated with the given publicIpId for lookup purposes */
-    // conceivably this may have to be access-location specific
+    /**
+     * Records a public hostname or address to be associated with the given publicIpId for lookup purposes.
+     * <p>
+     * Conceivably this may have to be access-location specific.
+     */
     public void recordPublicIpHostname(String publicIpId, String hostnameOrPublicIpAddress);
 
-    /** returns a recorded public hostname or address */
+    /** Returns a recorded public hostname or address. */
     public String getPublicIpHostname(String publicIpId);
     
-    /** clears a previous call to {@link #recordPublicIpHostname(String, String)} */
+    /** Clears a previous call to {@link #recordPublicIpHostname(String, String)}. */
     public boolean forgetPublicIpHostname(String publicIpId);
 
-    /** returns the public host and port for use accessing the given mapping */
-    // conceivably this may have to be access-location specific
+    /**
+     * Returns the public host and port for use accessing the given mapping.
+     * <p>
+     * Conceivably this may have to be access-location specific.
+     */
     public HostAndPort getPublicHostAndPort(PortMapping m);
-    // -----------------------------
+
+    // -----------------
     
-    /** reserves a unique public port for the purpose of forwarding to the given target,
-     * associated with a given location for subsequent lookup purpose;
-     * if already allocated, returns the previously allocated */
+    /**
+     * Reserves a unique public port for the purpose of forwarding to the given target,
+     * associated with a given location for subsequent lookup purpose.
+     * <p>
+     * If already allocated, returns the previously allocated.
+     */
     public int acquirePublicPort(String publicIpId, Location l, int privatePort);
 
-    /** returns the public ip hostname and public port for use contacting the given endpoint;
-     * null if:
-     * * no publicPort is associated with this location and private port
-     * * no publicIpId is associated with this location and private port
-     * * no publicIpHostname is recorded against the associated publicIpId
+    /**
+     * Returns the public ip hostname and public port for use contacting the given endpoint.
+     * <p>
+     * Will return null if:
+     * <ul>
+     * <li>No publicPort is associated with this location and private port.
+     * <li>No publicIpId is associated with this location and private port.
+     * <li>No publicIpHostname is recorded against the associated publicIpId.
+     * </ul>
+     * Conceivably this may have to be access-location specific.
+     *
+     * @see #recordPublicIpHostname(String, String)
      */
-    // conceivably this may have to be access-location specific -- see recordPublicIpHostname
     public HostAndPort lookup(Location l, int privatePort);
     
-    /** records a location and private port against a publicIp and public port,
-     * to support {@link #lookup(Location, int)};
-     * superfluous if {@link #acquirePublicPort(String, Location, int)} was used;
+    /**
+     * Records a location and private port against a publicIp and public port,
+     * to support {@link #lookup(Location, int)}.
+     * <p>
+     * Superfluous if {@link #acquirePublicPort(String, Location, int)} was used,
      * but strongly recommended if {@link #acquirePublicPortExplicit(String, int)} was used
-     * e.g. if the location is not known ahead of time)
+     * e.g. if the location is not known ahead of time.
      */
     public void associate(String publicIpId, int publicPort, Location l, int privatePort);
 
-    /** returns the subset of port mappings associated with a given location */
+    /** Returns the subset of port mappings associated with a given location. */
     public Collection<PortMapping> getLocationPublicIpIds(Location l);
         
-    /** returns the mapping to a given private port, or null if none */
+    /** Returns the mapping to a given private port, or null if none. */
     public PortMapping getPortMappingWithPrivateSide(Location l, int privatePort);
 
-    /** true if this implementation is a client which is immutable/safe for serialization
-     * (ie it delegates to something on an entity or location elsewhere) */
+    /**
+     * Returns true if this implementation is a client which is immutable/safe for serialization
+     * i.e. it delegates to something on an entity or location elsewhere.
+     */
     public boolean isClient();
     
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a5f7b4c7/core/src/main/java/brooklyn/location/access/PortForwardManagerAuthority.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/access/PortForwardManagerAuthority.java b/core/src/main/java/brooklyn/location/access/PortForwardManagerAuthority.java
index 8f56e9c..b71bae1 100644
--- a/core/src/main/java/brooklyn/location/access/PortForwardManagerAuthority.java
+++ b/core/src/main/java/brooklyn/location/access/PortForwardManagerAuthority.java
@@ -47,9 +47,8 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         onChanged();
     }
     
-    /** reserves a unique public port on the given publicIpId
-     * (often followed by {@link #associate(String, int, Location, int)}
-     * to enable {@link #lookup(Location, int)}) */
+    /** {@inheritDoc} */
+    @Override
     public int acquirePublicPort(String publicIpId) {
         int port;
         synchronized (this) {
@@ -65,7 +64,8 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         return port;
     }
 
-    /** returns old mapping if it existed, null if it is new */
+    /** {@inheritDoc} */
+    @Override
     public PortMapping acquirePublicPortExplicit(String publicIpId, int port) {
         PortMapping mapping = new PortMapping(publicIpId, port, null, -1);
         log.debug("assigning explicit public port "+port+" at "+publicIpId);
@@ -78,12 +78,14 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         return publicIpId+":"+publicPort;
     }
 
-    /** returns the port mapping for a given publicIpId and public port */
+    /** {@inheritDoc} */
+    @Override
     public synchronized PortMapping getPortMappingWithPublicSide(String publicIpId, int publicPort) {
         return mappings.get(makeKey(publicIpId, publicPort));
     }
 
-    /** returns the subset of port mappings associated with a given public IP ID */
+    /** {@inheritDoc} */
+    @Override
     public synchronized Collection<PortMapping> getPortMappingWithPublicIpId(String publicIpId) {
         List<PortMapping> result = new ArrayList<PortMapping>();
         for (PortMapping m: mappings.values())
@@ -91,7 +93,8 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         return result;
     }
 
-    /** clears the given port mapping, returning the mapping if there was one */
+    /** {@inheritDoc} */
+    @Override
     public PortMapping forgetPortMapping(String publicIpId, int publicPort) {
         PortMapping result;
         synchronized (this) {
@@ -102,14 +105,14 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         return result;
     }
     
+    /** {@inheritDoc} */
+    @Override
     public boolean forgetPortMapping(PortMapping m) {
         return (forgetPortMapping(m.publicIpId, m.publicPort) != null);
     }
 
-    // -----------------
-    
-    /** records a public hostname or address to be associated with the given publicIpId for lookup purposes */
-    // conceivably this may have to be access-location specific
+    /** {@inheritDoc} */
+    @Override
     public void recordPublicIpHostname(String publicIpId, String hostnameOrPublicIpAddress) {
         log.debug("recording public IP "+publicIpId+" associated with "+hostnameOrPublicIpAddress);
         synchronized (publicIpIdToHostname) {
@@ -120,14 +123,16 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         onChanged();
     }
 
-    /** returns a recorded public hostname or address */
+    /** {@inheritDoc} */
+    @Override
     public String getPublicIpHostname(String publicIpId) {
         synchronized (publicIpIdToHostname) {
             return publicIpIdToHostname.get(publicIpId);
         }
     }
     
-    /** clears a previous call to {@link #recordPublicIpHostname(String, String)} */
+    /** {@inheritDoc} */
+    @Override
     public boolean forgetPublicIpHostname(String publicIpId) {
         log.debug("forgetting public IP "+publicIpId+" association");
         boolean result;
@@ -136,11 +141,10 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         }
         onChanged();
         return result;
-
     }
 
-    /** returns the public host and port for use accessing the given mapping */
-    // conceivably this may have to be access-location specific
+    /** {@inheritDoc} */
+    @Override
     public HostAndPort getPublicHostAndPort(PortMapping m) {
         String hostname = getPublicIpHostname(m.publicIpId);
         if (hostname==null)
@@ -148,11 +152,8 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         return HostAndPort.fromParts(hostname, m.publicPort);
     }
 
-    // -----------------------------
-    
-    /** reserves a unique public port for the purpose of forwarding to the given target,
-     * associated with a given location for subsequent lookup purpose;
-     * if already allocated, returns the previously allocated */
+    /** {@inheritDoc} */
+    @Override
     public int acquirePublicPort(String publicIpId, Location l, int privatePort) {
         int publicPort;
         synchronized (this) {
@@ -171,13 +172,8 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         return publicPort;
     }
 
-    /** returns the public ip hostname and public port for use contacting the given endpoint;
-     * null if:
-     * * no publicPort is associated with this location and private port
-     * * no publicIpId is associated with this location and private port
-     * * no publicIpHostname is recorded against the associated publicIpId
-     */
-    // conceivably this may have to be access-location specific -- see recordPublicIpHostname
+    /** {@inheritDoc} */
+    @Override
     public synchronized HostAndPort lookup(Location l, int privatePort) {
         for (PortMapping m: mappings.values()) {
             if (l.equals(m.target) && privatePort==m.privatePort)
@@ -186,12 +182,8 @@ public class PortForwardManagerAuthority implements PortForwardManager {
         return null;
     }
     
-    /** records a location and private port against a publicIp and public port,
-     * to support {@link #lookup(Location, int)};
-     * superfluous if {@link #acquirePublicPort(String, Location, int)} was used;
-     * but strongly recommended if {@link #acquirePublicPortExplicit(String, int)} was used
-     * e.g. if the location is not known ahead of time)
-     */
+    /** {@inheritDoc} */
+    @Override
     public synchronized void associate(String publicIpId, int publicPort, Location l, int privatePort) {
         synchronized (this) {
             associateImpl(publicIpId, publicPort, l, privatePort);