/******************************************************************************* * ============LICENSE_START==================================================== * * org.onap.aaf * * =========================================================================== * * Copyright © 2017 AT&T Intellectual Property. All rights reserved. * * =========================================================================== * * Licensed 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. * * ============LICENSE_END==================================================== * * * * ECOMP is a trademark and service mark of AT&T Intellectual Property. * * ******************************************************************************/ package com.att.cadi.locator; import com.att.cadi.Access; import com.att.cadi.Access.Level; import com.att.cadi.Locator; import com.att.cadi.LocatorException; import com.att.cadi.routing.GreatCircle; import com.att.inno.env.util.Split; /** * This Locator is to handle Hot Peer load protection, when the Servers are * 1) Static * 2) Well known client URL * * The intention is to change traffic over to the Hot Peer, if a server goes down, and reinstate * when it is back up. * * Example of this kind of Service is a MS Certificate Server * * * * @param */ public abstract class HotPeerLocator implements Locator { private final String[] urlstrs; private final CLIENT[] clients; private final long[] failures; private final double[] distances; private int preferred; private long invalidateTime; private Thread refreshThread; protected Access access; /** * Construct: Expect one or more Strings in the form: * 192.555.112.223:39/38.88087/-77.30122 * separated by commas * * @param trans * @param urlstr * @param invalidateTime * @param localLatitude * @param localLongitude * @throws LocatorException */ @SuppressWarnings("unchecked") protected HotPeerLocator(Access access, final String urlstr, final long invalidateTime, final String localLatitude, final String localLongitude) throws LocatorException { this.access = access; urlstrs = Split.split(',', urlstr); clients = (CLIENT[])new Object[urlstrs.length]; failures = new long[urlstrs.length]; distances= new double[urlstrs.length]; this.invalidateTime = invalidateTime; double distance = Double.MAX_VALUE; for(int i=0;iSystem.currentTimeMillis()) { throw new LocatorException("Client requested is invalid"); } else { synchronized(clients) { c = _newClient(urlstrs[hpi.idx]); failures[hpi.idx]=0L; } } } else if(failures[hpi.idx]>0){ throw new LocatorException("Client requested is invalid"); } return c; } public String info(Item item) { HPItem hpi = (HPItem)item; if(hpi!=null && hpi.idx=clients.length) { return null; } return hpi; } @Override public boolean refresh() { boolean force = !hasItems(); // If no Items at all, reset boolean rv = true; long now = System.currentTimeMillis(); for(int i=0;i0L && (failures[i]