The three main steps implement the executeStep() method, which the execute() method in DSEStep invokes. DSEStep fires the ok event if everything is correct and the error event if any exception occurs during the access to the journal service. Note that you can override this behavior to suit a specific application design. The following code examples show possible implementations of the executeStep() methods for each of the three steps.
Journal entry step:
public void executeStep() throws Exception { JournalService journal; /* Get the data to be sent to the host by applying the format and saves the results in the context */ FormatElement toHostFmt =(FormatElement) getFormat("hostSendFormat"); setValueAt("hostBuffer",toHostFmt.format(getContext())); /* Writes to the journal using the appropriate format, which includes a reference to hostBuffer*/ journal = (JournalService)getService("Journal"); journal.addRecord(getContext(),"preSendJournalFmt"); journal.commit(); }
Host communications step:
public void executeStep() throws Exception { CommonCommunicationsService sna; CCMessage String toHostStr; String show = null; String info; toHostStr = (String) getValueAt("hostBuffer"); FormatElement fromHost =(FormatElement) getFormat("hostReceiveFormat"); // Register interest in the event "message" and send data to host handleEvent("message","host",getContext()); sna = (CommonCommunicationsService) getService("host"); sna.ccSendData(toHostStr); // Wait for the reply (see dispatchEvent method) getSem().waitOn(10000); // With return code OK, read and unformat the host reply messageFromHost =sna.ccReceiveData(0); if (messageFromHost.getReceiveRC() == 0) { fromHost.unformat(messageFromHost.getDataReceived(),this); } else { // With return code NOK, throw an exception. info = " Messsage received: "+messageFromHost.getDataReceived()+ "; Return code: "+messageFromHost.getReceiveRC()+ "; Data sent: "+messageFromHost.getDataSent()+ "; Timeout : "+messageFromHost.getTimeout(); throw (new Exception(info)); } }
In this case, the step implements the Handler interface and dispatches the message event from the host service as follows:
public Handler dispatchEvent(DSEEventObject anEvent) { try { if (anEvent.getName().equals("message")) { stopHandlingEvent("message","host",getContext()); getSem().signalOn(); } } catch(DSEException e) {//Trace an error condition } return null; }
The toolkit creates the shared semaphore when initializing the step.
Journal UpdateStep:
public void executeStep() throws Exception { // Writes to the journal using the appropriateformat */ JournalService journal; journal =(JournalService)getService("Journal"); journal.updateLastRecord(getContext(),"postReceiveJournalFmt"); journal.commit(); }
Once the flow reaches one of its final states, the requester can use its typeIdInfo to know whether the final state was whether it was OK or Error.