brooklyn.entity.basic.Entities.invokeEffector()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.8k)|赞(0)|评价(0)|浏览(120)

本文整理了Java中brooklyn.entity.basic.Entities.invokeEffector()方法的一些代码示例,展示了Entities.invokeEffector()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entities.invokeEffector()方法的具体详情如下:
包路径:brooklyn.entity.basic.Entities
类名称:Entities
方法名:invokeEffector

Entities.invokeEffector介绍

[英]convenience - invokes in parallel if multiple, but otherwise invokes the item directly
[中]便利性-如果有多个项目,则并行调用,否则直接调用该项目

代码示例

代码示例来源:origin: io.brooklyn/brooklyn-core

/** convenience - invokes in parallel if multiple, but otherwise invokes the item directly */
public static Task<?> invokeEffector(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
    final Effector<?> effector) {
  return invokeEffector(callingEntity, entitiesToCall, effector, Collections.<String,Object>emptyMap());
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** convenience - invokes in parallel if multiple, but otherwise invokes the item directly */
public static Task<?> invokeEffector(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
    final Effector<?> effector, final Map<String,?> parameters) {
  if (Iterables.size(entitiesToCall)==1)
    return invokeEffector(callingEntity, entitiesToCall.iterator().next(), effector, parameters);
  else
    return invokeEffectorList(callingEntity, entitiesToCall, effector, parameters);
}
/** convenience - invokes in parallel if multiple, but otherwise invokes the item directly */

代码示例来源:origin: io.brooklyn/brooklyn-core

public static <T> Task<T> invokeEffector(EntityLocal callingEntity, Entity entityToCall,
    final Effector<T> effector) {
  return invokeEffector(callingEntity, entityToCall, effector, Collections.<String,Object>emptyMap());
}

代码示例来源:origin: io.brooklyn/brooklyn-core

@SuppressWarnings("unchecked")
public static <T> Task<T> invokeEffectorWithArgs(EntityLocal callingEntity, Entity entityToCall,
    final Effector<T> effector, Object ...args) {
  return invokeEffector(callingEntity, entityToCall, effector,
      EffectorUtils.prepareArgsForEffectorAsMapFromArray(effector, args));
}
public static <T> Task<T> invokeEffector(EntityLocal callingEntity, Entity entityToCall,

代码示例来源:origin: io.brooklyn/brooklyn-core

/** Common implementation for stop in parent nodes; just invokes stop on all children of the entity */
public static void stop(EntityLocal e) {
  log.debug("Stopping entity "+e);
  Iterable<Entity> startables = filterStartableManagedEntities(e.getChildren());
  
  if (!Iterables.isEmpty(startables)) {
    Entities.invokeEffector(e, startables, Startable.STOP).getUnchecked();
  }
  if (log.isDebugEnabled()) log.debug("Stopped entity "+e);
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** Common implementation for restart in parent nodes; just invokes stop on all children of the entity */
public static void restart(EntityLocal e) {
  log.debug("Restarting entity "+e);
  Iterable<Entity> startables = filterStartableManagedEntities(e.getChildren());
  
  if (!Iterables.isEmpty(startables)) {
    Entities.invokeEffector(e, startables, Startable.RESTART).getUnchecked();
  }
  if (log.isDebugEnabled()) log.debug("Restarted entity "+e);
}

代码示例来源:origin: io.brooklyn/brooklyn-rest-server

public Task<?> start(Application app, ApplicationSpec spec) {
  // Start all the managed entities by asking the app instance to start in background
  Function<String, Location> buildLocationFromId = new Function<String, Location>() {
    @Override
    public Location apply(String id) {
      id = fixLocation(id);
      return getLocationRegistry().resolve(id);
    }
  };
  ArrayList<Location> locations = Lists.newArrayList(transform(spec.getLocations(), buildLocationFromId));
  return Entities.invokeEffector((EntityLocal)app, app, Startable.START,
      MutableMap.of("locations", locations));
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** Common implementation for start in parent nodes; just invokes start on all children of the entity */
public static void start(EntityLocal e, Collection<? extends Location> locations) {
  log.debug("Starting entity "+e+" at "+locations);
  Iterable<Entity> startables = filterStartableManagedEntities(e.getChildren());
  if (!Iterables.isEmpty(startables)) {
    Entities.invokeEffector(e, startables, Startable.START, MutableMap.of("locations", locations)).getUnchecked();
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** convenience for starting an entity, esp a new Startable instance which has been created dynamically
 * (after the application is started) */
public static void start(Entity e, Collection<? extends Location> locations) {
  if (!isManaged(e) && !manage(e)) {
    log.warn("Using discouraged mechanism to start management -- Entities.start(Application, Locations) -- caller should create and use the preferred management context");
    startManagement(e);
  }
  if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.START,
      MutableMap.of("locations", locations)).getUnchecked();
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/**
 * Decreases the cluster size by the given number.
 * Called when synchronized on mutex, so overriders beware!
 */
protected void shrink(int delta) {
  Collection<Entity> removedEntities = pickAndRemoveMembers(delta * -1);
  // FIXME symmetry in order of added as child, managed, started, and added to group
  // FIXME assume stoppable; use logic of grow?
  Task<?> invoke = Entities.invokeEffector(this, removedEntities, Startable.STOP, Collections.<String,Object>emptyMap());
  try {
    invoke.get();
  } catch (Exception e) {
    throw Exceptions.propagate(e);
  } finally {
    for (Entity removedEntity : removedEntities) {
      discardNode(removedEntity);
    }
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/** stops, destroys, and unmanages the given entity -- does as many as are valid given the type and state */
public static void destroy(Entity e) {
  if (isManaged(e)) {
    if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.STOP).getUnchecked();
    if (e instanceof EntityInternal) ((EntityInternal)e).destroy();
    unmanage(e);
    log.debug("destroyed and unmanaged "+e+"; mgmt now "+
        (e.getApplicationId()==null ? "(no app)" : e.getApplication().getManagementContext())+" - managed? "+isManaged(e));
  } else {
    log.debug("skipping destroy of "+e+": not managed");
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-core

/**
 * stops, destroys, and unmanages the given application -- and terminates the mangaement context;
 * does as many as are valid given the type and state
 * @deprecated since 0.6.0 use destroy(Application) if you DONT want to destroy the mgmt context,
 * or destroy(app.getManagementContext()) if you want to destory everything in the app's mgmt context
 */
@Deprecated
public static void destroyAll(Application app) {
  if (isManaged(app)) {
    ManagementContext managementContext = app.getManagementContext();
    if (app instanceof Startable) Entities.invokeEffector((EntityLocal)app, app, Startable.STOP).getUnchecked();
    if (app instanceof AbstractEntity) ((AbstractEntity)app).destroy();
    unmanage(app);
    if (managementContext instanceof ManagementContextInternal) ((ManagementContextInternal)managementContext).terminate();
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-policy

protected synchronized void onDetectedFailure(SensorEvent<Object> event) {
  if (isSuspended()) {
    LOG.warn("ServiceRestarter suspended, so not acting on failure detected at "+entity+" ("+event.getValue()+")");
    return;
  }
  LOG.warn("ServiceRestarter acting on failure detected at "+entity+" ("+event.getValue()+")");
  long current = System.currentTimeMillis();
  Long last = lastFailureTime.getAndSet(current);
  long elapsed = last==null ? -1 : current-last;
  if (elapsed>=0 && elapsed <= getConfig(FAIL_ON_RECURRING_FAILURES_IN_THIS_DURATION)) {
    onRestartFailed("Restart failure (failed again after "+Time.makeTimeStringRounded(elapsed)+") at "+entity+": "+event.getValue());
    return;
  }
  try {
    entity.setAttribute(Attributes.SERVICE_STATE, Lifecycle.STARTING);
    Entities.invokeEffector(entity, entity, Startable.RESTART).get();
  } catch (Exception e) {
    onRestartFailed("Restart failure (error "+e+") at "+entity+": "+event.getValue());
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-core

@Override
public void removeRegion(String id) {
  Entity entity = getManagementContext().getEntityManager().getEntity(id);
  Preconditions.checkNotNull(entity, "No entity found for %s", id);
  Preconditions.checkArgument(this.equals(entity.getParent()), "Wrong parent (%s) for %s", entity.getParent(), entity);
  Collection<Location> childLocations = entity.getLocations();
  
  if (entity instanceof Startable) {
    try {
      Entities.invokeEffector(this, entity, Startable.STOP).get();
    } catch (Exception e) {
      Exceptions.propagateIfFatal(e);
      log.warn("Error stopping "+entity+" ("+e+"); proceeding to remove it anyway");
      log.debug("Error stopping "+entity+" ("+e+"); proceeding to remove it anyway", e);
    }
  }
  removeChild(entity);
  removeLocations(childLocations);
}

代码示例来源:origin: io.brooklyn/brooklyn-core

@Override
public void stop() {
  setAttribute(SERVICE_STATE, Lifecycle.STOPPING);
  try {
    Iterable<Entity> stoppableChildren = Iterables.filter(getChildren(), Predicates.instanceOf(Startable.class));
    Task<?> invoke = Entities.invokeEffector(this, stoppableChildren, Startable.STOP);
    if (invoke != null) invoke.get();
    setAttribute(SERVICE_STATE, Lifecycle.STOPPED);
    setAttribute(SERVICE_UP, false);
  } catch (Exception e) {
    setAttribute(SERVICE_STATE, Lifecycle.ON_FIRE);
    throw Exceptions.propagate(e);
  }
}

代码示例来源:origin: io.brooklyn/brooklyn-software-messaging

@Override
public void start(Collection<? extends Location> locations) {
  if (isLegacyConstruction()) {
    init();
  }
  if (locations.isEmpty()) locations = getLocations();
  Iterables.getOnlyElement(locations); // Assert just one
  addLocations(locations);
  List<Entity> childrenToStart = MutableList.<Entity>of(getCluster());
  // Set the KafkaZookeeper entity as child of cluster, if it does not already have a parent
  if (getZookeeper().getParent() == null) {
    addChild(getZookeeper());
  } // And only start zookeeper if we are parent
  if (Objects.equal(this, getZookeeper().getParent())) childrenToStart.add(getZookeeper());
  Entities.invokeEffector(this, childrenToStart, Startable.START, ImmutableMap.of("locations", locations)).getUnchecked();
  connectSensors();
}

相关文章