notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r947 - trunk/main/transit/core/src/main/net/dpml/transit
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r947 - trunk/main/transit/core/src/main/net/dpml/transit
- Date: Sun, 22 Jan 2006 23:56:31 +0100
Author: mcconnell
Date: 2006-01-22 23:56:27 +0100 (Sun, 22 Jan 2006)
New Revision: 947
Added:
trunk/main/transit/core/src/main/net/dpml/transit/Disposable.java
Removed:
trunk/main/transit/core/src/main/net/dpml/transit/Service.java
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheHandler.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheModel.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentModel.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentRegistry.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentRegistryModel.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultHostModel.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutModel.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutRegistry.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutRegistryModel.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultModel.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultResourceHost.java
trunk/main/transit/core/src/main/net/dpml/transit/DefaultTransitModel.java
trunk/main/transit/core/src/main/net/dpml/transit/SecuredTransitContext.java
trunk/main/transit/core/src/main/net/dpml/transit/StandardLayoutModel.java
Log:
Across-the-board improvements on model disposal.
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheHandler.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheHandler.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheHandler.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -55,7 +55,7 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-class DefaultCacheHandler extends UnicastRemoteObject implements
CacheHandler, CacheListener, Service
+class DefaultCacheHandler extends UnicastRemoteObject implements
CacheHandler, CacheListener, Disposable
{
//
------------------------------------------------------------------------
// state
@@ -231,9 +231,9 @@
{
getLogger().debug( "removing host: " + id );
}
- if( host instanceof Service )
+ if( host instanceof Disposable )
{
- Service handler = (Service) host;
+ Disposable handler = (Disposable) host;
handler.dispose();
}
m_resourceHosts.remove( id );
@@ -242,7 +242,7 @@
}
//
------------------------------------------------------------------------
- // Service
+ // Disposable
//
------------------------------------------------------------------------
/**
@@ -257,14 +257,14 @@
m_model.removeCacheListener( this );
synchronized( m_resourceHosts )
{
-
- ResourceHost[] hosts = (ResourceHost[])
m_resourceHosts.values().toArray( new ResourceHost[0] );
+ ResourceHost[] hosts =
+ (ResourceHost[]) m_resourceHosts.values().toArray( new
ResourceHost[0] );
for( int i=0; i < hosts.length; i++ )
{
ResourceHost host = hosts[i];
- if( host instanceof Service )
+ if( host instanceof Disposable )
{
- Service handler = (Service) host;
+ Disposable handler = (Disposable) host;
handler.dispose();
}
}
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheModel.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheModel.java
2006-01-22 20:08:12 UTC (rev 946)
+++ trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheModel.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -19,7 +19,9 @@
package net.dpml.transit;
import java.io.File;
+import java.rmi.Remote;
import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.Collections;
@@ -283,11 +285,40 @@
* Disposal of the cache model.
* @exception RemoteException if a remote exception occurs
*/
- synchronized void dispose()
+ public synchronized void dispose()
{
+ HostModel[] hosts = getHostModels();
+ for( int i=0; i<hosts.length; i++ )
+ {
+ HostModel host = hosts[i];
+ dispose( host );
+ }
+ dispose( m_registry );
+ dispose( m_content );
super.dispose();
}
-
+
+ private void dispose( Object object )
+ {
+ if( object instanceof Disposable )
+ {
+ Disposable disposable = (Disposable) object;
+ disposable.dispose();
+ }
+ if( object instanceof Remote )
+ {
+ try
+ {
+ Remote remote = (Remote) object;
+ UnicastRemoteObject.unexportObject( remote, true );
+ }
+ catch( RemoteException re )
+ {
+ getLogger().warn( "Unexpected error during remote reference
removal.", re );
+ }
+ }
+ }
+
//
------------------------------------------------------------------------
// internal
//
------------------------------------------------------------------------
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentModel.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentModel.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentModel.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -34,7 +34,7 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-class DefaultContentModel extends DefaultCodeBaseModel implements
ContentModel
+class DefaultContentModel extends DefaultCodeBaseModel implements
ContentModel, Disposable
{
//----------------------------------------------------------------------
// state
@@ -108,7 +108,7 @@
/**
* Dispose of the content model.
*/
- void dispose()
+ public void dispose()
{
super.dispose();
}
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentRegistry.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentRegistry.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentRegistry.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -41,7 +41,7 @@
* @version @PROJECT-VERSION@
*/
class DefaultContentRegistry extends UnicastRemoteObject
- implements Service, ContentRegistry, ContentRegistryListener
+ implements ContentRegistry, ContentRegistryListener, Disposable
{
//
------------------------------------------------------------------------
// state
@@ -76,7 +76,7 @@
}
//
------------------------------------------------------------------------
- // Handler
+ // Disposable
//
------------------------------------------------------------------------
/**
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentRegistryModel.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentRegistryModel.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultContentRegistryModel.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -18,7 +18,9 @@
package net.dpml.transit;
+import java.rmi.Remote;
import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.util.Collections;
import java.util.List;
import java.util.LinkedList;
@@ -42,7 +44,7 @@
* @version @PROJECT-VERSION@
*/
class DefaultContentRegistryModel extends DefaultModel
- implements ContentRegistryModel
+ implements ContentRegistryModel, Disposable
{
//
------------------------------------------------------------------------
// state
@@ -78,10 +80,50 @@
}
//
------------------------------------------------------------------------
- // ContentRegistryModel
+ // Disposable
//
------------------------------------------------------------------------
/**
+ * Disposal of the model.
+ * @exception RemoteException if a remote exception occurs
+ */
+ public synchronized void dispose()
+ {
+ ContentModel[] models = getContentModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ ContentModel model = models[i];
+ dispose( model );
+ }
+ super.dispose();
+ }
+
+ private void dispose( Object object )
+ {
+ if( object instanceof Disposable )
+ {
+ Disposable disposable = (Disposable) object;
+ disposable.dispose();
+ }
+ if( object instanceof Remote )
+ {
+ try
+ {
+ Remote remote = (Remote) object;
+ UnicastRemoteObject.unexportObject( remote, true );
+ }
+ catch( RemoteException re )
+ {
+ getLogger().warn( "Unexpected error during remote reference
removal.", re );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
+ // ContentRegistryModel
+ //
------------------------------------------------------------------------
+
+ /**
* Return an array of content models currently assigned to the registry.
* @return the content model array
*/
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultHostModel.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/DefaultHostModel.java
2006-01-22 20:08:12 UTC (rev 946)
+++ trunk/main/transit/core/src/main/net/dpml/transit/DefaultHostModel.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -46,7 +46,7 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-class DefaultHostModel extends DefaultModel implements HostModel, Comparable
+class DefaultHostModel extends DefaultModel implements HostModel,
Comparable, Disposable
{
private static final int DEFAULT_PRIORITY = 600;
@@ -121,7 +121,7 @@
/**
* Dispose of the model.
*/
- void dispose()
+ public void dispose()
{
super.dispose();
}
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutModel.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutModel.java
2006-01-22 20:08:12 UTC (rev 946)
+++ trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutModel.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -36,7 +36,7 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-class DefaultLayoutModel extends DefaultCodeBaseModel implements LayoutModel
+class DefaultLayoutModel extends DefaultCodeBaseModel implements
LayoutModel, Disposable
{
//----------------------------------------------------------------------
// state
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutRegistry.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutRegistry.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutRegistry.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -38,7 +38,8 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-class DefaultLayoutRegistry extends UnicastRemoteObject implements
LayoutRegistry, LayoutRegistryListener
+class DefaultLayoutRegistry extends UnicastRemoteObject
+ implements LayoutRegistry, LayoutRegistryListener
{
//
------------------------------------------------------------------------
// state
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutRegistryModel.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutRegistryModel.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultLayoutRegistryModel.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -18,7 +18,9 @@
package net.dpml.transit;
+import java.rmi.Remote;
import java.rmi.RemoteException;
+import java.rmi.server.UnicastRemoteObject;
import java.util.List;
import java.util.LinkedList;
import java.util.EventObject;
@@ -85,8 +87,48 @@
addLayoutModel( directive, false );
}
}
-
+
//
------------------------------------------------------------------------
+ // Disposable
+ //
------------------------------------------------------------------------
+
+ /**
+ * Disposal of the cache model.
+ * @exception RemoteException if a remote exception occurs
+ */
+ public synchronized void dispose()
+ {
+ LayoutModel[] models = getLayoutModels();
+ for( int i=0; i<models.length; i++ )
+ {
+ LayoutModel model = models[i];
+ dispose( model );
+ }
+ super.dispose();
+ }
+
+ private void dispose( Object object )
+ {
+ if( object instanceof Disposable )
+ {
+ Disposable disposable = (Disposable) object;
+ disposable.dispose();
+ }
+ if( object instanceof Remote )
+ {
+ try
+ {
+ Remote remote = (Remote) object;
+ UnicastRemoteObject.unexportObject( remote, true );
+ }
+ catch( RemoteException re )
+ {
+ getLogger().warn( "Unexpected error during remote reference
removal.", re );
+ }
+ }
+ }
+
+ //
------------------------------------------------------------------------
// LayoutRegistryModel
//
------------------------------------------------------------------------
Modified: trunk/main/transit/core/src/main/net/dpml/transit/DefaultModel.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/DefaultModel.java
2006-01-22 20:08:12 UTC (rev 946)
+++ trunk/main/transit/core/src/main/net/dpml/transit/DefaultModel.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -36,7 +36,7 @@
* @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
* @version @PROJECT-VERSION@
*/
-public abstract class DefaultModel extends UnicastRemoteObject
+public abstract class DefaultModel extends UnicastRemoteObject implements
Disposable
{
//
------------------------------------------------------------------------
// state
@@ -151,7 +151,7 @@
return m_logger;
}
- synchronized void dispose()
+ public synchronized void dispose()
{
EventListener[] listeners = listeners();
for( int i=0; i < listeners.length; i++ )
@@ -159,6 +159,11 @@
EventListener listener = listeners[i];
removeListener( listener );
}
+ getLogger().debug( "disposed" );
+ }
+
+ synchronized void terminateDispatchThread()
+ {
if( null != m_EVENT_DISPATCH_THREAD )
{
m_EVENT_DISPATCH_THREAD.dispose();
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultResourceHost.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultResourceHost.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultResourceHost.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -66,7 +66,7 @@
* @version @PROJECT-VERSION@
*/
class DefaultResourceHost extends UnicastRemoteObject
- implements ResourceHost, HostListener, Service
+ implements ResourceHost, HostListener, Disposable
{
//
------------------------------------------------------------------------
// state
@@ -135,7 +135,7 @@
}
//
------------------------------------------------------------------------
- // Handler
+ // Disposable
//
------------------------------------------------------------------------
/**
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/DefaultTransitModel.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/DefaultTransitModel.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultTransitModel.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -214,34 +214,68 @@
*/
public synchronized void dispose()
{
- m_cache.dispose();
- if( null != m_proxy )
+ disposeCacheModel();
+ disposeProxyModel();
+ super.dispose();
+ terminateDispatchThread();
+ Thread thread = new Terminator( this );
+ thread.start();
+ }
+
+ private class Terminator extends Thread
+ {
+ private final DefaultTransitModel m_model;
+ Terminator( DefaultTransitModel model )
{
- m_proxy.dispose();
+ m_model = model;
}
- try
+
+ public void run()
{
- UnicastRemoteObject.unexportObject( m_cache, true );
+ try
+ {
+ UnicastRemoteObject.unexportObject( m_model, true );
+ }
+ catch( RemoteException e )
+ {
+ e.printStackTrace();
+ }
}
- catch( RemoteException e )
+ }
+
+ private synchronized void disposeProxyModel()
+ {
+ if( null == m_proxy )
{
- getLogger().warn( "Remote error during disposal.", e );
+ return;
}
- if( null != m_proxy )
+ else
{
+ m_proxy.dispose();
try
{
UnicastRemoteObject.unexportObject( m_proxy, true );
}
catch( RemoteException e )
{
- getLogger().warn( "Remote error during disposal.", e );
- }
+ getLogger().warn( "Remote error during proxy reference
removal.", e );
+ }
}
-
- super.dispose();
}
-
+
+ private synchronized void disposeCacheModel()
+ {
+ m_cache.dispose();
+ try
+ {
+ UnicastRemoteObject.unexportObject( m_cache, true );
+ }
+ catch( RemoteException e )
+ {
+ getLogger().warn( "Remote error during cache reference
removal.", e );
+ }
+ }
+
private DefaultProxyModel createProxyModel( final TransitDirective
directive )
{
try
Copied: trunk/main/transit/core/src/main/net/dpml/transit/Disposable.java
(from rev 946, trunk/main/transit/core/src/main/net/dpml/transit/Service.java)
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/Service.java
2006-01-22 20:08:12 UTC (rev 946)
+++ trunk/main/transit/core/src/main/net/dpml/transit/Disposable.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -0,0 +1,36 @@
+/*
+ * 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;
+
+/**
+ * The Disposable interface is implemented by a disposable sub-system within
Transit.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public interface Disposable
+{
+ /**
+ * Dispose of the service. During disposal a sub-system is required to
+ * release all references such as listeners and internal resources
+ * in preparation for garbage collection.
+ */
+ void dispose();
+}
+
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/SecuredTransitContext.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/SecuredTransitContext.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/SecuredTransitContext.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -301,9 +301,9 @@
private void handleDisposal( Object object )
{
- if( object instanceof Service )
+ if( object instanceof Disposable )
{
- Service handler = (Service) object;
+ Disposable handler = (Disposable) object;
try
{
handler.dispose();
Deleted: trunk/main/transit/core/src/main/net/dpml/transit/Service.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/Service.java
2006-01-22 20:08:12 UTC (rev 946)
+++ trunk/main/transit/core/src/main/net/dpml/transit/Service.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -1,36 +0,0 @@
-/*
- * 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;
-
-/**
- * The Service interface is implemented by a disposable sub-system within
Transit.
- *
- * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
- * @version @PROJECT-VERSION@
- */
-public interface Service
-{
- /**
- * Dispose of the service. During disposal a sub-system is required to
- * release all references such as listeners and internal resources
- * in preparation for garbage collection.
- */
- void dispose();
-}
-
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/StandardLayoutModel.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/StandardLayoutModel.java
2006-01-22 20:08:12 UTC (rev 946)
+++
trunk/main/transit/core/src/main/net/dpml/transit/StandardLayoutModel.java
2006-01-22 22:56:27 UTC (rev 947)
@@ -162,18 +162,6 @@
return new Value[0];
}
- //----------------------------------------------------------------------
- // Disposable
- //----------------------------------------------------------------------
-
- /**
- * Dispose of the layout model.
- */
- void dispose()
- {
- super.dispose();
- }
-
//
------------------------------------------------------------------------
// internal
//
------------------------------------------------------------------------
- r947 - trunk/main/transit/core/src/main/net/dpml/transit, mcconnell at BerliOS, 01/22/2006
Archive powered by MHonArc 2.6.24.