Exemplo n.º 1
0
 @Override
 public synchronized void stopAll() {
   for (TaskContext context : assignedWorkItems.keySet()) {
     stop(context);
   }
   templates.clear();
 }
Exemplo n.º 2
0
  public void testFetch(final SetMultimap<Integer, Integer> nodePartitions) {
    for (final Integer node : nodePartitions.keySet()) {
      System.out.println(
          "Testing fetch of node " + node + " partitions " + nodePartitions.get(node) + ": \n");
      measureFunction(
          new Measurable() {

            @Override
            public long apply() {
              long i = 0;
              Iterator<Pair<ByteArray, Versioned<byte[]>>> result =
                  adminClient.bulkFetchOps.fetchEntries(
                      node,
                      storeName,
                      new ArrayList<Integer>(nodePartitions.get(node)),
                      null,
                      false);
              while (result.hasNext()) {
                i++;
                result.next();
              }
              return i;
            }
          },
          1);
    }
  }
  public ReverseCFATransformerFactory(Set<CFAEdge> cfa) {
    reverseCFA = HashMultimap.create();
    Set<Location> nonSinks = new HashSet<Location>();
    for (CFAEdge e : cfa) {
      reverseCFA.put(e.getTarget(), e);
      nonSinks.add(e.getSource());
    }

    FastSet<Location> sinks = new FastSet<Location>();
    for (Location l : reverseCFA.keySet()) {
      if (!nonSinks.contains(l)) {
        sinks.add(l);
      }
    }

    if (sinks.size() == 1) {
      sink = sinks.pick();
    } else if (sinks.size() == 0) {
      throw new RuntimeException("CFA has no sink!");
    } else {
      // Generate artificial exit node
      sink = new Location(new AbsoluteAddress(0xFFFFFF01L));
      for (Location l : sinks) {
        reverseCFA.put(sink, new CFAEdge(l, sink, new RTLSkip()));
      }
    }
  }
Exemplo n.º 4
0
 public ImportManager build() {
   Set<String> nonConflictingImports = new LinkedHashSet<String>();
   for (Set<TypeReference> importGroup : Multimaps.asMap(implicitImports).values()) {
     if (importGroup.size() == 1) {
       TypeReference implicitImport = getOnlyElement(importGroup);
       if (implicitImport.isTopLevel()) {
         nonConflictingImports.add(implicitImport.getQualifiedName());
       }
     }
   }
   return new ImportManager(implicitImports.keySet(), nonConflictingImports);
 }
Exemplo n.º 5
0
  public void testFetchAndUpdate(final SetMultimap<Integer, Integer> from, final int to) {
    for (final Integer node : from.keySet()) {
      timeFunction(
          new Timed() {

            @Override
            public void apply() {
              List<Integer> partitionIds = Lists.newArrayList(from.get(node));
              adminClient.storeMntOps.migratePartitions(
                  node, to, storeName, partitionIds, null, null);
            }
          },
          1);
    }
  }
Exemplo n.º 6
0
 @Override
 public BindsConfig deserialize(
     JsonElement json, Type typeOfT, JsonDeserializationContext context)
     throws JsonParseException {
   BindsConfig result = new BindsConfig();
   JsonObject inputObj = json.getAsJsonObject();
   for (Map.Entry<String, JsonElement> entry : inputObj.entrySet()) {
     SetMultimap<String, Input> map = context.deserialize(entry.getValue(), SetMultimap.class);
     for (String id : map.keySet()) {
       SimpleUri uri = new SimpleUri(new Name(entry.getKey()), id);
       result.data.putAll(uri, map.get(id));
     }
   }
   return result;
 }
Exemplo n.º 7
0
 @Override
 public JsonElement serialize(
     BindsConfig src, Type typeOfSrc, JsonSerializationContext context) {
   JsonObject result = new JsonObject();
   SetMultimap<Name, SimpleUri> bindByModule = HashMultimap.create();
   for (SimpleUri key : src.data.keySet()) {
     bindByModule.put(key.getModuleName(), key);
   }
   List<Name> sortedModules = Lists.newArrayList(bindByModule.keySet());
   Collections.sort(sortedModules);
   for (Name moduleId : sortedModules) {
     SetMultimap<String, Input> moduleBinds = HashMultimap.create();
     for (SimpleUri bindUri : bindByModule.get(moduleId)) {
       moduleBinds.putAll(bindUri.getObjectName().toString(), src.data.get(bindUri));
     }
     JsonElement map = context.serialize(moduleBinds, SetMultimap.class);
     result.add(moduleId.toString(), map);
   }
   return result;
 }
  // batch job (possibly real-time using streaming APIs)
  public static void createProductAssociativityGraphPerCategory() {
    Set<String> customers = purchasesCache.keySet();
    customers.forEach(
        customer -> {
          List<String> customerPurchases = Lists.newArrayList(purchasesCache.get(customer));
          for (int i = 0; i < customerPurchases.size(); i++) {
            for (int j = i + 1; j < customerPurchases.size(); j++) {
              Product product1 = productCache.get(customerPurchases.get(i));
              Product product2 = productCache.get(customerPurchases.get(j));

              if (product1.category.equals(product2.category)) {
                ProductAssociativityGraph graph =
                    productAssociativityGraphMap.getOrDefault(
                        product1.category, ProductAssociativityGraph.create());

                graph.addAssociation(Vertex.create(product1.id), Vertex.create(product2.id), 1);
                productAssociativityGraphMap.putIfAbsent(product1.category, graph);
              }
            }
          }
        });
  }
Exemplo n.º 9
0
  public TaskSelection getSelection(String path) {
    SetMultimap<String, Task> tasksByName;
    String baseName;
    String prefix;

    ProjectInternal project = gradle.getDefaultProject();

    if (path.contains(Project.PATH_SEPARATOR)) {
      project = projectFinder.findProject(path, project);
      baseName = StringUtils.substringAfterLast(path, Project.PATH_SEPARATOR);
      prefix = project.getPath() + Project.PATH_SEPARATOR;

      tasksByName = taskNameResolver.select(baseName, project);
    } else {
      baseName = path;
      prefix = "";

      tasksByName = taskNameResolver.selectAll(path, project);
    }

    Set<Task> tasks = tasksByName.get(baseName);
    if (!tasks.isEmpty()) {
      // An exact match
      return new TaskSelection(path, tasks);
    }

    NameMatcher matcher = new NameMatcher();
    String actualName = matcher.find(baseName, tasksByName.keySet());

    if (actualName != null) {
      // A partial match
      return new TaskSelection(prefix + actualName, tasksByName.get(actualName));
    }

    throw new TaskSelectionException(matcher.formatErrorMessage("task", project));
  }
Exemplo n.º 10
0
  /** @see eu.esdihumboldt.hale.ui.cst.debug.metadata.internal.TreeGraphProvider#generateGraph() */
  @Override
  public Graph generateGraph() {

    tree.accept(graphVisitor);

    SetMultimap<String, String> connections = graphVisitor.getAllConnections();
    Set<String> ids = graphVisitor.getAllIds();

    TinkerGraph graph = new TinkerGraph();

    // add nodes to the graph
    for (String key : ids) {
      TransformationNode node = graphVisitor.getNode(key);
      Vertex vertex = graph.addVertex(key);
      setVertexProperty(node, vertex);
    }

    for (String key : connections.keySet()) {
      for (String value : connections.get(key)) {
        graph.addEdge(null, graph.getVertex(key), graph.getVertex(value), " ");
      }
    }
    return graph;
  }
Exemplo n.º 11
0
 @Override
 public Iterable<String> getBlockCategories() {
   return categoryLookup.keySet();
 }
 public Set<ClassName> getAllClasses() {
   return Collections.unmodifiableSet(_classToReferencedClassesMap.keySet());
 }
Exemplo n.º 13
0
  private List<SetMultimap<AbstractDirection, Point>> run(String folder, String branchName) {
    List<SetMultimap<AbstractDirection, Point>> res =
        new ArrayList<SetMultimap<AbstractDirection, Point>>();

    File[] files = new File(folder).listFiles();

    /*
     * Holds the number of the parse mapped to the station name mapped to the file for
     * that station
     */
    Map<Integer, List<String>> biDirectionalParseFolders = new HashMap<Integer, List<String>>();
    for (File f : files) {
      int individualParseId = new Integer(f.getName().split("-")[0]);
      String stationNameWithDotTxt = (f.getName().split("-")[2]);
      String stationName = stationNameWithDotTxt.substring(0, (stationNameWithDotTxt.length() - 4));

      if (!biDirectionalParseFolders.containsKey(individualParseId)) {
        biDirectionalParseFolders.put(individualParseId, new ArrayList<String>());
      }
      List<String> stationNames = biDirectionalParseFolders.get(individualParseId);
      stationNames.add(stationName);
    }

    List<List<String>> parseFiles = new ArrayList<List<String>>();
    for (int i = 0; i < biDirectionalParseFolders.size(); i++) {
      parseFiles.add(biDirectionalParseFolders.get(i));
    }

    for (int i = 0; i < parseFiles.size(); i++) {
      System.out.println("LongevityRecordedTests.run parsing id: " + i);
      TflSiteScraperFromSavedFilesForTesting scraper =
          new TflSiteScraperFromSavedFilesForTesting(new File(folder), "" + i);
      BranchIterator branchIterator =
          new BranchIteratorImpl(fixture.getSerializedFileDaoFactory(), scraper);
      SetMultimap<AbstractDirection, Point> map = branchIterator.run(branchName);
      res.add(branchIterator.run(branchName));

      int count = 0;
      for (AbstractDirection dir : map.keySet()) {
        List<Point> pointList = Lists.newArrayList(map.get(dir));
        count += pointList.size();
        System.out.println(dir + " total: " + pointList.size());
        for (Point point : pointList) {
          System.out.println(
              dir
                  + ": "
                  + ((DiscoveredTrain) point).getDescription()
                  + "   ('"
                  + ((DiscoveredTrain) point).getFurthestStation().getStationName()
                  + "')");
        }
      }
      // int totalMeasuredTrains =
      // SingletonStatsCollector.getInstance().allStats().get(branchName).iterator().next().getNumberOfTrainsFound();
      // System.out.println("total trains: "+count+ " total measured trains in stats:
      // "+totalMeasuredTrains);

    }

    return res;
  }