private void handleReparent(EclipseContext newParent, Set<Scheduled> scheduled) {
    // TBD should we lock waiting list while doing reparent?
    // Add "boolean inReparent" on the root context and process right away?
    processWaiting();
    // 1) everybody who depends on me: I need to collect combined list of names injected
    Set<String> usedNames = new HashSet<String>();
    collectDependentNames(usedNames);

    // 2) for each used name:
    for (Iterator<String> i = usedNames.iterator(); i.hasNext(); ) {
      String name = i.next();
      if (localValues.containsKey(name)) continue; // it is a local value
      Object oldValue = get(name);
      Object newValue = (newParent != null) ? newParent.get(name) : null;
      if (oldValue != newValue) invalidate(name, ContextChangeEvent.ADDED, oldValue, scheduled);
    }

    ContextChangeEvent event =
        new ContextChangeEvent(this, ContextChangeEvent.ADDED, null, null, null);
    for (Computation computation : localValueComputations.values()) {
      Collection<HashSet<Computation>> allListeners = listeners.values();
      for (HashSet<Computation> group : allListeners) {
        group.remove(computation);
      }
      computation.handleInvalid(event, scheduled);
    }
    localValueComputations.clear();
  }
  /**
   * The given name has been modified or removed in this context. Invalidate all local value
   * computations and listeners that depend on this name.
   */
  public void invalidate(String name, int eventType, Object oldValue, Set<Scheduled> scheduled) {
    ContextChangeEvent event = new ContextChangeEvent(this, eventType, null, name, oldValue);
    ValueComputation computation = localValueComputations.get(name);
    if (computation != null) {
      if (computation.shouldRemove(event)) {
        localValueComputations.remove(name);
        Collection<HashSet<Computation>> allListeners = listeners.values();
        for (HashSet<Computation> group : allListeners) {
          group.remove(computation);
        }
      }
      computation.handleInvalid(event, scheduled);
    }
    HashSet<Computation> namedComputations = listeners.get(name);
    if (namedComputations != null) {
      for (Computation listener : namedComputations) {
        listener.handleInvalid(event, scheduled);
      }
    }

    // invalidate this name in child contexts
    for (EclipseContext childContext : getChildren()) {
      childContext.invalidate(name, eventType, oldValue, scheduled);
    }
  }
Exemplo n.º 3
0
  public Computation compute(TypeManager types, SerializedValueVisitor<Computation> compiler) {
    Class<?> clazz = constructorParams.getType();
    List<String> statements = new ArrayList<>();

    List<Computation> computedParams =
        constructorParams
            .getValues()
            .stream()
            .map(value -> value.accept(compiler))
            .collect(toList());

    statements.addAll(
        computedParams
            .stream()
            .flatMap(computation -> computation.getStatements().stream())
            .collect(toList()));

    String[] params =
        computedParams.stream().map(computation -> computation.getValue()).toArray(String[]::new);

    String bean = newObject(types.getBestName(clazz), params);
    String constructorStatement =
        assignLocalVariableStatement(types.getSimpleName(clazz), name, bean);
    statements.add(constructorStatement);

    for (SetterParam param : setterParams) {
      Computation fieldComputation = param.computeValue().accept(compiler);
      statements.addAll(fieldComputation.getStatements());

      String setStatement = callMethodStatement(name, param.getName(), fieldComputation.getValue());
      statements.add(setStatement);
    }

    return new Computation(name, true, statements);
  }
Exemplo n.º 4
0
  @Override
  public void initialize() throws InstantiationException, IllegalAccessException {
    // If we run with separate master, we need to initialize the worker context
    // ourselves because a worker context is never created (and the worker context
    // is the one that initializes our configuration according to the user settings).
    WorkerContext workerContext = (WorkerContext) getConf().createWorkerContext();
    workerContext.setConf(getConf());

    Configuration conf = Configuration.get();

    CommunicationStrategy communicationStrategy =
        conf.createCommunicationStrategy(conf, null, workerContext);

    numPhases = communicationStrategy.getNumPhases();

    registeredAggregatorNames = new ArrayList<>();
    savedAggregatorValues = new HashMap<>();

    registerAggregator(AGG_EMBEDDINGS_GENERATED, LongSumAggregator.class);
    registerAggregator(AGG_EMBEDDINGS_PROCESSED, LongSumAggregator.class);
    registerAggregator(AGG_PROCESSED_SIZE_ODAG, LongMaxAggregator.class);
    registerAggregator(AGG_PROCESSED_SIZE_CACHE, LongSumAggregator.class);
    registerAggregator(AGG_CHILDREN_EVALUATED, LongSumAggregator.class);
    registerAggregator(AGG_EMBEDDINGS_OUTPUT, LongSumAggregator.class);

    Computation<?> computation = conf.createComputation();

    computation.initAggregations();

    Map<String, AggregationStorageMetadata> registeredAggregationStorages =
        conf.getAggregationsMetadata();

    LOG.info("Registered aggregation storages: " + registeredAggregationStorages);

    for (Map.Entry<String, AggregationStorageMetadata> entry :
        registeredAggregationStorages.entrySet()) {
      String aggName = entry.getKey();
      AggregationStorageMetadata aggStorageMetadata = entry.getValue();

      registerAggregationStore(aggName, aggStorageMetadata);
    }

    masterComputation = conf.createMasterComputation();
    masterComputation.setUnderlyingExecutionEngine(this);
    masterComputation.init();
  }
  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.e4.core.services.context.IEclipseContext#dispose()
   */
  public void dispose() {
    // dispose of child contexts first
    for (EclipseContext childContext : getChildren()) {
      childContext.dispose();
    }

    ContextChangeEvent event =
        new ContextChangeEvent(this, ContextChangeEvent.DISPOSE, null, null, null);
    Set<Scheduled> scheduled = new LinkedHashSet<Scheduled>();
    Set<Computation> allComputations = getListeners();
    listeners.clear();
    allComputations.addAll(activeRATs);
    activeRATs.clear();
    for (Computation computation : allComputations) {
      computation.handleInvalid(event, scheduled);
    }
    processScheduled(scheduled);

    synchronized (notifyOnDisposal) {
      for (IContextDisposalListener listener : notifyOnDisposal) {
        listener.disposed(this);
      }
    }

    localValueComputations.clear();

    // if this was the parent's active child, deactivate it
    EclipseContext parent = getParent();
    if (parent != null) {
      if (this == parent.getActiveChild()) parent.set(ACTIVE_CHILD, null);
    }

    localValues.clear();

    if (parent != null) parent.removeChild(this);

    if (debugAddOn != null)
      debugAddOn.notify(this, IEclipseContextDebugger.EventType.DISPOSED, null);
  }