Example #1
0
 // Warning: scrubTimestamp MUST be the start timestamp of the hard delete transaction that
 // triggers
 // the scrubbing; we need this start timestamp to check whether the hard delete transaction was
 // actually committed before we do any scrubbing
 /* package */ void queueCellsForScrubbing(
     Multimap<String, Cell> tableNameToCell, long scrubTimestamp) {
   if (tableNameToCell.isEmpty()) {
     return;
   }
   scrubberStore.queueCellsForScrubbing(tableNameToCell, scrubTimestamp, batchSizeSupplier.get());
 }
 private List<Cluster> doPrivilegedLookup(String partitionName, String vmTypeName)
     throws NotEnoughResourcesException {
   if (Partition.DEFAULT_NAME.equals(partitionName)) {
     Iterable<Cluster> authorizedClusters =
         Iterables.filter(
             Clusters.getInstance().listValues(),
             RestrictedTypes.filterPrivilegedWithoutOwner());
     Multimap<VmTypeAvailability, Cluster> sorted = TreeMultimap.create();
     for (Cluster c : authorizedClusters) {
       sorted.put(c.getNodeState().getAvailability(vmTypeName), c);
     }
     if (sorted.isEmpty()) {
       throw new NotEnoughResourcesException(
           "Not enough resources: no availability zone is available in which you have permissions to run instances.");
     } else {
       return Lists.newArrayList(sorted.values());
     }
   } else {
     ServiceConfiguration ccConfig =
         Topology.lookup(ClusterController.class, Partitions.lookupByName(partitionName));
     Cluster cluster = Clusters.lookup(ccConfig);
     if (cluster == null) {
       throw new NotEnoughResourcesException("Can't find cluster " + partitionName);
     }
     if (!RestrictedTypes.filterPrivilegedWithoutOwner().apply(cluster)) {
       throw new NotEnoughResourcesException("Not authorized to use cluster " + partitionName);
     }
     return Lists.newArrayList(cluster);
   }
 }
Example #3
0
 public void transition(LoaderState desiredState) {
   LoaderState oldState = state;
   state = state.transition(!errors.isEmpty());
   if (state != desiredState) {
     Throwable toThrow = null;
     FMLLog.severe(
         "Fatal errors were detected during the transition from %s to %s. Loading cannot continue",
         oldState, desiredState);
     StringBuilder sb = new StringBuilder();
     printModStates(sb);
     FMLLog.getLogger().severe(sb.toString());
     if (errors.size() > 0) {
       FMLLog.severe("The following problems were captured during this phase");
       for (Entry<String, Throwable> error : errors.entries()) {
         FMLLog.log(Level.SEVERE, error.getValue(), "Caught exception from %s", error.getKey());
         if (error.getValue() instanceof IFMLHandledException) {
           toThrow = error.getValue();
         } else if (toThrow == null) {
           toThrow = error.getValue();
         }
       }
     } else {
       FMLLog.severe(
           "The ForgeModLoader state engine has become corrupted. Probably, a state was missed by and invalid modification to a base class"
               + "ForgeModLoader depends on. This is a critical error and not recoverable. Investigate any modifications to base classes outside of"
               + "ForgeModLoader, especially Optifine, to see if there are fixes available.");
       throw new RuntimeException("The ForgeModLoader state engine is invalid");
     }
     if (toThrow != null && toThrow instanceof RuntimeException) {
       throw (RuntimeException) toThrow;
     } else {
       throw new LoaderException(toThrow);
     }
   }
 }
  /**
   * Update token map with a set of token/endpoint pairs in normal state.
   *
   * <p>Prefer this whenever there are multiple pairs to update, as each update (whether a single or
   * multiple) is expensive (CASSANDRA-3831).
   *
   * @param endpointTokens
   */
  public void updateNormalTokens(Multimap<InetAddress, Token> endpointTokens) {
    if (endpointTokens.isEmpty()) return;

    lock.writeLock().lock();
    try {
      boolean shouldSortTokens = false;
      for (InetAddress endpoint : endpointTokens.keySet()) {
        Collection<Token> tokens = endpointTokens.get(endpoint);

        assert tokens != null && !tokens.isEmpty();

        bootstrapTokens.removeValue(endpoint);
        tokenToEndpointMap.removeValue(endpoint);
        topology.addEndpoint(endpoint);
        leavingEndpoints.remove(endpoint);
        removeFromMoving(endpoint); // also removing this endpoint from moving

        for (Token token : tokens) {
          InetAddress prev = tokenToEndpointMap.put(token, endpoint);
          if (!endpoint.equals(prev)) {
            if (prev != null)
              logger.warn("Token {} changing ownership from {} to {}", token, prev, endpoint);
            shouldSortTokens = true;
          }
        }
      }

      if (shouldSortTokens) sortedTokens = sortTokens();
    } finally {
      lock.writeLock().unlock();
    }
  }
Example #5
0
  /**
   * ************************************************************************************************************
   * Add properties like adjectives to the given noun.
   *
   * @param noun
   * @return
   */
  private String addProperties(String noun) {
    if (entityProperties.isEmpty() || entityProperties.get(noun).isEmpty()) {
      return noun;
    }

    String retVal = noun;
    for (SumoProcessEntityProperty prop : entityProperties.get(noun)) {
      retVal = prop.getSurfaceFormForNoun(retVal, kb);
    }
    return retVal;
  }
Example #6
0
 private void deleteCellsAtTimestamps(
     TransactionManager txManager,
     String tableName,
     Multimap<Cell, Long> cellToTimestamp,
     Transaction.TransactionType transactionType) {
   if (!cellToTimestamp.isEmpty()) {
     for (Follower follower : followers) {
       follower.run(txManager, tableName, cellToTimestamp.keySet(), transactionType);
     }
     keyValueService.addGarbageCollectionSentinelValues(tableName, cellToTimestamp.keySet());
     keyValueService.delete(tableName, cellToTimestamp);
   }
 }
  private void sweepCells(
      String tableName, Multimap<Cell, Long> cellTsPairsToSweep, Set<Cell> sentinelsToAdd) {
    if (cellTsPairsToSweep.isEmpty()) {
      return;
    }

    for (Follower follower : followers) {
      follower.run(txManager, tableName, cellTsPairsToSweep.keySet(), TransactionType.HARD_DELETE);
    }
    if (!sentinelsToAdd.isEmpty()) {
      keyValueService.addGarbageCollectionSentinelValues(tableName, sentinelsToAdd);
    }
    keyValueService.delete(tableName, cellTsPairsToSweep);
  }
Example #8
0
 private void failFast(ChangeSet cs) throws ResourceConflictException {
   if (problems.isEmpty()) {
     return;
   }
   String msg =
       "Failed to submit "
           + cs.size()
           + " change"
           + (cs.size() > 1 ? "s" : "")
           + " due to the following problems:\n";
   List<String> ps = new ArrayList<>(problems.keySet().size());
   for (Change.Id id : problems.keySet()) {
     ps.add("Change " + id + ": " + Joiner.on("; ").join(problems.get(id)));
   }
   throw new ResourceConflictException(msg + Joiner.on('\n').join(ps));
 }
Example #9
0
 /**
  * Get SkyKeys for the FileValues for the given {@code pathFragments}. To do this, we look for a
  * package lookup node for each path fragment, since package lookup nodes contain the "root" of a
  * package. The returned SkyKeys correspond to FileValues that may not exist in the graph.
  */
 private Collection<SkyKey> getSkyKeysForFileFragments(Iterable<PathFragment> pathFragments) {
   Set<SkyKey> result = new HashSet<>();
   Multimap<PathFragment, PathFragment> currentToOriginal = ArrayListMultimap.create();
   for (PathFragment pathFragment : pathFragments) {
     currentToOriginal.put(pathFragment, pathFragment);
   }
   while (!currentToOriginal.isEmpty()) {
     Map<SkyKey, PathFragment> keys = new HashMap<>();
     for (PathFragment pathFragment : currentToOriginal.keySet()) {
       keys.put(
           PackageLookupValue.key(PackageIdentifier.createInDefaultRepo(pathFragment)),
           pathFragment);
     }
     Map<SkyKey, SkyValue> lookupValues = graph.getSuccessfulValues(keys.keySet());
     for (Map.Entry<SkyKey, SkyValue> entry : lookupValues.entrySet()) {
       PackageLookupValue packageLookupValue = (PackageLookupValue) entry.getValue();
       if (packageLookupValue.packageExists()) {
         PathFragment dir = keys.get(entry.getKey());
         Collection<PathFragment> originalFiles = currentToOriginal.get(dir);
         Preconditions.checkState(!originalFiles.isEmpty(), entry);
         for (PathFragment fileName : originalFiles) {
           result.add(
               FileValue.key(RootedPath.toRootedPath(packageLookupValue.getRoot(), fileName)));
         }
         currentToOriginal.removeAll(dir);
       }
     }
     Multimap<PathFragment, PathFragment> newCurrentToOriginal = ArrayListMultimap.create();
     for (PathFragment pathFragment : currentToOriginal.keySet()) {
       PathFragment parent = pathFragment.getParentDirectory();
       if (parent != null) {
         newCurrentToOriginal.putAll(parent, currentToOriginal.get(pathFragment));
       }
     }
     currentToOriginal = newCurrentToOriginal;
   }
   return result;
 }
  public void run(final ResultHandler<? super Void> handler) {
    if (operationDescriptors.isEmpty() && testClassNames.isEmpty() && testMethods.isEmpty()) {
      throw new TestExecutionException("No test declared for execution.");
    }
    final ConsumerOperationParameters operationParameters =
        operationParamsBuilder.setParameters(connectionParameters).build();
    final TestExecutionRequest testExecutionRequest =
        new TestExecutionRequest(
            operationDescriptors,
            ImmutableList.copyOf(testClassNames),
            ImmutableMultimap.copyOf(testMethods));
    connection.run(
        new ConsumerAction<Void>() {
          public ConsumerOperationParameters getParameters() {
            return operationParameters;
          }

          public Void run(ConsumerConnection connection) {
            connection.runTests(testExecutionRequest, getParameters());
            return null;
          }
        },
        new ResultHandlerAdapter(handler));
  }
Example #11
0
  /** Return a list of strings containing information about the item */
  @SideOnly(Side.CLIENT)
  public List getTooltip(EntityPlayer par1EntityPlayer, boolean par2) {
    ArrayList arraylist = new ArrayList();
    String s = this.getDisplayName();

    if (this.hasDisplayName()) {
      s = EnumChatFormatting.ITALIC + s + EnumChatFormatting.RESET;
    }

    int i;

    if (par2) {
      String s1 = "";

      if (s.length() > 0) {
        s = s + " (";
        s1 = ")";
      }

      i = Item.getIdFromItem(this.field_151002_e);

      if (this.getHasSubtypes()) {
        s =
            s
                + String.format(
                    "#%04d/%d%s",
                    new Object[] {Integer.valueOf(i), Integer.valueOf(this.itemDamage), s1});
      } else {
        s = s + String.format("#%04d%s", new Object[] {Integer.valueOf(i), s1});
      }
    } else if (!this.hasDisplayName() && this.field_151002_e == Items.filled_map) {
      s = s + " #" + this.itemDamage;
    }

    arraylist.add(s);
    this.field_151002_e.addInformation(this, par1EntityPlayer, arraylist, par2);

    if (this.hasTagCompound()) {
      NBTTagList nbttaglist = this.getEnchantmentTagList();

      if (nbttaglist != null) {
        for (i = 0; i < nbttaglist.tagCount(); ++i) {
          short short1 = nbttaglist.getCompoundTagAt(i).getShort("id");
          short short2 = nbttaglist.getCompoundTagAt(i).getShort("lvl");

          if (Enchantment.enchantmentsList[short1] != null) {
            arraylist.add(Enchantment.enchantmentsList[short1].getTranslatedName(short2));
          }
        }
      }

      if (this.stackTagCompound.hasKey("display", 10)) {
        NBTTagCompound nbttagcompound = this.stackTagCompound.getCompoundTag("display");

        if (nbttagcompound.hasKey("color", 3)) {
          if (par2) {
            arraylist.add(
                "Color: #" + Integer.toHexString(nbttagcompound.getInteger("color")).toUpperCase());
          } else {
            arraylist.add(EnumChatFormatting.ITALIC + StatCollector.translateToLocal("item.dyed"));
          }
        }

        if (nbttagcompound.func_150299_b("Lore") == 9) {
          NBTTagList nbttaglist1 = nbttagcompound.getTagList("Lore", 8);

          if (nbttaglist1.tagCount() > 0) {
            for (int j = 0; j < nbttaglist1.tagCount(); ++j) {
              arraylist.add(
                  EnumChatFormatting.DARK_PURPLE
                      + ""
                      + EnumChatFormatting.ITALIC
                      + nbttaglist1.getStringTagAt(j));
            }
          }
        }
      }
    }

    Multimap multimap = this.getAttributeModifiers();

    if (!multimap.isEmpty()) {
      arraylist.add("");
      Iterator iterator = multimap.entries().iterator();

      while (iterator.hasNext()) {
        Entry entry = (Entry) iterator.next();
        AttributeModifier attributemodifier = (AttributeModifier) entry.getValue();
        double d0 = attributemodifier.getAmount();
        double d1;

        if (attributemodifier.getOperation() != 1 && attributemodifier.getOperation() != 2) {
          d1 = attributemodifier.getAmount();
        } else {
          d1 = attributemodifier.getAmount() * 100.0D;
        }

        if (d0 > 0.0D) {
          arraylist.add(
              EnumChatFormatting.BLUE
                  + StatCollector.translateToLocalFormatted(
                      "attribute.modifier.plus." + attributemodifier.getOperation(),
                      new Object[] {
                        field_111284_a.format(d1),
                        StatCollector.translateToLocal("attribute.name." + (String) entry.getKey())
                      }));
        } else if (d0 < 0.0D) {
          d1 *= -1.0D;
          arraylist.add(
              EnumChatFormatting.RED
                  + StatCollector.translateToLocalFormatted(
                      "attribute.modifier.take." + attributemodifier.getOperation(),
                      new Object[] {
                        field_111284_a.format(d1),
                        StatCollector.translateToLocal("attribute.name." + (String) entry.getKey())
                      }));
        }
      }
    }

    if (this.hasTagCompound() && this.getTagCompound().getBoolean("Unbreakable")) {
      arraylist.add(EnumChatFormatting.BLUE + StatCollector.translateToLocal("item.unbreakable"));
    }

    if (par2 && this.isItemDamaged()) {
      arraylist.add(
          "Durability: "
              + (this.getMaxDamage() - this.getItemDamageForDisplay())
              + " / "
              + this.getMaxDamage());
    }
    ForgeEventFactory.onItemTooltip(this, par1EntityPlayer, arraylist, par2);

    return arraylist;
  }
  @Override
  public ASTNode transform(org.kframework.kil.Cell node) throws TransformerException {
    if (node.getContents() instanceof org.kframework.kil.Bag
        || node.getContents() instanceof org.kframework.kil.Cell) {
      List<org.kframework.kil.Term> contents;
      if (node.getContents() instanceof org.kframework.kil.Bag) {
        contents = new ArrayList<org.kframework.kil.Term>();
        KILtoBackendJavaKILTransformer.flattenBag(
            contents, ((org.kframework.kil.Bag) node.getContents()).getContents());
      } else {
        contents = Collections.singletonList(node.getContents());
      }

      Multimap<String, Cell> cells = HashMultimap.create();
      Variable variable = null;
      for (org.kframework.kil.Term term : contents) {
        if (term instanceof org.kframework.kil.Cell) {
          Cell cell = (Cell) term.accept(this);
          cells.put(cell.getLabel(), cell);
        } else if (variable == null
            && term instanceof org.kframework.kil.Variable
            && term.getSort().equals("Bag")) {
          variable = (Variable) term.accept(this);
        } else {
          throw new RuntimeException();
        }
      }

      // TODO(AndreiS): get the multiplicity
      boolean isStar = !cells.isEmpty() && cells.keySet().iterator().next().equals("thread");

      return new Cell<CellCollection>(node.getLabel(), new CellCollection(cells, variable, isStar));
    } else {
      Term content = (Term) node.getContents().accept(this);

      if (content instanceof KItem) {
        return new Cell<KItem>(node.getLabel(), (KItem) content);
      } else if (content instanceof Token) {
        return new Cell<Token>(node.getLabel(), (Token) content);
      } else if (content instanceof KSequence) {
        return new Cell<KSequence>(node.getLabel(), (KSequence) content);
      } else if (content instanceof KList) {
        return new Cell<KList>(node.getLabel(), (KList) content);
      } else if (content instanceof BuiltinList) {
        return new Cell<BuiltinList>(node.getLabel(), (BuiltinList) content);
        //            } else if (content instanceof ListUpdate) {
        //                return new Cell<ListUpdate>(node.getLabel(), (ListUpdate) content);
      } else if (content instanceof BuiltinSet) {
        return new Cell<BuiltinSet>(node.getLabel(), (BuiltinSet) content);
      } else if (content instanceof SetUpdate) {
        return new Cell<SetUpdate>(node.getLabel(), (SetUpdate) content);
      } else if (content instanceof BuiltinMap) {
        return new Cell<BuiltinMap>(node.getLabel(), (BuiltinMap) content);
      } else if (content instanceof MapUpdate) {
        return new Cell<MapUpdate>(node.getLabel(), (MapUpdate) content);
      } else if (content instanceof Variable) {
        return new Cell<Term>(node.getLabel(), content);
      } else {
        throw new RuntimeException();
      }
    }
  }
  public String toString(Reflections reflections) {
    if (reflections.getStore().get(TypesScanner.class).isEmpty()
        || reflections.getStore().get(TypeElementsScanner.class).isEmpty()) {
      if (log != null)
        log.warn("JavaCodeSerializer needs TypeScanner and TypeElemenetsScanner configured");
    }

    StringBuilder sb = new StringBuilder();

    List<String> prevPaths = Lists.newArrayList();
    int indent = 1;

    List<String> keys = Lists.newArrayList(reflections.getStore().get(TypesScanner.class).keySet());
    Collections.sort(keys);
    for (String fqn : keys) {
      List<String> typePaths = Lists.newArrayList(fqn.split("\\."));

      // skip indention
      int i = 0;
      while (i < Math.min(typePaths.size(), prevPaths.size())
          && typePaths.get(i).equals(prevPaths.get(i))) {
        i++;
      }

      // indent left
      for (int j = prevPaths.size(); j > i; j--) {
        sb.append(repeat("\t", --indent)).append("}\n");
      }

      // indent right - add packages
      for (int j = i; j < typePaths.size() - 1; j++) {
        sb.append(repeat("\t", indent++))
            .append("public interface ")
            .append(getNonDuplicateName(typePaths.get(j), typePaths, j))
            .append(" extends IPackage")
            .append(" {\n");
      }

      // indent right - add class
      String className = typePaths.get(typePaths.size() - 1);

      // get fields and methods
      List<String> fields = Lists.newArrayList();
      final Multimap<String, String> methods =
          Multimaps.newSetMultimap(
              new HashMap<String, Collection<String>>(),
              new Supplier<Set<String>>() {
                public Set<String> get() {
                  return Sets.newHashSet();
                }
              });

      for (String element : reflections.getStore().get(TypeElementsScanner.class, fqn)) {
        if (element.contains("(")) {
          // method
          if (!element.startsWith("<")) {
            int i1 = element.indexOf('(');
            String name = element.substring(0, i1);
            String params = element.substring(i1 + 1, element.indexOf(")"));

            String paramsDescriptor = "";
            if (params.length() != 0) {
              paramsDescriptor =
                  tokenSeparator
                      + params
                          .replace('.', pathSeparator)
                          .replace(", ", tokenSeparator)
                          .replace("[]", arrayDescriptor);
            }
            String normalized = name + paramsDescriptor;
            methods.put(name, normalized);
          }
        } else {
          // field
          fields.add(element);
        }
      }

      // add class and it's fields and methods
      sb.append(repeat("\t", indent++))
          .append("public interface ")
          .append(getNonDuplicateName(className, typePaths, typePaths.size() - 1))
          .append(" extends IClass")
          .append(" {\n");

      // add fields
      if (!fields.isEmpty()) {
        for (String field : fields) {
          sb.append(repeat("\t", indent))
              .append("public interface ")
              .append(getNonDuplicateName(field, typePaths))
              .append(" extends IField")
              .append(" {}\n");
        }
      }

      // add methods
      if (!methods.isEmpty()) {
        for (Map.Entry<String, String> entry : methods.entries()) {
          String simpleName = entry.getKey();
          String normalized = entry.getValue();

          String methodName = methods.get(simpleName).size() == 1 ? simpleName : normalized;

          methodName =
              getNonDuplicateName(
                  methodName,
                  fields); // because fields and methods are both inners of the type, they can't
                           // duplicate

          sb.append(repeat("\t", indent))
              .append("public interface ")
              .append(getNonDuplicateName(methodName, typePaths))
              .append(" extends IMethod")
              .append(" {}\n");
        }
      }

      prevPaths = typePaths;
    }

    // close indention
    for (int j = prevPaths.size(); j >= 1; j--) {
      sb.append(repeat("\t", j)).append("}\n");
    }

    return sb.toString();
  }
Example #14
0
 public boolean hasSuppressWarningLines() {
   return !suppressWarningLines.isEmpty();
 }
Example #15
0
 /**
  * @param source
  * @return whether the list consist anything
  */
 private boolean invalidList(Multimap<String, Task> source) {
   return source == null || source.isEmpty();
 }