Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2654 - in development/main/transit/core/handler/src: main/net/dpml/transit/manager main/net/dpml/transit/model test/net/dpml/transit/manager

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT dpml.net
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r2654 - in development/main/transit/core/handler/src: main/net/dpml/transit/manager main/net/dpml/transit/model test/net/dpml/transit/manager
  • Date: Mon, 23 May 2005 01:40:20 +0000

Author: mcconnell AT dpml.net
Date: Mon May 23 01:40:18 2005
New Revision: 2654

Added:

development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyEvent.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyExcludesEvent.java
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/TransitManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyChangeEvent.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyListener.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java

development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
Log:
Tweaking of the proxy manager following work on HI.

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
Mon May 23 01:40:18 2005
@@ -31,6 +31,8 @@

import net.dpml.transit.model.ProxyModel;
import net.dpml.transit.model.ProxyListener;
+import net.dpml.transit.model.ProxyEvent;
+import net.dpml.transit.model.ProxyExcludesEvent;
import net.dpml.transit.model.ProxyChangeEvent;
import net.dpml.transit.model.ModelException;

@@ -44,18 +46,23 @@
* @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 $
*/
-public class ProxyManager extends EventProducer implements ProxyModel,
PreferenceChangeListener
+public class ProxyManager extends EventProducer implements ProxyModel
{
//
------------------------------------------------------------------------
// state
//
------------------------------------------------------------------------

+ private final ModificationHandler m_modificationHandler = new
ModificationHandler();
+ private final ExcludesHandler m_excludesHandler = new ExcludesHandler();
+
private final Preferences m_preferences;
+ private final Preferences m_excludesPreferences;
private final Logger m_logger;

private PasswordAuthentication m_authentication;
private RequestIdentifier m_identifier;
- private String m_excludes;
+ private String[] m_excludes;
+ private String m_excludesString;

//
------------------------------------------------------------------------
// constructor
@@ -75,28 +82,59 @@

m_logger = logger;
m_preferences = prefs;
+ m_excludesPreferences = prefs.node( "excludes" );

//
// setup the proxy settings
//

- prefs.addPreferenceChangeListener( this );
+ m_preferences.addPreferenceChangeListener( m_modificationHandler );
+ m_excludesPreferences.addPreferenceChangeListener( m_excludesHandler
);
setupProxyConfiguration( prefs, false );
}

//
------------------------------------------------------------------------
- // PreferencesChangeListener (listens to changes to the uri attribute)
+ // ProxyManager
//
------------------------------------------------------------------------

- public void preferenceChange( PreferenceChangeEvent event )
+ public String getProxyHost()
{
- String key = event.getKey();
- String value = event.getNewValue();
- Preferences prefs = event.getNode();
- if( "modified".equals( key ) )
- {
- setupProxyConfiguration( prefs, true );
- }
+ Preferences prefs = getPreferences();
+ return prefs.get( "host", "" );
+ }
+
+ public void setProxyHost( String host )
+ {
+ Preferences prefs = getPreferences();
+ prefs.put( "host", host );
+ }
+
+ public void addExclude( String key )
+ {
+ Preferences excludes = getExcludesPreferences();
+ excludes.put( key, null );
+ }
+
+ public void removeExclude( String key )
+ {
+ Preferences excludes = getExcludesPreferences();
+ excludes.remove( key );
+ }
+
+ public void changeExclude( String key, String value )
+ {
+ Preferences excludes = getExcludesPreferences();
+ excludes.remove( key );
+ excludes.put( value, "" );
+ }
+
+ /**
+ * Dispose of the manager.
+ */
+ public void dispose()
+ {
+ getExcludesPreferences().removePreferenceChangeListener(
m_excludesHandler );
+ getPreferences().removePreferenceChangeListener(
m_modificationHandler );
}

//
------------------------------------------------------------------------
@@ -131,12 +169,21 @@
}

/**
+ * Return the set of excluded hosts as an array.
+ * @return the excluded host array
+ */
+ public String[] getExcludes()
+ {
+ return m_excludes;
+ }
+
+ /**
* Return the String identifying the non-proxy hosts.
* @return the non-proxied hosts value (possibly null)
*/
public String getProxyExcludes()
{
- return m_excludes;
+ return m_excludesString;
}

/**
@@ -158,42 +205,24 @@
}

//
------------------------------------------------------------------------
- // disposal
- //
------------------------------------------------------------------------
-
- /**
- * Dispose of the manager.
- */
- public void dispose()
- {
- try
- {
- m_preferences.removePreferenceChangeListener( this );
- }
- catch( Throwable e )
- {
- // ignore
- }
- }
-
- //
------------------------------------------------------------------------
// internal
//
------------------------------------------------------------------------

private void setupProxyConfiguration( Preferences prefs, boolean notify )
{
+ m_excludes = getProxyExcludesFromPrefs();
if( null != prefs.get( "host", null ) )
{
try
{
RequestIdentifier identifier = resolveRequestIdentifier(
prefs );
PasswordAuthentication authentication =
resolveProxyPasswordAuthentication( prefs );
- String excludes = resolveProxyExcludes( prefs );
+ String excludes = resolveProxyExcludes( m_excludes );
synchronized( this )
{
m_identifier = identifier;
m_authentication = authentication;
- m_excludes = excludes;
+ m_excludesString = excludes;
}
}
catch( Throwable e )
@@ -207,20 +236,19 @@
{
m_identifier = null;
m_authentication = null;
- m_excludes = null;
+ m_excludesString = null;
}
if( notify )
{
boolean enabled = isProxyEnabled();
ProxyChangeEvent event =
- new ProxyChangeEvent( this, enabled, m_identifier,
m_authentication, m_excludes );
+ new ProxyChangeEvent( this, enabled, m_identifier,
m_authentication, m_excludesString );
super.enqueueEvent( event );
}
}

protected void processEvent( EventObject eventObject )
{
- ProxyChangeEvent event = (ProxyChangeEvent) eventObject;
EventListener[] listeners = super.listeners();
for( int i=0; i<listeners.length; i++ )
{
@@ -228,15 +256,33 @@
if( listener instanceof ProxyListener )
{
ProxyListener pl = (ProxyListener) listener;
- try
+ if( eventObject instanceof ProxyChangeEvent )
{
- pl.proxySettingsChanged( event );
+ ProxyChangeEvent event = (ProxyChangeEvent) eventObject;
+ try
+ {
+ pl.proxySettingsChanged( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "PluginListener notification error.";
+ m_logger.log( Level.SEVERE, error, e );
+ }
}
- catch( Throwable e )
+ else if( eventObject instanceof ProxyExcludesEvent )
{
- final String error =
- "PluginListener notification error.";
- m_logger.log( Level.SEVERE, error, e );
+ ProxyExcludesEvent event = (ProxyExcludesEvent)
eventObject;
+ try
+ {
+ pl.proxyExcludesChanged( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "PluginListener excludes notification error.";
+ m_logger.log( Level.SEVERE, error, e );
+ }
}
}
}
@@ -272,26 +318,30 @@
* @param prefs the 'proxy' prefs node containing a child node named
'excludes'
* @return a string containing a sequence of excluded hosts (possibly
null)
*/
- private String resolveProxyExcludes( Preferences prefs )
+ private String resolveProxyExcludes( String[] names )
{
- Preferences excludes = prefs.node( "excludes" );
- try
+ String spec = null;
+ for( int i=0; i<names.length; i++ )
{
- String[] names = excludes.keys();
- String spec = null;
- for( int i=0; i<names.length; i++ )
+ String name = names[i];
+ if( null == spec )
{
- String name = names[i];
- if( null == spec )
- {
- spec = name;
- }
- else
- {
- spec = spec + "|" + name;
- }
+ spec = name;
}
- return spec;
+ else
+ {
+ spec = spec + "|" + name;
+ }
+ }
+ return spec;
+ }
+
+ private String[] getProxyExcludesFromPrefs()
+ {
+ Preferences prefs = getExcludesPreferences();
+ try
+ {
+ return prefs.keys();
}
catch( BackingStoreException e )
{
@@ -299,7 +349,7 @@
"Ignoring possible proxy exclude settings due to a
preferences backing store error."
+ "\nPreferences: " + prefs;
getLogger().log( Level.SEVERE, error, e );
- return null;
+ return new String[0];
}
}

@@ -334,9 +384,59 @@
}
}

+ private Preferences getExcludesPreferences()
+ {
+ return m_excludesPreferences;
+ }
+
+ private Preferences getPreferences()
+ {
+ return m_preferences;
+ }
+
private Logger getLogger()
{
return m_logger;
}
-}

+ private class ModificationHandler implements PreferenceChangeListener
+ {
+ public void preferenceChange( PreferenceChangeEvent prefsEvent )
+ {
+ String key = prefsEvent.getKey();
+ String value = prefsEvent.getNewValue();
+ Preferences prefs = prefsEvent.getNode();
+ if( "modified".equals( key ) )
+ {
+ setupProxyConfiguration( prefs, true );
+ }
+ }
+ }
+
+ private class ExcludesHandler implements PreferenceChangeListener
+ {
+ public void preferenceChange( PreferenceChangeEvent event )
+ {
+ String key = event.getKey();
+ Preferences prefs = event.getNode();
+ try
+ {
+ String[] keys = prefs.keys();
+ setExcludes( keys );
+ }
+ catch( BackingStoreException e )
+ {
+ final String error =
+ "Proxy excludes access error.";
+ m_logger.log( Level.SEVERE, error, e );
+ }
+ }
+ }
+
+ private void setExcludes( String[] excludes )
+ {
+ m_excludes = excludes;
+ ProxyExcludesEvent event = new ProxyExcludesEvent( this, m_excludes
);
+ enqueueEvent( event );
+ }
+}

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
Mon May 23 01:40:18 2005
@@ -69,6 +69,50 @@
}

//
------------------------------------------------------------------------
+ // TransitMananger
+ //
------------------------------------------------------------------------
+
+ /**
+ * Return the proxy model.
+ * @return the proxy configuration model.
+ */
+ public ProxyManager getProxyManager()
+ {
+ return m_proxy;
+ }
+
+ /**
+ * Return the cache model.
+ * @return the cache model
+ */
+ public CacheManager getCacheManager()
+ {
+ return m_cache;
+ }
+
+ /**
+ * Return the model maintiaining configuration information about
+ * the conent registry.
+ *
+ * @return the content director
+ */
+ public RegistryManager getContentRegistryManager()
+ {
+ return m_registry;
+ }
+
+ /**
+ * Return the model maintaining configuration information about
+ * the repository service.
+ *
+ * @return the repository director
+ */
+ public RepositoryManager getRepositoryManager()
+ {
+ return m_repository;
+ }
+
+ //
------------------------------------------------------------------------
// TransitModel
//
------------------------------------------------------------------------

@@ -78,7 +122,7 @@
*/
public ProxyModel getProxyModel()
{
- return m_proxy;
+ return getProxyManager();
}

/**
@@ -87,7 +131,7 @@
*/
public CacheModel getCacheModel()
{
- return m_cache;
+ return getCacheManager();
}

/**
@@ -98,7 +142,7 @@
*/
public RegistryModel getContentRegistryModel()
{
- return m_registry;
+ return getContentRegistryManager();
}

/**
@@ -109,7 +153,7 @@
*/
public RepositoryModel getRepositoryModel()
{
- return m_repository;
+ return getRepositoryManager();
}

//
------------------------------------------------------------------------

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyChangeEvent.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyChangeEvent.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyChangeEvent.java
Mon May 23 01:40:18 2005
@@ -27,7 +27,7 @@
/**
* An event pertaining to changes in the Transit proxy configuration.
*/
-public class ProxyChangeEvent extends EventObject
+public class ProxyChangeEvent extends ProxyEvent
{
private final boolean m_enabled;
private final RequestIdentifier m_identifier;
@@ -45,11 +45,6 @@
m_excludes = excludes;
}

- public ProxyModel getProxyModel()
- {
- return (ProxyModel) super.getSource();
- }
-
public boolean isProxyEnabled()
{
return m_enabled;

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyEvent.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyEvent.java
Mon May 23 01:40:18 2005
@@ -0,0 +1,41 @@
+/*
+ * 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.model;
+
+import java.net.URL;
+import java.util.EventObject;
+import java.net.PasswordAuthentication;
+
+import net.dpml.transit.network.RequestIdentifier;
+
+/**
+ * An event pertaining to the Transit proxy configuration.
+ */
+public abstract class ProxyEvent extends EventObject
+{
+ public ProxyEvent( ProxyModel model )
+ {
+ super( model );
+ }
+
+ public ProxyModel getProxyModel()
+ {
+ return (ProxyModel) super.getSource();
+ }
+}

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyExcludesEvent.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyExcludesEvent.java
Mon May 23 01:40:18 2005
@@ -0,0 +1,44 @@
+/*
+ * 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.model;
+
+import java.net.URL;
+import java.util.EventObject;
+import java.net.PasswordAuthentication;
+
+import net.dpml.transit.network.RequestIdentifier;
+
+/**
+ * An event pertaining to changes in the Transit proxy exclusion
configuration.
+ */
+public class ProxyExcludesEvent extends ProxyEvent
+{
+ private final String[] m_excludes;
+
+ public ProxyExcludesEvent( ProxyModel model, String[] excludes )
+ {
+ super( model );
+ m_excludes = excludes;
+ }
+
+ public String[] getExcludes()
+ {
+ return m_excludes;
+ }
+}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyListener.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyListener.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyListener.java
Mon May 23 01:40:18 2005
@@ -31,4 +31,11 @@
* @param event the proxy change event
*/
void proxySettingsChanged( ProxyChangeEvent event );
+
+ /**
+ * Notify a listener of the change to the set of excluded hosts.
+ * @param event the proxy excludes change event
+ */
+ void proxyExcludesChanged( ProxyExcludesEvent event );
+
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/ProxyModel.java
Mon May 23 01:40:18 2005
@@ -54,6 +54,12 @@
String getProxyExcludes();

/**
+ * Return the set of excluded hosts as an array.
+ * @return the excluded host array
+ */
+ String[] getExcludes();
+
+ /**
* Add a proxy listener to the model.
* @param listener the listener to add
*/

Modified:
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
==============================================================================
---
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
(original)
+++
development/main/transit/core/handler/src/test/net/dpml/transit/manager/ProxyManagerTestCase.java
Mon May 23 01:40:18 2005
@@ -33,6 +33,7 @@
import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.RegistryModel;
import net.dpml.transit.model.ProxyChangeEvent;
+import net.dpml.transit.model.ProxyExcludesEvent;
import net.dpml.transit.model.ProxyListener;

/**
@@ -148,6 +149,10 @@
event.getProxyModel().removeProxyListener( this );
assertTrue( "enabled", event.isProxyEnabled() );
}
+
+ public void proxyExcludesChanged( ProxyExcludesEvent event )
+ {
+ }
}

public class TestProxyExcludesListener implements ProxyListener
@@ -160,6 +165,10 @@
String expected =
"http://www.osm.net|http://repository.dpml.net";;
assertEquals( "excludes", expected.length(), result.length() );
}
+
+ public void proxyExcludesChanged( ProxyExcludesEvent event )
+ {
+ }
}

public class TestProxyAuthListener implements ProxyListener
@@ -173,6 +182,10 @@
String pwd = new String( auth.getPassword() );
assertEquals( "password", "rabbit", pwd );
}
+
+ public void proxyExcludesChanged( ProxyExcludesEvent event )
+ {
+ }
}
}




  • svn commit: r2654 - in development/main/transit/core/handler/src: main/net/dpml/transit/manager main/net/dpml/transit/model test/net/dpml/transit/manager, mcconnell, 05/22/2005

Archive powered by MHonArc 2.6.24.

Top of Page