notify-dpml AT lists.ibiblio.org
Subject: DPML Notify
List archive
r955 - in trunk/main: metro/runtime/src/main/net/dpml/metro/runtime transit/core transit/core/src/main/net/dpml/transit transit/core/src/main/net/dpml/transit/model
- From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
- To: notify-dpml AT lists.ibiblio.org
- Subject: r955 - in trunk/main: metro/runtime/src/main/net/dpml/metro/runtime transit/core transit/core/src/main/net/dpml/transit transit/core/src/main/net/dpml/transit/model
- Date: Tue, 24 Jan 2006 04:27:06 +0100
Author: mcconnell
Date: 2006-01-24 04:26:58 +0100 (Tue, 24 Jan 2006)
New Revision: 955
Added:
trunk/main/transit/core/src/main/net/dpml/transit/model/DisposalEvent.java
trunk/main/transit/core/src/main/net/dpml/transit/model/DisposalListener.java
Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/UnicastEventSource.java
trunk/main/transit/core/build.xml
trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheHandler.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/model/TransitModel.java
Log:
add rmi unexport of transit runtime model listeners
Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/UnicastEventSource.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/UnicastEventSource.java
2006-01-23 05:22:31 UTC (rev 954)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/UnicastEventSource.java
2006-01-24 03:26:58 UTC (rev 955)
@@ -197,6 +197,9 @@
thread.start();
}
+ /**
+ * Internal class that handles instance retraction for the RMI runtime.
+ */
private class Terminator extends Thread
{
private final UnicastEventSource m_source;
Modified: trunk/main/transit/core/build.xml
===================================================================
--- trunk/main/transit/core/build.xml 2006-01-23 05:22:31 UTC (rev 954)
+++ trunk/main/transit/core/build.xml 2006-01-24 03:26:58 UTC (rev 955)
@@ -57,11 +57,11 @@
<include name="**/DefaultRepositoryModel.class"/>
<include name="**/DefaultTransitModel.class"/>
<include name="**/DefaultProxyModel.class"/>
- <include name="**/DefaultCacheHandler.class"/>
- <include name="**/DefaultContentRegistry.class"/>
- <include name="**/DefaultLayoutRegistry.class"/>
- <include name="**/DefaultResourceHost.class"/>
- <include name="**/SecuredTransitContext$ProxyController.class"/>
+ <include name="**/DefaultCacheHandler.class"/> <!-- -->
+ <include name="**/DefaultContentRegistry.class"/> <!-- -->
+ <include name="**/DefaultLayoutRegistry.class"/> <!-- -->
+ <include name="**/DefaultResourceHost.class"/> <!-- -->
+ <include name="**/SecuredTransitContext$ProxyController.class"/> <!--
-->
</rmic>
</target>
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-23 05:22:31 UTC (rev 954)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultCacheHandler.java
2006-01-24 03:26:58 UTC (rev 955)
@@ -27,6 +27,8 @@
import java.io.InputStream;
import java.io.OutputStream;
import java.net.UnknownHostException;
+import java.rmi.Remote;
+import java.rmi.NoSuchObjectException;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.Date;
@@ -250,7 +252,7 @@
* release all references such as listeners and internal resources
* in preparation for garbage collection.
*/
- public void dispose()
+ public synchronized void dispose()
{
try
{
@@ -262,14 +264,12 @@
for( int i=0; i < hosts.length; i++ )
{
ResourceHost host = hosts[i];
- if( host instanceof Disposable )
- {
- Disposable handler = (Disposable) host;
- handler.dispose();
- }
+ terminate( host );
}
m_resourceHosts.clear();
}
+ terminate( m_registry );
+ terminate( m_content );
}
catch( RemoteException e )
{
@@ -279,6 +279,31 @@
}
}
+ private void terminate( 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( NoSuchObjectException e )
+ {
+ // ignore
+ }
+ catch( Throwable e )
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
//
------------------------------------------------------------------------
// impl
//
------------------------------------------------------------------------
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-23 05:22:31 UTC (rev 954)
+++
trunk/main/transit/core/src/main/net/dpml/transit/DefaultTransitModel.java
2006-01-24 03:26:58 UTC (rev 955)
@@ -28,6 +28,7 @@
import java.io.File;
import java.net.URL;
import java.net.URI;
+import java.util.EventListener;
import net.dpml.transit.info.CacheDirective;
import net.dpml.transit.info.ProxyDirective;
@@ -35,6 +36,8 @@
import net.dpml.transit.model.CacheModel;
import net.dpml.transit.model.ProxyModel;
import net.dpml.transit.model.TransitModel;
+import net.dpml.transit.model.DisposalEvent;
+import net.dpml.transit.model.DisposalListener;
import net.dpml.transit.monitor.LoggingAdapter;
/**
@@ -197,14 +200,61 @@
}
/**
+ * Add a disposal listener to the model.
+ * @param listener the listener to add
+ * @exception RemoteException if a remote exception occurs
+ */
+ public void addDisposalListener( DisposalListener listener )
+ {
+ super.addListener( listener );
+ }
+
+ /**
+ * Remove a disposal listener from the model.
+ * @param listener the listener to remove
+ * @exception RemoteException if a remote exception occurs
+ */
+ public void removeDisposalListener( DisposalListener listener )
+ {
+ super.removeListener( listener );
+ }
+
+ /**
* Internal event handler.
* @param eventObject the event to handle
*/
protected void processEvent( EventObject eventObject )
{
- // no event in this object
+ if( eventObject instanceof DisposalEvent )
+ {
+ DisposalEvent event = (DisposalEvent) eventObject;
+ processDisposalEvent( event );
+ }
}
+ private void processDisposalEvent( DisposalEvent event )
+ {
+ EventListener[] listeners = super.listeners();
+ for( int i=0; i < listeners.length; i++ )
+ {
+ EventListener listener = listeners[i];
+ if( listener instanceof DisposalListener )
+ {
+ DisposalListener pl = (DisposalListener) listener;
+ try
+ {
+ pl.notifyDisposal( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Disposal notification error.";
+ getLogger().error( error, e );
+ }
+ }
+ }
+ }
+
//
------------------------------------------------------------------------
// impl
//
------------------------------------------------------------------------
@@ -214,6 +264,8 @@
*/
public synchronized void dispose()
{
+ DisposalEvent event = new DisposalEvent( this );
+ enqueueEvent( event, true );
disposeCacheModel();
disposeProxyModel();
super.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-23 05:22:31 UTC (rev 954)
+++
trunk/main/transit/core/src/main/net/dpml/transit/SecuredTransitContext.java
2006-01-24 03:26:58 UTC (rev 955)
@@ -20,6 +20,8 @@
package net.dpml.transit;
import java.io.IOException;
+import java.rmi.NoSuchObjectException;
+import java.rmi.Remote;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.net.PasswordAuthentication;
@@ -34,6 +36,8 @@
import net.dpml.transit.model.ProxyListener;
import net.dpml.transit.model.ProxyEvent;
import net.dpml.transit.model.RequestIdentifier;
+import net.dpml.transit.model.DisposalListener;
+import net.dpml.transit.model.DisposalEvent;
import net.dpml.lang.UnknownKeyException;
import net.dpml.transit.monitor.LoggingAdapter;
@@ -145,6 +149,10 @@
* The repository service provider.
*/
private Repository m_repository;
+
+ private ProxyController m_proxyController;
+
+ private DisposalController m_disposalController;
//------------------------------------------------------------------
// constructors
@@ -170,10 +178,12 @@
synchronized( proxy )
{
setupProxy();
- ProxyController controller = new ProxyController();
- proxy.addProxyListener( controller );
+ m_proxyController = new ProxyController();
+ proxy.addProxyListener( m_proxyController );
}
}
+ m_disposalController = new DisposalController();
+ model.addDisposalListener( m_disposalController );
}
//------------------------------------------------------------------
@@ -299,23 +309,6 @@
getCacheHandler().initialize();
}
- private void handleDisposal( Object object )
- {
- if( object instanceof Disposable )
- {
- Disposable handler = (Disposable) object;
- try
- {
- handler.dispose();
- }
- catch( Throwable e )
- {
- // interesting but ignorable
- e.printStackTrace();
- }
- }
- }
-
/**
* Internal listener to the proxy model.
*/
@@ -349,6 +342,80 @@
}
}
+ /**
+ * Internal listener to the proxy model.
+ */
+ private class DisposalController extends UnicastRemoteObject implements
DisposalListener
+ {
+ /**
+ * Listener creation.
+ * @exeption RemoteException if a remote error occurs
+ */
+ public DisposalController() throws RemoteException
+ {
+ super();
+ }
+
+ /**
+ * Notify a listener of transit model disposal.
+ * @param event the disposal event
+ */
+ public void notifyDisposal( DisposalEvent event )
+ {
+ Thread thread = new Terminator();
+ thread.start();
+ }
+ }
+
+ /**
+ * Internal model terminator.
+ */
+ private class Terminator extends Thread
+ {
+ Terminator()
+ {
+ }
+
+ /**
+ * Initiate model retraction from the RMI.
+ */
+ public void run()
+ {
+ m_logger.debug( "initiating transit runtime disposal" );
+ terminate( m_proxyController );
+ terminate( m_cacheHandler );
+ terminate( m_disposalController );
+ m_logger.debug( "transit runtime disposal complete" );
+ }
+
+ private void terminate( 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( NoSuchObjectException e )
+ {
+ // ignore
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error encountered during transit runtime
termination.";
+ m_logger.warn( error, e );
+ }
+ }
+ }
+ }
+
private Logger getLogger()
{
return m_logger;
Added:
trunk/main/transit/core/src/main/net/dpml/transit/model/DisposalEvent.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/model/DisposalEvent.java
2006-01-23 05:22:31 UTC (rev 954)
+++
trunk/main/transit/core/src/main/net/dpml/transit/model/DisposalEvent.java
2006-01-24 03:26:58 UTC (rev 955)
@@ -0,0 +1,45 @@
+/*
+ * 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;
+
+/**
+ * A event pertaining to the disposal of a source object.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public class DisposalEvent extends EventObject
+{
+ /**
+ * Serial version identifier.
+ */
+ static final long serialVersionUID = 1L;
+
+ /**
+ * Creation of a new DisposalEvent.
+ *
+ * @param source the disposed object
+ */
+ public DisposalEvent( Object source )
+ {
+ super( source );
+ }
+}
Added:
trunk/main/transit/core/src/main/net/dpml/transit/model/DisposalListener.java
===================================================================
---
trunk/main/transit/core/src/main/net/dpml/transit/model/DisposalListener.java
2006-01-23 05:22:31 UTC (rev 954)
+++
trunk/main/transit/core/src/main/net/dpml/transit/model/DisposalListener.java
2006-01-24 03:26:58 UTC (rev 955)
@@ -0,0 +1,41 @@
+/*
+ * 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;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+
+/**
+ * A DisposalListener is implementated by objects that need to be notified
+ * abiout the disposal of an event source.
+ *
+ * @author <a href="@PUBLISHER-URL@">@PUBLISHER-NAME@</a>
+ * @version @PROJECT-VERSION@
+ */
+public interface DisposalListener extends EventListener, Remote
+{
+ /**
+ * Notify a listener of event souce disposal.
+ *
+ * @param event the disposal event
+ * @exception RemoteException if a remote exception occurs
+ */
+ void notifyDisposal( DisposalEvent event ) throws RemoteException;
+}
Modified:
trunk/main/transit/core/src/main/net/dpml/transit/model/TransitModel.java
===================================================================
--- trunk/main/transit/core/src/main/net/dpml/transit/model/TransitModel.java
2006-01-23 05:22:31 UTC (rev 954)
+++ trunk/main/transit/core/src/main/net/dpml/transit/model/TransitModel.java
2006-01-24 03:26:58 UTC (rev 955)
@@ -44,4 +44,18 @@
* @exception RemoteException if a remote exception occurs
*/
CacheModel getCacheModel() throws RemoteException;
+
+ /**
+ * Add a disposal listener to the model.
+ * @param listener the listener to add
+ * @exception RemoteException if a remote exception occurs
+ */
+ void addDisposalListener( DisposalListener listener ) throws
RemoteException;
+
+ /**
+ * Remove a disposal listener from the model.
+ * @param listener the listener to remove
+ * @exception RemoteException if a remote exception occurs
+ */
+ void removeDisposalListener( DisposalListener listener ) throws
RemoteException;
}
- r955 - in trunk/main: metro/runtime/src/main/net/dpml/metro/runtime transit/core transit/core/src/main/net/dpml/transit transit/core/src/main/net/dpml/transit/model, mcconnell at BerliOS, 01/23/2006
Archive powered by MHonArc 2.6.24.