X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cadi%2Fclient%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Faaf%2Fcadi%2Flocator%2FPropertyLocator.java;h=3488913899124b171057af7ae709cf35ad53bd43;hb=3d1706fcbe7f95830ff6fd23cf679ee55c6d0595;hp=4591122cb8cf019ddd4d7854c569882f2bab653e;hpb=0b8d6377d7d67800f5059d56352c017f712ccbc2;p=aaf%2Fauthz.git diff --git a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/PropertyLocator.java b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/PropertyLocator.java index 4591122c..34889138 100644 --- a/cadi/client/src/main/java/org/onap/aaf/cadi/locator/PropertyLocator.java +++ b/cadi/client/src/main/java/org/onap/aaf/cadi/locator/PropertyLocator.java @@ -36,263 +36,265 @@ import java.util.TimerTask; import org.onap.aaf.cadi.Locator; import org.onap.aaf.cadi.LocatorException; +import org.onap.aaf.cadi.util.FixURIinfo; import org.onap.aaf.misc.env.util.Split; public class PropertyLocator implements Locator { - private final URI [] orig; - private PLItem[] current; - private int end; - private final SecureRandom random; - private URI[] resolved; - private long lastRefreshed; - private long minRefresh; - private long backgroundRefresh; + private final URI [] orig; + private PLItem[] current; + private int end; + private final SecureRandom random; + private URI[] resolved; + private long lastRefreshed; + private long minRefresh; + private long backgroundRefresh; - public PropertyLocator(String locList) throws LocatorException { - this(locList,10000L, 1000*60*20L); // defaults, do not refresh more than once in 10 seconds, Refresh Locator every 20 mins. - } - /** - * comma delimited root url list - * - * @param locList - * @throws LocatorException - */ - public PropertyLocator(String locList, long minRefreshMillis, long backgroundRefreshMillis) throws LocatorException { - minRefresh = minRefreshMillis; - backgroundRefresh = backgroundRefreshMillis; - lastRefreshed=0L; - if(locList==null) { - throw new LocatorException("No Location List given for PropertyLocator"); - } - String[] locarray = Split.split(',',locList); - List uriList = new ArrayList(); - - random = new SecureRandom(); - - for(int i=0;i=0?locarray[i].substring(slash):""))); - } - } - } catch (NumberFormatException nf) { - throw new LocatorException("Invalid URI format: " + locarray[i]); - } catch (URISyntaxException e) { - throw new LocatorException(e); - } - } - orig = new URI[uriList.size()]; - uriList.toArray(orig); + public PropertyLocator(String locList) throws LocatorException { + this(locList,10000L, 1000*60*20L); // defaults, do not refresh more than once in 10 seconds, Refresh Locator every 20 mins. + } + /** + * comma delimited root url list + * + * @param locList + * @throws LocatorException + */ + public PropertyLocator(String locList, long minRefreshMillis, long backgroundRefreshMillis) throws LocatorException { + minRefresh = minRefreshMillis; + backgroundRefresh = backgroundRefreshMillis; + lastRefreshed=0L; + if (locList==null) { + throw new LocatorException("No Location List given for PropertyLocator"); + } + String[] locarray = Split.split(',',locList); + List uriList = new ArrayList<>(); + + random = new SecureRandom(); + + for (int i=0;i=0?locarray[i].substring(slash):""))); + } + } + } catch (NumberFormatException nf) { + throw new LocatorException("Invalid URI format: " + locarray[i]); + } catch (URISyntaxException e) { + throw new LocatorException(e); + } + } + orig = new URI[uriList.size()]; + uriList.toArray(orig); - refresh(); - new Timer("PropertyLocator Refresh Timer",true).scheduleAtFixedRate(new TimerTask() { - @Override - public void run() { - refresh(); - } - }, backgroundRefresh,backgroundRefresh); - } + refresh(); + new Timer("PropertyLocator Refresh Timer",true).scheduleAtFixedRate(new TimerTask() { + @Override + public void run() { + refresh(); + } + }, backgroundRefresh,backgroundRefresh); + } - @Override - public URI get(Item item) throws LocatorException { - synchronized(orig) { - if(item==null) { - return null; - } else { - return resolved[((PLItem)item).idx]; - } - } - } + @Override + public URI get(Item item) throws LocatorException { + synchronized(orig) { + if (item==null) { + return null; + } else { + return resolved[((PLItem)item).idx]; + } + } + } - @Override - public Item first() throws LocatorException { - return end>0?current[0]:null; - } + @Override + public Item first() throws LocatorException { + return end>0?current[0]:null; + } - @Override - public boolean hasItems() { - return end>0; - } + @Override + public boolean hasItems() { + return end>0; + } - @Override - public Item next(Item item) throws LocatorException { - if(item==null) { - return null; - } else { - int spot; - if((spot=(((PLItem)item).order+1))>=end)return null; - return current[spot]; - } - } + @Override + public Item next(Item item) throws LocatorException { + if (item==null) { + return null; + } else { + int spot; + if ((spot=(((PLItem)item).order+1))>=end)return null; + return current[spot]; + } + } - @Override - public synchronized void invalidate(Item item) throws LocatorException { - if(--end<0) { - refresh(); - return; - } - if(item==null) { - return; - } - PLItem pli = (PLItem)item; - int i,order; - for(i=0;ilastRefreshed) { - // Build up list - List resolve = new ArrayList(); - String realname; - for(int i = 0; i < orig.length ; ++i) { - try { - InetAddress ia[] = InetAddress.getAllByName(orig[i].getHost()); + @Override + public synchronized boolean refresh() { + if (System.currentTimeMillis()>lastRefreshed) { + // Build up list + List resolve = new ArrayList<>(); + String realname; + for (int i = 0; i < orig.length ; ++i) { + try { + FixURIinfo fui = new FixURIinfo(orig[i]); + InetAddress ia[] = InetAddress.getAllByName(fui.getHost()); - URI o,n; - for(int j=0;j