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
 /*
  * (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();
   }
 }
Exemplo n.º 3
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.º 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;
    }