You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/09/09 22:06:47 UTC
cvs commit: jakarta-avalon-apps/infomover/src/java/org/apache/infomover/notifier Notifier.java
bloritsch 2002/09/09 13:06:46
Modified: infomover/src/java/org/apache/infomover/jobmanager Job.java
infomover/src/java/org/apache/infomover/jobmanager/impl
JobImpl.java
Added: infomover/src/java/org/apache/infomover/jobmanager/impl
JobRunner.java
infomover/src/java/org/apache/infomover/notifier
Notifier.java
Log:
add a little meat on the bones. Adding the Pipeline code and a little of the management code
Revision Changes Path
1.5 +5 -0 jakarta-avalon-apps/infomover/src/java/org/apache/infomover/jobmanager/Job.java
Index: Job.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/infomover/src/java/org/apache/infomover/jobmanager/Job.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Job.java 9 Sep 2002 17:45:48 -0000 1.4
+++ Job.java 9 Sep 2002 20:06:46 -0000 1.5
@@ -68,6 +68,11 @@
long getLastRun();
/**
+ * Determine if the Job is still running
+ */
+ boolean isRunning();
+
+ /**
* Cancel or stop a running job
*/
void cancel();
1.2 +55 -4 jakarta-avalon-apps/infomover/src/java/org/apache/infomover/jobmanager/impl/JobImpl.java
Index: JobImpl.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-apps/infomover/src/java/org/apache/infomover/jobmanager/impl/JobImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JobImpl.java 9 Sep 2002 17:45:48 -0000 1.1
+++ JobImpl.java 9 Sep 2002 20:06:46 -0000 1.2
@@ -51,8 +51,10 @@
import org.apache.infomover.jobmanager.Job;
import org.apache.infomover.jobmanager.JobException;
-import org.apache.avalon.framework.configuration.*;
import org.apache.avalon.framework.activity.*;
+import org.apache.avalon.framework.configuration.*;
+import org.apache.avalon.framework.logger.*;
+import org.apache.avalon.framework.service.*;
/**
* The <code>Job</code> interface represents a job that can be
@@ -61,8 +63,29 @@
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version 1.0
*/
-public class JobImpl implements Job, Configurable, Suspendable, Startable
+public class JobImpl extends AbstractLogEnabled
+ implements Job, Configurable, Suspendable,
+ Serviceable, Startable, Initializable
{
+ private Configuration m_config;
+ private ServiceManager m_manager;
+
+ private int m_transactionCount;
+ private int m_successfulTransactionCount;
+ private long m_lastRun;
+ private boolean m_isRunning;
+
+ /**
+ * Set up a JobImpl with the basic state
+ */
+ public JobImpl()
+ {
+ m_transactionCount = 0;
+ m_successfulTransactionCount = 0;
+ m_lastRun = -1;
+ m_isRunning = false;
+ }
+
/**
* Returns the time when the job was last executed. It helps in checking
* if the job is current.
@@ -73,6 +96,14 @@
}
/**
+ * Determine if the Job is still running
+ */
+ public boolean isRunning()
+ {
+ return m_isRunning;
+ }
+
+ /**
* Cancel or stop a running job
*/
public void cancel()
@@ -88,7 +119,7 @@
*/
public int transactionCount()
{
- throw new UnsupportedOperationException();
+ return m_transactionCount;
}
/**
@@ -103,8 +134,19 @@
}
public void configure( Configuration config )
- throws ConfigurationException
{
+ m_config = config;
+ }
+
+ public void service( ServiceManager manager )
+ {
+ m_manager = manager;
+ }
+
+ public void initialize()
+ throws Exception
+ {
+ // Set up the resources.
throw new UnsupportedOperationException();
}
@@ -120,11 +162,20 @@
public void start()
{
+ m_transactionCount = 0;
+ m_successfulTransactionCount = 0;
+ m_lastRun = System.currentTimeMillis();
+ m_isRunning = true;
+
+ // Get the resources needed to process
throw new UnsupportedOperationException();
}
public void stop()
{
+ m_isRunning = false;
+
+ // Release the resources needed to process
throw new UnsupportedOperationException();
}
}
1.1 jakarta-avalon-apps/infomover/src/java/org/apache/infomover/jobmanager/impl/JobRunner.java
Index: JobRunner.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.infomover.jobmanager.impl;
import org.apache.infomover.input.Input;
import org.apache.infomover.manipulator.Manipulator;
import org.apache.infomover.output.Output;
import org.apache.infomover.notifier.Notifier;
import org.apache.infomover.transaction.*;
import org.apache.infomover.jobmanager.Job;
import org.apache.infomover.jobmanager.JobException;
import org.apache.avalon.framework.activity.*;
import org.apache.avalon.framework.configuration.*;
import org.apache.avalon.framework.logger.*;
import org.apache.avalon.framework.service.*;
/**
* The <code>Job</code> interface represents a job that can be
* executed.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version 1.0
*/
public class JobRunner extends AbstractLogEnabled
implements Suspendable, Executable
{
private volatile int m_transactionCount;
private volatile int m_successfulTransactionCount;
private volatile boolean m_isRunning;
private volatile boolean m_isPaused;
private volatile boolean m_isCanceled;
private final Object m_semaphore;
private final Input m_input;
private final Manipulator[] m_manipulators;
private final Output m_output;
private final Notifier m_notifier;
/**
* Set up a JobImpl with the basic state
*/
public JobRunner(Input in, Manipulator[] manip, Output out, Notifier notifier)
{
m_transactionCount = 0;
m_successfulTransactionCount = 0;
m_isRunning = false;
m_isPaused = false;
m_isCanceled = false;
m_semaphore = new Object();
m_input = in;
m_manipulators = manip;
m_output = out;
m_notifier = notifier;
}
public void execute() throws Exception
{
m_isRunning = true;
boolean hasMoreTransactions = true;
while ( ! m_isCanceled && hasMoreTransactions )
{
// Wait until we are no longer paused
synchronized( m_semaphore )
{
while ( m_isPaused )
{
try
{
// check every second
m_semaphore.wait( 1000 );
}
catch ( InterruptedException ie )
{
// ignore
}
}
}
Transaction trans = m_input.getNextTransaction();
hasMoreTransactions = trans != null;
if ( ! m_isCanceled && hasMoreTransactions )
{
m_transactionCount++;
for (int i = 0; i < m_manipulators.length && trans.isSuccessful(); i++)
{
trans = m_manipulators[i].process( trans );
}
Response result = null;
if ( trans.isSuccessful() )
{
result = m_output.process( trans );
}
else
{
result = trans.getResponse();
}
if ( result.isSuccessful() )
{
m_successfulTransactionCount++;
}
m_notifier.notify( result );
}
}
m_isRunning = false;
}
/**
* Determine if the Job is still running
*/
public boolean isRunning()
{
return m_isRunning;
}
/**
* Cancel or stop a running job
*/
public void cancel()
{
synchronized ( m_semaphore )
{
m_isCanceled = true;
m_semaphore.notifyAll();
}
}
/**
* Get the number of transactions processed in the last run. For jobs
* that are continually running (i.e. listening for input information
* from a network connection), it returns the cumulative number of
* transactions processed for this Job.
*/
public int transactionCount()
{
return m_transactionCount;
}
/**
* Get the number of transactions successfully processed in the last run.
* For jobs that are continually running (i.e. listening for input
* information from a network connection), it returns the cumulative
* number of successful transactions for this job.
*/
public int successfulTransactionCount()
{
return m_successfulTransactionCount;
}
public void suspend()
{
synchronized( m_semaphore )
{
m_isPaused = true;
m_semaphore.notifyAll();
}
}
public void resume()
{
synchronized( m_semaphore )
{
m_isPaused = false;
m_semaphore.notifyAll();
}
}
}
1.1 jakarta-avalon-apps/infomover/src/java/org/apache/infomover/notifier/Notifier.java
Index: Notifier.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
apache@apache.org.
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.infomover.notifier;
import org.apache.infomover.transaction.*;
/**
* The Notifier handles all the result notification policies.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version 1.0
*/
public interface Notifier
{
/**
* Perform the actual notification.
*/
void notify( Response result );
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>