From: cvs@openprivacy.orgCVS update: talon/src/java/talon
Date: Thursday February 8, 19101 @ 22:31
Author: burton
CVSWEB Options: -------------------
Main CVSWeb: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi
View this module: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon
-----------------------------------
Update of /usr/local/cvs/public/talon/src/java/talon
In directory giga:/tmp/cvs-serv22487/src/java/talon
Modified Files:
ComponentFactory.java ComponentHandle.java Initializer.java
Log Message:
on demand components should work...
*****************************************************************
File: talon/src/java/talon/ComponentFactory.java
CVSWEB Options: -------------------
CVSWeb: Annotate this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/ComponentFactory.java?annotate=1.5
CVSWeb: View this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/ComponentFactory.java?rev=1.5&content-type=text/x-cvsweb-markup
CVSWeb: Diff to previous version: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/ComponentFactory.java.diff?r1=1.5&r2=1.4
-----------------------------------
Index: talon/src/java/talon/ComponentFactory.java
diff -u talon/src/java/talon/ComponentFactory.java:1.4 talon/src/java/talon/ComponentFactory.java:1.5
--- talon/src/java/talon/ComponentFactory.java:1.4 Wed Feb 7 01:59:33 2001
+++ talon/src/java/talon/ComponentFactory.java Thu Feb 8 22:31:42 2001
@@ -17,26 +17,31 @@
* Create instances of components and manage their lifetimes.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentFactory.java,v 1.4 2001/02/07 09:59:33 burton Exp $
+ * @version $Id: ComponentFactory.java,v 1.5 2001/02/09 06:31:42 burton Exp $
*/
public class ComponentFactory {
+
+ public static final String LIFETIME_SINGLETON = "singleton";
+ public static final String LIFETIME_DEMAND = "demand";
// **************************************
// BEGIN DEFAULT TALON COMPONENTS
// **************************************
public static final ComponentHandle TALON_DEFAULT_LOGGER =
- new ComponentHandle( "TALON_DEFAULT_LOGGER",
- "talon.interfaces.Logger",
- "talon.implementations.SimpleLogger",
- new SimplePropertyManager().setProperty( "project", "talon" ) );
+ new ComponentHandle().setName( "TALON_DEFAULT_LOGGER" )
+ .setInterface( "talon.interfaces.Logger" )
+ .setImplementation( "talon.implementations.SimpleLogger" )
+ .setInitProperties( new SimplePropertyManager().setProperty( "project", "talon" ) )
+ .setLifetime( LIFETIME_SINGLETON );
public static final ComponentHandle TALON_DEFAULT_PROPERTY_MANAGER =
- new ComponentHandle( "TALON_DEFAULT_PROPERTY_MANAGER",
- "talon.interfaces.PropertyManager",
- "talon.implementations.SimplePropertyManager",
- new SimplePropertyManager().setProperty( "project", "talon" ) );
+ new ComponentHandle().setName( "TALON_DEFAULT_PROPERTY_MANAGER" )
+ .setInterface( "talon.interfaces.PropertyManager" )
+ .setImplementation( "talon.implementations.SimplePropertyManager" )
+ .setInitProperties( new SimplePropertyManager().setProperty( "project", "talon" ) )
+ .setLifetime( LIFETIME_SINGLETON );
// **************************************
// END DEFAULT TALON COMPONENTS
@@ -61,7 +66,7 @@
* Static initializer...
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentFactory.java,v 1.4 2001/02/07 09:59:33 burton Exp $
+ * @version $Id: ComponentFactory.java,v 1.5 2001/02/09 06:31:42 burton Exp $
*/
static {
@@ -75,7 +80,7 @@
* Given a ComponentHandle get a Component
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentFactory.java,v 1.4 2001/02/07 09:59:33 burton Exp $
+ * @version $Id: ComponentFactory.java,v 1.5 2001/02/09 06:31:42 burton Exp $
*/
public static Component getInstance( ComponentHandle handle )
throws TalonException {
@@ -87,33 +92,89 @@
//FIXME: if the component we fetch isn't the correct implementation of
//the given interface... throw an Exception because the resulting object
//won't be able to be (cast) and the application will get a RuntimeException
+ //write a use case for this.
+
+
+
+ //determine what lifetime to use
+
+ String lifetime = handle.getLifetime();
- try {
+ if ( lifetime == null || lifetime.equals( LIFETIME_DEMAND ) ) {
+ return getDemandBasedInstance( handle );
+ } else if ( lifetime.equals( LIFETIME_SINGLETON ) ) {
+ return getSingletonBasedInstance( handle );
+ }
+
+ throw new TalonException( "Do not know how to create " + handle.toString() );
+ }
+
+ /**
+ * Get a component instantiating a new one everytime we need it.
+ *
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: ComponentFactory.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ */
+ private static Component getDemandBasedInstance( ComponentHandle handle )
+ throws TalonException {
+
+ //since this component is always created... just return it.
+ return instantiateComponent( handle );
+
+ }
+
+
+ /**
+ * Get a singleton or create it if necessary.
+ *
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: ComponentFactory.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ */
+ private static Component getSingletonBasedInstance( ComponentHandle handle )
+ throws TalonException {
+
+ Component comp = (Component)singletons.get( handle );
- Component comp = (Component)singletons.get( handle );
+ if ( comp == null ) {
+ //we have to create it!
+
+ comp = instantiateComponent( handle );
+
+ putSingleton( handle, comp );
+ }
+
+ return comp;
+
- if ( comp == null ) {
- //we have to create it!
-
- comp = (Component)Class.forName( handle.getImplementation() ).newInstance();
- comp.setComponentHandle( handle );
- comp.init();
+ }
+
+ /**
+ * Perform basic instantiation on a component.
+ *
+ * @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
+ * @version $Id: ComponentFactory.java,v 1.5 2001/02/09 06:31:42 burton Exp $
+ */
+ private static Component instantiateComponent( ComponentHandle handle )
+ throws TalonException {
- putSingleton( handle, comp );
- }
+ try {
- return comp;
+ Component comp = (Component)Class.forName( handle.getImplementation() ).newInstance();
+ comp.setComponentHandle( handle );
+ comp.init();
+ return comp;
} catch ( Throwable t ) {
throw new NotFoundException( t.getMessage() );
}
+
}
-
+
/**
* Put a singleton to the Factory.
* FIXME: Should this throw an Exception if this object is already present?
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentFactory.java,v 1.4 2001/02/07 09:59:33 burton Exp $
+ * @version $Id: ComponentFactory.java,v 1.5 2001/02/09 06:31:42 burton Exp $
*/
static void putSingleton( ComponentHandle handle, Component comp ) {
singletons.put( handle, comp );
*****************************************************************
File: talon/src/java/talon/ComponentHandle.java
CVSWEB Options: -------------------
CVSWeb: Annotate this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/ComponentHandle.java?annotate=1.6
CVSWeb: View this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/ComponentHandle.java?rev=1.6&content-type=text/x-cvsweb-markup
CVSWeb: Diff to previous version: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/ComponentHandle.java.diff?r1=1.6&r2=1.5
-----------------------------------
Index: talon/src/java/talon/ComponentHandle.java
diff -u talon/src/java/talon/ComponentHandle.java:1.5 talon/src/java/talon/ComponentHandle.java:1.6
--- talon/src/java/talon/ComponentHandle.java:1.5 Thu Feb 8 20:18:08 2001
+++ talon/src/java/talon/ComponentHandle.java Thu Feb 8 22:31:42 2001
@@ -18,7 +18,7 @@
* Object which is used to find components within the system.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public class ComponentHandle {
@@ -47,7 +47,7 @@
* Create a basic ComponentHandle
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public ComponentHandle() {}
@@ -56,7 +56,7 @@
* pulled from the Talon properties.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public ComponentHandle( String _interface ) {
@@ -68,7 +68,7 @@
* The interface and classname.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public ComponentHandle( String _interface,
String _implementation ) {
@@ -83,7 +83,7 @@
* The interface and classname. You may specify a PropertyManager here.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public ComponentHandle( String _interface,
String _classname,
@@ -98,7 +98,7 @@
* Also set the name.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public ComponentHandle( String name,
String _interface,
@@ -164,7 +164,7 @@
*
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public String getLifetime() {
return this._lifetime;
@@ -175,30 +175,32 @@
*
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public ComponentHandle setLifetime( String _lifetime ) {
this._lifetime = _lifetime;
return this;
}
-
-
-
/**
* @see Component
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public PropertyManager getInitProperties() {
return this.initProperties;
}
+ public ComponentHandle setInitProperties( PropertyManager initProperties ) {
+ this.initProperties = initProperties;
+ return this;
+ }
+
/**
* Dump Handle information..
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: ComponentHandle.java,v 1.5 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: ComponentHandle.java,v 1.6 2001/02/09 06:31:42 burton Exp $
*/
public String toString() {
return this.getName() + ":" + this.getInterface() + " -> " + this.getImplementation();
*****************************************************************
File: talon/src/java/talon/Initializer.java
CVSWEB Options: -------------------
CVSWeb: Annotate this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/Initializer.java?annotate=1.4
CVSWeb: View this file: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/Initializer.java?rev=1.4&content-type=text/x-cvsweb-markup
CVSWeb: Diff to previous version: http://openprivacy.org/cgi-bin/cvsweb/cvsweb.cgi/talon/src/java/talon/Initializer.java.diff?r1=1.4&r2=1.3
-----------------------------------
Index: talon/src/java/talon/Initializer.java
diff -u talon/src/java/talon/Initializer.java:1.3 talon/src/java/talon/Initializer.java:1.4
--- talon/src/java/talon/Initializer.java:1.3 Thu Feb 8 20:18:08 2001
+++ talon/src/java/talon/Initializer.java Thu Feb 8 22:31:42 2001
@@ -18,7 +18,7 @@
* Handles intializing Talon and performing all startup procedures.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: Initializer.java,v 1.3 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: Initializer.java,v 1.4 2001/02/09 06:31:42 burton Exp $
*/
public class Initializer {
@@ -43,7 +43,7 @@
* Initialize Talon if necessary.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: Initializer.java,v 1.3 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: Initializer.java,v 1.4 2001/02/09 06:31:42 burton Exp $
*/
public static void init() {
@@ -92,6 +92,7 @@
}
//create the component handle
+
ComponentHandle handle = new ComponentHandle();
handle.setName( (String)ht.get( ComponentHandle.DEPLOY_PROPERTY_NAME ));
handle.setInterface( (String)ht.get( ComponentHandle.DEPLOY_PROPERTY_INTERFACE ) );
@@ -104,7 +105,7 @@
while ( keys.hasMoreElements() ) {
String name = (String)keys.nextElement();
String value = (String)ht.get( name );
- handle.getPropertyManager().setProperty( name, value );
+ handle.getInitProperties().setProperty( name, value );
}
logger.message( handle.toString() );
@@ -126,7 +127,7 @@
* Return true if Talon is initialized.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: Initializer.java,v 1.3 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: Initializer.java,v 1.4 2001/02/09 06:31:42 burton Exp $
*/
public static boolean isInitialized() {
return initialized;
@@ -136,7 +137,7 @@
* Return true if Talon is working.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: Initializer.java,v 1.3 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: Initializer.java,v 1.4 2001/02/09 06:31:42 burton Exp $
*/
public static boolean isWorking() {
return working;
@@ -146,7 +147,7 @@
* Return true if Talon should be initialized.
*
* @author <a href="mailto:burton@relativity.yi.org">Kevin A. Burton</a>
- * @version $Id: Initializer.java,v 1.3 2001/02/09 04:18:08 burton Exp $
+ * @version $Id: Initializer.java,v 1.4 2001/02/09 06:31:42 burton Exp $
*/
public static boolean shouldInitialize() {
return isWorking() == false && isInitialized() == false;
This archive was generated by hypermail 2b30 : Thu Feb 08 2001 - 22:33:03 PST