/** * @param ctxt the context in which the request was processed * @param request the request that was processed * @param response contains the output messages that the actor should send, or a * ProcessingException if some error was encountered during processing. */ protected void processFinished( ActorContext ctxt, ProcessRequest request, ProcessResponse response) { try { if (response.getException() == null) { // Mark the contexts as processed. // Not sure if this is still relevant for v5 actors, // as even PUSHed messages are assumed to be handled once, in the iteration when they are // offered to process(). Iterator<MessageInputContext> allInputContexts = request.getAllInputContexts(); while (allInputContexts.hasNext()) { MessageInputContext msgInputCtxt = allInputContexts.next(); msgInputCtxt.setProcessed(true); } // and now send out the results MessageOutputContext[] outputs = response.getOutputs(); if (outputs != null) { for (MessageOutputContext output : outputs) { sendOutputMsg(output.getPort(), output.getMessage()); } } outputs = response.getOutputsInSequence(); if (outputs != null && outputs.length > 0) { Long seqID = MessageFactory.getInstance().createSequenceID(); for (int i = 0; i < outputs.length; i++) { MessageOutputContext context = outputs[i]; boolean isLastMsg = (i == (outputs.length - 1)); try { ManagedMessage msgInSeq = MessageFactory.getInstance() .createMessageCopyInSequence( context.getMessage(), seqID, new Long(i), isLastMsg); sendOutputMsg(context.getPort(), msgInSeq); } catch (MessageException e) { throw new ProcessingException( ErrorCode.MSG_CONSTRUCTION_ERROR, "Error creating output sequence msg for msg " + context.getMessage().getID(), this, context.getMessage(), e); } } } } else { throw response.getException(); } } catch (ProcessingException e) { try { getErrorControlStrategy().handleFireException(this, e); } catch (IllegalActionException e1) { getLogger().error("Error handling exception ", e); } } finally { getDirectorAdapter().notifyActorFinishedTask(this, response.getRequest()); } }
@Override protected boolean doPostFire() throws ProcessingException { getLogger().trace("{} - doPostFire() - entry", getFullName()); if (currentProcessResponse != null && ProcessingMode.SYNCHRONOUS.equals( getProcessingMode( currentProcessResponse.getContext(), currentProcessResponse.getRequest()))) { processFinished( currentProcessResponse.getContext(), currentProcessResponse.getRequest(), currentProcessResponse); } currentProcessResponse = null; boolean result = super.doPostFire(); if (!result) { // check if we don't have asynch work ongoing result = getDirectorAdapter().isActorBusy(this); } if (result) { // create new proc req for next iteration iterationCount++; currentProcessRequest = new ProcessRequest(); currentProcessRequest.setIterationCount(iterationCount); try { triggerNextIteration(); } catch (IllegalActionException e) { throw new ProcessingException( ErrorCode.FLOW_EXECUTION_ERROR, "Error triggering a fire iteration for source actor " + getFullName(), this, e); } } getLogger().trace("{} - doPostFire() - exit : {}", getFullName(), result); return result; }