You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by hl...@apache.org on 2005/08/17 19:53:10 UTC
svn commit: r233214 - in
/jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama:
discussions/ mail/ startup/impl/
Author: hlship
Date: Wed Aug 17 10:53:04 2005
New Revision: 233214
URL: http://svn.apache.org/viewcvs?rev=233214&view=rev
Log:
Add missing copyrights.
Move examples to org.apache.examples (to satisfy the license on Clover).
Added:
jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/discussions/
jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/discussions/DiscussionsStartup.java
jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/mail/
jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/mail/MailStartup.java
jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/
jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/ExecuteStatic.java
jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/Task.java
jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/TaskExecutor.java
Added: jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/discussions/DiscussionsStartup.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/discussions/DiscussionsStartup.java?rev=233214&view=auto
==============================================================================
--- jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/discussions/DiscussionsStartup.java (added)
+++ jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/discussions/DiscussionsStartup.java Wed Aug 17 10:53:04 2005
@@ -0,0 +1,31 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.examples.panorama.discussions;
+
+/**
+ * Placeholder for startup logic for the Discussions tool. This style reflects the
+ * "legacy" approach in Panorama, which relied on a startup class invoking a central EJB, which
+ * then invoked public static methods. As tools are updated to make use of HiveMind, these
+ * startup classes are converted into startup services.
+ *
+ * @author Howard Lewis Ship
+ */
+public class DiscussionsStartup
+{
+ public static void init()
+ {
+ System.out.println("DiscussionsStartup invoked.");
+ }
+}
Added: jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/mail/MailStartup.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/mail/MailStartup.java?rev=233214&view=auto
==============================================================================
--- jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/mail/MailStartup.java (added)
+++ jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/mail/MailStartup.java Wed Aug 17 10:53:04 2005
@@ -0,0 +1,31 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.examples.panorama.mail;
+
+import org.apache.examples.panorama.startup.Executable;
+
+/**
+ * Placeholder for startup logic related to the Mail tool.
+ *
+ * @author Howard Lewis Ship
+ */
+public class MailStartup implements Executable
+{
+ public void execute() throws Exception
+ {
+ System.out.println("MailStartup invoked.");
+ }
+
+}
Added: jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/ExecuteStatic.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/ExecuteStatic.java?rev=233214&view=auto
==============================================================================
--- jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/ExecuteStatic.java (added)
+++ jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/ExecuteStatic.java Wed Aug 17 10:53:04 2005
@@ -0,0 +1,58 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.examples.panorama.startup.impl;
+
+import java.lang.reflect.Method;
+
+import org.apache.examples.panorama.startup.Executable;
+
+/**
+ * Used to access the legacy startup code that is in the form
+ * of a public static method (usually <code>init()</code>) on some
+ * class.
+ *
+ * @author Howard Lewis Ship
+ */
+public class ExecuteStatic implements Executable
+{
+ private String _methodName = "init";
+ private Class _targetClass;
+
+ public void execute() throws Exception
+ {
+ Method m = _targetClass.getMethod(_methodName, null);
+
+ m.invoke(null, null);
+ }
+
+ /**
+ * Sets the name of the method to invoke; if not set, the default is <code>init</code>.
+ * The target class must have a public static method with that name taking no
+ * parameters.
+ */
+ public void setMethodName(String string)
+ {
+ _methodName = string;
+ }
+
+ /**
+ * Sets the class to invoke the method on.
+ */
+ public void setTargetClass(Class targetClass)
+ {
+ _targetClass = targetClass;
+ }
+
+}
Added: jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/Task.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/Task.java?rev=233214&view=auto
==============================================================================
--- jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/Task.java (added)
+++ jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/Task.java Wed Aug 17 10:53:04 2005
@@ -0,0 +1,93 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.examples.panorama.startup.impl;
+
+import org.apache.hivemind.impl.BaseLocatable;
+
+import org.apache.examples.panorama.startup.Executable;
+
+/**
+ * An operation that may be executed. A Task exists to wrap an
+ * {@link org.apache.examples.panorama.startup.Executable} object with a title and ordering information (id, after,
+ * before).
+ *
+ * @author Howard Lewis Ship
+ */
+public class Task extends BaseLocatable implements Executable
+{
+ private String _id;
+
+ private String _title;
+
+ private String _after;
+
+ private String _before;
+
+ private Executable _executable;
+
+ public String getBefore()
+ {
+ return _before;
+ }
+
+ public String getId()
+ {
+ return _id;
+ }
+
+ public String getAfter()
+ {
+ return _after;
+ }
+
+ public String getTitle()
+ {
+ return _title;
+ }
+
+ public void setExecutable(Executable executable)
+ {
+ _executable = executable;
+ }
+
+ public void setBefore(String string)
+ {
+ _before = string;
+ }
+
+ public void setId(String string)
+ {
+ _id = string;
+ }
+
+ public void setAfter(String string)
+ {
+ _after = string;
+ }
+
+ public void setTitle(String string)
+ {
+ _title = string;
+ }
+
+ /**
+ * Delegates to the {@link #setExecutable(Executable) executable} object.
+ */
+ public void execute() throws Exception
+ {
+ _executable.execute();
+ }
+
+}
\ No newline at end of file
Added: jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/TaskExecutor.java
URL: http://svn.apache.org/viewcvs/jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/TaskExecutor.java?rev=233214&view=auto
==============================================================================
--- jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/TaskExecutor.java (added)
+++ jakarta/hivemind/trunk/examples/src/java/org/apache/examples/panorama/startup/impl/TaskExecutor.java Wed Aug 17 10:53:04 2005
@@ -0,0 +1,152 @@
+// Copyright 2004, 2005 The Apache Software Foundation
+//
+// Licensed 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.examples.panorama.startup.impl;
+
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.commons.logging.Log;
+import org.apache.hivemind.ErrorLog;
+import org.apache.hivemind.Messages;
+import org.apache.hivemind.order.Orderer;
+
+/**
+ * A service that executes a series of {@link org.apache.examples.panorama.startup.impl.Task}s. Tasks have an
+ * ordering based on pre- and post-requisites.
+ *
+ * @author Howard Lewis Ship
+ */
+public class TaskExecutor implements Runnable
+{
+ private Log _log;
+
+ private ErrorLog _errorLog;
+
+ private List _tasks;
+
+ private Messages _messages;
+
+ /**
+ * Orders the {@link #setTasks(List) tasks} into an execution order, and executes each in turn.
+ * Logs the elapsed time, number of tasks, and the number of failures (if any).
+ */
+ public void run()
+ {
+ long startTime = System.currentTimeMillis();
+
+ Orderer orderer = new Orderer(_errorLog, task());
+
+ Iterator i = _tasks.iterator();
+ while (i.hasNext())
+ {
+ Task t = (Task) i.next();
+
+ orderer.add(t, t.getId(), t.getAfter(), t.getBefore());
+ }
+
+ List orderedTasks = orderer.getOrderedObjects();
+
+ int failures = 0;
+
+ i = orderedTasks.iterator();
+ while (i.hasNext())
+ {
+ Task t = (Task) i.next();
+
+ if (!execute(t))
+ failures++;
+ }
+
+ long elapsedTime = System.currentTimeMillis() - startTime;
+
+ if (failures == 0)
+ _log.info(success(orderedTasks.size(), elapsedTime));
+ else
+ _log.info(failure(failures, orderedTasks.size(), elapsedTime));
+ }
+
+ /**
+ * Execute a single task.
+ *
+ * @return true on success, false on failure
+ */
+ private boolean execute(Task t)
+ {
+ _log.info(executingTask(t));
+
+ try
+ {
+ t.execute();
+
+ return true;
+ }
+ catch (Exception ex)
+ {
+ _errorLog.error(exceptionInTask(t, ex), t.getLocation(), ex);
+
+ return false;
+ }
+ }
+
+ private String task()
+ {
+ return _messages.getMessage("task");
+ }
+
+ private String executingTask(Task t)
+ {
+ return _messages.format("executing-task", t.getTitle());
+ }
+
+ private String exceptionInTask(Task t, Throwable cause)
+ {
+ return _messages.format("exception-in-task", t.getTitle(), cause);
+ }
+
+ private String success(int count, long elapsedTimeMillis)
+ {
+ return _messages.format("success", new Integer(count), new Long(elapsedTimeMillis));
+ }
+
+ private String failure(int failureCount, int totalCount, long elapsedTimeMillis)
+ {
+ return _messages.format(
+ "failure",
+ new Integer(failureCount),
+ new Integer(totalCount),
+ new Long(elapsedTimeMillis));
+ }
+
+ public void setLog(Log log)
+ {
+ _log = log;
+ }
+
+ public void setErrorLog(ErrorLog errorLog)
+ {
+ _errorLog = errorLog;
+ }
+
+ public void setMessages(Messages messages)
+ {
+ _messages = messages;
+ }
+
+ public void setTasks(List list)
+ {
+ _tasks = list;
+ }
+
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org