Skip to Content.
Sympa Menu

notify-dpml - r943 - in trunk/main/metro: part/api/src/main/net/dpml/part/local runtime/src/main/net/dpml/metro/runtime

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell at BerliOS <mcconnell AT mail.berlios.de>
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: r943 - in trunk/main/metro: part/api/src/main/net/dpml/part/local runtime/src/main/net/dpml/metro/runtime
  • Date: Sun, 22 Jan 2006 04:42:58 +0100

Author: mcconnell
Date: 2006-01-22 04:42:52 +0100 (Sun, 22 Jan 2006)
New Revision: 943

Modified:
trunk/main/metro/part/api/src/main/net/dpml/part/local/Handler.java
trunk/main/metro/part/api/src/main/net/dpml/part/local/PartsManager.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultPartsManager.java

trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/UnicastEventSource.java
Log:
Move the static component event queue from ComponentHandler to
CompositionController.

Modified: trunk/main/metro/part/api/src/main/net/dpml/part/local/Handler.java
===================================================================
--- trunk/main/metro/part/api/src/main/net/dpml/part/local/Handler.java
2006-01-22 02:37:47 UTC (rev 942)
+++ trunk/main/metro/part/api/src/main/net/dpml/part/local/Handler.java
2006-01-22 03:42:52 UTC (rev 943)
@@ -25,6 +25,7 @@

import net.dpml.part.remote.Component;
import net.dpml.part.remote.Provider;
+import net.dpml.part.remote.Model;

/**
* Local interface through which a component implementation may

Modified:
trunk/main/metro/part/api/src/main/net/dpml/part/local/PartsManager.java
===================================================================
--- trunk/main/metro/part/api/src/main/net/dpml/part/local/PartsManager.java
2006-01-22 02:37:47 UTC (rev 942)
+++ trunk/main/metro/part/api/src/main/net/dpml/part/local/PartsManager.java
2006-01-22 03:42:52 UTC (rev 943)
@@ -19,6 +19,8 @@
package net.dpml.part.local;

import net.dpml.part.ControlException;
+import net.dpml.part.remote.Component;
+import net.dpml.part.remote.Model;

import net.dpml.lang.UnknownKeyException;

@@ -38,6 +40,20 @@
String[] getKeys();

/**
+ * Return an internal component.
+ * @param key the internal component key
+ * @return the component
+ */
+ Component getComponent( String key ) throws UnknownKeyException;
+
+ /**
+ * Return the component model for the supplied component.
+ * @param component the component
+ * @return the component model
+ */
+ Model getComponentModel( Component component );
+
+ /**
* Return a local component handler.
* @param key the internal part key
* @return the local component handler

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
2006-01-22 02:37:47 UTC (rev 942)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/CompositionController.java
2006-01-22 03:42:52 UTC (rev 943)
@@ -22,6 +22,9 @@
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
+import java.util.EventObject;
+import java.util.LinkedList;
+import java.util.List;

import net.dpml.logging.Logger;

@@ -41,6 +44,7 @@

import net.dpml.transit.Repository;
import net.dpml.transit.Transit;
+import net.dpml.transit.util.ExceptionHelper;

/**
* The composition controller is the controller used to establish remotely
accessible
@@ -408,4 +412,115 @@
throw new RuntimeException( e );
}
}
+
+ /**
+ * Queue of pending notification events. When an event for which
+ * there are one or more listeners occurs, it is placed on this queue
+ * and the queue is notified. A background thread waits on this queue
+ * and delivers the events. This decouples event delivery from
+ * the application concern, greatly simplifying locking and reducing
+ * opportunity for deadlock.
+ */
+ private static final List EVENT_QUEUE = new LinkedList();
+
+ /**
+ * Enqueue an event for delivery to registered
+ * listeners unless there are no registered
+ * listeners.
+ * @param event the event to enqueue
+ */
+ static void enqueueEvent( EventObject event )
+ {
+ synchronized( EVENT_QUEUE )
+ {
+ EVENT_QUEUE.add( event );
+ EVENT_QUEUE.notify();
+ }
+ }
+
+ /**
+ * A single background thread ("the event notification thread") monitors
+ * the event queue and delivers events that are placed on the queue.
+ */
+ private static class EventDispatchThread extends Thread
+ {
+ public void run()
+ {
+ while( true )
+ {
+ // Wait on EVENT_QUEUE till an event is present
+ EventObject event = null;
+ synchronized( EVENT_QUEUE )
+ {
+ try
+ {
+ while( EVENT_QUEUE.isEmpty() )
+ {
+ EVENT_QUEUE.wait();
+ }
+ Object object = EVENT_QUEUE.remove( 0 );
+ try
+ {
+ event = (EventObject) object;
+ }
+ catch( ClassCastException cce )
+ {
+ final String error =
+ "Unexpected class cast exception while
processing an event."
+ + "\nEvent: " + object;
+ throw new IllegalStateException( error );
+ }
+ }
+ catch( InterruptedException e )
+ {
+ return;
+ }
+ }
+
+ Object source = event.getSource();
+ if( source instanceof UnicastEventSource )
+ {
+ UnicastEventSource producer = (UnicastEventSource)
source;
+ try
+ {
+ producer.processEvent( event );
+ }
+ catch( Throwable e )
+ {
+ final String error =
+ "Unexpected error while processing event."
+ + "\nEvent: " + event
+ + "\nSource: " + source;
+ String msg = ExceptionHelper.packException( error,
e, true );
+ System.err.println( msg );
+ }
+ }
+ else
+ {
+ final String error =
+ "Event source ["
+ + source.getClass().getName()
+ + "] is not an instance of " +
UnicastEventSource.class.getName();
+ throw new IllegalStateException( error );
+ }
+ }
+ }
+ }
+
+ private static Thread m_EVENT_DISPATCH_THREAD = null;
+
+ /**
+ * This method starts the event dispatch thread the first time it
+ * is called. The event dispatch thread will be started only
+ * if someone registers a listener.
+ */
+ static synchronized void startEventDispatchThread()
+ {
+ if( m_EVENT_DISPATCH_THREAD == null )
+ {
+ m_EVENT_DISPATCH_THREAD = new EventDispatchThread();
+ m_EVENT_DISPATCH_THREAD.setDaemon( true );
+ m_EVENT_DISPATCH_THREAD.start();
+ }
+ }
}

Modified:
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultPartsManager.java
===================================================================
---
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultPartsManager.java
2006-01-22 02:37:47 UTC (rev 942)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/DefaultPartsManager.java
2006-01-22 03:42:52 UTC (rev 943)
@@ -29,6 +29,7 @@

import net.dpml.part.ControlException;
import net.dpml.part.remote.Component;
+import net.dpml.part.remote.Model;
import net.dpml.part.local.PartsManager;
import net.dpml.part.local.Handler;

@@ -120,7 +121,7 @@
}

//-------------------------------------------------------------------
- // Parts
+ // PartsManager
//-------------------------------------------------------------------

/**
@@ -134,8 +135,48 @@

/**
* Return a component handler.
+ * @param key the internal component key
* @return the local component handler
*/
+ public synchronized Component getComponent( String key ) throws
UnknownKeyException
+ {
+ if( m_handlers.containsKey( key ) )
+ {
+ return (Component) m_handlers.get( key );
+ }
+ else
+ {
+ throw new UnknownKeyException( key );
+ }
+ }
+
+ /**
+ * Return the component model for the supplied component.
+ * @param component the component
+ * @return the component model
+ */
+ public Model getComponentModel( Component component )
+ {
+ if( component instanceof ComponentHandler )
+ {
+ ComponentHandler handler = (ComponentHandler) component;
+ return handler.getComponentModel();
+ }
+ else
+ {
+ final String error =
+ "Component ["
+ + component
+ + "] is not castable to
net.dpml.metro.runtime.ComponentHandler.";
+ throw new IllegalArgumentException( error );
+ }
+ }
+
+ /**
+ * Return a component handler.
+ * @param key the internal component key
+ * @return the local component handler
+ */
public synchronized Handler getComponentHandler( String key ) throws
UnknownKeyException
{
if( m_handlers.containsKey( key ) )
@@ -148,6 +189,10 @@
}
}

+ /**
+ * Return the commissioned state of the part collection.
+ * @return true if commissioned else false
+ */
public boolean isCommissioned()
{
return m_commissioned;

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-22 02:37:47 UTC (rev 942)
+++
trunk/main/metro/runtime/src/main/net/dpml/metro/runtime/UnicastEventSource.java
2006-01-22 03:42:52 UTC (rev 943)
@@ -91,7 +91,7 @@
System.arraycopy( old, 0, m_listeners, 0, old.length );
m_listeners[old.length] = listener;
}
- startEventDispatchThread();
+ CompositionController.startEventDispatchThread();
}

/**
@@ -175,108 +175,13 @@
}
catch( NoSuchObjectException e )
{
+ // ignore
}
m_listeners = new EventListener[0];
m_disposed = true;
}
}

- /**
- * Queue of pending notification events. When an event for which
- * there are one or more listeners occurs, it is placed on this queue
- * and the queue is notified. A background thread waits on this queue
- * and delivers the events. This decouples event delivery from
- * the application concern, greatly simplifying locking and reducing
- * opportunity for deadlock.
- */
- private static final List EVENT_QUEUE = new LinkedList();
-
- /**
- * A single background thread ("the event notification thread") monitors
- * the event queue and delivers events that are placed on the queue.
- */
- private static class EventDispatchThread extends Thread
- {
- public void run()
- {
- while( true )
- {
- // Wait on EVENT_QUEUE till an event is present
- EventObject event = null;
- synchronized( EVENT_QUEUE )
- {
- try
- {
- while( EVENT_QUEUE.isEmpty() )
- {
- EVENT_QUEUE.wait();
- }
- Object object = EVENT_QUEUE.remove( 0 );
- try
- {
- event = (EventObject) object;
- }
- catch( ClassCastException cce )
- {
- final String error =
- "Unexpected class cast exception while
processing an event."
- + "\nEvent: " + object;
- throw new IllegalStateException( error );
- }
- }
- catch( InterruptedException e )
- {
- return;
- }
- }
-
- Object source = event.getSource();
- if( source instanceof UnicastEventSource )
- {
- UnicastEventSource producer = (UnicastEventSource)
source;
- try
- {
- producer.processEvent( event );
- }
- catch( Throwable e )
- {
- final String error =
- "Unexpected error while processing event."
- + "\nEvent: " + event
- + "\nSource: " + source;
- String msg = ExceptionHelper.packException( error,
e, true );
- System.err.println( msg );
- }
- }
- else
- {
- final String error =
- "Event source ["
- + source.getClass().getName()
- + "] is not an instance of " +
UnicastEventSource.class.getName();
- throw new IllegalStateException( error );
- }
- }
- }
- }
-
- private static Thread m_EVENT_DISPATCH_THREAD = null;
-
- /**
- * This method starts the event dispatch thread the first time it
- * is called. The event dispatch thread will be started only
- * if someone registers a listener.
- */
- private static synchronized void startEventDispatchThread()
- {
- if( m_EVENT_DISPATCH_THREAD == null )
- {
- m_EVENT_DISPATCH_THREAD = new EventDispatchThread();
- m_EVENT_DISPATCH_THREAD.setDaemon( true );
- m_EVENT_DISPATCH_THREAD.start();
- }
- }
-
/**
* Return this node's preference/node change listeners. Even though
* we're using a copy-on-write lists, we use synchronized accessors to
@@ -302,11 +207,7 @@
{
if( m_listeners.length != 0 )
{
- synchronized( EVENT_QUEUE )
- {
- EVENT_QUEUE.add( event );
- EVENT_QUEUE.notify();
- }
+ CompositionController.enqueueEvent( event );
}
}
}




  • r943 - in trunk/main/metro: part/api/src/main/net/dpml/part/local runtime/src/main/net/dpml/metro/runtime, mcconnell at BerliOS, 01/21/2006

Archive powered by MHonArc 2.6.24.

Top of Page