Example #1
0
 private List<String> getCurrentServerIds(boolean nag, boolean lagged) {
   try (Jedis jedis = pool.getResource()) {
     long time = getRedisTime(jedis.time());
     int nagTime = 0;
     if (nag) {
       nagTime = nagAboutServers.decrementAndGet();
       if (nagTime <= 0) {
         nagAboutServers.set(10);
       }
     }
     ImmutableList.Builder<String> servers = ImmutableList.builder();
     Map<String, String> heartbeats = jedis.hgetAll("heartbeats");
     for (Map.Entry<String, String> entry : heartbeats.entrySet()) {
       try {
         long stamp = Long.parseLong(entry.getValue());
         if (lagged ? time >= stamp + 30 : time <= stamp + 30) servers.add(entry.getKey());
         else if (nag && nagTime <= 0) {
           getLogger()
               .severe(
                   entry.getKey()
                       + " is "
                       + (time - stamp)
                       + " seconds behind! (Time not synchronized or server down?)");
         }
       } catch (NumberFormatException ignored) {
       }
     }
     return servers.build();
   } catch (JedisConnectionException e) {
     getLogger().log(Level.SEVERE, "Unable to fetch server IDs", e);
     return Collections.singletonList(configuration.getServerId());
   }
 }
Example #2
0
 private ImmutableMap<ColumnIdent, IndexReferenceInfo> createIndexDefinitions() {
   ImmutableMap.Builder<ColumnIdent, IndexReferenceInfo> builder = ImmutableMap.builder();
   for (Map.Entry<ColumnIdent, IndexReferenceInfo.Builder> entry : indicesBuilder.entrySet()) {
     builder.put(entry.getKey(), entry.getValue().build());
   }
   indices = builder.build();
   return indices;
 }
  public String printRelocatingRanges() {
    StringBuilder sb = new StringBuilder();

    for (Map.Entry<Token, InetAddress> entry : relocatingTokens.entrySet())
      sb.append(String.format("%s:%s%n", entry.getKey(), entry.getValue()));

    return sb.toString();
  }
Example #4
0
 public List<Range> getPendingRanges(String table, InetAddress endpoint) {
   List<Range> ranges = new ArrayList<Range>();
   for (Map.Entry<Range, InetAddress> entry : getPendingRangesMM(table).entries()) {
     if (entry.getValue().equals(endpoint)) {
       ranges.add(entry.getKey());
     }
   }
   return ranges;
 }
  public static List<NameValuePair> convertAttributesToNameValuePair(
      Map<String, String> aAttributes) {
    List<NameValuePair> myNameValuePairs = Lists.newArrayList();

    for (Map.Entry<String, String> myEntry : aAttributes.entrySet()) {
      myNameValuePairs.add(new BasicNameValuePair(myEntry.getKey(), myEntry.getValue()));
    }
    return myNameValuePairs;
  }
 /** 按照要求打印结果 */
 public void printStackInfo(Multimap<String, ThreadInfo> w_IdMap) {
   List<Map.Entry<String, Integer>> orderList = getOrderList(w_IdMap);
   for (Map.Entry<String, Integer> entry : orderList) {
     logger.info(entry.getKey() + "," + entry.getValue()); // 输出wait_id 对应个数
     Collection<ThreadInfo> threads = w_IdMap.get(entry.getKey()); // 输出wait_id对应的ThreadInfo集合
     for (ThreadInfo thread : threads) {
       logger.info("{}", thread);
     }
     logger.info("");
   }
 }
 /** @return an endpoint to token multimap representation of tokenToEndpointMap (a copy) */
 public Multimap<InetAddress, Token> getEndpointToTokenMapForReading() {
   lock.readLock().lock();
   try {
     Multimap<InetAddress, Token> cloned = HashMultimap.create();
     for (Map.Entry<Token, InetAddress> entry : tokenToEndpointMap.entrySet())
       cloned.put(entry.getValue(), entry.getKey());
     return cloned;
   } finally {
     lock.readLock().unlock();
   }
 }
Example #8
0
  private void resolveAnnotationConstructors(@NotNull TopDownAnalysisContext c) {
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        c.getDeclaredClasses().entrySet()) {
      JetClassOrObject classOrObject = entry.getKey();
      MutableClassDescriptor classDescriptor = (MutableClassDescriptor) entry.getValue();

      if (classOrObject instanceof JetClass && DescriptorUtils.isAnnotationClass(classDescriptor)) {
        processPrimaryConstructor(c, classDescriptor, (JetClass) classOrObject);
      }
    }
  }
Example #9
0
 private void resolveAnnotationStubsOnClassesAndConstructors(@NotNull TopDownAnalysisContext c) {
   for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
       c.getDeclaredClasses().entrySet()) {
     JetModifierList modifierList = entry.getKey().getModifierList();
     if (modifierList != null) {
       MutableClassDescriptor descriptor = (MutableClassDescriptor) entry.getValue();
       descriptor.addAnnotations(
           annotationResolver.resolveAnnotationsWithoutArguments(
               descriptor.getScopeForClassHeaderResolution(), modifierList, trace));
     }
   }
 }
Example #10
0
  public String printPendingRanges() {
    StringBuilder sb = new StringBuilder();

    for (Map.Entry<String, Multimap<Range, InetAddress>> entry : pendingRanges.entrySet()) {
      for (Map.Entry<Range, InetAddress> rmap : entry.getValue().entries()) {
        sb.append(rmap.getValue() + ":" + rmap.getKey());
        sb.append(System.getProperty("line.separator"));
      }
    }

    return sb.toString();
  }
Example #11
0
  /** extracts index definitions as well */
  @SuppressWarnings("unchecked")
  private void internalExtractColumnDefinitions(
      ColumnIdent columnIdent, Map<String, Object> propertiesMap) {
    if (propertiesMap == null) {
      return;
    }

    for (Map.Entry<String, Object> columnEntry : propertiesMap.entrySet()) {
      Map<String, Object> columnProperties = (Map) columnEntry.getValue();
      DataType columnDataType = getColumnDataType(columnProperties);
      ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey());

      columnProperties = furtherColumnProperties(columnProperties);
      ReferenceInfo.IndexType columnIndexType = getColumnIndexType(columnProperties);
      if (columnDataType == DataTypes.OBJECT
          || (columnDataType.id() == ArrayType.ID
              && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) {
        ColumnPolicy columnPolicy = ColumnPolicy.of(columnProperties.get("dynamic"));
        add(newIdent, columnDataType, columnPolicy, ReferenceInfo.IndexType.NO, false);

        if (columnProperties.get("properties") != null) {
          // walk nested
          internalExtractColumnDefinitions(
              newIdent, (Map<String, Object>) columnProperties.get("properties"));
        }
      } else if (columnDataType != DataTypes.NOT_SUPPORTED) {
        List<String> copyToColumns = getNested(columnProperties, "copy_to");

        // extract columns this column is copied to, needed for indices
        if (copyToColumns != null) {
          for (String copyToColumn : copyToColumns) {
            ColumnIdent targetIdent = ColumnIdent.fromPath(copyToColumn);
            IndexReferenceInfo.Builder builder = getOrCreateIndexBuilder(targetIdent);
            builder.addColumn(
                newInfo(newIdent, columnDataType, ColumnPolicy.DYNAMIC, columnIndexType));
          }
        }
        // is it an index?
        if (indicesMap.containsKey(newIdent.fqn())) {
          IndexReferenceInfo.Builder builder = getOrCreateIndexBuilder(newIdent);
          builder
              .indexType(columnIndexType)
              .ident(new ReferenceIdent(ident, newIdent))
              .analyzer((String) columnProperties.get("analyzer"));
        } else {
          add(newIdent, columnDataType, columnIndexType);
        }
      }
    }
  }
Example #12
0
  private void createFunctionsForDataClasses(@NotNull TopDownAnalysisContext c) {
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        c.getDeclaredClasses().entrySet()) {
      JetClassOrObject klass = entry.getKey();
      MutableClassDescriptor classDescriptor = (MutableClassDescriptor) entry.getValue();

      if (klass instanceof JetClass
          && klass.hasPrimaryConstructor()
          && KotlinBuiltIns.getInstance().isData(classDescriptor)) {
        ConstructorDescriptor constructor =
            DescriptorUtils.getConstructorOfDataClass(classDescriptor);
        createComponentFunctions(classDescriptor, constructor);
        createCopyFunction(classDescriptor, constructor);
      }
    }
  }
Example #13
0
  public String toString() {
    StringBuilder sb = new StringBuilder();
    lock.readLock().lock();
    try {
      Set<InetAddress> eps = tokenToEndPointMap.inverse().keySet();

      if (!eps.isEmpty()) {
        sb.append("Normal Tokens:");
        sb.append(System.getProperty("line.separator"));
        for (InetAddress ep : eps) {
          sb.append(ep);
          sb.append(":");
          sb.append(tokenToEndPointMap.inverse().get(ep));
          sb.append(System.getProperty("line.separator"));
        }
      }

      if (!bootstrapTokens.isEmpty()) {
        sb.append("Bootstrapping Tokens:");
        sb.append(System.getProperty("line.separator"));
        for (Map.Entry<Token, InetAddress> entry : bootstrapTokens.entrySet()) {
          sb.append(entry.getValue() + ":" + entry.getKey());
          sb.append(System.getProperty("line.separator"));
        }
      }

      if (!leavingEndPoints.isEmpty()) {
        sb.append("Leaving EndPoints:");
        sb.append(System.getProperty("line.separator"));
        for (InetAddress ep : leavingEndPoints) {
          sb.append(ep);
          sb.append(System.getProperty("line.separator"));
        }
      }

      if (!pendingRanges.isEmpty()) {
        sb.append("Pending Ranges:");
        sb.append(System.getProperty("line.separator"));
        sb.append(printPendingRanges());
      }
    } finally {
      lock.readLock().unlock();
    }

    return sb.toString();
  }
  /**
   * Create a copy of TokenMetadata with tokenToEndpointMap reflecting situation after all current
   * leave, move, and relocate operations have finished.
   *
   * @return new token metadata
   */
  public TokenMetadata cloneAfterAllSettled() {
    lock.readLock().lock();

    try {
      TokenMetadata metadata = cloneOnlyTokenMap();

      for (InetAddress endpoint : leavingEndpoints) metadata.removeEndpoint(endpoint);

      for (Pair<Token, InetAddress> pair : movingEndpoints)
        metadata.updateNormalToken(pair.left, pair.right);

      for (Map.Entry<Token, InetAddress> relocating : relocatingTokens.entrySet())
        metadata.updateNormalToken(relocating.getKey(), relocating.getValue());

      return metadata;
    } finally {
      lock.readLock().unlock();
    }
  }
Example #15
0
  private void resolveFunctionAndPropertyHeaders(@NotNull TopDownAnalysisContext c) {
    for (Map.Entry<JetFile, WritableScope> entry : c.getFileScopes().entrySet()) {
      JetFile file = entry.getKey();
      WritableScope fileScope = entry.getValue();
      PackageLikeBuilder packageBuilder = c.getPackageFragments().get(file).getBuilder();

      resolveFunctionAndPropertyHeaders(
          c, file.getDeclarations(), fileScope, fileScope, fileScope, packageBuilder);
    }
    for (Map.Entry<JetClassOrObject, ClassDescriptorWithResolutionScopes> entry :
        c.getDeclaredClasses().entrySet()) {
      JetClassOrObject classOrObject = entry.getKey();
      MutableClassDescriptor classDescriptor = (MutableClassDescriptor) entry.getValue();

      resolveFunctionAndPropertyHeaders(
          c,
          classOrObject.getDeclarations(),
          classDescriptor.getScopeForMemberDeclarationResolution(),
          classDescriptor.getScopeForInitializerResolution(),
          classDescriptor.getScopeForMemberDeclarationResolution(),
          classDescriptor.getBuilder());
    }

    // TODO : Extensions
  }
Example #16
0
 @Override
 public Map<String, Object> getValuesDeep() {
   final Tag tag = this.findLastTag(this.path, false);
   if (!(tag instanceof CompoundTag)) {
     return Collections.emptyMap();
   }
   final Queue<Node> node =
       new ArrayDeque<Node>(
           (Collection<? extends Node>) ImmutableList.of((Object) new Node(tag)));
   final Map<String, Object> values = (Map<String, Object>) Maps.newHashMap();
   while (!node.isEmpty()) {
     final Node root = node.poll();
     for (final Map.Entry<String, Tag> entry : root.values.entrySet()) {
       final String key = this.createRelativeKey(root.parent, entry.getKey());
       if (entry.getValue() instanceof CompoundTag) {
         node.add(new Node(key, entry.getValue()));
       } else {
         values.put(key, entry.getValue().getValue());
       }
     }
   }
   return values;
 }
Example #17
0
 private ImmutableMap<ColumnIdent, String> getAnalyzers(
     ColumnIdent columnIdent, Map<String, Object> propertiesMap) {
   ImmutableMap.Builder<ColumnIdent, String> builder = ImmutableMap.builder();
   for (Map.Entry<String, Object> columnEntry : propertiesMap.entrySet()) {
     Map<String, Object> columnProperties = (Map) columnEntry.getValue();
     DataType columnDataType = getColumnDataType(columnProperties);
     ColumnIdent newIdent = childIdent(columnIdent, columnEntry.getKey());
     columnProperties = furtherColumnProperties(columnProperties);
     if (columnDataType == DataTypes.OBJECT
         || (columnDataType.id() == ArrayType.ID
             && ((ArrayType) columnDataType).innerType() == DataTypes.OBJECT)) {
       if (columnProperties.get("properties") != null) {
         builder.putAll(
             getAnalyzers(newIdent, (Map<String, Object>) columnProperties.get("properties")));
       }
     }
     String analyzer = (String) columnProperties.get("analyzer");
     if (analyzer != null) {
       builder.put(newIdent, analyzer);
     }
   }
   return builder.build();
 }