Exemplo n.º 1
0
  public Applications toApplications() {
    Map<String, Application> appsByName = new HashMap<>();
    Iterator<InstanceInfo> it = serviceIterator();
    while (it.hasNext()) {
      InstanceInfo instanceInfo = it.next();
      Application instanceApp = appsByName.get(instanceInfo.getAppName());
      if (instanceApp == null) {
        instanceApp = new Application(instanceInfo.getAppName());
        appsByName.put(instanceInfo.getAppName(), instanceApp);
      }
      instanceApp.addInstance(instanceInfo);
    }

    // Do not pass application list to the constructor, as it does not initialize properly
    // Applications
    // data structure.
    Applications applications = new Applications();
    for (Application app : appsByName.values()) {
      applications.addApplication(app);
    }

    applications.setAppsHashCode(applications.getReconcileHashCode());

    return applications;
  }
Exemplo n.º 2
0
  public Applications takeDelta(int count) {
    if (currentIt == null) {
      currentIt = serviceIterator();
      allApplications = new Applications();
    }
    List<InstanceInfo> instanceBatch = new ArrayList<InstanceInfo>();
    for (int i = 0; i < count; i++) {
      InstanceInfo next = currentIt.next();
      next.setActionType(ActionType.ADDED);
      instanceBatch.add(next);
    }
    Applications nextBatch = EurekaEntityFunctions.toApplications(toApplicationMap(instanceBatch));
    allApplications = mergeApplications(allApplications, nextBatch);
    nextBatch.setAppsHashCode(allApplications.getAppsHashCode());

    return nextBatch;
  }
Exemplo n.º 3
0
    /*
     * (non-Javadoc)
     *
     * @see
     * com.thoughtworks.xstream.converters.Converter#unmarshal(com.thoughtworks
     * .xstream.io.HierarchicalStreamReader,
     * com.thoughtworks.xstream.converters.UnmarshallingContext)
     */
    @Override
    public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
      Applications apps = new Applications();
      while (reader.hasMoreChildren()) {
        reader.moveDown();

        String nodeName = reader.getNodeName();

        if (NODE_APP.equals(nodeName)) {
          apps.addApplication((Application) context.convertAnother(apps, Application.class));
        } else if (VERSIONS_DELTA.equals(nodeName)) {
          apps.setVersion(Long.valueOf(reader.getValue()));
        } else if (APPS_HASHCODE.equals(nodeName)) {
          apps.setAppsHashCode(reader.getValue());
        }
        reader.moveUp();
      }
      return apps;
    }