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;
  }
Exemple #2
0
 /*
  * (non-Javadoc)
  *
  * @see
  * com.thoughtworks.xstream.converters.Converter#marshal(java.lang.Object
  * , com.thoughtworks.xstream.io.HierarchicalStreamWriter,
  * com.thoughtworks.xstream.converters.MarshallingContext)
  */
 @Override
 public void marshal(
     Object source, HierarchicalStreamWriter writer, MarshallingContext context) {
   Applications apps = (Applications) source;
   writer.startNode(VERSIONS_DELTA);
   writer.setValue(apps.getVersion().toString());
   writer.endNode();
   writer.startNode(APPS_HASHCODE);
   writer.setValue(apps.getAppsHashCode());
   writer.endNode();
   for (Application app : apps.getRegisteredApplications()) {
     writer.startNode(NODE_APP);
     context.convertAnother(app);
     writer.endNode();
   }
 }
  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;
  }
Exemple #4
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;
    }