@Override public PortMapping getPortMappingWithPrivateSide(Location l, int privatePort) { synchronized (mutex) { for (PortMapping m : mappings.values()) if (l.equals(m.getTarget()) && privatePort == m.privatePort) return m; } return null; }
/** returns the subset of port mappings associated with a given location */ @Override public Collection<PortMapping> getLocationPublicIpIds(Location l) { List<PortMapping> result = new ArrayList<PortMapping>(); synchronized (mutex) { for (PortMapping m : mappings.values()) if (l.equals(m.getTarget())) result.add(m); } return result; }
@Override public HostAndPort lookup(Location l, int privatePort) { synchronized (mutex) { for (PortMapping m : mappings.values()) { if (l.equals(m.target) && privatePort == m.privatePort) return getPublicHostAndPort(m); } } return null; }
@Override public boolean forgetPortMappings(Location l) { List<PortMapping> result = Lists.newArrayList(); synchronized (mutex) { for (Iterator<PortMapping> iter = mappings.values().iterator(); iter.hasNext(); ) { PortMapping m = iter.next(); if (l.equals(m.target)) { iter.remove(); result.add(m); emitAssociationDeletedEvent(associationMetadataFromPortMapping(m)); } } } if (log.isDebugEnabled()) log.debug("cleared all port mappings for " + l + " - " + result); if (!result.isEmpty()) { onChanged(); } return !result.isEmpty(); }