notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
svn commit: r2642 - in development/main/transit/core/handler/src: main/net/dpml/transit main/net/dpml/transit/manager test/net/dpml/transit/manager
- From: mcconnell AT dpml.net
- To: notify-dpml AT lists.ibiblio.org
- Subject: svn commit: r2642 - in development/main/transit/core/handler/src: main/net/dpml/transit main/net/dpml/transit/manager test/net/dpml/transit/manager
- Date: Sat, 21 May 2005 05:48:02 +0000
Author: mcconnell AT dpml.net
Date: Sat May 21 05:48:00 2005
New Revision: 2642
Added:
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/AbstractPluginManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
Log:
Add manager disposal semantics.
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/Transit.java
Sat May 21 05:48:00 2005
@@ -355,7 +355,8 @@
* system property, the DPML_HOME environment variable. If DPML_HOME is
* not declared, the behaviour is platform specific. If the os is
Windows,
* the value returned is equivalent to $APPDATA\DPML whereas Unix
environment
- * will return ${user.home}/.dpml.
+ * will return ${user.home}/.dpml. The value returned may be overriden by
+ * setting a 'dpml.home' system property.
*
* @return the DPML home directory
*/
@@ -441,13 +442,19 @@
/**
* Resolve the DPML data directory. If the platform is Windows
* the returned value is equivalent to ${dpml.home}/Data
- * whereas the Unix variant returns ${dpml.home}/data.
+ * whereas the Unix variant returns ${dpml.home}/data. The value
+ * returned may be overriden by setting a 'dpml.data' system property.
*
* @param dir the default DPML_HOME value
* @return the transit personal data directory
*/
private static File resolveDataDirectory( File dir )
{
+ String path = System.getProperty( DATA_KEY );
+ if( null != path )
+ {
+ return new File( path );
+ }
String os = System.getProperty( "os.name" ).toLowerCase();
if( os.indexOf( "win" ) >= 0 )
{
@@ -462,13 +469,19 @@
/**
* Resolve the DPML prefs directory. If the platform is Windows
* the returned value is equivalent to ${dpml.home}/Preferences
- * whereas the Unix variant returns ${dpml.home}/prefs.
+ * whereas the Unix variant returns ${dpml.home}/prefs. The value
+ * returned may be overriden by setting a 'dpml.prefs' system property.
*
* @param dir the default DPML_HOME value
* @return the transit personal data directory
*/
private static File resolvePreferencesDirectory( File dir )
{
+ String path = System.getProperty( PREFS_KEY );
+ if( null != path )
+ {
+ return new File( path );
+ }
String os = System.getProperty( "os.name" ).toLowerCase();
if( os.indexOf( "win" ) >= 0 )
{
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/AbstractPluginManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/AbstractPluginManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/AbstractPluginManager.java
Sat May 21 05:48:00 2005
@@ -126,6 +126,25 @@
}
//
------------------------------------------------------------------------
+ // disposal
+ //
------------------------------------------------------------------------
+
+ /**
+ * Dispose of the manager.
+ */
+ public void dispose()
+ {
+ try
+ {
+ getPreferences().removePreferenceChangeListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
+ }
+
+ //
------------------------------------------------------------------------
// internals
//
------------------------------------------------------------------------
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/CacheManager.java
Sat May 21 05:48:00 2005
@@ -97,6 +97,39 @@
}
//
------------------------------------------------------------------------
+ // disposal
+ //
------------------------------------------------------------------------
+
+ /**
+ * Dispose of the manager.
+ */
+ public void dispose()
+ {
+ super.dispose();
+ try
+ {
+ getPreferences().removeNodeChangeListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
+ HostModel[] models = getHostModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ HostModel model = models[i];
+ try
+ {
+ model.removePluginListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
// PluginListener (listens to changes to plugin uris)
//
------------------------------------------------------------------------
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/ProxyManager.java
Sat May 21 05:48:00 2005
@@ -38,7 +38,8 @@
import net.dpml.transit.event.EventProducer;
/**
- * The TransitManager class is the default TransitModel implementation.
+ * The ProxyManager class maintains an active configuration model of the
+ * Transit proxy settings.
*
* @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
* @version $Id: StandardTransitDirector.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
@@ -92,7 +93,10 @@
String key = event.getKey();
String value = event.getNewValue();
Preferences prefs = event.getNode();
- setupProxyConfiguration( prefs, true );
+ if( "modified".equals( key ) )
+ {
+ setupProxyConfiguration( prefs, true );
+ }
}
//
------------------------------------------------------------------------
@@ -105,7 +109,7 @@
*/
public boolean isProxyEnabled()
{
- return ( m_identifier != null );
+ return ( null != m_preferences.get( "host", null ) );
}
/**
@@ -154,6 +158,25 @@
}
//
------------------------------------------------------------------------
+ // disposal
+ //
------------------------------------------------------------------------
+
+ /**
+ * Dispose of the manager.
+ */
+ public void dispose()
+ {
+ try
+ {
+ m_preferences.removePreferenceChangeListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
+ }
+
+ //
------------------------------------------------------------------------
// internal
//
------------------------------------------------------------------------
@@ -161,9 +184,24 @@
{
if( null != prefs.get( "host", null ) )
{
- m_identifier = resolveRequestIdentifier( prefs );
- m_authentication = resolveProxyPasswordAuthentication( prefs );
- m_excludes = resolveProxyExcludes( prefs );
+ try
+ {
+ RequestIdentifier identifier = resolveRequestIdentifier(
prefs );
+ PasswordAuthentication authentication =
resolveProxyPasswordAuthentication( prefs );
+ String excludes = resolveProxyExcludes( prefs );
+ synchronized( this )
+ {
+ m_identifier = identifier;
+ m_authentication = authentication;
+ m_excludes = excludes;
+ }
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Proxy configuration setup error.";
+ m_logger.log( Level.SEVERE, error, e );
+ }
}
else
{
@@ -205,17 +243,7 @@
public void finalize()
{
- if( null != m_preferences )
- {
- try
- {
- m_preferences.removePreferenceChangeListener( this );
- }
- catch( Throwable e )
- {
- // ignore
- }
- }
+ dispose();
}
private PasswordAuthentication resolveProxyPasswordAuthentication(
Preferences prefs )
@@ -246,7 +274,7 @@
Preferences excludes = prefs.node( "excludes" );
try
{
- String[] names = excludes.childrenNames();
+ String[] names = excludes.keys();
String spec = null;
for( int i=0; i<names.length; i++ )
{
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/RegistryManager.java
Sat May 21 05:48:00 2005
@@ -91,6 +91,39 @@
}
//
------------------------------------------------------------------------
+ // disposal
+ //
------------------------------------------------------------------------
+
+ /**
+ * Dispose of the manager.
+ */
+ public void dispose()
+ {
+ super.dispose();
+ try
+ {
+ getPreferences().removeNodeChangeListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
+ ContentModel[] models = getContentModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ ContentModel model = models[i];
+ try
+ {
+ model.removePluginListener( this );
+ }
+ catch( Throwable e )
+ {
+ // ignore
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
// PluginListener (listens to changes to plugin uris)
//
------------------------------------------------------------------------
Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/TransitManager.java
Sat May 21 05:48:00 2005
@@ -41,10 +41,10 @@
// state
//
------------------------------------------------------------------------
- private final CacheModel m_cache;
- private final RegistryModel m_registry;
- private final RepositoryModel m_repository;
- private final ProxyModel m_proxy;
+ private final CacheManager m_cache;
+ private final RegistryManager m_registry;
+ private final RepositoryManager m_repository;
+ private final ProxyManager m_proxy;
//
------------------------------------------------------------------------
// constructor
@@ -112,31 +112,46 @@
}
//
------------------------------------------------------------------------
+ // AbstractManager
+ //
------------------------------------------------------------------------
+
+ /**
+ * Dispose of the manager.
+ */
+ public void dispose()
+ {
+ m_cache.dispose();
+ m_registry.dispose();
+ m_repository.dispose();
+ m_proxy.dispose();
+ }
+
+ //
------------------------------------------------------------------------
// internal
//
------------------------------------------------------------------------
- private CacheModel createCacheModel( Logger logger, Preferences root )
throws ModelException
+ private CacheManager createCacheModel( Logger logger, Preferences root )
throws ModelException
{
Preferences prefs = root.node( "cache" );
Logger log = getLogger( logger, "cache" );
return new CacheManager( log, prefs );
}
- private RegistryModel createRegistryModel( Logger logger, Preferences
root ) throws ModelException
+ private RegistryManager createRegistryModel( Logger logger, Preferences
root ) throws ModelException
{
Preferences prefs = root.node( "content" );
Logger log = getLogger( logger, "content" );
return new RegistryManager( log, prefs );
}
- private RepositoryModel createRepositoryModel( Logger logger,
Preferences root )
+ private RepositoryManager createRepositoryModel( Logger logger,
Preferences root )
{
Preferences prefs = root.node( "repository" );
Logger log = getLogger( logger, "repository" );
return new RepositoryManager( log, prefs );
}
- private ProxyModel createProxyModel( Logger logger, Preferences root )
+ private ProxyManager createProxyModel( Logger logger, Preferences root )
{
Preferences prefs = root.node( "proxy" );
Logger log = getLogger( logger, "proxy" );
Added:
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
Sat May 21 05:48:00 2005
@@ -0,0 +1,146 @@
+/*
+ * 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.transit.manager;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.Date;
+import java.util.logging.Logger;
+import java.util.prefs.Preferences;
+
+import junit.framework.TestCase;
+
+import net.dpml.transit.Transit;
+import net.dpml.transit.model.RepositoryModel;
+import net.dpml.transit.model.CacheModel;
+import net.dpml.transit.model.RegistryModel;
+
+/**
+ * @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
+ */
+public class ProxyManagerTestCase extends TestCase
+{
+ private Preferences m_prefs;
+ private TransitManager m_manager;
+ private File m_data;
+
+ public void setUp() throws Exception
+ {
+ String path = "target/test/data";
+ m_data = new File( path );
+ System.setProperty( "dpml.data", path );
+ Preferences prefs = Preferences.userNodeForPackage( Transit.class );
+ m_prefs = prefs.node( "test" );
+ Logger logger = Logger.getLogger( "test" );
+ m_manager = new TransitManager( logger, m_prefs );
+ }
+
+ public void tearDown() throws Exception
+ {
+ m_manager.dispose();
+ }
+
+ public void testDefaultProxySetting() throws Exception
+ {
+ Preferences prefs = m_prefs.node( "proxy" );
+ try
+ {
+ boolean enabled = m_manager.getProxyModel().isProxyEnabled();
+ assertFalse( "proxy-disabled", enabled );
+ }
+ catch( Throwable e )
+ {
+ prefs.exportNode( System.out );
+ }
+ }
+
+ public void testProxyEnabled() throws Exception
+ {
+ Preferences prefs = m_prefs.node( "proxy" );
+ try
+ {
+ prefs.put( "host", "http://proxy.dpml.net" );
+ prefs.put( "scheme", "a-scheme" );
+ prefs.put( "prompt", "a-prompt" );
+ prefs.putLong( "modified", new Date().getTime() );
+ prefs.flush();
+ boolean enabled = m_manager.getProxyModel().isProxyEnabled();
+ }
+ finally
+ {
+ prefs.clear();
+ }
+ }
+
+ public void testProxyAuthentication() throws Exception
+ {
+ Preferences prefs = m_prefs.node( "proxy" );
+ try
+ {
+ String username = "peter";
+ String password = "rabbit";
+ prefs.put( "host", "http://proxy.dpml.net" );
+ prefs.put( "scheme", "a-scheme" );
+ prefs.put( "prompt", "a-prompt" );
+ prefs.put( "username", username );
+ prefs.put( "password", password );
+ prefs.putLong( "modified", new Date().getTime() );
+ prefs.flush();
+ assertEquals(
+ "username", username,
+
m_manager.getProxyModel().getProxyAuthentication().getUserName() );
+ String pwd =
+ new String(
+
m_manager.getProxyModel().getProxyAuthentication().getPassword() );
+ assertEquals( "password", password, pwd );
+ }
+ finally
+ {
+ prefs.clear();
+ }
+ }
+
+ public void testProxyExcludes() throws Exception
+ {
+ Preferences prefs = m_prefs.node( "proxy" );
+ Preferences excludes = prefs.node( "excludes" );
+ excludes.put( "http://www.osm.net", "" );
+ excludes.put( "http://repository.dpml.net", "" );
+ try
+ {
+ prefs.put( "host", "http://proxy.dpml.net" );
+ prefs.put( "scheme", "a-scheme" );
+ prefs.put( "prompt", "a-prompt" );
+ prefs.putLong( "modified", new Date().getTime() );
+ prefs.flush();
+ assertEquals(
+ "excludes", "http://www.osm.net|http://repository.dpml.net",
+ m_manager.getProxyModel().getProxyExcludes() );
+ }
+ finally
+ {
+ prefs.clear();
+ excludes.clear();
+ excludes.removeNode();
+ prefs.flush();
+ }
+ }
+}
+
Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/manager/TransitManagerTestCase.java
Sat May 21 05:48:00 2005
@@ -20,6 +20,8 @@
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.util.Date;
import java.util.logging.Logger;
import java.util.prefs.Preferences;
@@ -30,25 +32,44 @@
import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.RegistryModel;
-
/**
* @author <a href="http://www.dpml.net">The Digital Product Meta Library</a>
*/
public class TransitManagerTestCase extends TestCase
{
+ private Preferences m_prefs;
private TransitManager m_manager;
+ private File m_data;
public void setUp() throws Exception
{
- System.setProperty( "dpml.data", "target/test/data" );
- Logger logger = Logger.getLogger( "test" );
+ String path = "target/test/data";
+ m_data = new File( path );
+ System.setProperty( "dpml.data", path );
+
+ File archive = new File( "target/test/prefs.xml" );
Preferences prefs = Preferences.userNodeForPackage( Transit.class );
- Preferences test = prefs.node( "test" );
- m_manager = new TransitManager( logger, test );
+ m_prefs = prefs.node( "test" );
+ m_prefs.importPreferences( new FileInputStream( archive ) );
+ m_prefs.sync();
+
+ Logger logger = Logger.getLogger( "test" );
+ m_manager = new TransitManager( logger, m_prefs );
+ }
+
+ public void tearDown() throws Exception
+ {
+ synchronized( this )
+ {
+ m_manager.dispose();
+ }
}
- public void testTransitManager()
+ public void testCacheDirectory()
{
+ File cache = m_manager.getCacheModel().getCacheDirectory();
+ File dir = new File( m_data, "cache" );
+ assertEquals( "cache", dir, cache );
}
}
- svn commit: r2642 - in development/main/transit/core/handler/src: main/net/dpml/transit main/net/dpml/transit/manager test/net/dpml/transit/manager, mcconnell, 05/21/2005
Archive powered by MHonArc 2.6.24.