From: <st...@us...> - 2007-03-06 17:39:44
|
Revision: 3969 http://svn.sourceforge.net/smartfrog/?rev=3969&view=rev Author: steve_l Date: 2007-03-06 09:39:36 -0800 (Tue, 06 Mar 2007) Log Message: ----------- Exception thrower can throw exceptions in different places now Modified Paths: -------------- trunk/core/smartfrog/src/org/smartfrog/services/assertions/ExceptionThrower.java trunk/core/smartfrog/src/org/smartfrog/services/assertions/ExceptionThrowerImpl.java trunk/core/smartfrog/src/org/smartfrog/services/assertions/components.sf Added Paths: ----------- trunk/core/smartfrog/src/org/smartfrog/services/assertions/exceptionthrower.sf trunk/core/smartfrog/src/org/smartfrog/services/assertions/fail.sf Modified: trunk/core/smartfrog/src/org/smartfrog/services/assertions/ExceptionThrower.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/assertions/ExceptionThrower.java 2007-03-06 17:39:00 UTC (rev 3968) +++ trunk/core/smartfrog/src/org/smartfrog/services/assertions/ExceptionThrower.java 2007-03-06 17:39:36 UTC (rev 3969) @@ -30,4 +30,11 @@ public String ATTR_MESSAGE="message"; + /** {@value} */ + public String ATTR_THROW_ON_STARTUP = "throwOnStartup"; + /** {@value} */ + public String ATTR_THROW_ON_DEPLOY = "throwOnDeploy"; + /** {@value} */ + public String ATTR_THROW_ON_PING = "throwOnPing"; + } Modified: trunk/core/smartfrog/src/org/smartfrog/services/assertions/ExceptionThrowerImpl.java =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/assertions/ExceptionThrowerImpl.java 2007-03-06 17:39:00 UTC (rev 3968) +++ trunk/core/smartfrog/src/org/smartfrog/services/assertions/ExceptionThrowerImpl.java 2007-03-06 17:39:36 UTC (rev 3969) @@ -20,7 +20,10 @@ package org.smartfrog.services.assertions; import org.smartfrog.sfcore.prim.PrimImpl; +import org.smartfrog.sfcore.prim.Liveness; +import org.smartfrog.sfcore.prim.TerminationRecord; import org.smartfrog.sfcore.common.SmartFrogException; +import org.smartfrog.sfcore.common.SmartFrogLivenessException; import org.smartfrog.services.assertions.ExceptionThrower; import java.rmi.RemoteException; @@ -33,13 +36,74 @@ public class ExceptionThrowerImpl extends PrimImpl implements ExceptionThrower { + private boolean throwOnStartup; + private boolean throwOnDeploy; + private boolean throwOnPing; + private String classname; + private String message; + public ExceptionThrowerImpl() throws RemoteException { } + + /** + * Called after instantiation for deployment purposes. Heart monitor is started and if there is a parent the + * deployed component is added to the heartbeat. Subclasses can override to provide additional deployment behavior. + * + * @throws SmartFrogException error while deploying + * @throws RemoteException In case of network/rmi error + */ + public synchronized void sfDeploy() throws SmartFrogException, RemoteException { + super.sfDeploy(); + classname = sfResolve(ATTR_CLASSNAME, "", true); + message = sfResolve(ATTR_MESSAGE, "", true); + throwOnStartup = sfResolve(ATTR_THROW_ON_STARTUP, false, true); + throwOnDeploy = sfResolve(ATTR_THROW_ON_DEPLOY, false, true); + throwOnPing = sfResolve(ATTR_THROW_ON_PING, false, true); + if(throwOnDeploy) { + raiseException(classname, message); + } + } + + /** + * Startup may raise an exception if that is required from the component settings + * @throws SmartFrogException + * @throws RemoteException + */ public synchronized void sfStart() throws SmartFrogException, RemoteException { super.sfStart(); - String classname=sfResolve(ATTR_CLASSNAME,"",true); - String message= sfResolve(ATTR_MESSAGE, "", false); + if (throwOnStartup) { + raiseException(classname, message); + } + } + + + /** + * Liveness call in to check if this component is still alive. + * @param source source of call + * @throws SmartFrogLivenessException component is terminated + * @throws RemoteException for consistency with the {@link Liveness} interface + */ + public void sfPing(Object source) throws SmartFrogLivenessException, RemoteException { + super.sfPing(source); + if (throwOnStartup) { + try { + raiseException(classname, message); + } catch (SmartFrogException e) { + throw (SmartFrogLivenessException) SmartFrogLivenessException.forward(e); + } + } + } + + /** + * Raise an exception + * @param classname name of the class to use + * @param message message to raise + * @throws RemoteException network problems or this exception was asked for + * @throws SmartFrogException which can be the exception, or wrap something inside + * @throws RuntimeException if that was asked for + */ + protected void raiseException(String classname, String message) throws RemoteException, SmartFrogException { Throwable instance; try { Class eClass = getClass().getClassLoader().loadClass(classname); @@ -73,8 +137,6 @@ throw (RemoteException) instance; } throw SmartFrogException.forward(instance); - - } Modified: trunk/core/smartfrog/src/org/smartfrog/services/assertions/components.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/assertions/components.sf 2007-03-06 17:39:00 UTC (rev 3968) +++ trunk/core/smartfrog/src/org/smartfrog/services/assertions/components.sf 2007-03-06 17:39:36 UTC (rev 3969) @@ -23,88 +23,5 @@ #include "/org/smartfrog/services/assertions/assert.sf" #include "/org/smartfrog/services/assertions/testcomponents.sf" #include "/org/smartfrog/services/assertions/testblock.sf" - - -/** - * This is a component that will fail on demand. - * Its original role was for testing workflows such as repeat, retry, etc, - * but users may find other uses for the component, taking advantage of - * its conditional failure and ability to choose a normal or abnormal - * termination. - * Its very useful for testing that composite components handle - * all expected outcomes. - * - * Failure is triggered in a separate thread than the one that - * executes sfStart; it will delay a specified number of seconds, <=0 - * means 'no delay' - */ -Fail extends Prim { - sfClass "org.smartfrog.services.assertions.FailComponent"; - failSchema extends Schema { - //exit message - message extends String; - //should the failure be a normal or abnormal termination - normal extends Boolean; - //expression that must evaluate to true to trigger failure - condition extends Boolean; - //delay in seconds before termination. - delay extends Integer; - //should we detach from our parent - detach extends Boolean; - //notify the parent? - notifyParent extends Boolean; - } - - message "Failure Component initiating termination"; - normal true; - condition true; - delay 0; - detach false; - notifyParent true; -} - -/** - * this is an abnormal failure - */ -FailAbnormal extends Fail { - normal false; -} - - -/** - * A component to create and throw an exception at startup time - * A RuntimeException, RemoteException or SmartFrog exception is thrown as is. - * Any other kind of exception is wrapped by a SmartFrog exception. - * - * This is clearly a test component; its aim in life is to force suprises on containers - * and to see how they handle such things in a replicable manner. - */ -ExceptionThrower extends Prim { - schema extends Schema { - classname extends String; - - message extends OptionalString; - - } - sfClass "org.smartfrog.services.assertions.ExceptionThrowerImpl"; -} - -NullPointerException extends ExceptionThrower { - classname "java.lang.NullPointerException"; -} - - -SmartFrogException extends ExceptionThrower { - classname "org.smartfrog.sfcore.common.SmartFrogException"; -} - -RemoteException extends ExceptionThrower { - classname "java.rmi.RemoteException"; - message "simulated remote exception"; -} - -FileNotFoundException extends ExceptionThrower { - file ""; - classname "java.io.FileNotFoundException"; - message ("Missing file "++file); -} \ No newline at end of file +#include "/org/smartfrog/services/assertions/exceptionthrower.sf" +#include "/org/smartfrog/services/assertions/fail.sf" \ No newline at end of file Added: trunk/core/smartfrog/src/org/smartfrog/services/assertions/exceptionthrower.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/assertions/exceptionthrower.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/assertions/exceptionthrower.sf 2007-03-06 17:39:36 UTC (rev 3969) @@ -0,0 +1,66 @@ +/** (C) Copyright 2007 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/components.sf" + + +/** + * A component to create and throw an exception at startup time + * A RuntimeException, RemoteException or SmartFrog exception is thrown as is. + * Any other kind of exception is wrapped by a SmartFrog exception. + * + * This is clearly a test component; its aim in life is to force suprises on containers + * and to see how they handle such things in a replicable manner. + */ +ExceptionThrower extends Prim { + schema extends Schema { + throwOnStartup extends Boolean; + throwOnDeploy extends Boolean; + throwOnPing extends Boolean; + classname extends String; + + message extends String; + + } + sfClass "org.smartfrog.services.assertions.ExceptionThrowerImpl"; + message ""; + throwOnStartup true; + throwOnDeploy false; + throwOnPing false; +} + +NullPointerException extends ExceptionThrower { + classname "java.lang.NullPointerException"; +} + + +SmartFrogException extends ExceptionThrower { + classname "org.smartfrog.sfcore.common.SmartFrogException"; +} + +RemoteException extends ExceptionThrower { + classname "java.rmi.RemoteException"; + message "simulated remote exception"; +} + +FileNotFoundException extends ExceptionThrower { + file ""; + classname "java.io.FileNotFoundException"; + message ("Missing file "++file); +} \ No newline at end of file Added: trunk/core/smartfrog/src/org/smartfrog/services/assertions/fail.sf =================================================================== --- trunk/core/smartfrog/src/org/smartfrog/services/assertions/fail.sf (rev 0) +++ trunk/core/smartfrog/src/org/smartfrog/services/assertions/fail.sf 2007-03-06 17:39:36 UTC (rev 3969) @@ -0,0 +1,67 @@ +/** (C) Copyright 2007 Hewlett-Packard Development Company, LP + +This library is free software; you can redistribute it and/or +modify it under the terms of the GNU Lesser General Public +License as published by the Free Software Foundation; either +version 2.1 of the License, or (at your option) any later version. + +This library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Lesser General Public License for more details. + +You should have received a copy of the GNU Lesser General Public +License along with this library; if not, write to the Free Software +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +For more information: www.smartfrog.org + +*/ +#include "/org/smartfrog/components.sf" + + +/** + * This is a component that will fail on demand. + * Its original role was for testing workflows such as repeat, retry, etc, + * but users may find other uses for the component, taking advantage of + * its conditional failure and ability to choose a normal or abnormal + * termination. + * It's very useful for testing that composite components handle + * all expected outcomes. + * + * Failure is triggered in a separate thread than the one that + * executes sfStart; it will delay a specified number of seconds, <=0 + * means 'no delay' + */ +Fail extends Prim { + sfClass "org.smartfrog.services.assertions.FailComponent"; + failSchema extends Schema { + //exit message + message extends String; + //should the failure be a normal or abnormal termination + normal extends Boolean; + //expression that must evaluate to true to trigger failure + condition extends Boolean; + //delay in seconds before termination. + delay extends Integer; + //should we detach from our parent + detach extends Boolean; + //notify the parent? + notifyParent extends Boolean; + } + + message "Failure Component initiating termination"; + normal true; + condition true; + delay 0; + detach false; + notifyParent true; +} + +/** + * this is an abnormal failure + */ +FailAbnormal extends Fail { + normal false; +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |