@Test
 public void testGetEffector() throws Exception {
   TestEntity entity2 = app.createAndManageChild(EntitySpecs.spec(TestEntity.class));
   Effector<?> effector = entity2.getEntityType().getEffector("myEffector");
   Effector<?> effector2 = entity2.getEntityType().getEffector("identityEffector", Object.class);
   assertEquals(effector.getName(), "myEffector");
   assertEquals(effector2.getName(), "identityEffector");
 }
Esempio n. 2
0
  /** Invokes the effector so that its progress is tracked. */
  public static <T> T invokeEffector(Entity entity, Effector<T> eff, Object[] args) {
    String id = entity.getId();
    String name = eff.getName();

    try {
      if (log.isDebugEnabled())
        log.debug("Invoking effector {} on {}", new Object[] {name, entity});
      if (log.isTraceEnabled())
        log.trace("Invoking effector {} on {} with args {}", new Object[] {name, entity, args});
      EntityManagementSupport mgmtSupport = ((EntityInternal) entity).getManagementSupport();
      if (!mgmtSupport.isDeployed()) {
        mgmtSupport.attemptLegacyAutodeployment(name);
      }
      ManagementContextInternal mgmtContext =
          (ManagementContextInternal) ((EntityInternal) entity).getManagementContext();

      mgmtSupport.getEntityChangeListener().onEffectorStarting(eff);
      try {
        return mgmtContext.invokeEffectorMethodSync(entity, eff, args);
      } finally {
        mgmtSupport.getEntityChangeListener().onEffectorCompleted(eff);
      }
    } catch (CancellationException ce) {
      log.info("Execution of effector {} on entity {} was cancelled", name, id);
      throw ce;
    } catch (ExecutionException ee) {
      log.info("Execution of effector {} on entity {} failed with {}", new Object[] {name, id, ee});
      // Exceptions thrown in Futures are wrapped
      // FIXME Shouldn't pretend exception came from this thread?! Should we remove this unwrapping?
      if (ee.getCause() != null) throw Exceptions.propagate(ee.getCause());
      else throw Exceptions.propagate(ee);
    }
  }
Esempio n. 3
0
 public static Effector<?> findEffectorMatching(
     Set<Effector<?>> effectors, String effectorName, Map<String, ?> parameters) {
   // TODO Support overloading: check parameters as well
   for (Effector<?> effector : effectors) {
     if (effector.getName().equals(effectorName)) {
       return effector;
     }
   }
   return null;
 }
Esempio n. 4
0
 public static Effector<?> findEffectorMatching(Entity entity, Method method) {
   effector:
   for (Effector<?> effector : entity.getEntityType().getEffectors()) {
     if (!effector.getName().equals(entity)) continue;
     if (effector.getParameters().size() != method.getParameterTypes().length) continue;
     for (int i = 0; i < effector.getParameters().size(); i++) {
       if (effector.getParameters().get(i).getParameterClass() != method.getParameterTypes()[i])
         continue effector;
     }
     return effector;
   }
   return null;
 }
Esempio n. 5
0
  public static <T> Task<T> invokeEffectorAsync(
      AbstractEntity entity, Effector<T> eff, Map<String, ?> parameters) {
    String id = entity.getId();
    String name = eff.getName();

    if (log.isDebugEnabled())
      log.debug("Invoking-async effector {} on {}", new Object[] {name, entity});
    if (log.isTraceEnabled())
      log.trace(
          "Invoking-async effector {} on {} with args {}", new Object[] {name, entity, parameters});
    EntityManagementSupport mgmtSupport = ((EntityInternal) entity).getManagementSupport();
    if (!mgmtSupport.isDeployed()) {
      mgmtSupport.attemptLegacyAutodeployment(name);
    }
    ManagementContextInternal mgmtContext =
        (ManagementContextInternal) ((EntityInternal) entity).getManagementContext();

    mgmtSupport.getEntityChangeListener().onEffectorStarting(eff);
    try {
      return mgmtContext.invokeEffector(entity, eff, parameters);
    } finally {
      mgmtSupport.getEntityChangeListener().onEffectorCompleted(eff);
    }
  }
 @Override
 public boolean apply(@Nullable Effector<?> input) {
   return name.equals(input.getName());
 }