hivemind-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hls...@apache.org
Subject cvs commit: jakarta-hivemind/examples build.xml
Date Tue, 20 Jul 2004 17:22:54 GMT
hlship      2004/07/20 10:22:54

  Added:       examples/src/descriptor/META-INF panorama.mail.sdl
                        panorama.sdl panorama.startup.properties
                        panorama.discussions.sdl panorama.startup.sdl
                        hivemodule.sdl
               examples/src/documentation/content/xdocs/hivemind-examples
                        index.xml
               examples/src/java/com/panorama/startup/impl
                        TaskExecutor.java Task.java ExecuteStatic.java
               examples/src/java/com/panorama Main.java
               examples/src/java/com/panorama/mail MailStartup.java
               examples/src/conf log4j.properties
               examples/src/test/com/panorama/startup/impl
                        ExecutableFixture.java TestExecuteStatic.java
                        TestTaskExecutor.java
               examples/src/java/com/panorama/startup Executable.java
               examples/src/java/com/panorama/discussions
                        DiscussionsStartup.java
               examples build.xml
  Log:
  Add a new module containing example code.
  
  Revision  Changes    Path
  1.1                  jakarta-hivemind/examples/src/descriptor/META-INF/panorama.mail.sdl
  
  Index: panorama.mail.sdl
  ===================================================================
  //  Copyright 2004 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.
  
  module (id=panorama.mail version="1.0.0")
  {
    "Panorama Mail module -- demonstrates use of a startup service."
    
    contribution (configuration-id=panorama.startup.Startup)
    {
      task (id=mail title=Mail executable=service:MailStartup)
    }
    
    service-point (id=MailStartup interface=com.panorama.startup.Executable)
    {
      create-instance (class=com.panorama.mail.MailStartup)
    }
  }
  
  
  1.1                  jakarta-hivemind/examples/src/descriptor/META-INF/panorama.sdl
  
  Index: panorama.sdl
  ===================================================================
  //  Copyright 2004 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.
  
  module (id=panorama version="1.0.0")
  {
    "The Panorama example application, which includes several sub-modules."
    
    sub-module (descriptor=panorama.startup.sdl)  
    sub-module (descriptor=panorama.mail.sdl)
    sub-module (descriptor=panorama.discussions.sdl)
  
  }
  
  
  1.1                  jakarta-hivemind/examples/src/descriptor/META-INF/panorama.startup.properties
  
  Index: panorama.startup.properties
  ===================================================================
  #
  # Copyright 2004 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.
  
  task=task
  executing-task=Executing task {0}.
  exception-in-task=Exception while executing task {0}: {1}
  success=Executed {0,choice,1#one task|1<{0} tasks} (in {0} milliseconds).
  failure=Executed {0,choice,1#one task|1<{0} tasks} with {1,choice,1#one failure|1<{1}
failures} (in {2} milliseconds).
  
  
  1.1                  jakarta-hivemind/examples/src/descriptor/META-INF/panorama.discussions.sdl
  
  Index: panorama.discussions.sdl
  ===================================================================
  //  Copyright 2004 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.
  
  module (id=panorama.discussions version="1.0.0")
  {
    "Panorama Discussions module -- demonstrates the use of a static method startup task."
    
    contribution (configuration-id=panorama.startup.Startup)
    {
      static-task (id=discussions title=Discussions after=mail class=com.panorama.discussions.DiscussionsStartup)
    }
    
  }
  
  
  1.1                  jakarta-hivemind/examples/src/descriptor/META-INF/panorama.startup.sdl
  
  Index: panorama.startup.sdl
  ===================================================================
  //  Copyright 2004 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.
  
  module (id=panorama.startup version="1.0.0")
  {
    "Startup logic for Panorama."
    
    schema (id=Tasks)
    {
      "Defines tasks that can be executed by a task executor service."
      
      element (name=task)
      {
        "A task which can invoke an object, or service, that implements Executable."
        
        attribute (name=title required=true)
        {
          "A short, user presentable description of the task, used in logging output."
        }
        
        attribute (name=id required=true)
        {
          "A unique id for the task, which is used to set the order of execution of all tasks."
        }
        
        attribute (name=before)
        {
          "A comma-seperated list of task ids whose execution should follow this task, or
* to "
          "indicate that this task must run first."
        }
        
        attribute (name=after)
        {
          "A comma-seperated list of task ids whose execution should precede this tasks execution,
or * "
          "to indicate that this task must run last."
        }
        
        attribute (name=executable required=true translator=object)
        {
          "An object or service that implements Executable."
        }
        
        conversion (class=com.panorama.startup.impl.Task)
      }
      
      element (name=static-task)
      {
        "A task which can invoke an object, or service, that implements Executable."
        
        attribute (name=title required=true)
        {
          "A short, user presentable description of the task, used in logging output."
        }
        
        attribute (name=id required=true)
        {
          "A unique id for the task, which is used to set the order of execution of all tasks."
        }
        
        attribute (name=before)
        {
          "A comma-seperated list of task ids whose execution should follow this task, or
* to "
          "indicate that this task must run first."
        }
  
        attribute (name=after)
        {
          "A comma-seperated list of task ids whose execution should precede this tasks execution,
or * "
          "to indicate that this task must run last."
        }
              
        attribute (name=class translator=class required=true)
        {
          "A class containing a public static method to execute."
        }
        
        attribute (name=method)
        {
          "The name of a public static method of the class; if not specified, 'init' is used."
        }    
        
        rules
        {
          create-object (class=com.panorama.startup.impl.Task)
          invoke-parent (method=addElement)
          
          read-attribute (attribute=id property=id)
          read-attribute (attribute=title property=title)
          read-attribute (attribute=before property=before)
          read-attribute (attribute=after property=after)
          
          create-object (class=com.panorama.startup.impl.ExecuteStatic)
          invoke-parent (method=setExecutable)
          
          read-attribute (attribute=class property=targetClass)
          read-attribute (attribute=method property=methodName)
          
        }
      }
    }
  
    configuration-point (id=Startup schema-id=Tasks)
      
    service-point (id=Startup interface=java.lang.Runnable)
    {
      invoke-factory (service-id=hivemind.BuilderFactory)
      {
        construct (class=com.panorama.startup.impl.TaskExecutor)
        {
          set-configuration (property=tasks configuration-id=Startup)
        }
      }
    }
    
    // Have the Panorama Startup execute when the Registry itself is
    // created.
    
    contribution (configuration-id=hivemind.Startup)
    {
      service (service-id=Startup)
    }
  }
  
  
  1.1                  jakarta-hivemind/examples/src/descriptor/META-INF/hivemodule.sdl
  
  Index: hivemodule.sdl
  ===================================================================
  //  Copyright 2004 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.
  
  module (id=examples version="1.0.0")
  {
    "Top level descriptor for all the examples; brings in the other module descriptors as
submodules."
    
    sub-module (descriptor=panorama.sdl)
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/documentation/content/xdocs/hivemind-examples/index.xml
  
  Index: index.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     Copyright 2004 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.
  -->
  <!DOCTYPE document PUBLIC "-//APACHE//DTD Documentation V1.2//EN" "./dtd/document-v12.dtd">
  <document>
  
    <header>
      <title>HiveMind Examples</title>
  	</header>
  	
    <body>
  
  <p>
  Example code demonstrating many HiveMind features.
  </p>
  
      
    </body>
  </document>
  
  
  
  1.1                  jakarta-hivemind/examples/src/java/com/panorama/startup/impl/TaskExecutor.java
  
  Index: TaskExecutor.java
  ===================================================================
  //  Copyright 2004 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 com.panorama.startup.impl;
  
  import java.util.Iterator;
  import java.util.List;
  
  import org.apache.commons.logging.Log;
  import org.apache.hivemind.ErrorHandler;
  import org.apache.hivemind.Messages;
  import org.apache.hivemind.order.Orderer;
  
  /**
   * A service that executes a series of {@link com.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 ErrorHandler _errorHandler;
      private Log _log;
      private List _tasks;
      private Messages _messages;
  
      public void run()
      {
          Orderer orderer = new Orderer(_log, _errorHandler, 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;
          long startTime = System.currentTimeMillis();
  
          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)
          {
              _errorHandler.error(_log, 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 setErrorHandler(ErrorHandler handler)
      {
          _errorHandler = handler;
      }
  
      public void setLog(Log log)
      {
          _log = log;
      }
  
      public void setMessages(Messages messages)
      {
          _messages = messages;
      }
  
      public void setTasks(List list)
      {
          _tasks = list;
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/java/com/panorama/startup/impl/Task.java
  
  Index: Task.java
  ===================================================================
  //  Copyright 2004 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 com.panorama.startup.impl;
  
  import org.apache.hivemind.Orderable;
  import org.apache.hivemind.impl.BaseLocatable;
  
  import com.panorama.startup.Executable;
  
  /**
   * An operation that may be executed. A Task exists to wrap
   * an {@link com.panorama.startup.Executable} object with
   * a title and ordering information (name, followingNames, precedingNames).
   *
   * @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();
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/java/com/panorama/startup/impl/ExecuteStatic.java
  
  Index: ExecuteStatic.java
  ===================================================================
  //  Copyright 2004 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 com.panorama.startup.impl;
  
  import java.lang.reflect.Method;
  
  import com.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;
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/java/com/panorama/Main.java
  
  Index: Main.java
  ===================================================================
  //  Copyright 2004 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 com.panorama;
  
  import org.apache.hivemind.Registry;
  import org.apache.hivemind.impl.RegistryBuilder;
  
  public class Main
  {
  
      public static void main(String[] args)
      {
          Registry r = RegistryBuilder.constructDefaultRegistry();
  
          r.shutdown();
      }
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/java/com/panorama/mail/MailStartup.java
  
  Index: MailStartup.java
  ===================================================================
  //  Copyright 2004 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 com.panorama.mail;
  
  import com.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.");
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/conf/log4j.properties
  
  Index: log4j.properties
  ===================================================================
  #
  # Copyright 2004 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.
  
  log4j.rootCategory=WARN, A1
  
  # A1 is set to be a ConsoleAppender. 
  log4j.appender.A1=org.apache.log4j.ConsoleAppender
  
  # A1 uses PatternLayout.
  log4j.appender.A1.layout=org.apache.log4j.PatternLayout
  log4j.appender.A1.layout.ConversionPattern=%c{1} [%p] %m%n
  
  log4j.category.panorama=info
  
  
  
  
  
  1.1                  jakarta-hivemind/examples/src/test/com/panorama/startup/impl/ExecutableFixture.java
  
  Index: ExecutableFixture.java
  ===================================================================
  //  Copyright 2004 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 com.panorama.startup.impl;
  
  import com.panorama.startup.Executable;
  
  
  public class ExecutableFixture implements Executable
  {
  	private String _token;
  	
  	public ExecutableFixture(String token)
  	{
  		_token = token;
  	}
  	
      public void execute() throws Exception
      {
  		TestTaskExecutor.addToken(_token);
      }
  
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/test/com/panorama/startup/impl/TestExecuteStatic.java
  
  Index: TestExecuteStatic.java
  ===================================================================
  //  Copyright 2004 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 com.panorama.startup.impl;
  
  import junit.framework.TestCase;
  
  public class TestExecuteStatic extends TestCase
  {
      private static boolean _staticMethodInvoked;
  
      public static void staticMethod()
      {
          _staticMethodInvoked = true;
      }
  
      protected void tearDown()
      {
          _staticMethodInvoked = false;
      }
  
      public void testInvoke() throws Exception
      {
          ExecuteStatic e = new ExecuteStatic();
  
          e.setMethodName("staticMethod");
          e.setTargetClass(TestExecuteStatic.class);
  
          e.execute();
  
          assertEquals(true, _staticMethodInvoked);
      }
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/test/com/panorama/startup/impl/TestTaskExecutor.java
  
  Index: TestTaskExecutor.java
  ===================================================================
  //  Copyright 2004 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 com.panorama.startup.impl;
  
  import java.util.ArrayList;
  import java.util.Collections;
  import java.util.List;
  import java.util.Locale;
  
  import org.apache.commons.logging.Log;
  import org.apache.hivemind.ApplicationRuntimeException;
  import org.apache.hivemind.ErrorHandler;
  import org.apache.hivemind.Messages;
  import org.apache.hivemind.impl.DefaultClassResolver;
  import org.apache.hivemind.impl.MessagesImpl;
  import org.apache.hivemind.test.ExceptionAwareArgumentsMatcher;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.apache.hivemind.test.RegexpArgumentsMatcher;
  import org.apache.hivemind.util.ClasspathResource;
  import org.easymock.MockControl;
  
  import com.panorama.startup.Executable;
  
  /**
   * Tests for the {@link com.panorama.startup.impl.TaskExecutor} service.
   *
   * @author Howard Lewis Ship
   */
  public class TestTaskExecutor extends HiveMindTestCase
  {
      private static List _tokens = new ArrayList();
  
      protected void setUp()
      {
          _tokens.clear();
      }
  
      protected void tearDown()
      {
          _tokens.clear();
      }
  
      public static void addToken(String token)
      {
          _tokens.add(token);
      }
  
      public Messages getMessages()
      {
          ClasspathResource r =
              new ClasspathResource(new DefaultClassResolver(), "/META-INF/panorama.startup.sdl");
  
          return new MessagesImpl(r, Locale.getDefault());
      }
  
      public void testSuccess()
      {
          ExecutableFixture f1 = new ExecutableFixture("f1");
  
          Task t1 = new Task();
  
          t1.setExecutable(f1);
          t1.setId("first");
          t1.setAfter("second");
          t1.setTitle("Fixture #1");
  
          ExecutableFixture f2 = new ExecutableFixture("f2");
  
          Task t2 = new Task();
          t2.setExecutable(f2);
          t2.setId("second");
          t2.setTitle("Fixture #2");
  
          List tasks = new ArrayList();
          tasks.add(t1);
          tasks.add(t2);
  
          MockControl logControl = newControl(Log.class);
          Log log = (Log) logControl.getMock();
  
          TaskExecutor e = new TaskExecutor();
  
          ErrorHandler errorHandler = (ErrorHandler) newMock(ErrorHandler.class);
  
          e.setErrorHandler(errorHandler);
          e.setLog(log);
          e.setMessages(getMessages());
          e.setTasks(tasks);
  
  		// Note the ordering; explicitly set, to check that ordering does
  		// take place.
          log.info("Executing task Fixture #2.");
          log.info("Executing task Fixture #1.");
          log.info("Executed 2 tasks \\(in \\d+ milliseconds\\)\\.");
          logControl.setMatcher(new RegexpArgumentsMatcher());
  
          replayControls();
  
          e.run();
  
          assertListsEqual(new String[] { "f2", "f1" }, _tokens);
  
          verifyControls();
      }
  
      public void testFailure()
      {
          Executable f = new Executable()
          {
              public void execute() throws Exception
              {
                  throw new ApplicationRuntimeException("Failure!");
              }
          };
  
          Task t = new Task();
  
          t.setExecutable(f);
          t.setId("failure");
          t.setTitle("Failure");
  
          List tasks = Collections.singletonList(t);
  
          MockControl logControl = newControl(Log.class);
          Log log = (Log) logControl.getMock();
  
          MockControl errorHandlerControl = newControl(ErrorHandler.class);
          ErrorHandler errorHandler = (ErrorHandler) errorHandlerControl.getMock();
  
          log.info("Executing task Failure.");
  
          errorHandler.error(
              log,
              "Exception while executing task Failure: Failure!",
              null,
              new ApplicationRuntimeException(""));
          errorHandlerControl.setMatcher(new ExceptionAwareArgumentsMatcher());
  
          log.info("Executed one task with one failure \\(in \\d+ milliseconds\\)\\.");
          logControl.setMatcher(new RegexpArgumentsMatcher());
  
          replayControls();
  
          TaskExecutor e = new TaskExecutor();
  
          e.setErrorHandler(errorHandler);
          e.setLog(log);
          e.setMessages(getMessages());
          e.setTasks(tasks);
          
          e.run();
  
          verifyControls();
      }
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/java/com/panorama/startup/Executable.java
  
  Index: Executable.java
  ===================================================================
  //  Copyright 2004 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 com.panorama.startup;
  
  /**
   * Much like {@link java.lang.Runnable}, but allows the caller
   * to handle any exceptions thrown.
   *
   * @author Howard Lewis Ship
   */
  public interface Executable
  {
      public void execute() throws Exception;
  }
  
  
  
  1.1                  jakarta-hivemind/examples/src/java/com/panorama/discussions/DiscussionsStartup.java
  
  Index: DiscussionsStartup.java
  ===================================================================
  //  Copyright 2004 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 com.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.");
      }
  }
  
  
  
  1.1                  jakarta-hivemind/examples/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0"?>
  <!-- 
     Copyright 2004 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.
  -->
  <project name="HiveMind Examples" default="jar">
  
  	<property name="module.name" value="hivemind-examples"/>
  	<property name="javadoc.package" value="com.panorama.*"/>
  	
  	<property name="module.install.dir" value="target"/>
  	
  	<property name="root.dir" value=".."/>
  	<import file="${root.dir}/hivebuild/jar-module.xml"/>
  	<import file="${hivebuild.dir}/javadoc-report.xml"/>	
  	<import file="${hivebuild.dir}/clover-report.xml"/>
  		
  	<!-- HiveDoc report is normally setup for project level, but we're using it
  	     at the module level, so we need to tweak. -->
  	     		
  	<path id="hivedoc.taskdef.classpath">
  	  <fileset dir="${module.lib.dir}" includes="**/*.jar"/>
  	  <pathelement location="${conf.src.dir}"/>
  	</path>
  	
  	<path id="hivedoc.classpath">
  	  <path refid="hivedoc.taskdef.classpath"/>
  	  <pathelement location="${descriptor.src.dir}/META-INF/hivemodule.sdl"/>
  	</path>
  		
  	<property name="hivedoc.output.dir" location="${module.docs.target.dir}/hivedocs"/>
  	
  	<import file="${hivebuild.dir}/hivedoc-report.xml"/>
  			
  	<target name="compile">
  		<ibiblio-dependency jar="geronimo-spec-ejb-1.0-M1.jar" group-id="geronimo-spec"/>
  		<ibiblio-dependency jar="spring-full-1.0.1.jar" group-id="springframework"/>
  		<ibiblio-dependency jar="commons-logging-1.0.3.jar" group-id="commons-logging"/>
  		
  		<ibiblio-dependency jar="log4j-1.2.7.jar" group-id="log4j" use="run"/>				
  		<ibiblio-dependency jar="javassist-2.6.jar" group-id="jboss" use="run"/>			
  		<ibiblio-dependency jar="oro-2.0.6.jar" group-id="oro" use="run"/>			
  		<ibiblio-dependency jar="easymock-1.1.jar" group-id="easymock" use="test"/>
  		
  		<project-dependency name="hivemind"/>
  		
  		<default-compile/>
  	</target>
  	
  	<target name="run-reports">
  	  <javadoc-report/>
  	  <hivedoc-report doc-path-id="hivedoc.classpath" taskdef-path-id="hivedoc.taskdef.classpath"/>
  	  <clover-report/>
  	</target>
  
  
  </project>
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org


Mime
View raw message