public Collection<NamedExpr> getAllNamedExprs() {
   List<NamedExpr> namedExprList = Lists.newArrayList();
   for (Map.Entry<Integer, Expr> entry : idToExprBiMap.entrySet()) {
     namedExprList.add(new NamedExpr(entry.getValue(), idToNamesMap.get(entry.getKey()).get(0)));
   }
   return namedExprList;
 }
示例#2
0
  @Override
  protected void runTask() {
    DateTime start = new DateTime(DateTimeZones.UTC);
    log.info("C4 EPG Update initiated");

    DayRange dayRange = rangeGenerator.generate(new LocalDate(DateTimeZones.UTC));

    BiMap<String, Channel> channelMap = c4AtomApi.getChannelMap();
    int total = Iterables.size(dayRange) * channelMap.size();
    int processed = 0;
    UpdateProgress progress = UpdateProgress.START;

    for (Map.Entry<String, Channel> channelEntry : channelMap.entrySet()) {
      for (LocalDate scheduleDay : dayRange) {
        reportStatus(progressReport("Processing", processed++, total, progress));
        progress =
            progress.reduce(
                channelDayUpdater.update(
                    channelEntry.getKey(), channelEntry.getValue(), scheduleDay));
      }
    }

    reportStatus(progressReport("Processed", processed++, total, progress));
    String runTime =
        new Period(start, new DateTime(DateTimeZones.UTC)).toString(PeriodFormat.getDefault());
    log.info("C4 EPG Update finished in " + runTime);

    if (progress.hasFailures()) {
      throw new IllegalStateException(
          String.format("Completed with %s failures", progress.getFailures()));
    }
  }
示例#3
0
 private List<String> getSortedStringReferences() {
   ArrayList<Map.Entry<String, Integer>> s = new ArrayList<>(stringReferences.entrySet());
   Collections.sort(s, new StringReferenceSortComparator());
   String[] array = new String[s.size()];
   for (int i = 0; i < array.length; i++) {
     array[i] = s.get(i).getKey();
   }
   return Arrays.asList(array);
 }
示例#4
0
  private void exportApplicationsForOrg(Entry<UUID, String> orgIdAndName, String queryString)
      throws Exception {

    LOG.info("organization: {} / {}", orgIdAndName.getValue(), orgIdAndName.getKey());

    String orgName = orgIdAndName.getValue();

    BiMap<UUID, String> applications =
        managementService.getApplicationsForOrganization(orgIdAndName.getKey());
    for (Entry<UUID, String> appIdAndName : applications.entrySet()) {

      String appName = appIdAndName.getValue();
      appName = appName.substring(appName.indexOf('/') + 1);

      LOG.info("application {} / {}", appName, appIdAndName.getKey());

      EntityManager em = emf.getEntityManager(appIdAndName.getKey());
      Map<String, String[]> cfm = getCollectionFieldMap();

      // Loop through the collections of the Application
      Set<String> collections = em.getApplicationCollections();
      for (String collectionName : collections) {

        // set up for retrieving only the necessary properties
        String entityType = InflectionUtils.singularize(collectionName);
        String[] props = cfm.get(entityType);
        Collection<String> properties =
            new ArrayList<String>(BASE_ATTRIBUTES.length + (props != null ? props.length : 0));
        properties.addAll(Arrays.asList(BASE_ATTRIBUTES));
        if (props != null) {
          properties.addAll(Arrays.asList(props));
        }

        Query query = Query.fromQL(queryString);
        query.setLimit(MAX_ENTITY_FETCH);
        query.setResultsLevel(Level.REFS);
        Results results = em.searchCollection(em.getApplicationRef(), collectionName, query);

        while (results.size() > 0) {

          List<Entity> entities = em.getPartialEntities(results.getIds(), properties);

          for (Entity entity : entities) {
            write(orgName, appName, entity, em);
          }

          if (results.getCursor() == null) {
            break;
          }

          query.setCursor(results.getCursor());
          results = em.searchCollection(em.getApplicationRef(), collectionName, query);
        }
      }
    }
  }
  /**
   * Renders the page-to-page navigation graph into the file {@code navgraph.gv} in the {@code
   * .errai} cache directory.
   */
  private void renderNavigationToDotFile(BiMap<String, MetaClass> pages) {
    final File dotFile = new File(RebindUtils.getErraiCacheDir().getAbsolutePath(), "navgraph.gv");
    PrintWriter out = null;
    try {
      out = new PrintWriter(dotFile);
      out.println("digraph Navigation {");
      final MetaClass transitionToType = MetaClassFactory.get(TransitionTo.class);
      final MetaClass transitionAnchorType = MetaClassFactory.get(TransitionAnchor.class);
      final MetaClass transitionAnchorFactoryType =
          MetaClassFactory.get(TransitionAnchorFactory.class);
      for (Map.Entry<String, MetaClass> entry : pages.entrySet()) {
        String pageName = entry.getKey();
        MetaClass pageClass = entry.getValue();

        // entry for the node itself
        out.print("\"" + pageName + "\"");

        Page pageAnnotation = pageClass.getAnnotation(Page.class);
        List<Class<? extends PageRole>> roles = Arrays.asList(pageAnnotation.role());
        if (roles.contains(DefaultPage.class)) {
          out.print(" [penwidth=3]");
        }
        out.println();

        for (MetaField field : getAllFields(pageClass)) {
          if (field.getType().getErased().equals(transitionToType)
              || field.getType().getErased().equals(transitionAnchorType)
              || field.getType().getErased().equals(transitionAnchorFactoryType)) {
            MetaType targetPageType = field.getType().getParameterizedType().getTypeParameters()[0];
            String targetPageName = pages.inverse().get(targetPageType);

            // entry for the link between nodes
            out.println(
                "\""
                    + pageName
                    + "\" -> \""
                    + targetPageName
                    + "\" [label=\""
                    + field.getName()
                    + "\"]");
          }
        }
      }
      out.println("}");
    } catch (FileNotFoundException e) {
      throw new RuntimeException(e);
    } finally {
      if (out != null) {
        out.close();
      }
    }
  }
示例#6
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();
  }
  protected static SwitchPortStatistics generateSwitchPortStatistics(
      Map<String, SwitchPortStatistics> switchesStatistics,
      BiMap<String, DevicePortId> networkDevicePortIdsMap)
      throws Exception {

    Map<String, PortStatistics> stats = new HashMap<String, PortStatistics>();

    // extract own network port IDs and associate obtained PortStatistics
    for (Entry<String, DevicePortId> entry : networkDevicePortIdsMap.entrySet()) {
      // get underlying network element and port IDs
      String networkElementId = entry.getValue().getDeviceId();
      String networkElementPortId = entry.getValue().getDevicePortId();

      // check existence of statistics for element and port
      if (!switchesStatistics.containsKey(networkElementId)
          || switchesStatistics.get(networkElementId).getStatistics() == null
          || !switchesStatistics
              .get(networkElementId)
              .getStatistics()
              .containsKey(entry.getKey())) {
        throw new Exception(
            "Could not find statistics for network element with ID = "
                + networkElementId
                + " and port ID = "
                + networkElementPortId
                + "!");
      }

      // get PortStatistics and associate it to own network port ID
      PortStatistics portStatistics =
          switchesStatistics.get(networkElementId).getStatistics().get(entry.getKey());
      stats.put(entry.getKey(), portStatistics);
    }

    // generate SwitchPortStatistics from stats
    SwitchPortStatistics switchPortStatistics = new SwitchPortStatistics();
    switchPortStatistics.setStatistics(stats);

    return switchPortStatistics;
  }
 public void add(final BiMap<StringWrapper, UUID> toAdd) {
   if (uuidMap.size() == 0) {
     uuidMap = toAdd;
   }
   for (Map.Entry<StringWrapper, UUID> entry : toAdd.entrySet()) {
     UUID uuid = entry.getValue();
     StringWrapper name = entry.getKey();
     if ((uuid == null) || (name == null)) {
       continue;
     }
     BiMap<UUID, StringWrapper> inverse = uuidMap.inverse();
     if (inverse.containsKey(uuid)) {
       if (uuidMap.containsKey(name)) {
         continue;
       }
       rename(uuid, name);
       continue;
     }
     uuidMap.put(name, uuid);
   }
   PS.debug(C.PREFIX.s() + "&6Cached a total of: " + uuidMap.size() + " UUIDs");
 }
示例#9
0
  public Symbols(BytecodeCompleter bytecodeCompleter) {
    defaultPackage = new JavaSymbol.PackageJavaSymbol("", rootPackage);

    predefClass = new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "", rootPackage);
    predefClass.members = new Scope(predefClass);
    ((JavaType.ClassJavaType) predefClass.type).interfaces = ImmutableList.of();

    // TODO should have type "noType":
    noSymbol = new JavaSymbol.TypeJavaSymbol(0, "", rootPackage);

    methodClass = new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "", noSymbol);

    // builtin types
    byteType = initType(JavaType.BYTE, "byte");
    charType = initType(JavaType.CHAR, "char");
    shortType = initType(JavaType.SHORT, "short");
    intType = initType(JavaType.INT, "int");
    longType = initType(JavaType.LONG, "long");
    floatType = initType(JavaType.FLOAT, "float");
    doubleType = initType(JavaType.DOUBLE, "double");
    booleanType = initType(JavaType.BOOLEAN, "boolean");
    nullType = initType(JavaType.BOT, "<nulltype>");
    voidType = initType(JavaType.VOID, "void");

    bytecodeCompleter.init(this);

    // predefined types for java lang
    JavaSymbol.PackageJavaSymbol javalang = bytecodeCompleter.enterPackage("java.lang");
    // define a star import scope to let resolve types to java.lang when needed.
    javalang.members = new Scope.StarImportScope(javalang, bytecodeCompleter);
    javalang.members.enter(javalang);

    objectType = bytecodeCompleter.loadClass("java.lang.Object").type;
    classType = bytecodeCompleter.loadClass("java.lang.Class").type;
    stringType = bytecodeCompleter.loadClass("java.lang.String").type;
    cloneableType = bytecodeCompleter.loadClass("java.lang.Cloneable").type;
    serializableType = bytecodeCompleter.loadClass("java.io.Serializable").type;
    annotationType = bytecodeCompleter.loadClass("java.lang.annotation.Annotation").type;
    enumType = bytecodeCompleter.loadClass("java.lang.Enum").type;

    // Associate boxed types
    boxedTypes = HashBiMap.create();
    boxedTypes.put(byteType, bytecodeCompleter.loadClass("java.lang.Byte").type);
    boxedTypes.put(charType, bytecodeCompleter.loadClass("java.lang.Character").type);
    boxedTypes.put(shortType, bytecodeCompleter.loadClass("java.lang.Short").type);
    boxedTypes.put(intType, bytecodeCompleter.loadClass("java.lang.Integer").type);
    boxedTypes.put(longType, bytecodeCompleter.loadClass("java.lang.Long").type);
    boxedTypes.put(floatType, bytecodeCompleter.loadClass("java.lang.Float").type);
    boxedTypes.put(doubleType, bytecodeCompleter.loadClass("java.lang.Double").type);
    boxedTypes.put(booleanType, bytecodeCompleter.loadClass("java.lang.Boolean").type);

    for (Entry<JavaType, JavaType> entry : boxedTypes.entrySet()) {
      entry.getKey().primitiveWrapperType = entry.getValue();
      entry.getValue().primitiveType = entry.getKey();
    }

    // TODO comment me
    arrayClass = new JavaSymbol.TypeJavaSymbol(Flags.PUBLIC, "Array", noSymbol);
    JavaType.ClassJavaType arrayClassType = (JavaType.ClassJavaType) arrayClass.type;
    arrayClassType.supertype = objectType;
    arrayClassType.interfaces = ImmutableList.of(cloneableType, serializableType);
    arrayClass.members = new Scope(arrayClass);
    arrayClass
        .members()
        .enter(
            new JavaSymbol.VariableJavaSymbol(
                Flags.PUBLIC | Flags.FINAL, "length", intType, arrayClass));
    // TODO arrayClass implements clone() method

    enterOperators();
  }