From: Patrick G. <sf...@us...> - 2004-06-14 17:23:18
|
Update of /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/workflow/components In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv25872 Modified Files: OnEvent.java Log Message: modified to deal with single or multiple events Index: OnEvent.java =================================================================== RCS file: /cvsroot/smartfrog/core/smartfrog/src/org/smartfrog/sfcore/workflow/components/OnEvent.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** OnEvent.java 1 Jun 2004 12:40:56 -0000 1.2 --- OnEvent.java 14 Jun 2004 17:23:06 -0000 1.3 *************** *** 25,28 **** --- 25,30 ---- import org.smartfrog.sfcore.common.SmartFrogException; import org.smartfrog.sfcore.common.SmartFrogResolutionException; + import org.smartfrog.sfcore.common.Logger; + import org.smartfrog.sfcore.componentdescription.ComponentDescription; import org.smartfrog.sfcore.compound.Compound; *************** *** 40,43 **** --- 42,54 ---- public class OnEvent extends EventCompoundImpl implements Compound { + /* whether to handle a single event, or multiple */ + boolean singleEvent = false; + + /* whether the event handler should continue to handle events */ + boolean finished = false; + + /* ensure that each child event handler is differently named */ + int index = 0; + /** * Constructs OnEvent. *************** *** 57,60 **** --- 68,76 ---- ComponentDescription act; + synchronized (this) { + if (finished) return; + if (singleEvent) finished = true; // even if not known how to handle... + } + try { String name = "otherwise"; *************** *** 66,75 **** } ! sfCreateNewChild(name+"_actionRunning", act, null); ! } catch (Exception e) { sfTerminate(TerminationRecord.abnormal( "error in event handler for event " + event, null)); } } } --- 82,134 ---- } ! sfCreateNewChild(name+index++, act, null); ! } catch (SmartFrogResolutionException e) { ! // no handler - log and ignore ! Logger.log(this.sfCompleteNameSafe()+"ignoring unknown event " + event); ! } catch (Exception e) { ! // error in handler - log and ignore sfTerminate(TerminationRecord.abnormal( "error in event handler for event " + event, null)); } } + + public synchronized void sfDeploy() throws SmartFrogException, RemoteException { + singleEvent = sfResolve("singleEvent", false, false); + } + + public synchronized void sfTerminateWith(TerminationRecord tr) { + finished = true; + super.sfTerminateWith(tr); + } + + + /** + * It is invoked by sub-components at termination. If normal termiantion, + * and OnEvent is not in single event mode, then it simply accepts + * the child termination. Otherwsie it terminates itself as well, + * propagating child event handler termination status. + * + * @param status termination status of sender + * @param comp sender of termination + */ + public void sfTerminatedWith(TerminationRecord status, Prim comp) { + if (sfContainsChild(comp)) { + try { + if (singleEvent) { + super.sfTerminatedWith(status, comp); + } + + if (!(status.errorType.equals("normal".intern()))) { + super.sfTerminatedWith(status, comp); + } else { + sfRemoveChild(comp); + } + } catch (Exception e) { + Logger.log(this.sfCompleteNameSafe()+" - error handling child event handler termination ",e ); + sfTerminate(TerminationRecord.abnormal( + "error handling child event handler termination " + e, sfCompleteNameSafe())); + } + } + } } |