Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
Service as a function allowing teams to quickly expose microserviceAPIs without needing to spend time
worrying about how they are deployed, consumed, etc.
/*
* Copyright 2021 IBM Corporation
*
* 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.
*/
package com.ibm.watson.litelinks.client;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.ibm.watson.litelinks.ThreadPoolHelper;
import com.ibm.watson.litelinks.ServiceProperties;
import com.ibm.watson.litelinks.server.ZookeeperWatchedService;
import com.ibm.watson.zk.ZookeeperClient;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.imps.CuratorFrameworkState;
import org.apache.curator.framework.recipes.cache.ChildData;
import org.apache.curator.framework.recipes.cache.NodeCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCache;
import org.apache.curator.framework.recipes.cache.PathChildrenCache.StartMode;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheEvent;
import org.apache.curator.framework.recipes.cache.PathChildrenCacheListener;
import org.apache.zookeeper.KeeperException;
import org.apache.zookeeper.data.Stat;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Properties;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static com.ibm.watson.litelinks.server.ZookeeperWatchedService.getServicePath;
/**
* Zookeeper-based service discovery client implementation
*/
public class ZookeeperServiceRegistry implements ServiceRegistryClient {
public final String connString;
public ZookeeperServiceRegistry(String connString) {
// if(connString == null) throw new IllegalArgumentException();
this.connString = ZookeeperClient.resolveConnString(connString);
}
@Override
public ServiceWatcher newServiceWatcher(String serviceName) {
return new ZookeeperServiceWatcher(serviceName);
}
private static final Logger logger = LoggerFactory.getLogger(ZookeeperServiceWatcher.class);
public static final int CONF_UNAVAILABLE_TIMEOUT_SECS = 3;
private static final int MAX_THREADS = 32;
private static final ThreadPoolExecutor sharedThreadPool =
ThreadPoolHelper.newThreadPool(1, MAX_THREADS, 3, TimeUnit.HOURS,
ThreadPoolHelper.threadFactory("ll-zk-discovery-thread-%d"));
protected static final Listener.Server[] NO_SERVERS = new Listener.Server[0];
/**
*
*/
public final class ZookeeperServiceWatcher extends ServiceWatcher implements PathChildrenCacheListener {
/* Soon, the NodeCache & PathChildrenCache will likely be replaced by a single TreeCache
*/
private final String serviceName, zkPath;
private final CuratorFramework curator; // curator wraps zookeeper client
private final NodeCache nodeCache; //this is the node cache for this service
private final PathChildrenCache childCache; //this is the child (instance) cache for this service
private final SerializingExecutorService cacheExecutor; // serialized executor used by the caches
private boolean childCacheStarted; // non-volatile optimization
private volatile boolean closed;
private final SettableFuture initFuture = SettableFuture.create();
private volatile Map