You are viewing a plain text version of this content. The canonical link for it is here.
Posted to lokahi-commits@incubator.apache.org by to...@apache.org on 2006/06/07 19:14:57 UTC
svn commit: r412490 - in
/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core: agent/
api/function/ common/interfaces/
Author: toback
Date: Wed Jun 7 12:14:56 2006
New Revision: 412490
URL: http://svn.apache.org/viewvc?rev=412490&view=rev
Log:
added some javadocs.
Modified:
incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/TMCAgent.java
incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/api/function/Function.java
incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Cacheable.java
incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Collectable.java
incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Dao.java
incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/GenericDatabaseBroker.java
incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/ReadOnlyBroker.java
Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/TMCAgent.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/TMCAgent.java?rev=412490&r1=412489&r2=412490&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/TMCAgent.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/agent/TMCAgent.java Wed Jun 7 12:14:56 2006
@@ -27,16 +27,30 @@
import java.sql.SQLException;
/**
+ * Main thread that controls the Agent's sub threads.
+ *
* @author Stephen Toback
* @version $Id: TMCAgent.java,v 1.1 2006/03/02 19:19:44 drtobes Exp $
*/
public class TMCAgent {
static final Logger logger = Logger.getLogger(TMCAgent.class);
+
+ /**
+ * <code>true</code> if thread should keep running
+ */
private static volatile boolean run = false;
private TMCAgent() {
}
+ /**
+ * Starts the main thread for either
+ * stopping or starting the Agent.
+ *
+ * @param args first argument should be either 'start'
+ * or 'stop'. All other will cause a help
+ * message to display.
+ */
public static void main(String[] args) { //todo write the 'bootstrappage'
//check to see if starting or stopping;
@@ -48,14 +62,16 @@
if (logger.isInfoEnabled()) {
logger.info("Exception: " + e.getMessage());
}
- } catch (SQLException e) {
- if (logger.isInfoEnabled()) {
- logger.info("Exception: " + e.getMessage());
- }
}
-
}
+ /**
+ * Starts all services and threads needed for
+ * the agent to run.
+ *
+ * @throws IOException if the socket can't be opened
+ * or a property file can't be opened.
+ */
public static void init() throws IOException {
//todo init log4j!
@@ -71,11 +87,22 @@
new Thread(new JobScheduler(), "JobScheduler");
}
- public static void destroy() throws SQLException {
+ /**
+ * Stops all services and threads needed for
+ * the agent to run.
+ *
+ */
+ public static void destroy() {
//stop the Job Scheduler
JobScheduler.setRun(false);
- DerbyBroker.shutDown();
+ try {
+ DerbyBroker.shutDown();
+ } catch (SQLException e) {
+ if (logger.isInfoEnabled()) {
+ logger.info("Exception: " + e.getMessage());
+ }
+ }
}
}
Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/api/function/Function.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/api/function/Function.java?rev=412490&r1=412489&r2=412490&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/api/function/Function.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/api/function/Function.java Wed Jun 7 12:14:56 2006
@@ -29,20 +29,43 @@
import java.util.LinkedHashMap;
/**
+ * Represents the actions that a user can perform on configurable
+ * items that lokahi maintains and controls.
+ *
* @author Stephen Toback
* @version $Id: Function.java,v 1.4 2006/03/13 21:56:59 drtobes Exp $
*/
public class Function extends XMLDao<Function> implements Serializable {
static final Logger logger = Logger.getLogger(Function.class);
private static final ReadOnlyBroker<Function> broker = new BrokerFactory<Function>().getBroker(new java.io.File(PropertiesFile.getConstantValue("prop.location") + "/WEB-INF/classes/function.xml"), Function.class);
+
+ /**
+ * primary key
+ */
private int id;
+
+ /**
+ * value displayed to the user identifing
+ * the ability
+ */
private String name;
+
+ /**
+ * short version of the function that is
+ * an identifier to lokahi as to what the
+ * function allows users to do
+ */
private String command;
public int getPk() {
return this.id;
}
+ /**
+ * Sets the primary key
+ *
+ * @param pk
+ */
public void setPk(int pk) {
this.id = pk;
}
@@ -51,21 +74,42 @@
return this.name;
}
+ /**
+ * Sets the name
+ *
+ * @param name
+ */
public void setName(String name) {
this.name = name;
}
+ /**
+ * @return the Command
+ */
public String getCommand() {
return command;
}
+ /**
+ * Sets the command
+ *
+ * @param command
+ */
public void setCommand(String command) {
this.command = command;
}
+ /**
+ * Default constructor, public for the sake of reflection
+ */
public Function() {
}
+ /**
+ * Prefered constructor for creation of new functions
+ * @param name
+ * @param command
+ */
public Function(String name, String command) {
this.setName(name);
this.setCommand(command);
Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Cacheable.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Cacheable.java?rev=412490&r1=412489&r2=412490&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Cacheable.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Cacheable.java Wed Jun 7 12:14:56 2006
@@ -19,9 +19,19 @@
import java.util.Collection;
/**
+ * Implementation required for use of lokahi caching of
+ * <code>Dao</code> objects.
+ *
* @author Stephen Toback
* @version $Id: Cacheable.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
*/
public interface Cacheable extends Dao {
+ /**
+ * Gets all of the particular <code>Dao</code>
+ * from the datastore without going to the cache
+ *
+ * @return a collection
+ * @throws SQLException
+ */
<T extends Cacheable> Collection<T> getAll() throws SQLException;
}
Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Collectable.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Collectable.java?rev=412490&r1=412489&r2=412490&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Collectable.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Collectable.java Wed Jun 7 12:14:56 2006
@@ -16,12 +16,24 @@
package org.apache.lokahi.core.common.interfaces;
/**
+ * Implementation required for use of lokahi collections classes.
+ *
* @author Stephen Toback
* @version $Id: Collectable.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
*/
public interface Collectable {
+ /**
+ * Gets the primary key
+ *
+ * @return the <code>int</code> primary key
+ */
int getPk();
+ /**
+ * Gets the name.
+ *
+ * @return the <code>String</code> name.
+ */
String getName();
}
Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Dao.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Dao.java?rev=412490&r1=412489&r2=412490&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Dao.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/Dao.java Wed Jun 7 12:14:56 2006
@@ -19,9 +19,21 @@
import java.sql.SQLException;
/**
+ * Required for use of any of the database brokers.
+ *
* @author Stephen Toback
* @version $Id: Dao.java,v 1.2 2006/03/07 22:05:23 drtobes Exp $
+ * @see GenericDatabaseBroker
*/
public interface Dao<T extends Dao> {
+ /**
+ * Creates the Dao from the passed resultset,
+ * internally calling the appriate constructor.
+ *
+ * @param r the resultset from a database call,
+ * should include the entire object
+ * @return Object populated from the resultset
+ * @throws SQLException
+ */
T fillObject(ResultSet r) throws SQLException;
}
Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/GenericDatabaseBroker.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/GenericDatabaseBroker.java?rev=412490&r1=412489&r2=412490&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/GenericDatabaseBroker.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/GenericDatabaseBroker.java Wed Jun 7 12:14:56 2006
@@ -22,12 +22,33 @@
import java.sql.SQLException;
/**
+ * Base class for interaction with sql databases.
+ * <p>
+ * Currently implements methods to build callable
+ * statements and build singular objects from the
+ * result set.
+ *
* @author Stephen Toback
* @version $Id: GenericDatabaseBroker.java,v 1.4 2006/03/07 22:05:24 drtobes Exp $
*/
public abstract class GenericDatabaseBroker<T extends Dao> {
static final Logger logger = Logger.getLogger(GenericDatabaseBroker.class);
+ /**
+ * Builds the parameter list for a <code>CallableStatement</code> object
+ * based upon the parameters passed, currently supports only objects of
+ * <code>Integer</code>, <code>String</code>, and <code>byte[]</code>
+ * (for blobs) types.
+ * <p>
+ * Prevents the need to explictitly code all <code>CallableStatement</code>s
+ *
+ * @param csmt
+ * @param returns <code>true</code> if the statement being built returns any value
+ * @param returnType as specified by the jdbc driver
+ * @param params passed to the stored procedure or function
+ * @return built <code>CallableStatement</code> populated with the objects in params
+ * @throws SQLException
+ */
protected CallableStatement buildParams(CallableStatement csmt, boolean returns, int returnType, Object... params) throws SQLException {
int modifier = 1;
if (returns) {
@@ -59,15 +80,20 @@
return csmt;
}
+ /**
+ * Finds and calls the appropriate <code>fillObject</code> for the given class
+ *
+ * @param c <code>Class</code> <i>that must</i> implements the
+ * <code>Dao</code> interface that the
+ * returned object is expected to be.
+ * @param r <code>ResultSet</code> to build the object out of
+ * @return populated object of <code>Class T</code> or <code>null</code>
+ */
protected T fillObject(Class<T> c, ResultSet r) {
T dao = null;
try {
dao = c.newInstance();
dao = (T) dao.fillObject(r);
-// } catch (NoSuchMethodException e) {
-// if (logger.isInfoEnabled()) {
-// logger.info("NoSuchMethodException: " + e.getMessage());
-// }
} catch (SecurityException e) {
if (logger.isInfoEnabled()) {
logger.info("SecurityException: " + e.getMessage());
@@ -80,10 +106,6 @@
if (logger.isInfoEnabled()) {
logger.info("IllegalAccessException: " + e.getMessage());
}
-// } catch (InvocationTargetException e) {
-// if (logger.isInfoEnabled()) {
-// logger.info("InvocationTargetException: " + e.getMessage());
-// }
} catch (SQLException e) {
if (logger.isInfoEnabled()) {
logger.info("SQLException: " + e.getMessage());
Modified: incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/ReadOnlyBroker.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/ReadOnlyBroker.java?rev=412490&r1=412489&r2=412490&view=diff
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/ReadOnlyBroker.java (original)
+++ incubator/lokahi/lokahi/trunk/src/java/org/apache/lokahi/core/common/interfaces/ReadOnlyBroker.java Wed Jun 7 12:14:56 2006
@@ -19,13 +19,35 @@
import java.util.Collection;
/**
+ * Allows reads to implementing datastores.
+ *
* @author Stephen Toback
* @version $Id: ReadOnlyBroker.java,v 1.3 2006/03/07 20:18:52 drtobes Exp $
*/
public interface ReadOnlyBroker<T extends Dao> {
+ /**
+ * Gets a singular object from the datastore.
+ *
+ * @param c <code>Class</code> of the expected object return.
+ * @param statement key to get the object from the datastore.
+ * @param cache <code>true</code> a cached object will suffice.
+ * @param params objects to look up the desired object by.
+ * @return object of <code>Class</code> c populated.
+ * @throws SQLException
+ */
T getObject(Class<T> c, String statement, boolean cache, Object... params) throws SQLException;
+ /**
+ * Gets a collection of objects from the datastore.
+ *
+ * @param c <code>Class</code> of the expected object return.
+ * @param statement key to get the object from the datastore.
+ * @param cache <code>true</code> a cached object will suffice.
+ * @param params objects to look up the desired object by.
+ * @return object of <code>Class</code> c populated.
+ * @throws SQLException
+ */
Collection<T> getObjects(Class<T> c, boolean cache, String statement, Object... params) throws SQLException;
}