/** * */ package vn.mobileid.fms.client.loadbalancing; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.List; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import javax.jcr.LoginException; import javax.jcr.NoSuchWorkspaceException; import javax.jcr.Node; import javax.jcr.PathNotFoundException; import javax.jcr.Repository; import javax.jcr.RepositoryException; import javax.jcr.SimpleCredentials; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.jackrabbit.commons.JcrUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import vn.mobileid.fms.client.FMSUtils; import vn.mobileid.fms.client.JCRException; import vn.mobileid.fms.client.ws.WorkspaceManagerProxy; /** * @author TRUONG.NNT * @created Jun 7, 2019 */ public class RepositoryManager { private static final Logger LOGGER = LoggerFactory.getLogger(RepositoryManager.class); public static String ACCESS_REPO = "/server"; public static String WORKSPACE_WSDL = "/WorkspaceManager?wsdl"; private String[] uris; private ConcurrentHashMap whiteList = new ConcurrentHashMap<>(); private List keyOfWhiteList; //private List whiteList; //private Map blackList; private List blackList; private List uriNotProcess; private CloseableHttpClient httpClient; private HealcheckConfig healcheckConfig; private AtomicInteger index; private ScheduledExecutorService scheduleWhiteCheck; private ScheduledExecutorService scheduleBlackCheck; private OneFMSActive oneFMSActive; /** * @throws RepositoryException * @throws JCRException * */ public RepositoryManager(String url, HealcheckConfig cfg, OneFMSActive oneFMSActive) throws JCRException { // TODO Auto-generated constructor stub this.uris = getUris(url); if (uris == null || uris.length == 0) { throw new JCRException("url of repository is null or empty"); } this.whiteList = new ConcurrentHashMap<>(); this.keyOfWhiteList = new ArrayList<>(); //this.whiteList = new ArrayList<>(); //this.blackList = new ConcurrentHashMap<>(); this.blackList = new ArrayList<>(); this.uriNotProcess = new ArrayList<>(); this.healcheckConfig = cfg; this.index = new AtomicInteger(0); this.oneFMSActive = oneFMSActive; int timeout = cfg.getTimeoutConn(); RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000) .setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build(); httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config) .setMaxConnTotal(2) .build(); } public void startWhiteCheck(){ scheduleWhiteCheck = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { private AtomicLong sequence = new AtomicLong(0); @Override public Thread newThread(Runnable r) { // TODO Auto-generated method stub Thread t = new Thread(r); String tName = "White-healcheck-" + sequence.incrementAndGet(); t.setName(tName); return t; } }); scheduleWhiteCheck.scheduleWithFixedDelay(new Runnable() { @Override public void run() { // TODO Auto-generated method stub //LOGGER.info("Start white heal-check"); if (!keyOfWhiteList.isEmpty()) { //for (String key : whiteList.keySet()) { List tmpWhiteKey = new ArrayList<>(keyOfWhiteList); for (Integer key : tmpWhiteKey) { RepositoryInfo rpInfo = whiteList.get(key); //AtomicInteger cntOK = new AtomicInteger(0); AtomicInteger cntFail = new AtomicInteger(0); while (true) { try { HttpGet httpGet = new HttpGet(rpInfo.uri.concat(healcheckConfig.getHealUri())); CloseableHttpResponse response = httpClient.execute(httpGet); response.close(); LOGGER.debug(rpInfo.uri.concat(healcheckConfig.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); // if (cntOK.incrementAndGet() == healcheckConfig.getCountWhiteCheck()) { // break; // } break; } catch (IOException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.error("Heal-check is fail, uri: " + rpInfo.uri.concat(healcheckConfig.getHealUri()) + ". Count/Max: " + cntFail.incrementAndGet() + "/" + healcheckConfig.getCountBlackCheck() + ". Reason " + e); if (cntFail.get() == healcheckConfig.getCountBlackCheck()) { //Integer blackKey = Integer.valueOf(key.split(":")[1]); LOGGER.info("Healcheck is FAIL, Remove uri from WHITE-LIST and Add uri into BLACK-LIST, uri: " + rpInfo.uri); //blackList.put(blackKey, whiteList.remove(key)); whiteList.remove(key); keyOfWhiteList.remove(key); blackList.add(rpInfo); break; } } } } } //checkUriNotProcess(); //LOGGER.info("Stop white heal-check"); } }, healcheckConfig.getIntervalWhiteCheck(), healcheckConfig.getIntervalWhiteCheck(), TimeUnit.SECONDS); } public void startBlackCheck() { scheduleBlackCheck = Executors.newSingleThreadScheduledExecutor(new ThreadFactory() { private AtomicLong sequence = new AtomicLong(0); @Override public Thread newThread(Runnable r) { // TODO Auto-generated method stub Thread t = new Thread(r); String tName = "Black-healcheck-" + sequence.incrementAndGet(); t.setName(tName); return t; } }); scheduleBlackCheck.scheduleWithFixedDelay(new Runnable() { @Override public void run() { // TODO Auto-generated method stub if (!blackList.isEmpty()) { //for (Integer key : blackList.keySet()) { List blackTmps = new ArrayList<>(blackList); for (RepositoryInfo rpInfo : blackTmps) { //RepositoryInfo rpInfo = blackList.get(key); AtomicInteger cntOK = new AtomicInteger(0); AtomicInteger cntFail = new AtomicInteger(0); while (true) { try { HttpGet httpGet = new HttpGet(rpInfo.uri.concat(healcheckConfig.getHealUri())); CloseableHttpResponse response = httpClient.execute(httpGet); response.close(); LOGGER.debug(rpInfo.uri.concat(healcheckConfig.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); if (cntOK.incrementAndGet() == healcheckConfig.getCountWhiteCheck()) { try { oneFMSActive.onAddWhite(rpInfo); blackList.remove(rpInfo); Integer key = rpInfo.uri.hashCode(); whiteList.put(key, rpInfo); keyOfWhiteList.add(key); LOGGER.info("Healcheck is OK, Add uri from WHITE-LIST and Remove uri into BLACK-LIST, uri: " + rpInfo.uri); //whiteList.add(rpInfo); } catch (JCRException | RepositoryException e) { // TODO Auto-generated catch block //e.printStackTrace(); LOGGER.error("FAIL to add uri {} into white-list, caused by {} ", rpInfo.uri.concat(ACCESS_REPO), e); } // if(whiteList.size() == 1) { // oneFMSActive.onload(rpInfo.repository); // }else { // //oneFMSActive. // } break; } } catch (IOException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.debug("Heal-check is fail, uri: " + rpInfo.uri.concat(healcheckConfig.getHealUri()) + ". Count/Max: " + cntFail.incrementAndGet() + "/" + healcheckConfig.getCountBlackCheck() + ". Reason " + e); // if (cntFail.get() == healcheckConfig.getCountBlackCheck()) { // break; // } break; } } } } checkUriNotProcess(); } }, healcheckConfig.getIntervalBlackCheck(), healcheckConfig.getIntervalBlackCheck(), TimeUnit.SECONDS); } public void init() { for (String uri : uris) { AtomicInteger cntOK = new AtomicInteger(0); AtomicInteger cntFail = new AtomicInteger(0); while (true) { try { HttpGet httpGet = new HttpGet(uri.concat(healcheckConfig.getHealUri())); CloseableHttpResponse response = httpClient.execute(httpGet); response.close(); LOGGER.debug( uri.concat(healcheckConfig.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); if (cntOK.incrementAndGet() == healcheckConfig.getCountWhiteCheck()) { Repository repo; try { repo = JcrUtils.getRepository(uri.concat(ACCESS_REPO)); RepositoryInfo newWhite = new RepositoryInfo(repo, uri); //whiteList.put(whiteList.size() + ":" + uri.hashCode(), new RepositoryInfo(repo, uri)); try { oneFMSActive.onAddWhite(newWhite); //blackList.remove(newWhite); //whiteList.add(newWhite); Integer key = uri.hashCode(); whiteList.put(key, newWhite); keyOfWhiteList.add(key); LOGGER.debug("Add uri into white-list, uri: " + uri); } catch (JCRException | RepositoryException e) { // TODO Auto-generated catch block //e.printStackTrace(); LOGGER.error("FAIL to add uri {} into white-list, caused by {} ", uri.concat(ACCESS_REPO), e); blackList.add(newWhite); } // if(whiteList.size() == 1) { // oneFMSActive.onload(repo); // } } catch (RepositoryException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.error("Fail to get repository for uri: " + uri.concat(ACCESS_REPO) + " due to " + e); uriNotProcess.add(uri); } break; } } catch (IOException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.error("Heal-check is fail, uri: " + uri.concat(healcheckConfig.getHealUri()) + ". Count/Max: " + cntFail.incrementAndGet() + "/" + healcheckConfig.getCountBlackCheck() + ". Reason " + e); if (cntFail.get() == healcheckConfig.getCountBlackCheck()) { uriNotProcess.add(uri); break; } } } } } public void addUri(String path) throws JCRException { String[] uris = getUris(path); for (String uri : uris) { AtomicInteger cntOK = new AtomicInteger(0); AtomicInteger cntFail = new AtomicInteger(0); while (true) { try { HttpGet httpGet = new HttpGet(uri.concat(healcheckConfig.getHealUri())); CloseableHttpResponse response = httpClient.execute(httpGet); response.close(); LOGGER.debug( uri.concat(healcheckConfig.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); if (cntOK.incrementAndGet() == healcheckConfig.getCountWhiteCheck()) { Repository repo; try { repo = JcrUtils.getRepository(uri.concat(ACCESS_REPO)); RepositoryInfo newWhite = new RepositoryInfo(repo, uri); try { oneFMSActive.onAddWhite(newWhite); Integer key = uri.hashCode(); whiteList.put(key, newWhite); keyOfWhiteList.add(key); LOGGER.debug("Add uri into white-list, uri: " + uri); } catch (JCRException | RepositoryException e) { // TODO Auto-generated catch block //e.printStackTrace(); LOGGER.error("FAIL to add uri {} into white-list, caused by {} ", uri.concat(ACCESS_REPO), e); blackList.add(newWhite); } } catch (RepositoryException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.error("Fail to get repository for uri: " + uri.concat(ACCESS_REPO) + " due to " + e); uriNotProcess.add(uri); } break; } } catch (IOException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.error("Heal-check is fail, uri: " + uri.concat(healcheckConfig.getHealUri()) + ". Count/Max: " + cntFail.incrementAndGet() + "/" + healcheckConfig.getCountBlackCheck() + ". Reason " + e); if (cntFail.get() == healcheckConfig.getCountBlackCheck()) { uriNotProcess.add(uri); break; } } } } } private void checkUriNotProcess() { if (uriNotProcess.isEmpty()) return; //Iterator it = uriNotProcess.iterator(); List urisNotyet = new ArrayList<>(uriNotProcess); for (String uri : urisNotyet) { //String uri = it.next(); AtomicInteger cntOK = new AtomicInteger(0); AtomicInteger cntFail = new AtomicInteger(0); while (true) { try { HttpGet httpGet = new HttpGet(uri.concat(healcheckConfig.getHealUri())); CloseableHttpResponse response = httpClient.execute(httpGet); response.close(); LOGGER.debug(uri.concat(healcheckConfig.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); if (cntOK.incrementAndGet() == healcheckConfig.getCountWhiteCheck()) { Repository repo; try { repo = JcrUtils.getRepository(uri.concat(ACCESS_REPO)); RepositoryInfo newWhite = new RepositoryInfo(repo, uri); //whiteList.put(whiteList.size() + ":" + uri.hashCode(), new RepositoryInfo(repo, uri)); try { oneFMSActive.onAddWhite(newWhite); //blackList.remove(newWhite); //whiteList.add(newWhite); Integer key = uri.hashCode(); whiteList.put(key, newWhite); keyOfWhiteList.add(key); LOGGER.debug("Add uri into white-list, uri: " + uri); } catch (JCRException | RepositoryException e) { // TODO Auto-generated catch block //e.printStackTrace(); LOGGER.error("FAIL to add uri {} into white-list, caused by {} ", uri.concat(ACCESS_REPO), e); blackList.add(newWhite); } // if(whiteList.size() == 1) { // oneFMSActive.onload(repo); // } uriNotProcess.remove(uri); } catch (RepositoryException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.error("Fail to get repository for uri: " + uri.concat(ACCESS_REPO) + " due to " + e); } break; } } catch (IOException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.debug("Heal-check is fail, uri: " + uri + ". Count/Max: " + cntFail.incrementAndGet() + "/" + healcheckConfig.getCountBlackCheck() + ". Reason " + e); if (cntFail.get() == healcheckConfig.getCountBlackCheck()) { break; } } } } } public Repository getRepository() throws JCRException { do { if (keyOfWhiteList.isEmpty()) { throw new JCRException("No repository is avaiable"); } try { Integer key = keyOfWhiteList.get(index.get()); if(index.incrementAndGet() >= keyOfWhiteList.size()) { index = new AtomicInteger(0); } RepositoryInfo rpInfo = whiteList.get(key); try { HttpGet httpGet = new HttpGet(rpInfo.uri.concat(healcheckConfig.getHealUri())); CloseableHttpResponse response = httpClient.execute(httpGet); response.close(); LOGGER.debug(rpInfo.uri.concat(healcheckConfig.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); return rpInfo.repository; } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); LOGGER.error("Fail to healcheck - uri {} caused by {}", rpInfo.uri, e); }finally { } }catch (IndexOutOfBoundsException e) { // TODO: handle exception LOGGER.error("Fail to get RepositoryInfo at {} caused by {}", index, e); index = new AtomicInteger(0); } }while(true); } public RepositoryInfo getRepositoryInfo() throws JCRException { do { if (keyOfWhiteList.isEmpty()) { throw new JCRException("No repository is avaiable"); } try { Integer key = keyOfWhiteList.get(index.get()); if(index.incrementAndGet() >= keyOfWhiteList.size()) { index = new AtomicInteger(0); } RepositoryInfo rpInfo = whiteList.get(key); try { HttpGet httpGet = new HttpGet(rpInfo.uri.concat(healcheckConfig.getHealUri())); CloseableHttpResponse response = httpClient.execute(httpGet); response.close(); LOGGER.debug(rpInfo.uri.concat(healcheckConfig.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); return rpInfo; } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); LOGGER.error("Fail to healcheck - uri {} caused by {}", rpInfo.uri, e); }finally { } }catch (IndexOutOfBoundsException e) { // TODO: handle exception LOGGER.error("Fail to get RepositoryInfo at {} caused by {}", index, e); index = new AtomicInteger(0); } }while(true); } public Integer getKeyWhiteRepositoryInfo() throws JCRException { do { if (keyOfWhiteList.isEmpty()) { throw new JCRException("No repository is avaiable"); } try { Integer key = keyOfWhiteList.get(index.get()); if(index.incrementAndGet() >= keyOfWhiteList.size()) { index = new AtomicInteger(0); } RepositoryInfo rpInfo = whiteList.get(key); try { HttpGet httpGet = new HttpGet(rpInfo.uri.concat(healcheckConfig.getHealUri())); CloseableHttpResponse response = httpClient.execute(httpGet); response.close(); LOGGER.debug(rpInfo.uri.concat(healcheckConfig.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); //Pair pair = new Pair(key, rpInfo); return key; } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); LOGGER.error("Fail to healcheck - uri {} caused by {}", rpInfo.uri, e); }finally { } }catch (IndexOutOfBoundsException e) { // TODO: handle exception LOGGER.error("Fail to get RepositoryInfo at {} caused by {}", index, e); index = new AtomicInteger(0); } }while(true); } public RepositoryInfo getWhiteRepositoryInfo(Integer key) { return whiteList.get(key); } public RepositoryInfo updateRepositoryInfo(Integer key, RepositoryInfo repo){ return whiteList.replace(key, repo); } public boolean healcheck(String uri) throws JCRException{ try { HttpGet httpGet = new HttpGet(uri.concat(healcheckConfig.getHealUri())); CloseableHttpResponse response = httpClient.execute(httpGet); response.close(); LOGGER.debug(uri.concat(healcheckConfig.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); return true; } catch (IOException e) { // TODO Auto-generated catch block //e.printStackTrace(); LOGGER.error("Fail to healcheck - uri {} caused by {}", uri, e); return false; }finally { } } public static Repository getRepository(String urls) throws JCRException { String[] _urls = getUris(urls); HealcheckConfig _healCfg = new HealcheckConfig(); int timeout = _healCfg.getTimeoutConn(); RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000) .setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build(); CloseableHttpClient _httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config) .setMaxConnTotal(2) .build(); for (String uri : _urls) { try { HttpGet httpGet = new HttpGet(uri.concat(_healCfg.getHealUri())); CloseableHttpResponse response = _httpClient.execute(httpGet); response.close(); LOGGER.debug( uri.concat(_healCfg.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); return JcrUtils.getRepository(uri.concat(ACCESS_REPO)); } catch (IOException | RepositoryException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.error("Heal-check is fail, uri: " + uri.concat(_healCfg.getHealUri())); } } throw new JCRException("No repository is avaiable"); } public static List getRepositories(String urls) throws JCRException { String[] _urls = getUris(urls); HealcheckConfig _healCfg = new HealcheckConfig(); int timeout = _healCfg.getTimeoutConn(); RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000) .setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build(); CloseableHttpClient _httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config) .setMaxConnTotal(2) .build(); List repositories = new ArrayList<>(); for (String uri : _urls) { try { HttpGet httpGet = new HttpGet(uri.concat(_healCfg.getHealUri())); CloseableHttpResponse response = _httpClient.execute(httpGet); response.close(); LOGGER.debug( uri.concat(_healCfg.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); repositories.add(JcrUtils.getRepository(uri.concat(ACCESS_REPO))); } catch (IOException | RepositoryException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.error("Heal-check is fail, uri: " + uri.concat(_healCfg.getHealUri())); } } if(repositories.isEmpty()) { throw new JCRException("No repository is avaiable"); } return repositories; } public List getWhiteWorkspaceManagerProxy() throws JCRException { if(keyOfWhiteList == null || keyOfWhiteList.size() == 0) { throw new JCRException("No uri is avaiable"); } List wsList = new ArrayList<>(); //Map hashMap1 = new ConcurrentHashMap<>(); //hashMap1.putAll(whiteList); //Set keyset = whiteList.keySet(); for (RepositoryInfo rpInfo : whiteList.values()) { wsList.add(new WorkspaceManagerProxy(rpInfo.uri.concat(WORKSPACE_WSDL))); } return wsList; } public static List getWhiteWorkspaceManagerProxy(String urls) throws JCRException { String[] _urls = getUris(urls); HealcheckConfig _healCfg = new HealcheckConfig(); int timeout = _healCfg.getTimeoutConn(); RequestConfig config = RequestConfig.custom().setConnectTimeout(timeout * 1000) .setConnectionRequestTimeout(timeout * 1000).setSocketTimeout(timeout * 1000).build(); CloseableHttpClient _httpClient = HttpClientBuilder.create().setDefaultRequestConfig(config) .setMaxConnTotal(2) .build(); List wsList = new ArrayList<>(); for (String uri : _urls) { try { HttpGet httpGet = new HttpGet(uri.concat(_healCfg.getHealUri())); CloseableHttpResponse response = _httpClient.execute(httpGet); response.close(); LOGGER.debug( uri.concat(_healCfg.getHealUri()) + " response: " + response.getStatusLine().getStatusCode()); wsList.add(new WorkspaceManagerProxy(uri.concat(WORKSPACE_WSDL))); } catch (IOException e) { // TODO Auto-generated catch block // e.printStackTrace(); LOGGER.error("Heal-check is fail, uri: " + uri.concat(_healCfg.getHealUri())); } } if(wsList.isEmpty()) { throw new JCRException("No WorkspaceManagerProxy is avaiable"); } return wsList; } public WorkspaceManagerProxy[] getAllWorkspaceManagerProxy() throws JCRException { if(uris == null || uris.length == 0) { throw new JCRException("No uri is avaiable"); } WorkspaceManagerProxy[] wsList = new WorkspaceManagerProxy[uris.length]; for (int i = 0; i < uris.length; i++) { wsList[i] = new WorkspaceManagerProxy(uris[i].concat(WORKSPACE_WSDL)); } return wsList; } // public static Repository[] getRepositories(String path) throws JCRException, RepositoryException { // if (path == null) { // throw new JCRException(JCRException.URL_INVALID, "Path is null"); // } // String[] schAndFile = path.split("://"); // String scheme = schAndFile[0]; // String[] authAndPath = schAndFile[1].split("/"); // StringBuilder jcrPath = new StringBuilder(authAndPath[1]); // if (authAndPath.length == 2) { // jcrPath.append("/server"); // } else if (authAndPath.length == 3) { // if (authAndPath[2].equals("server") || authAndPath[2].equals("repository")) {// .equals("server") && // // !segments.equals("repository")) // // { // jcrPath.append("/").append(authAndPath[2]); // } else { // throw new JCRException(JCRException.URL_INVALID, " URL is not JCR-url: " + path); // } // } else { // throw new JCRException(JCRException.URL_INVALID, " URL is not JCR-url: " + path); // } // // String strPath = jcrPath.toString(); // String[] auths = authAndPath[0].split(","); // Repository[] repositories = new Repository[auths.length]; // for (int i = 0; i < auths.length; i++) { // if (auths[i].isEmpty()) // continue; // // repositories[i] = JcrUtils.getRepository(scheme.concat("://").concat(auths[i]).concat("/").concat(strPath)); // } // // return repositories; // } private static String[] getUris(String path) throws JCRException { if (path == null) { throw new JCRException(JCRException.URL_INVALID, "Path is null"); } String[] schAndFile = path.split("://"); String scheme = schAndFile[0]; String[] authAndPath = schAndFile[1].split("/"); if(authAndPath.length > 3 || (authAndPath.length == 3 && !authAndPath[2].equals("server"))) { throw new JCRException(JCRException.URL_INVALID, " URL is invalid '" + path + "', it must be [scheme://authority1,authority2/context] or [scheme://authority1,authority2/context/server]" ); } // if (authAndPath.length != 2) { // throw new JCRException(JCRException.URL_INVALID, // " URL is invalid '" + path + "', it must be scheme://authority1,authority2/context"); // } String[] auths = authAndPath[0].split(","); String context = authAndPath[1]; String[] uris = new String[auths.length]; for (int i = 0; i < auths.length; i++) { if (auths[i].isEmpty()) continue; uris[i] = scheme.concat("://").concat(auths[i]).concat("/").concat(context); } return uris; } public void shutdown() { //scheduleBlackCheck.shutdownNow(); //scheduleWhiteCheck.shutdownNow(); FMSUtils.awaitTerminationAfterShutdown(scheduleBlackCheck); FMSUtils.awaitTerminationAfterShutdown(scheduleWhiteCheck); } /** * @param oneFMSActive the oneFMSActive to set */ public void setOneFMSActive(OneFMSActive oneFMSActive) { this.oneFMSActive = oneFMSActive; } public class RepositoryInfo { private Repository repository; private String uri; //private Node nodeToUse; private String folderName; private AtomicLong counterFile; private String prefix; private Node nodeToUse; /** * @param repository * @param uri * @throws MalformedURLException */ public RepositoryInfo(Repository repository, String uri) throws MalformedURLException { super(); this.repository = repository; this.uri = uri; this.prefix = new URL(uri).getHost() + "_"; counterFile = new AtomicLong(); } /** * @return the prefix */ public String getPrefix() { return prefix; } public long getCounterFile() { LOGGER.info("Counter file {}", counterFile.get()); return counterFile.get(); } public long incrementAndGetCounterFile() { return counterFile.incrementAndGet(); } public void setCounterFile(AtomicLong counterFile) { this.counterFile = counterFile; } public void setCounterFile(long counterFile) { this.counterFile.set(counterFile); } public String getFolderName() { return folderName; } public void setFolderName(String folderName) { this.folderName = folderName; } public Repository getRepository() { return repository; } /** * @param nodeToUse the nodeToUse to set */ public void setNodeToUse(Node nodeToUse) { this.nodeToUse = nodeToUse; } /** * @return the nodeToUse */ public Node getNodeToUse() { return nodeToUse; } // public void setRepository(Repository repository) { // this.repository = repository; // } /** * @return the uri */ public String getUri() { return uri; } public Node getNodeUse(SimpleCredentials credentials, String wsName) throws PathNotFoundException, LoginException, NoSuchWorkspaceException, RepositoryException { return repository.login(credentials, wsName).getRootNode().getNode(folderName); } } public interface OneFMSActive{ //void onload(Repository rp); void onAddWhite(RepositoryInfo rpInfo) throws LoginException, JCRException, RepositoryException; } // /** // * @param keyUse // * @param i // */ // public void setCounterFile(Integer key, long i) { // // TODO Auto-generated method stub // RepositoryInfo value = whiteList.get(key); // value.counterFile.set(i); // whiteList.replace(key, value); // } // // /** // * @param keyUse // * @param folderName // */ // public void setWhiteFolderName(Integer key, String folderName) { // // TODO Auto-generated method stub // RepositoryInfo value = whiteList.get(key); // value.folderName = folderName; // whiteList.replace(key, value); // // } }