Exemplo n.º 1
0
    @Override
    protected void fired(double currentTime, Future<VocalizationCommand> commandFuture) {
      IPerceptualBuffer pBuffer = (IPerceptualBuffer) getBuffer();
      IModel model = pBuffer.getModel();
      try {
        VocalizationCommand command = commandFuture.get();
        ActualState state = command.getActualState();
        if (state != ActualState.RUNNING && state != ActualState.COMPLETED)
          throw new IllegalStateException(
              "Processing vocalization failed : " + command.getResult());

        String msg = "Processing vocalization completed";
        if (LOGGER.isDebugEnabled()) LOGGER.debug(msg);
        if (Logger.hasLoggers(model)) Logger.log(model, Logger.Stream.VOCAL, msg);

        pBuffer.setProcessorChunk(model.getDeclarativeModule().getFreeChunk());
      } catch (InterruptedException e) {
        return;
      } catch (Exception e) {
        String msg = e.getMessage();
        if (e instanceof ExecutionException) msg = ((ExecutionException) e).getCause().getMessage();

        if (LOGGER.isDebugEnabled()) LOGGER.debug(msg);
        if (Logger.hasLoggers(model)) Logger.log(model, Logger.Stream.VOCAL, msg);

        IChunk error = model.getDeclarativeModule().getErrorChunk();
        pBuffer.setProcessorChunk(error);
        pBuffer.setStateChunk(error);
      }
    }
Exemplo n.º 2
0
 @Override
 protected Object startRequest(IRequest request, IActivationBuffer buffer, double requestTime) {
   /*
    * flag as busy
    */
   IChunk busy = _vocal.getModel().getDeclarativeModule().getBusyChunk();
   ((IPerceptualBuffer) buffer).setPreparationChunk(busy);
   ((IPerceptualBuffer) buffer).setStateChunk(busy);
   return _vocal.prepare(request);
 }
Exemplo n.º 3
0
  @Override
  protected void finishRequest(IRequest request, IActivationBuffer buffer, Object startValue) {
    final IModel model = buffer.getModel();
    VocalizationCommand command = null;
    IChunk error = model.getDeclarativeModule().getErrorChunk();
    IChunk free = model.getDeclarativeModule().getFreeChunk();
    IChunk busy = model.getDeclarativeModule().getBusyChunk();
    IPerceptualBuffer pBuffer = (IPerceptualBuffer) buffer;
    String rejection = null;
    try {
      command = ((Future<VocalizationCommand>) startValue).get();
    } catch (InterruptedException e) {
      // bail
      return;
    } catch (ExecutionException e) {
      rejection = e.getCause().getMessage();
      LOGGER.error("Failed to get vocalization future ", e);
    }

    if (command != null && command.getActualState() == ActualState.REJECTED)
      rejection = "Vocalization was rejected : " + command.getResult();

    if (rejection != null) {
      if (LOGGER.isDebugEnabled()) LOGGER.debug(rejection);
      if (Logger.hasLoggers(model)) Logger.log(model, Logger.Stream.VOCAL, rejection);

      pBuffer.setPreparationChunk(error);
      pBuffer.setStateChunk(error);
      return;
    }

    String msg = "Vocalization prepared.";

    if (LOGGER.isDebugEnabled()) LOGGER.debug(msg);
    if (Logger.hasLoggers(model)) Logger.log(model, Logger.Stream.VOCAL, msg);

    pBuffer.setPreparationChunk(free);

    /*
     * now to actually execute, we use another drifting timed event.. two
     * actually..
     */
    Future<VocalizationCommand> executeFuture = _vocal.execute(command);

    double start = ACTRRuntime.getRuntime().getClock(model).getTime();
    double procEnd = model.getProceduralModule().getDefaultProductionFiringTime() + start;
    double execEnd = _vocal.getExecutionTimeEquation().compute(getText(request), _vocal);

    ProcessTimedEvent procEvent = new ProcessTimedEvent(start, procEnd, executeFuture, buffer);

    ExecuteTimedEvent execEvent = new ExecuteTimedEvent(start, execEnd, executeFuture, buffer);

    /*
     * set some flags
     */
    pBuffer.setProcessorChunk(busy);
    pBuffer.setExecutionChunk(busy);

    model.getTimedEventQueue().enqueue(procEvent);
    model.getTimedEventQueue().enqueue(execEvent);
  }