notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2800 - in development/main: depot/console/src/main/net/dpml/depot depot/console/src/main/net/dpml/depot/lang depot/console/src/main/net/dpml/depot/profile transit/core/handler/src/main/net/dpml/transit/builder transit/core/handler/src/main/net/dpml/transit/manager
- From: mcconnell AT dpml.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2800 - in development/main: depot/console/src/main/net/dpml/depot depot/console/src/main/net/dpml/depot/lang depot/console/src/main/net/dpml/depot/profile transit/core/handler/src/main/net/dpml/transit/builder transit/core/handler/src/main/net/dpml/transit/manager
- Date: Wed, 08 Jun 2005 14:44:33 -0400
Author: mcconnell AT dpml.net
Date: Wed Jun 8 14:44:31 2005
New Revision: 2800
Added:
development/main/depot/console/src/main/net/dpml/depot/Main.java
Modified:
development/main/depot/console/src/main/net/dpml/depot/lang/DepotClassLoader.java
development/main/depot/console/src/main/net/dpml/depot/profile/DepotManager.java
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
development/main/depot/console/src/main/net/dpml/depot/profile/Profile.java
development/main/transit/core/handler/src/main/net/dpml/transit/builder/AbstractStorageUnit.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultManager.java
Log:
Rebuild main cli handled based on the profile models.
Added: development/main/depot/console/src/main/net/dpml/depot/Main.java
==============================================================================
--- (empty file)
+++ development/main/depot/console/src/main/net/dpml/depot/Main.java Wed
Jun 8 14:44:31 2005
@@ -0,0 +1,440 @@
+/*
+ * Copyright 2005 Stephen J. McConnell.
+ *
+ * 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 net.dpml.depot;
+
+import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URI;
+import java.rmi.Remote;
+import java.rmi.registry.Registry;
+import java.rmi.registry.LocateRegistry;
+import java.util.Date;
+import java.util.Properties;
+import java.util.prefs.BackingStoreException;
+import java.util.prefs.Preferences;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.TransitError;
+import net.dpml.transit.TransitException;
+import net.dpml.transit.adapter.LoggingAdapter;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.UnknownKeyException;
+import net.dpml.transit.builder.TransitStorageUnit;
+import net.dpml.transit.management.TransitHome;
+import net.dpml.transit.management.TransitManager;
+import net.dpml.transit.repository.Repository;
+
+import net.dpml.depot.lang.DPML;
+import net.dpml.depot.lang.DepotClassLoader;
+import net.dpml.depot.profile.Profile;
+import net.dpml.depot.profile.Profile.Connection;
+import net.dpml.depot.profile.PluginProfile;
+import net.dpml.depot.profile.BootstrapProfile;
+import net.dpml.depot.profile.DepotManager;
+import net.dpml.depot.profile.DepotStorage;
+
+
+/**
+ * CLI hander for the depot package.
+ *
+ * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
+ * @version $Id: Main.java 2480 2005-05-10 04:44:32Z mcconnell AT dpml.net $
+ */
+public final class Main
+{
+
//--------------------------------------------------------------------------
+ // static utilities for setup of logging manager
+
//--------------------------------------------------------------------------
+
+ static
+ {
+ System.setProperty( "java.util.logging.manager",
"net.dpml.depot.logging.LoggingManager" );
+ System.setProperty( "java.util.logging.manager.altclassloader",
"net.dpml.depot.logging.LoggingManager" );
+ System.setProperty( "java.util.logging.config.class",
"net.dpml.depot.logging.ConfigurationHandler" );
+
+ System.setProperty( Transit.SYSTEM_KEY,
Transit.DPML_SYSTEM.getAbsolutePath() );
+ System.setProperty( Transit.HOME_KEY,
Transit.DPML_HOME.getAbsolutePath() );
+ System.setProperty( Transit.DATA_KEY,
Transit.DPML_DATA.getAbsolutePath() );
+ System.setProperty( Transit.PREFS_KEY,
Transit.DPML_PREFS.getAbsolutePath() );
+ System.setProperty( DPML.BUILD_KEY, DPML.BUILD_ID );
+ }
+
+ public static void main( final String[] args )
+ throws Exception
+ {
+ try
+ {
+ //
+ // check if debug level logging should be enabled
+ //
+
+ for( int i=0; i < args.length; i++ )
+ {
+ String arg = args[i];
+ if( arg.equals( "-debug" ) )
+ {
+ System.setProperty( "dpml.logging.level", "FINE" );
+ }
+ }
+
+ Logger logger = getLogger();
+ logger.info( "Depot (Build ID: " + DPML.BUILD_ID + ")." );
+
+ //
+ // check if a preferences reset has been requested
+ //
+
+ for( int i=0; i < args.length; i++ )
+ {
+ String arg = args[i];
+ if( arg.equals( "-reset" ) )
+ {
+ clearPreferences( Main.class );
+ clearPreferences( Transit.class );
+ return;
+ }
+ }
+
+ //
+ // setup the depot managment model, get the name of the
requested
+ // application profile and load the profile from the depot
manager
+ //
+
+
+ Date creation = new Date();
+ Preferences prefs = getRootPreferences();
+ DepotStorage store = new DepotStorage( prefs, logger, creation,
false );
+ DepotManager manager = store.getDepotManager();
+ String target = getTargetProfile( args );
+ Profile profile = getApplicationProfile( manager, target );
+ Properties properties = profile.getSystemProperties();
+ setSystemProperties( properties );
+ DepotClassLoader system = getSystemClassLoader();
+ Connection connection = profile.getConnection();
+ Registry registry = getRegistry( connection );
+
+ if( profile instanceof PluginProfile )
+ {
+ PluginProfile p = (PluginProfile) profile;
+ URI uri = p.getURI();
+ try
+ {
+ Thread thread = null;
+ TransitHome home = new TransitStorageUnit();
+ TransitManager model = home.create();
+ Transit transit = Transit.getInstance( model );
+ Repository loader = transit.getRepository();
+ Object object = loader.getPlugin( system, uri, new
Object[]{ args, model } );
+ if( registry != null )
+ {
+ String id = profile.getID();
+ registry.bind( id, (Remote) object );
+ logger.info(
+ "service bound to " + connection.getHost()
+ + ":" + connection.getPort() + "/" + id );
+ }
+ else if( object instanceof Runnable )
+ {
+ //
+ // run the plugin
+ //
+
+ logger.info( "starting " +
object.getClass().getName() );
+ thread = new Thread( (Runnable) object );
+ thread.start();
+ }
+ setShutdownHook( thread );
+ }
+ catch( TransitError e )
+ {
+ final String error =
+ "Cannot load profile to an unrecoverable Transit
error.";
+ getLogger().error( error, e );
+ throw new HandledError();
+ }
+ catch( TransitException e )
+ {
+ final String error =
+ "Cannot load profile to an Transit error.";
+ getLogger().error( error, e );
+ throw new HandledError();
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Cannot load profile due to an application
establishment error.";
+ getLogger().error( error, e );
+ throw new HandledError();
+ }
+ }
+ else
+ {
+ BootstrapProfile p = (BootstrapProfile) profile;
+ String classname = p.getClassname();
+ String[] classpath = p.getClasspath();
+ try
+ {
+ system.setClasspath( classpath );
+ Class c = system.loadClass( classname );
+ deploy( c, args );
+ }
+ catch( ClassNotFoundException e )
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "Application class not found." );
+ buffer.append( "\nClassname: " + classname );
+ buffer.append( "\nDepot Main Codesource: " );
+ buffer.append( getCodeSourceLocation().toString() );
+ buffer.append( "\nSystem classpath:" );
+ URL[] urls = system.getURLs();
+ for( int i=0; i<urls.length; i++ )
+ {
+ buffer.append( "\n" + (i+1) + "\t" + urls[i] );
+ }
+ String error = buffer.toString();
+ getLogger().error( error );
+ throw new HandledError();
+ }
+ catch( Exception e )
+ {
+ StringBuffer buffer = new StringBuffer();
+ buffer.append( "Application error." );
+ buffer.append( "\nDepot Codesource: " );
+ buffer.append( getCodeSourceLocation().toString() );
+ buffer.append( "\nSystem classpath:" );
+ URL[] urls = system.getURLs();
+ for( int i=0; i<urls.length; i++ )
+ {
+ buffer.append( "\n" + (i+1) + "\t" + urls[i] );
+ }
+ String error = buffer.toString();
+ getLogger().error( error, e );
+ throw new HandledError();
+ }
+ }
+ }
+ catch( HandledError handledError )
+ {
+ System.exit( -1 );
+ }
+ }
+
+ public static Registry getRegistry( Connection connection )
+ {
+ if( null == connection )
+ {
+ return null;
+ }
+ else
+ {
+ try
+ {
+ String host = connection.getHost();
+ int port = connection.getPort();
+ return LocateRegistry.getRegistry( host, port );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unable to establish the RMI Registry.";
+ getLogger().error( error, e );
+ throw new HandledError();
+ }
+ }
+ }
+
+ private static Profile getApplicationProfile( DepotManager manager,
String target )
+ {
+ try
+ {
+ return manager.getProfile( target );
+ }
+ catch( UnknownKeyException e )
+ {
+ final String error =
+ "Requested application profile '" + target + "' does not
exist.";
+ getLogger().error( error );
+ throw new HandledError();
+ }
+ }
+
+ private static DepotClassLoader getSystemClassLoader()
+ {
+ try
+ {
+ return (DepotClassLoader) ClassLoader.getSystemClassLoader();
+ }
+ catch( ClassCastException e )
+ {
+ final String error =
+ "The Depot console must be invoked with the
\"java.system.class.loader\" "
+ + "system property with the value of \""
+ + DepotClassLoader.class.getName()
+ + "\".";
+ getLogger().error( error );
+ throw new HandledError();
+ }
+ }
+
+ private static void clearPreferences( Class c )
+ {
+ try
+ {
+ Preferences prefs = Preferences.userNodeForPackage( c );
+ getLogger().info( "Resetting: " + prefs );
+ prefs.removeNode();
+ }
+ catch( Throwable e )
+ {
+ getLogger().error( "User preferences reset failure.", e );
+ }
+ }
+
+ /**
+ * Setup the system properties for the target.
+ * @param prefs the profile's system properties preferences node
+ */
+ private static void setSystemProperties( Properties properties ) throws
BackingStoreException
+ {
+ String[] keys = (String[]) properties.keySet().toArray( new
String[0] );
+ for( int i=0; i<keys.length; i++ )
+ {
+ String key = keys[i];
+ String value = properties.getProperty( key, null );
+ if( null != value )
+ {
+ System.setProperty( key, value );
+ }
+ }
+ }
+
+ private static void deploy( Class c, String[] args ) throws Exception
+ {
+ try
+ {
+ Method method = c.getDeclaredMethod( "main", new Class[]{
String[].class } );
+ Object[] params = new Object[]{ args };
+ method.invoke( null, params );
+ setShutdownHook( null );
+ }
+ catch( NoSuchMethodException e )
+ {
+ Thread thread = null;
+ Object object = c.newInstance();
+ if( object instanceof Runnable )
+ {
+ thread = new Thread( (Runnable) object );
+ thread.start();
+ }
+ setShutdownHook( thread );
+ }
+ }
+
+ private static String getTargetProfile( String[] args ) throws
BackingStoreException
+ {
+ for( int i=0; i<args.length; i++ )
+ {
+ String arg = args[i];
+ if( arg.equals( "-profile" ) )
+ {
+ if( i+1 < args.length )
+ {
+ String profile = args[ i+1 ];
+ return profile;
+ }
+ else
+ {
+ final String error =
+ "Missing profile name.";
+ getLogger().error( error );
+ throw new HandledError();
+ }
+ }
+ }
+ return "prefs";
+ }
+
+ /**
+ * Constructor (disabled).
+ */
+ private Main()
+ {
+ // disabled
+ }
+
+ private static URL getCodeSourceLocation()
+ {
+ return
Main.class.getProtectionDomain().getCodeSource().getLocation();
+ }
+
+ /**
+ * Create a shutdown hook that will trigger shutdown of the supplied
plugin.
+ * @param thread the application thread
+ */
+ private static void setShutdownHook( final Thread thread )
+ {
+ //
+ // Create a shutdown hook to trigger clean disposal of the
+ // controller
+ //
+
+ Runtime.getRuntime().addShutdownHook(
+ new Thread()
+ {
+ public void run()
+ {
+ if( null != thread )
+ {
+ try
+ {
+ thread.interrupt();
+ }
+ catch( Throwable e )
+ {
+ // ignore it
+ }
+ }
+ System.runFinalization();
+ }
+ }
+ );
+ }
+
+ private static Preferences getRootPreferences()
+ {
+ return ROOT_PREFS;
+ }
+
+ private static Logger getLogger()
+ {
+ return DEFAULT_LOGGER;
+ }
+
+ private static final Logger DEFAULT_LOGGER =
+ new LoggingAdapter( java.util.logging.Logger.getLogger( "depot" ) );
+ private static final Preferences ROOT_PREFS =
+ Preferences.userNodeForPackage( Main.class );
+
+ private static class HandledError extends Error
+ {
+ }
+}
+
Modified:
development/main/depot/console/src/main/net/dpml/depot/lang/DepotClassLoader.java
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/lang/DepotClassLoader.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/lang/DepotClassLoader.java
Wed Jun 8 14:44:31 2005
@@ -50,6 +50,24 @@
super( new URL[0], parent );
}
+ public void setClasspath( String[] classpath ) throws
BackingStoreException, IOException
+ {
+ if( m_sealed )
+ {
+ final String error =
+ "Illegal attempt to modify the bootstrap classpath.";
+ throw new IllegalStateException( error );
+ }
+ Properties properties = System.getProperties();
+ for( int i=0; i<classpath.length; i++ )
+ {
+ String entry = classpath[i];
+ URL url = resolveURL( properties, entry );
+ addURL( url );
+ }
+ m_sealed = true;
+ }
+
/**
* Assignment of a preferences object to the classloader from which
* urls shall be resolved. The implementation resolves urls values
Modified:
development/main/depot/console/src/main/net/dpml/depot/profile/DepotManager.java
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/profile/DepotManager.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/DepotManager.java
Wed Jun 8 14:44:31 2005
@@ -23,6 +23,7 @@
import java.util.Date;
import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.UnknownKeyException;
import net.dpml.transit.manager.DefaultManager;
import net.dpml.transit.management.Home;
@@ -47,4 +48,18 @@
return m_profiles;
}
+ public Profile getProfile( String key ) throws UnknownKeyException
+ {
+ Profile[] profiles = getProfiles();
+ for( int i=0; i<profiles.length; i++ )
+ {
+ Profile profile = profiles[i];
+ if( key.equals( profile.getID() ) )
+ {
+ return profile;
+ }
+ }
+ throw new UnknownKeyException( key );
+ }
+
}
Modified:
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/DepotStorage.java
Wed Jun 8 14:44:31 2005
@@ -85,6 +85,11 @@
// utils
//
------------------------------------------------------------------------
+ public DepotManager getDepotManager()
+ {
+ return m_depot;
+ }
+
private Profile[] getProfiles() throws ProfileException
{
Preferences prefs = getPreferences().node( "profiles" );
@@ -94,9 +99,9 @@
Profile[] profiles = new Profile[ names.length ];
for( int i=0; i<names.length; i++ )
{
- String name = names[i];
- Preferences p = prefs.node( name );
- Logger logger = getLogger().getChildLogger( name );
+ String id = names[i];
+ Preferences p = prefs.node( id );
+ Logger logger = getLogger().getChildLogger( id );
boolean policy = getStoragePolicy();
Date creation = getCreationDate();
ProfileStorage store = new ProfileStorage( p, logger,
creation, policy );
Modified:
development/main/depot/console/src/main/net/dpml/depot/profile/Profile.java
==============================================================================
---
development/main/depot/console/src/main/net/dpml/depot/profile/Profile.java
(original)
+++
development/main/depot/console/src/main/net/dpml/depot/profile/Profile.java
Wed Jun 8 14:44:31 2005
@@ -32,28 +32,23 @@
*/
public class Profile extends DefaultManager
{
- private String m_title;
+ private String m_id;
private Properties m_properties;
private Connection m_connection;
- public Profile( Logger logger, Date creation, Home home, String title,
Properties properties, Connection connection )
+ public Profile( Logger logger, Date creation, Home home, String id,
Properties properties, Connection connection )
throws NullPointerException
{
super( logger, creation, home );
- m_title = title;
+ m_id = id;
m_properties = properties;
m_connection = connection;
}
- public String getTitle()
+ public String getID()
{
- return m_title;
- }
-
- public void setTitle( String title )
- {
- m_title = title;
+ return m_id;
}
public Properties getSystemProperties()
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/AbstractStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/AbstractStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/AbstractStorageUnit.java
Wed Jun 8 14:44:31 2005
@@ -35,10 +35,9 @@
import net.dpml.transit.model.VetoDisposalException;
/**
- * Utility class that provides support for the creation of URI and URL
- * values from preference attributes.
+ * Abstract base class providing a framework for preferences based
persistance.
*/
-abstract class AbstractStorageUnit implements ModificationListener,
DisposalListener
+public abstract class AbstractStorageUnit implements ModificationListener,
DisposalListener
{
//
------------------------------------------------------------------------
// state
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultManager.java
Wed Jun 8 14:44:31 2005
@@ -36,7 +36,6 @@
import net.dpml.transit.model.DisposalEvent;
import net.dpml.transit.model.DisposalListener;
import net.dpml.transit.model.VetoDisposalException;
-import net.dpml.transit.util.ExceptionHelper;
/**
* A abstract base class that established an event queue and handles event
dispatch
- svn commit: r2800 - in development/main: depot/console/src/main/net/dpml/depot depot/console/src/main/net/dpml/depot/lang depot/console/src/main/net/dpml/depot/profile transit/core/handler/src/main/net/dpml/transit/builder transit/core/handler/src/main/net/dpml/transit/manager, mcconnell, 06/08/2005
Archive powered by MHonArc 2.6.24.