Author: jawi
Date: Thu Oct 17 15:37:27 2013
New Revision: 1533124
URL: http://svn.apache.org/r1533124
Log:
ACE-375 - build initial scenario for batch job support:
- added three new Gogo commands, "put" and "get" to put and get a
script (as String) to/from a queue; and "execute" to execute a
string as Gogo script. With these three commands we have all
basic blocks to support batch jobs.
Added:
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ExecuteCommands.java (with
props)
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ScriptExecutor.java
- copied, changed from r1532991, ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/ScriptExecutor.java
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/QueueCommands.java (with
props)
Removed:
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/ScriptExecutor.java
Modified:
ace/trunk/org.apache.ace.gogo/bnd.bnd
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/Activator.java
ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java
Modified: ace/trunk/org.apache.ace.gogo/bnd.bnd
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/bnd.bnd?rev=1533124&r1=1533123&r2=1533124&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/bnd.bnd (original)
+++ ace/trunk/org.apache.ace.gogo/bnd.bnd Thu Oct 17 15:37:27 2013
@@ -6,14 +6,16 @@
org.apache.felix.gogo.runtime,\
org.apache.ace.bnd.repository;version=latest
-Bundle-Name: Apache ACE OBR Gogo commands
-Bundle-Description: Provides Gogo commands for working with repositories
+Bundle-Name: Apache ACE Gogo commands
+Bundle-Description: Provides Gogo commands for working with ACE
Bundle-Version: 1.0.0
Bundle-Activator: org.apache.ace.gogo.Activator
Private-Package: org.apache.ace.bnd.repository,\
org.apache.ace.gogo,\
+ org.apache.ace.gogo.execute,\
org.apache.ace.gogo.math,\
org.apache.ace.gogo.misc,\
+ org.apache.ace.gogo.queue,\
org.apache.ace.gogo.repo,\
aQute.lib.json;-split-package:=merge-last,\
aQute.libg.filelock;-split-package:=merge-last,\
Modified: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/Activator.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/Activator.java?rev=1533124&r1=1533123&r2=1533124&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/Activator.java (original)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/Activator.java Thu Oct 17 15:37:27
2013
@@ -20,8 +20,11 @@ package org.apache.ace.gogo;
import java.util.Properties;
+import org.apache.ace.gogo.execute.ExecuteCommands;
+import org.apache.ace.gogo.execute.ScriptExecutor;
import org.apache.ace.gogo.math.MathCommands;
import org.apache.ace.gogo.misc.MiscCommands;
+import org.apache.ace.gogo.queue.QueueCommands;
import org.apache.ace.gogo.repo.RepoCommands;
import org.apache.felix.dm.DependencyActivatorBase;
import org.apache.felix.dm.DependencyManager;
@@ -31,47 +34,52 @@ import org.osgi.framework.BundleContext;
public class Activator extends DependencyActivatorBase {
@Override
+ public void destroy(BundleContext context, DependencyManager manager) throws Exception
{
+ // Nop
+ }
+
+ @Override
public void init(BundleContext context, DependencyManager manager) throws Exception {
+ manager.add(createComponent()
+ .setInterface(Object.class.getName(), createProps(RepoCommands.SCOPE, RepoCommands.FUNCTIONS))
+ .setImplementation(RepoCommands.class));
+
+ manager.add(createComponent()
+ .setInterface(Object.class.getName(), createProps(MathCommands.SCOPE, MathCommands.FUNCTIONS))
+ .setImplementation(MathCommands.class));
- Properties repoProps = new Properties();
- repoProps.put(CommandProcessor.COMMAND_SCOPE, RepoCommands.SCOPE);
- repoProps.put(CommandProcessor.COMMAND_FUNCTION, RepoCommands.FUNCTIONS);
manager.add(createComponent()
- .setInterface(Object.class.getName(), repoProps)
- .setImplementation(RepoCommands.class)
- );
-
- Properties mathProps = new Properties();
- mathProps.put(CommandProcessor.COMMAND_SCOPE, MathCommands.SCOPE);
- mathProps.put(CommandProcessor.COMMAND_FUNCTION, MathCommands.FUNCTIONS);
+ .setInterface(Object.class.getName(), createProps(MiscCommands.SCOPE, MiscCommands.FUNCTIONS))
+ .setImplementation(MiscCommands.class));
+
manager.add(createComponent()
- .setInterface(Object.class.getName(), mathProps)
- .setImplementation(MathCommands.class)
- );
-
- Properties miscProps = new Properties();
- miscProps.put(CommandProcessor.COMMAND_SCOPE, MiscCommands.SCOPE);
- miscProps.put(CommandProcessor.COMMAND_FUNCTION, MiscCommands.FUNCTIONS);
+ .setInterface(Object.class.getName(), createProps(QueueCommands.SCOPE, QueueCommands.FUNCTIONS))
+ .setImplementation(QueueCommands.class));
+
manager.add(createComponent()
- .setInterface(Object.class.getName(), miscProps)
- .setImplementation(MiscCommands.class)
- );
-
- if (System.getProperty("ace.gogo.script") != null) {
- String script = System.getProperty("ace.gogo.script");
- long delay = 300;
- if (System.getProperty("ace.gogo.script.delay") != null) {
- delay = Long.parseLong(System.getProperty("ace.gogo.script.delay"));
- }
+ .setInterface(Object.class.getName(), createProps(ExecuteCommands.SCOPE, ExecuteCommands.FUNCTIONS))
+ .setImplementation(ExecuteCommands.class)
+ .add(createServiceDependency()
+ .setService(CommandProcessor.class)
+ .setRequired(true)));
+
+ String script = System.getProperty("ace.gogo.script");
+ if (script != null) {
+ long delay = Long.getLong("ace.gogo.script.delay", 300L);
+
manager.add(createComponent()
.setImplementation(new ScriptExecutor(script, delay))
+ .setComposition("getInstances")
.add(createServiceDependency()
.setService(CommandProcessor.class)
.setRequired(true)));
}
}
- @Override
- public void destroy(BundleContext arg0, DependencyManager arg1) throws Exception {
+ private Properties createProps(String scope, String[] functions) {
+ Properties props = new Properties();
+ props.put(CommandProcessor.COMMAND_SCOPE, scope);
+ props.put(CommandProcessor.COMMAND_FUNCTION, functions);
+ return props;
}
}
Added: 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=1533124&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ExecuteCommands.java (added)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ExecuteCommands.java Thu
Oct 17 15:37:27 2013
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.ace.gogo.execute;
+
+import org.apache.felix.service.command.CommandProcessor;
+import org.apache.felix.service.command.CommandSession;
+import org.apache.felix.service.command.Descriptor;
+
+/**
+ * Executes a Gogo script.
+ */
+public class ExecuteCommands {
+ public final static String SCOPE = "script";
+ public final static String[] FUNCTIONS = new String[] { "execute" };
+
+ // Injected by Felix DM...
+ private volatile CommandProcessor m_processor;
+
+ @Descriptor("executes a given Gogo script")
+ public void execute(CommandSession session, String script) throws Exception {
+ CommandSession newSession = m_processor.createSession(session.getKeyboard(), session.getConsole(),
System.err);
+ try {
+ newSession.execute(script);
+ }
+ finally {
+ newSession.close();
+ }
+ }
+}
Propchange: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ExecuteCommands.java
------------------------------------------------------------------------------
svn:eol-style = native
Copied: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ScriptExecutor.java
(from r1532991, ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/ScriptExecutor.java)
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ScriptExecutor.java?p2=ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ScriptExecutor.java&p1=ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/ScriptExecutor.java&r1=1532991&r2=1533124&rev=1533124&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/ScriptExecutor.java (original)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/execute/ScriptExecutor.java Thu
Oct 17 15:37:27 2013
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.ace.gogo;
+package org.apache.ace.gogo.execute;
import java.io.BufferedReader;
import java.io.File;
@@ -31,36 +31,59 @@ import org.apache.felix.service.command.
import org.apache.felix.service.command.CommandSession;
public class ScriptExecutor {
-
- private volatile DependencyManager m_dependencyManager;
- private volatile Component m_component;
- private volatile CommandProcessor m_processor;
-
- private final String m_scriptPath;
+ private final ScriptTask m_task;
private final long m_delay;
- private Timer m_timer;
+ private volatile DependencyManager m_dm;
+ private volatile Component m_component;
+ private volatile Timer m_timer;
public ScriptExecutor(String scriptPath, long delay) {
- m_scriptPath = scriptPath;
+ m_task = new ScriptTask(scriptPath);
m_delay = delay;
}
- public void start() throws Exception {
+ /**
+ * @return an array with all components that need to be injected with dependencies.
+ */
+ protected Object[] getInstances() {
+ return new Object[] { this, m_task };
+ }
+
+ /**
+ * Called by Felix DM.
+ */
+ protected void start() throws Exception {
m_timer = new Timer();
- m_timer.schedule(new ScriptTask(), m_delay);
+ m_timer.schedule(m_task, m_delay);
}
- public void complete() {
+ /**
+ * Called by Felix DM.
+ */
+ protected void stop() {
m_timer.cancel();
- m_dependencyManager.remove(m_component);
+ m_timer = null;
}
- class ScriptTask extends TimerTask {
+ /**
+ * Called when the script is executed and this service needs to be removed.
+ */
+ void complete() {
+ m_dm.remove(m_component);
+ }
+
+ final class ScriptTask extends TimerTask {
+ private final String m_scriptPath;
+ // Injected by Felix DM...
+ private volatile CommandProcessor m_processor;
+
+ public ScriptTask(String scriptPath) {
+ m_scriptPath = scriptPath;
+ }
@Override
public void run() {
-
CommandSession session = null;
BufferedReader reader = null;
String line;
@@ -78,16 +101,19 @@ public class ScriptExecutor {
e.printStackTrace();
}
finally {
- if (session != null)
+ if (session != null) {
session.close();
- if (reader != null)
+ }
+ if (reader != null) {
try {
reader.close();
}
catch (IOException e) {
e.printStackTrace();
}
- m_timer.cancel();
+ }
+
+ complete();
}
}
}
Modified: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java
URL: http://svn.apache.org/viewvc/ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java?rev=1533124&r1=1533123&r2=1533124&view=diff
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java (original)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/misc/MiscCommands.java Thu Oct 17
15:37:27 2013
@@ -46,7 +46,6 @@ public class MiscCommands {
public void shutdown(long delay) {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
-
@Override
public void run() {
try {
Added: 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=1533124&view=auto
==============================================================================
--- ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/QueueCommands.java (added)
+++ ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/QueueCommands.java Thu Oct
17 15:37:27 2013
@@ -0,0 +1,47 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.ace.gogo.queue;
+
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+
+import org.apache.felix.service.command.Descriptor;
+
+/**
+ * Provides the commands for putting and removing scripts from the queue.
+ */
+public class QueueCommands {
+ public final static String SCOPE = "queue";
+ public final static String[] FUNCTIONS = new String[] { "put", "get" };
+
+ private final BlockingQueue<String> m_queue = new LinkedBlockingQueue<String>();
+
+ @Descriptor("puts a new script on the queue")
+ public void put(String script) throws Exception {
+ if (script == null) {
+ throw new IllegalArgumentException("Script cannot be null!");
+ }
+ m_queue.put(script);
+ }
+
+ @Descriptor("returns the first script from the queue, if available")
+ public String get() throws Exception {
+ return m_queue.poll();
+ }
+}
Propchange: ace/trunk/org.apache.ace.gogo/src/org/apache/ace/gogo/queue/QueueCommands.java
------------------------------------------------------------------------------
svn:eol-style = native
|