Tabnine Logo
DiscoveryTreeNode
Code IndexAdd Tabnine to your IDE (free)

How to use
DiscoveryTreeNode
in
org.apache.servicecomb.serviceregistry.discovery

Best Java code snippets using org.apache.servicecomb.serviceregistry.discovery.DiscoveryTreeNode (Showing top 20 results out of 315)

origin: apache/servicecomb-java-chassis

 @Override
 public void init(DiscoveryContext context, DiscoveryTreeNode parent) {
  Map<String, MicroserviceInstance> instances = parent.data();
  Map<String, MicroserviceInstance> filteredServers = new HashMap<>();
  for (String key : instances.keySet()) {
   MicroserviceInstance instance = instances.get(key);
   if (MicroserviceInstanceStatus.UP == instance.getStatus()) {
    filteredServers.put(key, instance);
   }
  }

  if (filteredServers.isEmpty()) {
   return;
  }
  DiscoveryTreeNode child = new DiscoveryTreeNode().subName(parent, UP_INSTANCES).data(filteredServers);
  parent.child(UP_INSTANCES, child);
 }
}
origin: apache/servicecomb-java-chassis

@Override
protected void init(DiscoveryContext context, DiscoveryTreeNode parent) {
 MicroserviceInstance myself = RegistryUtils.getMicroserviceInstance();
 Map<String, MicroserviceInstance> instancesRegionAndAZMatch = new HashMap<>();
 Map<String, MicroserviceInstance> instancesAZMatch = new HashMap<>();
 Map<String, MicroserviceInstance> instancesNoMatch = new HashMap<>();
 Map<String, MicroserviceInstance> instances = parent.data();
 for (String id : instances.keySet()) {
  MicroserviceInstance target = instances.get(id);
  if (regionAndAZMatch(myself, target)) {
   instancesRegionAndAZMatch.put(id, target);
  } else if (regionMatch(myself, target)) {
   instancesAZMatch.put(id, target);
  } else {
   instancesNoMatch.put(id, target);
  }
 }
 Map<String, DiscoveryTreeNode> children = new HashMap<>();
 children.put(GROUP_RegionAndAZMatch, new DiscoveryTreeNode()
   .subName(parent, GROUP_RegionAndAZMatch)
   .data(instancesRegionAndAZMatch));
 children.put(GROUP_instancesAZMatch, new DiscoveryTreeNode()
   .subName(parent, GROUP_instancesAZMatch)
   .data(instancesAZMatch));
 children.put(GROUP_instancesNoMatch, new DiscoveryTreeNode()
   .subName(parent, GROUP_instancesNoMatch)
   .data(instancesNoMatch));
 parent.children(children);
}
origin: apache/servicecomb-java-chassis

protected Map<String, DiscoveryTreeNode> initOperationNodes(DiscoveryTreeNode parent,
  Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap) {
 Map<String, DiscoveryTreeNode> tmpChildren = new ConcurrentHashMapEx<>();
 versionMap
   .keySet()
   .stream()
   .sorted(Comparator.comparing(MicroserviceVersion::getVersion))
   .forEach(meta -> {
    for (OperationMeta operationMeta : meta.getMicroserviceMeta().getOperations()) {
     tmpChildren.computeIfAbsent(operationMeta.getMicroserviceQualifiedName(), qualifiedName -> {
      VersionRule versionRule = VersionRuleUtils.getOrCreate(meta.getVersion().getVersion() + "+");
      return new DiscoveryTreeNode()
        .attribute(VERSION_RULE, versionRule)
        .subName(parent, versionRule.getVersionRule())
        .data(new HashMap<>());
     });
    }
   });
 return tmpChildren;
}
origin: apache/servicecomb-java-chassis

@Override
public DiscoveryTreeNode discovery(DiscoveryContext context, DiscoveryTreeNode parent) {
 if (!parent.childrenInited()) {
  synchronized (parent) {
   if (!parent.childrenInited()) {
    init(context, parent);
    parent.childrenInited(true);
   }
  }
 }
 String childName = findChildName(context, parent);
 DiscoveryTreeNode node = parent.child(childName);
 if (node == null) {
  LOGGER.warn("discovery filter {} return null.", this.getClass().getName());
  return new DiscoveryTreeNode().subName(parent, "empty").data(new HashMap<>());
 }
 return node;
}
origin: apache/servicecomb-java-chassis

protected void fillInstances(Map<String, DiscoveryTreeNode> operationNodes,
  Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap) {
 for (Entry<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> entry : versionMap.entrySet()) {
  for (DiscoveryTreeNode node : operationNodes.values()) {
   // versionRule is startFrom logic, so isAccept is enough
   VersionRule versionRule = node.attribute(VERSION_RULE);
   if (versionRule.isAccept(entry.getKey().getVersion())) {
    node.mapData().putAll(entry.getValue());
   }
  }
 }
}
origin: apache/servicecomb-java-chassis

 @SuppressWarnings("unchecked")
 protected DiscoveryTreeNode createDiscoveryTreeNode(DiscoveryContext context,
   DiscoveryTreeNode parent) {
  String serviceName = context.getInputParameters();

  List<Object> instances = new ArrayList<>();
  for (MicroserviceInstance instance : ((Map<String, MicroserviceInstance>) parent.data()).values()) {
   for (String endpoint : instance.getEndpoints()) {
    String scheme = endpoint.split(":", 2)[0];
    if (!scheme.equalsIgnoreCase("rest")) {
     LOGGER.info("Endpoint {} is not supported in Spring Cloud, ignoring.", endpoint);
     continue;
    }
    URIEndpointObject uri = new URIEndpointObject(endpoint);
    instances.add(instanceFactory.createInstance(serviceName, uri));
   }
  }

  return new DiscoveryTreeNode()
    .subName(parent, serviceName)
    .data(instances);
 }
};
origin: apache/servicecomb-java-chassis

@Override
public DiscoveryTreeNode discovery(DiscoveryContext context, DiscoveryTreeNode parent) {
 Map<String, MicroserviceInstance> instances = parent.data();
 Invocation invocation = context.getInputParameters();
 if (!Configuration.INSTANCE.isIsolationFilterOpen(invocation.getMicroserviceName())) {
  return parent;
 }
 Map<String, MicroserviceInstance> filteredServers = new HashMap<>();
 for (String key : instances.keySet()) {
  MicroserviceInstance instance = instances.get(key);
  if (allowVisit(invocation, instance)) {
   filteredServers.put(key, instance);
  }
 }
 DiscoveryTreeNode child = new DiscoveryTreeNode();
 if (filteredServers.isEmpty() && DynamicPropertyFactory.getInstance()
   .getBooleanProperty("servicecomb.loadbalance.filter.isolation.emptyInstanceProtectionEnabled", false).get()) {
  LOGGER.warn("All servers have been isolated, allow one of them based on load balance rule.");
  child.data(instances);
 } else {
  child.data(filteredServers);
 }
 parent.child("filterred", child);
 return child;
}
origin: apache/servicecomb-java-chassis

public DiscoveryTreeNode discovery(DiscoveryContext context, VersionedCache inputCache) {
 DiscoveryTreeNode tmpRoot = getOrCreateRoot(inputCache);
 DiscoveryTreeNode parent = tmpRoot.children()
   .computeIfAbsent(inputCache.name(), name -> new DiscoveryTreeNode().fromCache(inputCache));
 return doDiscovery(context, parent);
}
origin: apache/servicecomb-java-chassis

@Override
public void init(DiscoveryContext context, DiscoveryTreeNode parent) {
 Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap =
   groupByVersion(context.getInputParameters(), parent.data());
 Map<String, DiscoveryTreeNode> operationNodes = initOperationNodes(parent, versionMap);
 fillInstances(operationNodes, versionMap);
 parent.children(operationNodes);
}
origin: apache/servicecomb-java-chassis

protected DiscoveryTreeNode getOrCreateRoot(VersionedCache inputCache) {
 DiscoveryTreeNode tmpRoot = root;
 if (isMatch(tmpRoot, inputCache)) {
  return tmpRoot;
 }
 synchronized (lock) {
  if (isExpired(root, inputCache)) {
   // not initialized or inputCache newer than root, create new root
   root = new DiscoveryTreeNode().cacheVersion(inputCache.cacheVersion());
   return root;
  }
  if (root.isSameVersion(inputCache)) {
   // reuse root directly
   return root;
  }
 }
 // root newer than inputCache, it's a minimal probability event:
 // 1) thread 1, use v1 inputCache, run into getOrCreateRoot, but did not run any code yet, suspend and switch to thread 2
 // 2) thread 2, use v2 inputCache, v2 > v1, create new root
 // 3) thread 1 go on, then root is newer than inputCache
 //    but if create old children in new version root, it's a wrong logic
 // so just create a temporary root for the inputCache, DO NOT assign to root
 return new DiscoveryTreeNode().cacheVersion(inputCache.cacheVersion());
}
origin: apache/servicecomb-java-chassis

@Override
public DiscoveryTreeNode discovery(DiscoveryContext context, DiscoveryTreeNode parent) {
 String expectTransportName = findTransportName(context, parent);
 return parent.children()
   .computeIfAbsent(expectTransportName, etn -> createDiscoveryTreeNode(expectTransportName, context, parent));
}
origin: apache/servicecomb-java-chassis

 public DiscoveryTreeNode fromCache(VersionedCache other) {
  this.cacheVersion = other.cacheVersion();
  this.name = other.name();
  this.data(other.data());
  return this;
 }
}
origin: org.apache.servicecomb/service-registry

@Override
public DiscoveryTreeNode discovery(DiscoveryContext context, DiscoveryTreeNode parent) {
 if (!parent.childrenInited()) {
  synchronized (parent) {
   if (!parent.childrenInited()) {
    init(context, parent);
    parent.childrenInited(true);
   }
  }
 }
 String childName = findChildName(context, parent);
 return parent.child(childName);
}
origin: apache/servicecomb-java-chassis

@SuppressWarnings("unchecked")
protected DiscoveryTreeNode createDiscoveryTreeNode(String expectTransportName, DiscoveryContext context,
  DiscoveryTreeNode parent) {
 List<Object> endpoints = new ArrayList<>();
 for (MicroserviceInstance instance : ((Map<String, MicroserviceInstance>) parent.data()).values()) {
  for (String endpoint : instance.getEndpoints()) {
   try {
    URI uri = URI.create(endpoint);
    String transportName = uri.getScheme();
    if (!isTransportNameMatch(transportName, expectTransportName)) {
     continue;
    }
    Object objEndpoint = createEndpoint(transportName, endpoint, instance);
    if (objEndpoint == null) {
     continue;
    }
    endpoints.add(objEndpoint);
   } catch (Exception e) {
    LOGGER.warn("unrecognized address find, ignore {}.", endpoint);
   }
  }
 }
 return new DiscoveryTreeNode()
   .subName(parent, expectTransportName)
   .data(endpoints);
}
origin: org.apache.servicecomb/handler-loadbalance

@Override
public DiscoveryTreeNode discovery(DiscoveryContext context, DiscoveryTreeNode parent) {
 Map<String, MicroserviceInstance> instances = parent.data();
 Invocation invocation = context.getInputParameters();
 if (!Configuration.INSTANCE.isIsolationFilterOpen(invocation.getMicroserviceName())) {
  return parent;
 }
 Map<String, MicroserviceInstance> filteredServers = new HashMap<>();
 for (String key : instances.keySet()) {
  MicroserviceInstance instance = instances.get(key);
  if (allowVisit(invocation, instance)) {
   filteredServers.put(key, instance);
  }
 }
 DiscoveryTreeNode child = new DiscoveryTreeNode().data(filteredServers);
 parent.child("filterred", child);
 return child;
}
origin: org.apache.servicecomb/service-registry

public DiscoveryTreeNode discovery(DiscoveryContext context, VersionedCache inputCache) {
 DiscoveryTreeNode tmpRoot = getOrCreateRoot(inputCache);
 DiscoveryTreeNode parent = tmpRoot.children()
   .computeIfAbsent(inputCache.name(), name -> new DiscoveryTreeNode().fromCache(inputCache));
 return doDiscovery(context, parent);
}
origin: org.apache.servicecomb/java-chassis-core

@Override
public void init(DiscoveryContext context, DiscoveryTreeNode parent) {
 Map<MicroserviceVersionMeta, Map<String, MicroserviceInstance>> versionMap =
   groupByVersion(context.getInputParameters(), parent.data());
 Map<String, DiscoveryTreeNode> operationNodes = initOperationNodes(parent, versionMap);
 fillInstances(operationNodes, versionMap);
 parent.children(operationNodes);
}
origin: org.apache.servicecomb/service-registry

protected DiscoveryTreeNode getOrCreateRoot(VersionedCache inputCache) {
 DiscoveryTreeNode tmpRoot = root;
 if (isMatch(tmpRoot, inputCache)) {
  return tmpRoot;
 }
 synchronized (lock) {
  if (isExpired(root, inputCache)) {
   // not initialized or inputCache newer than root, create new root
   root = new DiscoveryTreeNode().cacheVersion(inputCache.cacheVersion());
   return root;
  }
  if (root.isSameVersion(inputCache)) {
   // reuse root directly
   return root;
  }
 }
 // root newer than inputCache, it's a minimal probability event:
 // 1) thread 1, use v1 inputCache, run into getOrCreateRoot, but did not run any code yet, suspend and switch to thread 2
 // 2) thread 2, use v2 inputCache, v2 > v1, create new root
 // 3) thread 1 go on, then root is newer than inputCache
 //    but if create old children in new version root, it's a wrong logic
 // so just create a temporary root for the inputCache, DO NOT assign to root
 return new DiscoveryTreeNode().cacheVersion(inputCache.cacheVersion());
}
origin: apache/servicecomb-java-chassis

@Override
public DiscoveryTreeNode discovery(DiscoveryContext context, DiscoveryTreeNode parent) {
 return parent.children()
   .computeIfAbsent(context.getInputParameters(), etn -> createDiscoveryTreeNode(context, parent));
}
origin: org.apache.servicecomb/service-registry

 public DiscoveryTreeNode fromCache(VersionedCache other) {
  this.cacheVersion = other.cacheVersion();
  this.name = other.name();
  this.data(other.data());
  return this;
 }
}
org.apache.servicecomb.serviceregistry.discoveryDiscoveryTreeNode

Most used methods

  • <init>
  • children
  • data
  • subName
  • child
  • attribute
  • cacheVersion
  • childrenInited
  • fromCache
  • isEmpty
  • isSameVersion
  • level
  • isSameVersion,
  • level,
  • mapData,
  • name

Popular in Java

  • Finding current android device location
  • startActivity (Activity)
  • setScale (BigDecimal)
  • getExternalFilesDir (Context)
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • Cipher (javax.crypto)
    This class provides access to implementations of cryptographic ciphers for encryption and decryption
  • Servlet (javax.servlet)
    Defines methods that all servlets must implement. A servlet is a small Java program that runs within
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now