Skip to Content.
Sympa Menu

notify-dpml - svn commit: r2780 - in development/main/transit/core/handler/src/main/net/dpml/transit: builder management manager model

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: r2780 - in development/main/transit/core/handler/src/main/net/dpml/transit: builder management manager model
  • Date: Tue, 07 Jun 2005 15:59:29 -0400

Author: mcconnell AT dpml.net
Date: Tue Jun 7 15:59:27 2005
New Revision: 2780

Added:

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

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

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

development/main/transit/core/handler/src/main/net/dpml/transit/builder/ContentRegistryStorageUnit.java

development/main/transit/core/handler/src/main/net/dpml/transit/builder/ContentStorageUnit.java

development/main/transit/core/handler/src/main/net/dpml/transit/builder/HostStorageUnit.java

development/main/transit/core/handler/src/main/net/dpml/transit/builder/LayoutRegistryStorageUnit.java

development/main/transit/core/handler/src/main/net/dpml/transit/builder/LayoutStorageUnit.java

development/main/transit/core/handler/src/main/net/dpml/transit/builder/ProxyStorageUnit.java

development/main/transit/core/handler/src/main/net/dpml/transit/builder/RepositoryStorageUnit.java

development/main/transit/core/handler/src/main/net/dpml/transit/builder/TransitStorageUnit.java

development/main/transit/core/handler/src/main/net/dpml/transit/management/Home.java

development/main/transit/core/handler/src/main/net/dpml/transit/management/Manager.java

development/main/transit/core/handler/src/main/net/dpml/transit/management/ModelReferenceException.java

development/main/transit/core/handler/src/main/net/dpml/transit/management/ModificationListener.java

development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultCacheManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultHostManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultLayoutRegistryManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultManager.java

development/main/transit/core/handler/src/main/net/dpml/transit/model/Model.java
Log:
Update the event/listener model to include an explicit disposal listener and
vetoable disposal event used in conjuction with assurance of referential
integrity of layouts, hosts and the cache model. Also include preferences
destruction following storage uint removal (trigger by disposal event).

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
Tue Jun 7 15:59:27 2005
@@ -25,19 +25,34 @@
import java.util.prefs.Preferences;
import java.util.prefs.BackingStoreException;

+import net.dpml.transit.management.Manager;
+import net.dpml.transit.management.ModificationEvent;
+import net.dpml.transit.management.ModificationListener;
+import net.dpml.transit.model.DisposalEvent;
+import net.dpml.transit.model.DisposalListener;
import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.Model;
+import net.dpml.transit.model.VetoDisposalException;

/**
* Utility class that provides support for the creation of URI and URL
* values from preference attributes.
*/
-class AbstractStorageUnit
+abstract class AbstractStorageUnit implements ModificationListener,
DisposalListener
{
+ //
------------------------------------------------------------------------
+ // state
+ //
------------------------------------------------------------------------
+
private Preferences m_prefs;
private boolean m_policy;
private Logger m_logger;
private Date m_creation;

+ //
------------------------------------------------------------------------
+ // constructors
+ //
------------------------------------------------------------------------
+
public AbstractStorageUnit( Preferences prefs, Logger logger, Date
creation, boolean policy )
{
m_prefs = prefs;
@@ -46,6 +61,10 @@
m_logger = logger;
}

+ //
------------------------------------------------------------------------
+ // constructor
+ //
------------------------------------------------------------------------
+
public boolean getStoragePolicy()
{
return m_policy;
@@ -66,6 +85,40 @@
return m_logger;
}

+ //
------------------------------------------------------------------------
+ // ModificationListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
+ public void modified( ModificationEvent event )
+ {
+ }
+
+ //
------------------------------------------------------------------------
+ // DisposalListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify the listener of the disposal of a manager.
+ */
+ public void disposing( DisposalEvent event ) throws VetoDisposalException
+ {
+ }
+
+ /**
+ * Notify the listener of the disposal of a manager.
+ */
+ public void disposed( DisposalEvent event )
+ {
+ }
+
+ //
------------------------------------------------------------------------
+ // impl
+ //
------------------------------------------------------------------------
+
public URI getURI( String key ) throws BuilderException
{
Preferences prefs = getPreferences();

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/CacheStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/CacheStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/CacheStorageUnit.java
Tue Jun 7 15:59:27 2005
@@ -25,12 +25,6 @@
import java.util.prefs.Preferences;
import java.util.prefs.BackingStoreException;

-import net.dpml.transit.model.Logger;
-import net.dpml.transit.model.UnknownKeyException;
-import net.dpml.transit.model.DuplicateKeyException;
-import net.dpml.transit.model.LayoutRegistryModel;
-import net.dpml.transit.model.LayoutModel;
-
import net.dpml.transit.management.CacheHome;
import net.dpml.transit.management.CacheManager;
import net.dpml.transit.management.ContentRegistryManager;
@@ -38,9 +32,12 @@
import net.dpml.transit.management.HostManager;
import net.dpml.transit.management.ModificationEvent;
import net.dpml.transit.management.LayoutRegistryManager;
-
import net.dpml.transit.manager.DefaultCacheManager;
-
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.UnknownKeyException;
+import net.dpml.transit.model.DuplicateKeyException;
+import net.dpml.transit.model.LayoutRegistryModel;
+import net.dpml.transit.model.LayoutModel;
import net.dpml.transit.util.PropertyResolver;

/**
@@ -85,41 +82,6 @@
}
}

- private LayoutRegistryManager createLayoutRegistryManager()
- {
- Preferences prefs = getPreferences().node( "layout" );
- Logger logger = getLogger().getChildLogger( "layout" );
- Date creation = getCreationDate();
- boolean policy = getStoragePolicy();
-
- try
- {
- LayoutRegistryStorageUnit unit =
- new LayoutRegistryStorageUnit( prefs, logger, creation, policy
);
- return unit.getLayoutRegistryManager();
- }
- catch( DuplicateKeyException e )
- {
- final String error =
- "Unable to construct layout registry manager due to a
duplicate layout key.";
- throw new BuilderException( error, e );
- }
- }
-
- private LayoutModel getLayoutModel( LayoutRegistryModel registry, String
key )
- {
- try
- {
- return registry.getLayoutModel( key );
- }
- catch( UnknownKeyException e )
- {
- final String error =
- "Unable to construct cache storage unit due unknown layout
key.";
- throw new BuilderException( error, e );
- }
- }
-
//
------------------------------------------------------------------------
// CacheHome
//
------------------------------------------------------------------------
@@ -139,6 +101,14 @@
return unit.createHostManager( m_registry );
}

+ //
------------------------------------------------------------------------
+ // ModificationListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
public void modified( ModificationEvent event )
{
if( getStoragePolicy() )
@@ -167,6 +137,41 @@
return m_manager;
}

+ private LayoutRegistryManager createLayoutRegistryManager()
+ {
+ Preferences prefs = getPreferences().node( "layout" );
+ Logger logger = getLogger().getChildLogger( "layout" );
+ Date creation = getCreationDate();
+ boolean policy = getStoragePolicy();
+
+ try
+ {
+ LayoutRegistryStorageUnit unit =
+ new LayoutRegistryStorageUnit( prefs, logger, creation, policy
);
+ return unit.getLayoutRegistryManager();
+ }
+ catch( DuplicateKeyException e )
+ {
+ final String error =
+ "Unable to construct layout registry manager due to a
duplicate layout key.";
+ throw new BuilderException( error, e );
+ }
+ }
+
+ private LayoutModel getLayoutModel( LayoutRegistryModel registry, String
key )
+ {
+ try
+ {
+ return registry.getLayoutModel( key );
+ }
+ catch( UnknownKeyException e )
+ {
+ final String error =
+ "Unable to construct cache storage unit due unknown layout
key.";
+ throw new BuilderException( error, e );
+ }
+ }
+
private HostManager[] createHostManagers()
{
Preferences prefs = getHostsNodePreferences();

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/ContentRegistryStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/ContentRegistryStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/ContentRegistryStorageUnit.java
Tue Jun 7 15:59:27 2005
@@ -23,15 +23,13 @@
import java.util.prefs.Preferences;
import java.util.prefs.BackingStoreException;

-import net.dpml.transit.model.Logger;
-import net.dpml.transit.model.DuplicateKeyException;
-
import net.dpml.transit.management.ContentRegistryHome;
import net.dpml.transit.management.ContentRegistryManager;
import net.dpml.transit.management.ContentManager;
import net.dpml.transit.management.ModificationEvent;
-
import net.dpml.transit.manager.DefaultContentRegistryManager;
+import net.dpml.transit.model.DuplicateKeyException;
+import net.dpml.transit.model.Logger;

/**
* The LayoutRegistryHelper class provides support for the crreating of a
@@ -76,6 +74,14 @@
return home.createContentManager();
}

+ //
------------------------------------------------------------------------
+ // ModificationListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
public void modified( ModificationEvent event )
{
if( getStoragePolicy() )
@@ -83,14 +89,13 @@
try
{
ContentRegistryManager manager = (ContentRegistryManager)
event.getManager();
- Date date = new Date();
store( manager );
+ Date date = new Date();
manager.setCreationDate( date );
}
catch( Throwable e )
{
- // TODO: propergate the error up to the HCI
- getLogger().error( "storage failure", e );
+ getLogger().error( "storage modification failure", e );
}
}
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/ContentStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/ContentStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/ContentStorageUnit.java
Tue Jun 7 15:59:27 2005
@@ -20,13 +20,15 @@
import java.net.MalformedURLException;
import java.util.Date;
import java.util.prefs.Preferences;
+import java.util.prefs.BackingStoreException;

-import net.dpml.transit.model.Logger;
import net.dpml.transit.management.ContentHome;
import net.dpml.transit.management.ContentManager;
import net.dpml.transit.management.ModificationEvent;
import net.dpml.transit.management.LayoutManager;
import net.dpml.transit.manager.DefaultContentManager;
+import net.dpml.transit.model.DisposalEvent;
+import net.dpml.transit.model.Logger;

/**
* The ContentSorageUnit class is responsible for the setup of initial
factory
@@ -44,9 +46,13 @@
}

//
------------------------------------------------------------------------
- // ContentHome
+ // ModificationListener
//
------------------------------------------------------------------------

+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
public void modified( ModificationEvent event )
{
if( getStoragePolicy() )
@@ -54,19 +60,37 @@
try
{
ContentManager manager = (ContentManager) event.getManager();
- Date date = new Date();
store( manager );
+ Date date = new Date();
manager.setCreationDate( date );
}
catch( Throwable e )
{
- // TODO: propergate the error up to the HCI
- getLogger().error( "storage failure", e );
+ getLogger().error( "storage modification failure", e );
}
}
}

//
------------------------------------------------------------------------
+ // DisposalListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify the listener of the disposal of a manager.
+ */
+ public void disposed( DisposalEvent event )
+ {
+ try
+ {
+ getPreferences().removeNode();
+ }
+ catch( BackingStoreException e )
+ {
+ getLogger().error( "storage removal failure", e );
+ }
+ }
+
+ //
------------------------------------------------------------------------
// impl
//
------------------------------------------------------------------------


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/HostStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/HostStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/HostStorageUnit.java
Tue Jun 7 15:59:27 2005
@@ -24,18 +24,19 @@
import java.util.prefs.BackingStoreException;
import java.net.PasswordAuthentication;

-import net.dpml.transit.model.Logger;
-import net.dpml.transit.model.LayoutModel;
-import net.dpml.transit.model.LayoutRegistryModel;
-import net.dpml.transit.model.UnknownKeyException;
-
import net.dpml.transit.management.HostHome;
import net.dpml.transit.management.HostManager;
import net.dpml.transit.management.ModificationEvent;
-
+import net.dpml.transit.management.Manager;
import net.dpml.transit.manager.DefaultManager.Local;
import net.dpml.transit.manager.DefaultManager.Plugin;
import net.dpml.transit.manager.DefaultHostManager;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.LayoutModel;
+import net.dpml.transit.model.LayoutRegistryModel;
+import net.dpml.transit.model.Model;
+import net.dpml.transit.model.UnknownKeyException;
+import net.dpml.transit.model.DisposalEvent;

/**
* The LayoutHelper class is responsible for the setup of initial factory
@@ -62,29 +63,51 @@
}

//
------------------------------------------------------------------------
- // Home
+ // ModificationListener
//
------------------------------------------------------------------------

+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
public void modified( ModificationEvent event )
{
if( getStoragePolicy() )
{
- HostManager manager = (HostManager) event.getManager();
try
{
- Date date = new Date();
+ HostManager manager = (HostManager) event.getManager();
store( manager );
+ Date date = new Date();
manager.setCreationDate( date );
}
catch( Throwable e )
{
- // TODO: propergate the error up to the HCI
- manager.getLogger().error( "storage failure", e );
+ getLogger().error( "storage modification failure", e );
}
}
}

//
------------------------------------------------------------------------
+ // DisposalListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify the listener of the disposal of a manager.
+ */
+ public void disposed( DisposalEvent event )
+ {
+ try
+ {
+ getPreferences().removeNode();
+ }
+ catch( BackingStoreException e )
+ {
+ getLogger().error( "storage removal failure", e );
+ }
+ }
+
+ //
------------------------------------------------------------------------
// impl
//
------------------------------------------------------------------------


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/LayoutRegistryStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/LayoutRegistryStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/LayoutRegistryStorageUnit.java
Tue Jun 7 15:59:27 2005
@@ -75,6 +75,14 @@
return unit.createLayoutManager();
}

+ //
------------------------------------------------------------------------
+ // ModificationListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
public void modified( ModificationEvent event )
{
if( getStoragePolicy() )
@@ -82,14 +90,13 @@
try
{
LayoutRegistryManager manager = (LayoutRegistryManager)
event.getManager();
- Date date = new Date();
store( manager );
+ Date date = new Date();
manager.setCreationDate( date );
}
catch( Throwable e )
{
- // TODO: propergate the error up to the HCI
- getLogger().error( "storage failure", e );
+ getLogger().error( "storage modification failure", e );
}
}
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/LayoutStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/LayoutStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/LayoutStorageUnit.java
Tue Jun 7 15:59:27 2005
@@ -20,14 +20,17 @@
import java.net.URI;
import java.util.Date;
import java.util.prefs.Preferences;
+import java.util.prefs.BackingStoreException;

-import net.dpml.transit.model.Logger;
import net.dpml.transit.manager.DefaultManager.Plugin;
import net.dpml.transit.manager.DefaultManager.Local;
import net.dpml.transit.manager.DefaultLayoutManager;
import net.dpml.transit.management.LayoutManager;
import net.dpml.transit.management.LayoutHome;
import net.dpml.transit.management.ModificationEvent;
+import net.dpml.transit.model.DisposalEvent;
+import net.dpml.transit.model.LayoutModel;
+import net.dpml.transit.model.Logger;

/**
* The LayoutHelper class is responsible for the setup of initial factory
@@ -45,9 +48,13 @@
}

//
------------------------------------------------------------------------
- // Home
+ // ModificationListener
//
------------------------------------------------------------------------

+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
public void modified( ModificationEvent event )
{
if( getStoragePolicy() )
@@ -55,14 +62,36 @@
try
{
LayoutManager manager = (LayoutManager) event.getManager();
- Date date = new Date();
store( manager );
+ Date date = new Date();
manager.setCreationDate( date );
}
catch( Throwable e )
{
- // TODO: propergate the error up to the HCI
- getLogger().error( "storage failure", e );
+ getLogger().error( "storage modification failure", e );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // DisposalListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify the listener of the disposal of a manager.
+ */
+ public void disposed( DisposalEvent event )
+ {
+ LayoutModel model = (LayoutModel) event.getModel();
+ if( false == model.isBootstrap() )
+ {
+ try
+ {
+ getPreferences().removeNode();
+ }
+ catch( BackingStoreException e )
+ {
+ getLogger().error( "storage deletion failure", e );
}
}
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/ProxyStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/ProxyStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/ProxyStorageUnit.java
Tue Jun 7 15:59:27 2005
@@ -23,12 +23,12 @@
import java.util.prefs.BackingStoreException;
import java.util.Date;

-import net.dpml.transit.model.Logger;
import net.dpml.transit.management.ProxyManager;
import net.dpml.transit.management.ProxyHome;
import net.dpml.transit.management.ModificationListener;
import net.dpml.transit.management.ModificationEvent;
import net.dpml.transit.manager.DefaultProxyManager;
+import net.dpml.transit.model.Logger;

/**
* The LayoutHelper class is responsible for the setup of initial factory
@@ -46,9 +46,13 @@
}

//
------------------------------------------------------------------------
- // ProxyHome
+ // ModificationListener
//
------------------------------------------------------------------------

+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
public void modified( ModificationEvent event )
{
if( getStoragePolicy() )

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/RepositoryStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/RepositoryStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/RepositoryStorageUnit.java
Tue Jun 7 15:59:27 2005
@@ -23,12 +23,12 @@
import java.util.prefs.BackingStoreException;
import java.util.Date;

-import net.dpml.transit.model.Logger;
import net.dpml.transit.management.RepositoryHome;
import net.dpml.transit.management.RepositoryManager;
import net.dpml.transit.management.ModificationListener;
import net.dpml.transit.management.ModificationEvent;
import net.dpml.transit.manager.DefaultRepositoryManager;
+import net.dpml.transit.model.Logger;

/**
* The LayoutHelper class is responsible for the setup of initial factory
@@ -46,9 +46,13 @@
}

//
------------------------------------------------------------------------
- // RepositoryHome
+ // ModificationListener
//
------------------------------------------------------------------------

+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
public void modified( ModificationEvent event )
{
if( getStoragePolicy() )

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/builder/TransitStorageUnit.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/builder/TransitStorageUnit.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/builder/TransitStorageUnit.java
Tue Jun 7 15:59:27 2005
@@ -36,6 +36,9 @@
import net.dpml.transit.management.ModificationListener;
import net.dpml.transit.management.ModificationEvent;
import net.dpml.transit.management.TransitHome;
+import net.dpml.transit.model.VetoDisposalException;
+import net.dpml.transit.model.DisposalListener;
+import net.dpml.transit.model.DisposalEvent;

import net.dpml.transit.manager.DefaultTransitManager;

@@ -94,11 +97,28 @@
*/
public void modified( ModificationEvent event )
{
- //System.out.println( "# mod: " +
event.getManager().getClass().getName() );
}

//
------------------------------------------------------------------------
- // TransitHome
+ // DisposalListener
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify the listener of the disposal of a manager.
+ */
+ public void disposing( DisposalEvent event ) throws VetoDisposalException
+ {
+ }
+
+ /**
+ * Notify the listener of the disposal of a manager.
+ */
+ public void disposed( DisposalEvent event )
+ {
+ }
+
+ //
------------------------------------------------------------------------
+ // impl
//
------------------------------------------------------------------------

public void setLogger( Logger logger )

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/management/Home.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/management/Home.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/management/Home.java
Tue Jun 7 15:59:27 2005
@@ -18,11 +18,13 @@

package net.dpml.transit.management;

+import net.dpml.transit.model.DisposalListener;
+
/**
* The ProxyManager is an interface implemented by proxy managers.
*
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
*/
-public interface Home extends ModificationListener
+public interface Home extends ModificationListener, DisposalListener
{
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/management/Manager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/management/Manager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/management/Manager.java
Tue Jun 7 15:59:27 2005
@@ -39,6 +39,4 @@

void removeModificationListener( ModificationListener listener );

- void dispose();
-
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/management/ModelReferenceException.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/management/ModelReferenceException.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/management/ModelReferenceException.java
Tue Jun 7 15:59:27 2005
@@ -20,6 +20,7 @@

import net.dpml.transit.model.Model;
import net.dpml.transit.model.ModelException;
+import net.dpml.transit.model.LayoutModel;

/**
* Exception raised when an attempt is made to remove a model
@@ -29,8 +30,8 @@
*/
public class ModelReferenceException extends ModelException
{
- private Model m_target;
- private final Object[] m_consumers;
+ private final Model m_source;
+ private final LayoutModel m_layout;

/**
* Construct a new <code>ModelReferenceException</code> instance.
@@ -38,38 +39,21 @@
* @param target the target model
* @param consumers the consumer models
*/
- public ModelReferenceException( final Model target, final Object[]
consumers )
+ public ModelReferenceException( final Model source, final LayoutModel
layout )
{
- super( buildMessage( target, consumers ) );
-
- m_target = target;
- m_consumers = consumers;
+ super( "Referential integrity error." );
+ m_source = source;
+ m_layout = layout;
}

public Model getModel()
{
- return m_target;
- }
-
- public Object[] getConsumers()
- {
- return m_consumers;
+ return m_source;
}

- private static String buildMessage( final Model target, final Object[]
consumers )
+ public LayoutModel getLayoutModel()
{
- int n = consumers.length;
- final String error =
- "Cannot remove a model due to "
- + n
- + " active consumers.";
- StringBuffer buffer = new StringBuffer( error );
- for( int i=0; i<consumers.length; i++ )
- {
- Object consumer = consumers[i];
- buffer.append( "\nReference: " + consumer );
- }
- return buffer.toString();
+ return m_layout;
}
}


Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/management/ModificationListener.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/management/ModificationListener.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/management/ModificationListener.java
Tue Jun 7 15:59:27 2005
@@ -31,5 +31,4 @@
* @param event the modification event
*/
void modified( ModificationEvent event );
-
}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultCacheManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultCacheManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultCacheManager.java
Tue Jun 7 15:59:27 2005
@@ -41,6 +41,7 @@
import java.util.prefs.BackingStoreException;

import net.dpml.transit.Transit;
+import net.dpml.transit.TransitError;

import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.LayoutModel;
@@ -61,14 +62,15 @@
import net.dpml.transit.model.DuplicateKeyException;

import net.dpml.transit.model.LayoutRegistryModel;
+import net.dpml.transit.model.DisposalListener;
+import net.dpml.transit.model.DisposalEvent;
+import net.dpml.transit.model.VetoDisposalException;
import net.dpml.transit.management.CacheHome;
import net.dpml.transit.management.CacheManager;
import net.dpml.transit.management.LayoutManager;
import net.dpml.transit.management.LayoutRegistryManager;
import net.dpml.transit.management.HostManager;
import net.dpml.transit.management.ModelReferenceException;
-import net.dpml.transit.management.ModificationListener;
-import net.dpml.transit.management.ModificationEvent;

import net.dpml.transit.util.PropertyResolver;

@@ -80,7 +82,7 @@
* @version $Id: StandardTransitDirector.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
*/
public class DefaultCacheManager extends DefaultPluginManager
- implements CacheManager, ModificationListener
+ implements CacheManager, DisposalListener
{
//
------------------------------------------------------------------------
// state
@@ -118,6 +120,7 @@
m_layout = layout;
m_registry = registry;
setCacheDirectory( cache, false );
+ m_layout.addDisposalListener( this );
for( int i=0; i<hosts.length; i++ )
{
HostManager host = hosts[i];
@@ -126,17 +129,26 @@
}

//
------------------------------------------------------------------------
- // ModificationListener (listen to modification to hosts)
+ // DisposalListener (listen to modification to the assigned layout)
//
------------------------------------------------------------------------

/**
- * Notify a listener of a change to the manager modification date.
- * @param event the modification event
+ * Notify the listener of the disposal of a layout.
*/
- public void modified( ModificationEvent event )
+ public void disposing( DisposalEvent event ) throws VetoDisposalException
{
- //ModificationEvent e = new ModificationEvent( this, event );
- //enqueueEvent( e );
+ final String message = "Layout currently assigned to cache.";
+ throw new VetoDisposalException( this, message );
+ }
+
+ /**
+ * Notify the listener of the disposal of a manager.
+ */
+ public void disposed( DisposalEvent event ) // should never happen
+ {
+ final String error =
+ "Unexpected notification of disposal of an assigned cache layout.";
+ throw new TransitError( error );
}

//
------------------------------------------------------------------------
@@ -259,12 +271,11 @@
catch( UnknownKeyException e )
{
m_list.add( manager );
- manager.addModificationListener( this );
if( notify )
{
+ setModified();
HostAddedEvent event = new HostAddedEvent( this, manager
);
enqueueEvent( event );
- setModified();
}
}
}
@@ -273,13 +284,14 @@
public void removeHostManager( HostManager manager )
{
synchronized( m_lock )
- {
- Object[] listeners = manager.getListeners();
+ {
+System.out.println( "# initiating host manager disposal" );
+ manager.dispose();
+System.out.println( "# removing host form list" );
m_list.remove( manager );
- setModified(); // <---- need to review this
- manager.removeModificationListener( this );
+System.out.println( "# firing host removed event" );
HostRemovedEvent event = new HostRemovedEvent( this, manager );
- super.enqueueEvent( event );
+ enqueueEvent( event );
}
}

@@ -332,6 +344,12 @@
// internal
//
------------------------------------------------------------------------

+ protected void destroy()
+ {
+ m_layout.removeDisposalListener( this );
+ super.destroy();
+ }
+
public void processEvent( EventObject event )
{
if( event instanceof HostNodeEvent )

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultHostManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultHostManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultHostManager.java
Tue Jun 7 15:59:27 2005
@@ -40,6 +40,7 @@
import net.dpml.transit.model.HostNameEvent;
import net.dpml.transit.model.HostPriorityEvent;
import net.dpml.transit.model.LayoutModel;
+import net.dpml.transit.model.LayoutListener;
import net.dpml.transit.model.Logger;
import net.dpml.transit.model.ModelException;
import net.dpml.transit.model.PluginModel;
@@ -48,7 +49,9 @@
import net.dpml.transit.management.HostHome;
import net.dpml.transit.management.HostManager;
import net.dpml.transit.management.BootstrapException;
-import net.dpml.transit.management.ModificationListener;
+import net.dpml.transit.model.DisposalEvent;
+import net.dpml.transit.model.DisposalListener;
+import net.dpml.transit.model.VetoDisposalException;

import net.dpml.transit.network.RequestIdentifier;

@@ -61,7 +64,8 @@
*
* @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
*/
-public class DefaultHostManager extends DefaultPluginManager implements
HostManager
+public class DefaultHostManager extends DefaultPluginManager
+ implements HostManager, DisposalListener
{
private final String m_id;

@@ -100,6 +104,7 @@
m_index = index;
m_authentication = auth;

+ m_layout.addDisposalListener( this );
m_identifier = getRequestIdentifier( base, scheme, prompt );
if( strategy instanceof Plugin )
{
@@ -114,6 +119,35 @@
}
}

+ //
------------------------------------------------------------------------
+ // DisposalListener (listen to modification to the assigned layout)
+ //
------------------------------------------------------------------------
+
+ /**
+ * Notify the listener of the disposal of a layout.
+ */
+ public void disposing( DisposalEvent event ) throws VetoDisposalException
+ {
+ final String id = getID();
+ final String message = "Layout currently assigned to host: " + id;
+ throw new VetoDisposalException( this, message );
+ }
+
+ /**
+ * Notify the listener of the disposal of the layout.
+ */
+ public void disposed( DisposalEvent event ) // should never happen
+ {
+ setEnabled( false );
+ final String error =
+ "Internal error."
+ + "\nUnexpected notification of disposal of an assigned layout."
+ + "\nHost set to disabled state."
+ + "\nHost: " + getID()
+ + "\nLayout: " + m_layout.getID();
+ getLogger().error( error );
+ }
+
//----------------------------------------------------------------------
// HostManager
//----------------------------------------------------------------------
@@ -182,7 +216,8 @@
throw new BootstrapException( error );
}
}
-
+ m_layout.removeDisposalListener( this );
+ layout.addDisposalListener( this );
m_layout = layout;
setModified();
HostLayoutEvent e = new HostLayoutEvent( this, m_layout );
@@ -366,6 +401,20 @@
// internal
//----------------------------------------------------------------------

+ private void setEnabled( boolean enabled )
+ {
+ synchronized( m_lock )
+ {
+ m_enabled = enabled ;
+ setModified();
+ }
+ }
+
+ protected void destroy()
+ {
+ m_layout.removeDisposalListener( this );
+ super.destroy();
+ }

protected void processEvent( EventObject event )
{

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultLayoutRegistryManager.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultLayoutRegistryManager.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/manager/DefaultLayoutRegistryManager.java
Tue Jun 7 15:59:27 2005
@@ -48,6 +48,7 @@
import net.dpml.transit.management.ModelReferenceException;
import net.dpml.transit.management.ModificationListener;
import net.dpml.transit.management.ModificationEvent;
+import net.dpml.transit.model.VetoDisposalException;

/**
* Default implementation of a layout subsystem that maitains
@@ -57,7 +58,7 @@
* @version $Id: StandardTransitDirector.java 2480 2005-05-10 04:44:32Z
mcconnell AT dpml.net $
*/
public class DefaultLayoutRegistryManager extends DefaultPluginManager
- implements LayoutRegistryManager, ModificationListener
+ implements LayoutRegistryManager
{
//
------------------------------------------------------------------------
// state
@@ -86,20 +87,6 @@
}

//
------------------------------------------------------------------------
- // Home (listen to modification to hosts)
- //
------------------------------------------------------------------------
-
- /**
- * Notify a listener of a change to the manager modification date.
- * @param event the modification event
- */
- public void modified( ModificationEvent event )
- {
- //ModificationEvent e = new ModificationEvent( this, event );
- //enqueueEvent( e );
- }
-
- //
------------------------------------------------------------------------
// LayoutRegistryModel
//
------------------------------------------------------------------------

@@ -163,7 +150,6 @@
catch( UnknownKeyException e )
{
m_list.add( manager );
- manager.addModificationListener( this );
if( notify )
{
LayoutAddedEvent event = new LayoutAddedEvent( this,
manager );
@@ -210,19 +196,18 @@
public void removeLayoutManager( LayoutManager manager ) throws
ModelReferenceException
{
synchronized( m_lock )
- {
- Object[] listeners = manager.getListeners();
- if( listeners.length == 1 )
+ {
+ try
{
+ manager.dispose();
m_list.remove( manager );
- manager.removeModificationListener( this );
LayoutRemovedEvent event = new LayoutRemovedEvent( this,
manager );
enqueueEvent( event );
setModified();
}
- else
+ catch( VetoDisposalException e )
{
- throw new ModelReferenceException( manager, listeners );
+ throw new ModelReferenceException( this, manager );
}
}
}

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
Tue Jun 7 15:59:27 2005
@@ -27,13 +27,16 @@
import java.util.Map;
import java.util.WeakHashMap;

-import net.dpml.transit.util.ExceptionHelper;
-import net.dpml.transit.model.Logger;
-import net.dpml.transit.model.Model;
+import net.dpml.transit.management.Home;
import net.dpml.transit.management.Manager;
import net.dpml.transit.management.ModificationEvent;
import net.dpml.transit.management.ModificationListener;
-import net.dpml.transit.management.Home;
+import net.dpml.transit.model.Logger;
+import net.dpml.transit.model.Model;
+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
@@ -86,6 +89,7 @@
if( null != home )
{
addModificationListener( home );
+ addDisposalListener( home );
}
}

@@ -153,18 +157,39 @@
removeListener( listener );
}

- public void dispose()
+ public void addDisposalListener( DisposalListener listener )
{
- if( null != m_home )
- {
- removeModificationListener( m_home );
- }
+ addListener( listener );
+ }
+
+ public void removeDisposalListener( DisposalListener listener )
+ {
+ removeListener( listener );
+ }
+
+ public void dispose() throws VetoDisposalException
+ {
+ m_modification = new Date();
+ VetoableDisposalEvent veto = new VetoableDisposalEvent( this );
+ enqueueEvent( veto, false );
+ DisposalEvent disposal = new DisposalEvent( this );
+ enqueueEvent( disposal, false );
+ destroy();
}

//
------------------------------------------------------------------------
// DefaultManager
//
------------------------------------------------------------------------

+ protected void destroy()
+ {
+ if( null != m_home )
+ {
+ removeModificationListener( m_home );
+ removeDisposalListener( m_home );
+ }
+ }
+
protected Home getHome()
{
return m_home;
@@ -197,7 +222,37 @@
{
final String error =
"Modification listener notification error.";
- getLogger().error( error, e );
+ getLogger().error( error, e );
+ }
+ }
+ }
+ }
+ else if( eventObject instanceof DisposalEvent )
+ {
+ DisposalEvent event = (DisposalEvent) eventObject;
+ EventListener[] listeners = listeners();
+ for( int i=0; i<listeners.length; i++ )
+ {
+ EventListener listener = listeners[i];
+ if( listener instanceof DisposalListener )
+ {
+ DisposalListener pl = (DisposalListener) listener;
+ if( event instanceof VetoableDisposalEvent )
+ {
+ pl.disposing( event );
+ }
+ else
+ {
+ try
+ {
+ pl.disposed( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Disposal listener notification error.";
+ getLogger().error( error, e );
+ }
}
}
}
@@ -445,4 +500,12 @@
}
}

+ private static class VetoableDisposalEvent extends DisposalEvent
+ {
+ public VetoableDisposalEvent( Model source )
+ {
+ super( source );
+ }
+ }
+
}

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/DisposalEvent.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/DisposalEvent.java
Tue Jun 7 15:59:27 2005
@@ -0,0 +1,37 @@
+/*
+ * 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.util.EventObject;
+
+/**
+ * An event signalling a model modification.
+ */
+public class DisposalEvent extends EventObject
+{
+ public DisposalEvent( Model model )
+ {
+ super( model );
+ }
+
+ public Model getModel()
+ {
+ return (Model) getSource();
+ }
+}

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/DisposalListener.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/DisposalListener.java
Tue Jun 7 15:59:27 2005
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2005 Stephen 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.util.EventListener;
+
+/**
+ * A ProxyListener maintains information about the configuration of
+ * tranist proxy settings.
+ */
+public interface DisposalListener extends EventListener
+{
+ /**
+ * Notify the listener of the disposal of a manager.
+ */
+ void disposing( DisposalEvent event ) throws VetoDisposalException;
+
+ /**
+ * Notify a listener of a change to the manager modification date.
+ * @param event the modification event
+ */
+ void disposed( DisposalEvent event );
+}

Modified:
development/main/transit/core/handler/src/main/net/dpml/transit/model/Model.java
==============================================================================
---
development/main/transit/core/handler/src/main/net/dpml/transit/model/Model.java
(original)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/Model.java
Tue Jun 7 15:59:27 2005
@@ -28,4 +28,10 @@
* @return the logging channel.
*/
Logger getLogger();
+
+ void addDisposalListener( DisposalListener listener );
+
+ void removeDisposalListener( DisposalListener listener );
+
+ void dispose();
}

Added:
development/main/transit/core/handler/src/main/net/dpml/transit/model/VetoDisposalException.java
==============================================================================
--- (empty file)
+++
development/main/transit/core/handler/src/main/net/dpml/transit/model/VetoDisposalException.java
Tue Jun 7 15:59:27 2005
@@ -0,0 +1,56 @@
+/*
+ * 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;
+
+/**
+ * Exception raised to veto a disposal request.
+ *
+ * @author <a href="http://www.dpml.net";>The Digital Product Meta Library</a>
+ */
+public class VetoDisposalException extends RuntimeException
+{
+ private Object m_source;
+
+ /**
+ * Construct a new <code>VetoDisposalException</code> instance.
+ *
+ * @param source the object initiating the veto
+ */
+ public VetoDisposalException( Object source )
+ {
+ super( "Disposal veto." );
+ }
+
+ /**
+ * Construct a new <code>VetoDisposalException</code> instance.
+ *
+ * @param source the object initiating the veto
+ * @param message the reason for the veto
+ */
+ public VetoDisposalException( Object source, String message )
+ {
+ super( message );
+ }
+
+ public Object getSource()
+ {
+ return m_source;
+ }
+}
+



  • svn commit: r2780 - in development/main/transit/core/handler/src/main/net/dpml/transit: builder management manager model, mcconnell, 06/07/2005

Archive powered by MHonArc 2.6.24.

Top of Page