Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1904 - development/main/transit/core/handler/src/main/net/dpml/transit/artifact

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1904 - development/main/transit/core/handler/src/main/net/dpml/transit/artifact
  • Date: Fri, 25 Feb 2005 17:56:34 +0100

Author: mcconnell
Date: Fri Feb 25 17:56:34 2005
New Revision: 1904

Modified:

development/main/transit/core/handler/src/main/net/dpml/transit/artifact/CacheHandler.java

development/main/transit/core/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java

development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ResourceManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java

development/main/transit/core/handler/src/main/net/dpml/transit/artifact/StandardResourceManager.java
Log:
Improvements following hands-on coding of custom resource manager.

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/CacheHandler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/CacheHandler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/CacheHandler.java
Fri Feb 25 17:56:34 2005
@@ -56,14 +56,6 @@
static final String RESOLVER_CLASS_KEY = DOMAIN +
".cache.locationresolver.class";

/**
- * Return a set of features describing the implementation. Keys
- * and values may be implementation dependent.
- *
- * @return the feature collection
- */
- Map getCacheHandlerFeatures();
-
- /**
* Attempts to download and cache a remote artifact using a set of remote
* repositories. The operation is not fail fast and so it keeps trying
if
* the first repository does not have the artifact in question.

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/FileCacheHandler.java
Fri Feb 25 17:56:34 2005
@@ -36,9 +36,9 @@
import net.dpml.transit.monitors.CacheMonitorRouter;

/**
- * Internal default cache handler that maintains a file based cache.
+ * Default cache handler that maintains a file based cache.
*/
-class FileCacheHandler
+public class FileCacheHandler
implements CacheHandler
{
//
------------------------------------------------------------------------
@@ -94,19 +94,28 @@
monitor.trace( "created file based cache on: " + m_cacheDir );
}

- /**
- * Return a set of features describing the implementation. Keys
- * and values may be implementation dependent.
- *
- * @return the feature collection
- */
- public Map getCacheHandlerFeatures()
- {
- Properties properties = new Properties();
- properties.setProperty( "Class", getClass().getName() );
- properties.setProperty( "Directory", m_cacheDir.toString() );
- return properties;
- }
+ /**
+ * Set the local cache directory.
+ *
+ * @return the feature collection
+ */
+ void setLocalCacheDirectory( File file )
+ {
+ synchronized( m_cacheDir )
+ {
+ m_cacheDir = file;
+ }
+ }
+
+ /**
+ * Return a directory established to provide the local cache.
+ *
+ * @return the feature collection
+ */
+ File getLocalCacheDirectory()
+ {
+ return m_cacheDir;
+ }

//
------------------------------------------------------------------------
// CacheHandler

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ResourceManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ResourceManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/ResourceManager.java
Fri Feb 25 17:56:34 2005
@@ -48,13 +48,11 @@
"net.dpml.transit.artifact.StandardResourceManager";

/**
- * Creation of a new cache handler.
- * @param authorative the authorative base url
- * @param monitor the internal monitor
- * @return the cache handler
+ * Return the cache handler.
* @exception IOException if an io error occurs
* @exception TransitException if a transit system error occurs
*/
- CacheHandler createCacheHandler( URL authorative, SystemMonitor monitor )
- throws TransitException, IOException;
+ CacheHandler createCacheHandler() throws TransitException, IOException;
+
+
}
\ No newline at end of file

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
Fri Feb 25 17:56:34 2005
@@ -23,6 +23,8 @@
import java.io.IOException;
import java.io.FileNotFoundException;

+import java.lang.reflect.Constructor;
+
import java.net.InetAddress;
import java.net.MalformedURLException;
import java.net.URL;
@@ -192,8 +194,9 @@
URL authorative = establishAuthority( monitor );
monitor.notifyAuthority( authorative );
Properties props = getTransitProperties( authorative );
- ResourceManager manager = createResourceManager( props );
- CacheHandler ch = manager.createCacheHandler( authorative,
monitor );
+ String classname = getResourceManagerClassname( props );
+ ResourceManager manager = createResourceManager( classname,
authorative, monitor );
+ CacheHandler ch = manager.createCacheHandler();
monitor.notifyCacheHandlerCreation( ch );
m_CONTEXT = new SecuredTransitContext( authorative, ch, props );
return m_CONTEXT;
@@ -215,16 +218,20 @@
* @param props the transit properties
* @return the resource manager
*/
- private static ResourceManager createResourceManager( Properties props )
throws TransitException
+ private static ResourceManager createResourceManager(
+ String classname, URL authorative, SystemMonitor monitor ) throws
TransitException
{
- String classname =
- props.getProperty(
- ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME_KEY,
- ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME );
try
{
Class cls = ResourceManager.class.getClassLoader().loadClass(
classname );
- return (ResourceManager) cls.newInstance();
+ Class[] params = new Class[]{
+ URL.class,
+ SystemMonitor.class};
+ Object[] args = new Object[]{
+ authorative,
+ monitor};
+ Constructor cons = cls.getConstructor( params );
+ return (ResourceManager) cons.newInstance( args );
}
catch( Throwable e )
{
@@ -236,6 +243,21 @@
}
}

+ /**
+ * Return the classname of the class implementating the resource manager.
+ * Resolved relative to the transit property
'dpml.transit.authority.resourcemanager.classname'.
+ * If undefined the default classname is returned.
+ *
+ * @param props the transit properties
+ * @return the resource manager classname
+ */
+ private static String getResourceManagerClassname( Properties props )
throws TransitException
+ {
+ return props.getProperty(
+ ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME_KEY,
+ ResourceManager.TRANSIT_RESOURCE_MANAGER_CLASSNAME );
+ }
+
/** This constructor should only be used for the testcases.
* @param authorative the authorative url
* @param hosts the set of hosts

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/StandardResourceManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/StandardResourceManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/artifact/StandardResourceManager.java
Fri Feb 25 17:56:34 2005
@@ -36,7 +36,7 @@
*
* The CacheHandler constructor MUST have the signature of;
* <code><pre>
- * MyCacheHandler( Monitor monitor, ResourceHost[] hosts, Properties
propsm LocationResolver resolve )
+ * MyCacheHandler( Monitor monitor, ResourceHost[] hosts, Properties
props, LocationResolver resolver )
* </pre></code>
* @return the cache handler
* @exception IOException if an io error occurs
@@ -66,29 +66,69 @@
"net.dpml.transit.artifact.ClassicResolver";

//
------------------------------------------------------------------------
- // implementation
+ // state
+ //
------------------------------------------------------------------------
+
+ private final URL m_authorative;
+ private final SystemMonitor m_monitor;
+ private final ResourceHost[] m_hosts;
+ private final Properties m_properties;
+ private final LocationResolver m_resolver;
+
+ //
------------------------------------------------------------------------
+ // constructor
//
------------------------------------------------------------------------

/**
- * Creation of a new cache handler.
+ * Creation of a new resource manager.
* @param authorative the authorative base url
* @param monitor the internal monitor
* @return the cache handler
* @exception IOException if an io error occurs
* @exception TransitException if a transit system error occurs
*/
- public CacheHandler createCacheHandler( URL authorative, SystemMonitor
monitor )
+ public StandardResourceManager( URL authorative, SystemMonitor monitor )
throws TransitException, IOException
{
- ResourceHostFactory factory = new ResourceHostFactory( authorative,
monitor );
- ResourceHost[] hosts = factory.createResourceHosts();
+ m_authorative = authorative;
+ m_monitor = monitor;
+
+ ResourceHostFactory factory = new ResourceHostFactory(
m_authorative, m_monitor );
+ m_hosts = factory.createResourceHosts();
+
+ m_properties = getCacheProperties( m_authorative );
+ m_resolver = createResolver( m_properties );
+ }

- Properties props = getCacheProperties( authorative );
- LocationResolver resolver = createResolver( props );
+ //
------------------------------------------------------------------------
+ // implementation
+ //
------------------------------------------------------------------------

+ /**
+ * Creation of a new cache handler.
+ * @return the cache handler
+ * @exception IOException if an io error occurs
+ * @exception TransitException if a transit system error occurs
+ */
+ public CacheHandler createCacheHandler()
+ throws TransitException, IOException
+ {
String classname =
- props.getProperty( CacheHandler.CACHE_CLASS_KEY,
TRANSIT_CACHE_DEFAULT_HANDLER_CLASSNAME );
+ m_properties.getProperty( CacheHandler.CACHE_CLASS_KEY,
TRANSIT_CACHE_DEFAULT_HANDLER_CLASSNAME );
+ return createCacheHandler( classname );
+ }

+ /**
+ * Creation of a new cache handler using a supplied class.
+ * @param authorative the authorative base url
+ * @param monitor the internal monitor
+ * @return the cache handler
+ * @exception IOException if an io error occurs
+ * @exception TransitException if a transit system error occurs
+ */
+ CacheHandler createCacheHandler( String classname )
+ throws TransitException, IOException
+ {
try
{
Class cls = getClass().getClassLoader().loadClass( classname );
@@ -98,19 +138,24 @@
Properties.class,
LocationResolver.class};
Object[] args = new Object[]{
- monitor,
- hosts,
- props,
- resolver};
+ m_monitor,
+ m_hosts,
+ m_properties,
+ m_resolver};
Constructor cons = cls.getConstructor( params );
return (CacheHandler) cons.newInstance( args );
}
catch( Exception e )
{
- throw new TransitException( "Unable to create CacheHandler: " +
classname, e );
+ final String error =
+ "Unable to create CacheHandler using ["
+ + classname
+ + "].";
+ throw new TransitException( error, e );
}
}

+
private LocationResolver createResolver( Properties props )
{
String classname =



  • svn commit: r1904 - development/main/transit/core/handler/src/main/net/dpml/transit/artifact, mcconnell, 02/25/2005

Archive powered by MHonArc 2.6.24.

Top of Page