You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ace.apache.org by ja...@apache.org on 2013/10/23 11:54:31 UTC
svn commit: r1534969 - in
/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo:
execute/ExecuteCommands.java queue/QueueCommands.java
Author: jawi
Date: Wed Oct 23 09:54:30 2013
New Revision: 1534969
URL: http://svn.apache.org/r1534969
Log:
ACE-376 - add support for recalculation jobs:
- added some clarifying JavaDoc to the QueueCommands;
- renamed the old execute to executeAll and added support for executing
a simple script again;
- in case of invalid script definitions, do not bail out, but ignore
this invalid script definition.
Modified:
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ExecuteCommands.java
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/QueueCommands.java
Modified: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ExecuteCommands.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ExecuteCommands.java?rev=1534969&r1=1534968&r2=1534969&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ExecuteCommands.java (original)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ExecuteCommands.java Wed Oct 23 09:54:30 2013
@@ -29,33 +29,36 @@ import org.apache.felix.service.command.
*/
public class ExecuteCommands {
public final static String SCOPE = "script";
- public final static String[] FUNCTIONS = new String[] { "execute" };
+ public final static String[] FUNCTIONS = new String[] { "execute", "executeAll" };
// Injected by Felix DM...
private volatile CommandProcessor m_processor;
- @Descriptor("executes a script definition")
- public void execute(CommandSession session, @Descriptor("the script definition(s) to execute, which consists of a map with at least a 'script' key") Map<String, String>... defs) throws Exception {
+ @Descriptor("executes one or more script definition")
+ public void executeAll(CommandSession session, @Descriptor("the script definition(s) to execute, which consists of a map with at least a 'script' key") Map<String, String>... defs) throws Exception {
if (defs == null || defs.length == 0) {
throw new IllegalArgumentException("Need at least one script definition!");
}
- // Check whether all definitions are valid...
+
for (Map<String, String> def : defs) {
String script = def.get("script");
- if (script == null || "".equals(script.trim())) {
- throw new IllegalArgumentException("Script definition *must* define at least a 'script' property!");
+ if (script != null && !"".equals(script.trim())) {
+ execute(session, def.get("script"));
+ }
+ else {
+ session.getConsole().printf("Ignoring script definition without 'script': %s...%n", def);
}
}
+ }
- // Execute all scripts, in order...
- for (Map<String, String> def : defs) {
- CommandSession newSession = m_processor.createSession(session.getKeyboard(), session.getConsole(), System.err);
- try {
- newSession.execute(def.get("script"));
- }
- finally {
- newSession.close();
- }
+ @Descriptor("executes a script definition")
+ public void execute(CommandSession session, @Descriptor("the script to execute, multiple commands should be separated by semicolons") String script) throws Exception {
+ CommandSession newSession = m_processor.createSession(session.getKeyboard(), session.getConsole(), System.err);
+ try {
+ newSession.execute(script);
+ }
+ finally {
+ newSession.close();
}
}
}
Modified: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/QueueCommands.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/QueueCommands.java?rev=1534969&r1=1534968&r2=1534969&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/QueueCommands.java (original)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/QueueCommands.java Wed Oct 23 09:54:30 2013
@@ -34,6 +34,40 @@ import org.osgi.framework.FrameworkUtil;
/**
* Provides the commands for putting and removing scripts from the queue.
+ * <p>
+ * The commands can be used in the following way:
+ * </p>
+ * <dl>
+ * <dt><tt>put [ propA=valueA script='echo A' propB=valueB ]</tt></dt>
+ * <dd>Puts a new script definition on the queue. The definition is a simple map containing at least a <tt>script</tt>
+ * key associated with the actual script to execute. A script contains one or more Gogo commands that should be
+ * separated by semicolons (<tt>;</tt>) or newlines;</dd>
+ * <dt><tt>get</tt></dt>
+ * <dd>Returns the first script definition (as java.util.Map) on the queue, or <code>null</code> if the queue is empty.
+ * The returned script definition is removed from the queue;</dd>
+ * <dt><tt>get '(propA=*)'</tt></dt>
+ * <dd>Returns an array with all script definitions matching a given OSGi/LDAP-filter. In case no script definitions
+ * matched the given filter, an empty array is returned. The returned script definitions are removed from the queue;</dd>
+ * <dt><tt>contains</tt></dt>
+ * <dd>Returns <code>true</code> when there is at least one script definition present on the queue, <code>false</code>
+ * otherwise;</dd>
+ * <dt><tt>contains '(propA=*)'</tt></dt>
+ * <dd>Returns <code>true</code> when there is at least one script definition present on the queue that matches the
+ * given OSGi/LDAP-filter, <code>false</code> otherwise.</dd>
+ * </dl>
+ * <p>
+ * Some examples:
+ * </p>
+ * <ul>
+ * <li><tt>put [ name=foo script='echo A' ] [ name=bar script='echo B' ] [ name=qux script='echo C' ]</tt> will put
+ * three script definitions onto the queue;</li>
+ * <li><tt>contains</tt> will return <code>true</code> as the queue has three entries;</li>
+ * <li><tt>get</tt> will return <tt>[ name=foo script='echo A' ]</tt> as this is the first entry on the queue;</li>
+ * <li><tt>get '(name=qux)'</tt> will return <tt>[ name=qux script='echo C' ]</tt>, which is the last entry on the
+ * queue;</li>
+ * <li><tt>contains '(name=qux)'</tt> will return <code>false</code> as this script definition is no longer queued;</li>
+ * <li><tt>contains '(name=bar)'</tt> will return <code>true</code> as this script definition is still queued.</li>
+ * </ul>
*/
public class QueueCommands {
public final static String SCOPE = "queue";