Skip to Content.
Sympa Menu

notify-dpml - svn commit: r1179 - in development/main/transit/handler/src/main/net/dpml/transit: . adapter artifact monitors

notify-dpml AT lists.ibiblio.org

Subject: DPML Notify

List archive

Chronological Thread  
  • From: mcconnell AT netcompartner.com
  • To: notify-dpml AT lists.ibiblio.org
  • Subject: svn commit: r1179 - in development/main/transit/handler/src/main/net/dpml/transit: . adapter artifact monitors
  • Date: Tue, 14 Dec 2004 17:53:54 +0100

Author: mcconnell
Date: Tue Dec 14 17:53:53 2004
New Revision: 1179

Added:

development/main/transit/handler/src/main/net/dpml/transit/monitors/AbstractMonitorRouter.java
(contents, props changed)

development/main/transit/handler/src/main/net/dpml/transit/monitors/NullMonitor.java
(contents, props changed)
Modified:
development/main/transit/handler/src/main/net/dpml/transit/Main.java
development/main/transit/handler/src/main/net/dpml/transit/Transit.java

development/main/transit/handler/src/main/net/dpml/transit/adapter/AbstractAdapter.java

development/main/transit/handler/src/main/net/dpml/transit/adapter/CacheMonitorAdapter.java

development/main/transit/handler/src/main/net/dpml/transit/adapter/ConsoleAdapter.java

development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java

development/main/transit/handler/src/main/net/dpml/transit/monitors/CacheMonitorRouter.java

development/main/transit/handler/src/main/net/dpml/transit/monitors/ConnectionMonitorRouter.java

development/main/transit/handler/src/main/net/dpml/transit/monitors/Monitor.java

development/main/transit/handler/src/main/net/dpml/transit/monitors/NetworkMonitorRouter.java

development/main/transit/handler/src/main/net/dpml/transit/monitors/RepositoryMonitorRouter.java

development/main/transit/handler/src/main/net/dpml/transit/monitors/Router.java
Log:
Updates to the transit system to enable the association of a boostrap monitor
so we can look inside to see what is happening from the very beginning.

Modified: development/main/transit/handler/src/main/net/dpml/transit/Main.java
==============================================================================
--- development/main/transit/handler/src/main/net/dpml/transit/Main.java
(original)
+++ development/main/transit/handler/src/main/net/dpml/transit/Main.java
Tue Dec 14 17:53:53 2004
@@ -61,22 +61,16 @@
public static void main( final String[] args )
throws Exception
{
- String path = System.getProperty( BOOTSTRAP_URI_KEY );
- if( null == path )
- {
- final String error =
- "The system property '"
- + BOOTSTRAP_URI_KEY
- + "' is undefined.";
- throw new IllegalStateException( error );
- }
-
//
// Setup transit protocol handler
//

System.setProperty( "java.protocol.handler.pkgs", "net.dpml.transit"
);

+ //
+ // Setup debug policy
+ //
+
boolean debug = false;
for( int i=0; i < args.length; i++ )
{
@@ -86,9 +80,11 @@
break;
}
}
+
String[] arguments = collapseArgs( args );

- Transit transit = Transit.getInstance();
+ Monitor monitor = new BootstrapMonitor( debug );
+ Transit transit = Transit.getInstance( monitor );

Adapter adapter = new ConsoleAdapter( debug );
RepositoryMonitor repoMonitor = new RepositoryMonitorAdapter(
adapter );
@@ -99,6 +95,22 @@
transit.getCacheMonitorRouter().addMonitor( cacheMonitor );
transit.getNetworkMonitorRouter().addMonitor( netMonitor );

+ //
+ // get the bootstrap plugin
+ //
+
+ String path = System.getProperty( BOOTSTRAP_URI_KEY );
+ if( null == path )
+ {
+ final String error =
+ "The system property '"
+ + BOOTSTRAP_URI_KEY
+ + "' is undefined.";
+ System.err.println( error );
+ System.getProperties().list( System.err );
+ throw new IllegalStateException( error );
+ }
+
URI uri = Artifact.createArtifact( path ).toURI();
Monitor[] monitors = new Monitor[]{repoMonitor, cacheMonitor,
netMonitor};
Object[] params = new Object[]{monitors, arguments};
@@ -135,5 +147,39 @@
{
// disabled
}
+
+ private static class BootstrapMonitor implements Monitor
+ {
+ private static final String TAG = "[transit] ";
+ private final boolean m_trace;
+
+ BootstrapMonitor( boolean trace )
+ {
+ m_trace = trace;
+ }
+
+ /**
+ * Test is trace monitoring is enabled.
+ * @return true if debug trace messages are enabled elese false
+ */
+ public boolean isTraceEnabled()
+ {
+ return m_trace;
+ }
+
+ /**
+ * Process a trace message.
+ *
+ * @param message the trace level message
+ */
+ public void trace( String message )
+ {
+ if( isTraceEnabled() )
+ {
+ System.out.print( TAG );
+ System.out.println( message );
+ }
+ }
+ }
}


Modified:
development/main/transit/handler/src/main/net/dpml/transit/Transit.java
==============================================================================
--- development/main/transit/handler/src/main/net/dpml/transit/Transit.java
(original)
+++ development/main/transit/handler/src/main/net/dpml/transit/Transit.java
Tue Dec 14 17:53:53 2004
@@ -26,9 +26,11 @@

import net.dpml.transit.artifact.SecuredTransitContext;

+import net.dpml.transit.monitors.Monitor;
import net.dpml.transit.monitors.RepositoryMonitorRouter;
import net.dpml.transit.monitors.CacheMonitorRouter;
import net.dpml.transit.monitors.NetworkMonitorRouter;
+import net.dpml.transit.monitors.NullMonitor;

import net.dpml.transit.repository.Repository;
import net.dpml.transit.repository.StandardLoader;
@@ -51,6 +53,11 @@
public static final String HOME_SYMBOL = "DPML_HOME";

/**
+ * Transit trace policy system property key.
+ */
+ public static final String TRACE_KEY =
"dpml.transit.trace.policy";
+
+ /**
* Singleton transit instance.
*/
private static Transit transitSingletonInstance;
@@ -90,11 +97,28 @@
public static Transit getInstance()
throws TransitException
{
+ return Transit.getInstance( new NullMonitor() );
+ }
+
+ /**
+ * Returns the singleton instance of the transit system. If this method
+ * has already been invoked the monitor argument will be ignored.
+ * @param monitor the bootstrap monitor
+ * @return the singleton transit instance
+ * @exception TransitException if an error occurs during establishment
+ */
+ public static Transit getInstance( Monitor monitor )
+ throws TransitException
+ {
+ if( null == monitor )
+ {
+ throw new NullPointerException( "monitor" );
+ }
synchronized( Transit.class )
{
if( transitSingletonInstance == null )
{
- transitSingletonInstance = new Transit();
+ transitSingletonInstance = new Transit( monitor );
}
return transitSingletonInstance;
}
@@ -102,17 +126,22 @@

/**
* Private constructor of a transit instance.
+ * @param monitor the bootstrap monitor
* @exception TransitException if an establishment error occurs
*/
- private Transit()
+ private Transit( Monitor monitor )
throws TransitException
{
try
{
- SecuredTransitContext.create(); // Ensure secured environment.
- m_repositoryMonitor = new RepositoryMonitorRouter();
- m_cacheMonitor = new CacheMonitorRouter();
- m_networkMonitor = new NetworkMonitorRouter();
+ if( monitor.isTraceEnabled() )
+ {
+ monitor.trace( "creating transit instance" );
+ }
+ SecuredTransitContext.create( monitor ); // Ensure secured
environment.
+ m_repositoryMonitor = new RepositoryMonitorRouter( monitor);
+ m_cacheMonitor = new CacheMonitorRouter( monitor );
+ m_networkMonitor = new NetworkMonitorRouter( monitor );
}
catch( Throwable e )
{

Modified:
development/main/transit/handler/src/main/net/dpml/transit/adapter/AbstractAdapter.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/adapter/AbstractAdapter.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/adapter/AbstractAdapter.java
Tue Dec 14 17:53:53 2004
@@ -47,4 +47,28 @@
{
return m_adapter;
}
+
+ /**
+ * Test is debug trace monitoring is enabled.
+ * @return true if debug trace messages are enabled else false
+ */
+ public boolean isTraceEnabled()
+ {
+ return getAdapter().isDebugEnabled();
+ }
+
+ /**
+ * Notify the monitor of a trace level message to log. An implement
+ * is responsible for checking if trace debug logging is enabled
+ * before handling content.
+ *
+ * @param message the trace level message to log
+ */
+ public void trace( String message )
+ {
+ if( getAdapter().isDebugEnabled() )
+ {
+ getAdapter().debug( message );
+ }
+ }
}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/adapter/CacheMonitorAdapter.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/adapter/CacheMonitorAdapter.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/adapter/CacheMonitorAdapter.java
Tue Dec 14 17:53:53 2004
@@ -59,10 +59,6 @@
*/
public void addedToLocalCache( URL resource, File localFile )
{
- if( getAdapter().isDebugEnabled() )
- {
- getAdapter().debug( "added [" + resource + "] to cache as [" +
localFile + "]" );
- }
}

/**

Modified:
development/main/transit/handler/src/main/net/dpml/transit/adapter/ConsoleAdapter.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/adapter/ConsoleAdapter.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/adapter/ConsoleAdapter.java
Tue Dec 14 17:53:53 2004
@@ -33,6 +33,8 @@
*/
private static final int KBYTE = 1024;

+ private static final String TAG = "[transit] ";
+
/**
* The debug mode.
*/
@@ -83,7 +85,7 @@
{
if( m_debug )
{
- System.out.println( message );
+ log( message );
}
}

@@ -93,7 +95,7 @@
*/
public void info( String message )
{
- System.out.println( message );
+ log( message );
}

/**
@@ -102,7 +104,7 @@
*/
public void warn( String message )
{
- System.out.println( message );
+ log( message );
}

/**
@@ -122,7 +124,7 @@
public void error( String message, Throwable e )
{
String error = ExceptionHelper.packException( message, e, m_debug );
- System.out.println( error );
+ log( error );
}

/**
@@ -135,7 +137,7 @@
{
if( isAnt() && total == count )
{
- System.out.println( "downloaded: " + resource );
+ log( "downloaded: " + resource );
return;
}

@@ -145,7 +147,7 @@

String value = getFranctionalValue( count );
int pad = max.length() - value.length();
- StringBuffer buffer = new StringBuffer( "Progress: " );
+ StringBuffer buffer = new StringBuffer( TAG + "Progress: " );
for( int i=0; i < pad; i++ )
{
buffer.append( " " );
@@ -219,5 +221,11 @@
return value;
}
}
+
+ private void log( String message )
+ {
+ System.out.print( TAG );
+ System.out.println( message );
+ }
}


Modified:
development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/artifact/SecuredTransitContext.java
Tue Dec 14 17:53:53 2004
@@ -29,6 +29,8 @@

import net.dpml.transit.Transit;
import net.dpml.transit.TransitException;
+import net.dpml.transit.monitors.Monitor;
+import net.dpml.transit.monitors.NullMonitor;

/**
* The initial context of the transit system.
@@ -85,7 +87,11 @@
/**
* The singleton transit context.
*/
- private static SecuredTransitContext secuteTransitContext;
+ private static SecuredTransitContext secureTransitContext;
+
+ //------------------------------------------------------------------
+ // state
+ //------------------------------------------------------------------

/**
* The cache handler.
@@ -102,6 +108,10 @@
*/
private ResourceHost[] m_resourceHosts;

+ //------------------------------------------------------------------
+ // implementation
+ //------------------------------------------------------------------
+
/**
* Creation of the transit context. If the transit context has already
* been established the method returns the singeton context otherwise a
new context
@@ -113,19 +123,42 @@
public static SecuredTransitContext create()
throws TransitException
{
- if( secuteTransitContext != null )
+ return SecuredTransitContext.create( new NullMonitor() );
+ }
+
+ /**
+ * Creation of the transit context. If the transit context has already
+ * been established the method returns the singeton context otherwise a
new context
+ * is created relative to the authoritve url and returned.
+ *
+ * @param monitor the bootstrap monitor
+ * @return the secured transit context
+ * @exception TransitException if an error occurs during context creation
+ */
+ public static SecuredTransitContext create( final Monitor monitor )
+ throws TransitException
+ {
+ if( secureTransitContext != null )
+ {
+ return secureTransitContext;
+ }
+ if( null == monitor )
+ {
+ throw new NullPointerException( "monitor" );
+ }
+ if( monitor.isTraceEnabled() )
{
- return secuteTransitContext;
+ monitor.trace( "creating secure transit context" );
}
try
{
- URL authorative = establishAuthority();
+ URL authorative = establishAuthority( monitor );
ResourceHostFactory rhFactory = new ResourceHostFactory(
authorative );
ResourceHost[] hosts = rhFactory.createResourceHosts();
CacheHandlerFactory chFactory = new CacheHandlerFactory(
authorative );
CacheHandler ch = chFactory.createCacheHandler( hosts );
- secuteTransitContext = new SecuredTransitContext( authorative,
hosts, ch );
- return secuteTransitContext;
+ secureTransitContext = new SecuredTransitContext( authorative,
hosts, ch );
+ return secureTransitContext;
}
catch( IOException e )
{
@@ -202,7 +235,7 @@
* @return the authorative url
* @exception TransitException if an error occurs during authority url
creation
*/
- private static URL establishAuthority()
+ private static URL establishAuthority( final Monitor monitor )
throws TransitException
{
try
@@ -225,6 +258,14 @@
}
else
{
+ if( monitor.isTraceEnabled() )
+ {
+ final String message =
+ "using system property
'dpml.transit.authority.file' ["
+ + path
+ + "]";
+ monitor.trace( message );
+ }
return useForAuthority( authorativeFile );
}
}
@@ -239,6 +280,14 @@
artifactAuthFile = new File( transitDir, AUTHORITY_FILENAME );
if( artifactAuthFile.exists() )
{
+ if( monitor.isTraceEnabled() )
+ {
+ final String message =
+ "using authority file ["
+ + artifactAuthFile
+ + "]";
+ monitor.trace( message );
+ }
return useForAuthority( artifactAuthFile );
}

@@ -251,6 +300,14 @@
artifactAuthFile = new File( extlib, AUTHORITY_FILENAME );
if( artifactAuthFile.exists() )
{
+ if( monitor.isTraceEnabled() )
+ {
+ final String message =
+ "using extension authority file ["
+ + artifactAuthFile
+ + "]";
+ monitor.trace( message );
+ }
return useForAuthority( artifactAuthFile );
}

@@ -260,12 +317,21 @@
// authority directory.
//

+ if( monitor.isTraceEnabled() )
+ {
+ final String message =
+ "using transit home as default authorative source ["
+ + artifactAuthFile
+ + "]";
+ monitor.trace( message );
+ }
+
return new File( Transit.HOME, "transit" ).toURL();

}
catch( Exception e )
{
- throw new TransitException( "Artifact AUTHORITY can not be
established.", e );
+ throw new TransitException( "Artifact AUTHORITY cannot be
established.", e );
}
}


Added:
development/main/transit/handler/src/main/net/dpml/transit/monitors/AbstractMonitorRouter.java
==============================================================================
--- (empty file)
+++
development/main/transit/handler/src/main/net/dpml/transit/monitors/AbstractMonitorRouter.java
Tue Dec 14 17:53:53 2004
@@ -0,0 +1,154 @@
+/*
+ * Copyright 2004 Niclas Hedhman.
+ *
+ * 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.monitors;
+
+import java.net.URI;
+import java.lang.reflect.Constructor;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+
+/**
+ * A repository monitor router handles mutlicast distribution of monitor
events to
+ * a set of subscribed monitors.
+ */
+public class AbstractMonitorRouter implements Router, Monitor
+{
+ //--------------------------------------------------------------------
+ // static
+ //--------------------------------------------------------------------
+
+ private static final Monitor[] EMPTY_MONITORS = new Monitor[0];
+
+ //--------------------------------------------------------------------
+ // state
+ //--------------------------------------------------------------------
+
+ /**
+ * List of attached monitors.
+ */
+ private ArrayList m_monitors;
+
+ /**
+ * The trace policy.
+ */
+ private final Monitor m_trace;
+
+ //--------------------------------------------------------------------
+ // constructors
+ //--------------------------------------------------------------------
+
+ public AbstractMonitorRouter( Monitor trace )
+ {
+ m_trace = trace;
+ }
+
+ //--------------------------------------------------------------------
+ // Router
+ //--------------------------------------------------------------------
+
+ /**
+ * Add a monitor to the set of monitors managed by this router.
+ * @param monitor the monitor to add
+ */
+ public void addMonitor( Monitor monitor )
+ {
+ synchronized( this )
+ {
+ ArrayList list;
+ if( m_monitors == null )
+ {
+ list = new ArrayList();
+ }
+ else
+ {
+ list = (ArrayList) m_monitors.clone();
+ }
+ list.add( monitor );
+ m_monitors = list;
+ }
+ }
+
+ /**
+ * Remove a monitor from the set of monitors managed by this router.
+ * @param monitor the monitor to remove
+ */
+ public void removeMonitor( Monitor monitor )
+ {
+ synchronized( this )
+ {
+ if( m_monitors == null )
+ {
+ return;
+ }
+ ArrayList list = (ArrayList) m_monitors.clone();
+ list.remove( monitor );
+ if( list.size() == 0 )
+ {
+ m_monitors = null;
+ }
+ else
+ {
+ m_monitors = list;
+ }
+ }
+ }
+
+ /**
+ * Return the list of monitors.
+ * @return an array of connected monitors
+ */
+ Monitor[] getMonitors()
+ {
+ if( null == m_monitors )
+ {
+ return EMPTY_MONITORS;
+ }
+ else
+ {
+ return (Monitor[]) m_monitors.toArray( new Monitor[0] );
+ }
+ }
+
+ //--------------------------------------------------------------------
+ // Monitor
+ //--------------------------------------------------------------------
+
+ /**
+ * Test is debug trace monitoring is enabled.
+ * @return true if debug trace messages are enabled else false
+ */
+ public boolean isTraceEnabled()
+ {
+ return m_trace.isTraceEnabled();
+ }
+
+ /**
+ * Notify the monitor of a trace level message to log. An implement
+ * is responsible for checking if trace debug logging is enabled
+ * before handling content.
+ *
+ * @param message the trace level message to log
+ */
+ public void trace( String message )
+ {
+ m_trace.trace( message );
+ }
+}
+

Modified:
development/main/transit/handler/src/main/net/dpml/transit/monitors/CacheMonitorRouter.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/monitors/CacheMonitorRouter.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/monitors/CacheMonitorRouter.java
Tue Dec 14 17:53:53 2004
@@ -31,29 +31,33 @@
* The cache monitor router is responsible for the dispatiching of cache
monitor
* events to registered monitors.
*/
-public class CacheMonitorRouter
+public class CacheMonitorRouter extends AbstractMonitorRouter
implements CacheMonitor, Router
{
- /**
- * List of assigned monitors.
- */
- private ArrayList m_monitors;
-
+ //--------------------------------------------------------------------
+ // constructors
+ //--------------------------------------------------------------------
+
+ public CacheMonitorRouter( Monitor trace )
+ {
+ super( trace );
+ }
+
+ //--------------------------------------------------------------------
+ // CacheMonitor
+ //--------------------------------------------------------------------
+
/**
* Notify all monitors that a request for an artifact has been received.
* @param artifact the requested artifact
*/
public void resourceRequested( Artifact artifact )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- CacheMonitor mon = (CacheMonitor) list.next();
- mon.resourceRequested( artifact );
+ CacheMonitor monitor = (CacheMonitor) monitors[i];
+ monitor.resourceRequested( artifact );
}
}

@@ -64,15 +68,11 @@
*/
public void addedToLocalCache( URL resource, File localFile )
{
- if( m_monitors == null )
- {
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- CacheMonitor mon = (CacheMonitor) list.next();
- mon.addedToLocalCache( resource, localFile );
+ CacheMonitor monitor = (CacheMonitor) monitors[i];
+ monitor.addedToLocalCache( resource, localFile );
}
}

@@ -83,15 +83,11 @@
*/
public void updatedLocalCache( URL resource, File localFile )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- CacheMonitor mon = (CacheMonitor) list.next();
- mon.updatedLocalCache( resource, localFile );
+ CacheMonitor monitor = (CacheMonitor) monitors[i];
+ monitor.addedToLocalCache( resource, localFile );
}
}

@@ -102,15 +98,11 @@
*/
public void removedFromLocalCache( URL resource, File localFile )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- CacheMonitor mon = (CacheMonitor) list.next();
- mon.removedFromLocalCache( resource, localFile );
+ CacheMonitor monitor = (CacheMonitor) monitors[i];
+ monitor.removedFromLocalCache( resource, localFile );
}
}

@@ -122,15 +114,11 @@
*/
public void failedDownloadFromHost( String host, Artifact artifact,
Exception cause )
{
- if( m_monitors == null )
- {
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- CacheMonitor mon = (CacheMonitor) list.next();
- mon.failedDownloadFromHost( host, artifact, cause );
+ CacheMonitor monitor = (CacheMonitor) monitors[i];
+ monitor.failedDownloadFromHost( host, artifact, cause );
}
}

@@ -140,15 +128,11 @@
*/
public void failedDownload( Artifact artifact )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- CacheMonitor mon = (CacheMonitor) list.next();
- mon.failedDownload( artifact );
+ CacheMonitor monitor = (CacheMonitor) monitors[i];
+ monitor.failedDownload( artifact );
}
}

@@ -159,48 +143,13 @@
*/
public void addMonitor( Monitor monitor ) throws IllegalArgumentException
{
- if( !( monitor instanceof CacheMonitor ) )
+ if( !( monitor instanceof CacheMonitor) )
{
throw new IllegalArgumentException( "monitor must be
CacheMonitor type." );
}
- synchronized( this )
- {
- ArrayList list;
- if( m_monitors == null )
- {
- list = new ArrayList();
- }
- else
- {
- list = (ArrayList) m_monitors.clone();
- }
- list.add( monitor );
- m_monitors = list;
- }
- }
-
- /**
- * Remove of a monitor to the list of monitors maintained by this router.
- * @param monitor the monitor to remove
- */
- public void removeMonitor( Monitor monitor )
- {
- synchronized( this )
+ else
{
- if( m_monitors == null )
- {
- return;
- }
- ArrayList list = (ArrayList) m_monitors.clone();
- list.remove( monitor );
- if( list.size() == 0 )
- {
- m_monitors = null;
- }
- else
- {
- m_monitors = list;
- }
+ super.addMonitor( monitor );
}
}
}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/monitors/ConnectionMonitorRouter.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/monitors/ConnectionMonitorRouter.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/monitors/ConnectionMonitorRouter.java
Tue Dec 14 17:53:53 2004
@@ -27,29 +27,33 @@
* A commection monitor implemetation that routes connection notification
requests
* to registered listeners.
*/
-public class ConnectionMonitorRouter
+public class ConnectionMonitorRouter extends AbstractMonitorRouter
implements ConnectionMonitor, Router
{
- /**
- * List of attached monitors.
- */
- private ArrayList m_monitors;
-
+ //--------------------------------------------------------------------
+ // constructors
+ //--------------------------------------------------------------------
+
+ public ConnectionMonitorRouter( Monitor trace )
+ {
+ super( trace );
+ }
+
+ //--------------------------------------------------------------------
+ // ConnectionMonitor
+ //--------------------------------------------------------------------
+
/**
* Notify registered monitors of a connection opened event.
* @param url the target url
*/
public void connectionOpened( URL url )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- ConnectionMonitor mon = (ConnectionMonitor) list.next();
- mon.connectionOpened( url );
+ ConnectionMonitor monitor = (ConnectionMonitor) monitors[i];
+ monitor.connectionOpened( url );
}
}

@@ -59,15 +63,11 @@
*/
public void connectStarted( URL url )
{
- if( m_monitors == null )
- {
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- ConnectionMonitor mon = (ConnectionMonitor) list.next();
- mon.connectStarted( url );
+ ConnectionMonitor monitor = (ConnectionMonitor) monitors[i];
+ monitor.connectStarted( url );
}
}

@@ -77,15 +77,11 @@
*/
public void connectCompleted( URL url )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- ConnectionMonitor mon = (ConnectionMonitor) list.next();
- mon.connectCompleted( url );
+ ConnectionMonitor monitor = (ConnectionMonitor) monitors[i];
+ monitor.connectCompleted( url );
}
}

@@ -99,44 +95,9 @@
{
throw new IllegalArgumentException( "monitor must be
ConnectionMonitor type." );
}
- synchronized( this )
- {
- ArrayList list;
- if( m_monitors == null )
- {
- list = new ArrayList();
- }
- else
- {
- list = (ArrayList) m_monitors.clone();
- }
- list.add( monitor );
- m_monitors = list;
- }
- }
-
- /**
- * Remove a monitors from the set of registered monitors.
- * @param monitor the monitor to remove
- */
- public void removeMonitor( Monitor monitor )
- {
- synchronized( this )
+ else
{
- if( m_monitors == null )
- {
- return;
- }
- ArrayList list = (ArrayList) m_monitors.clone();
- list.remove( monitor );
- if( list.size() == 0 )
- {
- m_monitors = null;
- }
- else
- {
- m_monitors = list;
- }
+ super.addMonitor( monitor );
}
}
}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/monitors/Monitor.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/monitors/Monitor.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/monitors/Monitor.java
Tue Dec 14 17:53:53 2004
@@ -23,5 +23,17 @@
*/
public interface Monitor
{
+ /**
+ * Test is trace monitoring is enabled.
+ * @return true if debug trace messages are enabled elese false
+ */
+ boolean isTraceEnabled();
+
+ /**
+ * Notify the monitor of a trace level message to log.
+ *
+ * @param message the trace level message
+ */
+ void trace( String message );
}


Modified:
development/main/transit/handler/src/main/net/dpml/transit/monitors/NetworkMonitorRouter.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/monitors/NetworkMonitorRouter.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/monitors/NetworkMonitorRouter.java
Tue Dec 14 17:53:53 2004
@@ -26,13 +26,21 @@
/**
* A router that handles multicasr distribution of monitor events to
registered monitors.
*/
-public class NetworkMonitorRouter
+public class NetworkMonitorRouter extends AbstractMonitorRouter
implements NetworkMonitor, Router
{
- /**
- * List of monitors.
- */
- private ArrayList m_monitors;
+ //--------------------------------------------------------------------
+ // constructors
+ //--------------------------------------------------------------------
+
+ public NetworkMonitorRouter( Monitor trace )
+ {
+ super( trace );
+ }
+
+ //--------------------------------------------------------------------
+ // NetworkMonitor
+ //--------------------------------------------------------------------

/**
* Notify all subscribing monitors of a updated event.
@@ -42,15 +50,11 @@
*/
public void notifyUpdate( URL resource, int expected, int count )
{
- if( m_monitors == null )
- {
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- NetworkMonitor mon = (NetworkMonitor) list.next();
- mon.notifyUpdate( resource, expected, count );
+ NetworkMonitor monitor = (NetworkMonitor) monitors[i];
+ monitor.notifyUpdate( resource, expected, count );
}
}

@@ -60,15 +64,11 @@
*/
public void notifyCompletion( URL resource )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- NetworkMonitor mon = (NetworkMonitor) list.next();
- mon.notifyCompletion( resource );
+ NetworkMonitor monitor = (NetworkMonitor) monitors[i];
+ monitor.notifyCompletion( resource );
}
}

@@ -83,44 +83,9 @@
{
throw new IllegalArgumentException( "monitor must be
NetworkMonitor type." );
}
- synchronized( this )
- {
- ArrayList list;
- if( m_monitors == null )
- {
- list = new ArrayList();
- }
- else
- {
- list = (ArrayList) m_monitors.clone();
- }
- list.add( monitor );
- m_monitors = list;
- }
- }
-
- /**
- * Remove the supplied monitor from the list of registered monitors.
- * @param monitor the monitor to remove
- */
- public void removeMonitor( Monitor monitor )
- {
- synchronized( this )
+ else
{
- if( m_monitors == null )
- {
- return;
- }
- ArrayList list = (ArrayList) m_monitors.clone();
- list.remove( monitor );
- if( list.size() == 0 )
- {
- m_monitors = null;
- }
- else
- {
- m_monitors = list;
- }
+ super.addMonitor( monitor );
}
}
}

Added:
development/main/transit/handler/src/main/net/dpml/transit/monitors/NullMonitor.java
==============================================================================
--- (empty file)
+++
development/main/transit/handler/src/main/net/dpml/transit/monitors/NullMonitor.java
Tue Dec 14 17:53:53 2004
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2004 Niclas Hedhman.
+ *
+ * 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.monitors;
+
+/**
+ * A null monitor.
+ */
+public class NullMonitor implements Monitor
+{
+ /**
+ * Test is trace monitoring is enabled.
+ * @return true if debug trace messages are enabled elese false
+ */
+ public boolean isTraceEnabled()
+ {
+ return false;
+ }
+
+ /**
+ * Process a trace message.
+ *
+ * @param message the trace level message
+ */
+ public void trace( final String message )
+ {
+ }
+}

Modified:
development/main/transit/handler/src/main/net/dpml/transit/monitors/RepositoryMonitorRouter.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/monitors/RepositoryMonitorRouter.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/monitors/RepositoryMonitorRouter.java
Tue Dec 14 17:53:53 2004
@@ -28,29 +28,33 @@
* A repository monitor router handles mutlicast distribution of monitor
events to
* a set of subscribed monitors.
*/
-public class RepositoryMonitorRouter
+public class RepositoryMonitorRouter extends AbstractMonitorRouter
implements RepositoryMonitor, Router
-{
- /**
- * List of attached monitors.
- */
- private ArrayList m_monitors;
-
+{
+ //--------------------------------------------------------------------
+ // constructors
+ //--------------------------------------------------------------------
+
+ public RepositoryMonitorRouter( Monitor trace )
+ {
+ super( trace );
+ }
+
+ //--------------------------------------------------------------------
+ // RepositoryMonitor
+ //--------------------------------------------------------------------
+
/**
* Notify all subscribed monitors of a info message event.
* @param info the information message
*/
public void sequenceInfo( String info )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- RepositoryMonitor mon = (RepositoryMonitor) list.next();
- mon.sequenceInfo( info );
+ RepositoryMonitor monitor = (RepositoryMonitor) monitors[i];
+ monitor.sequenceInfo( info );
}
}

@@ -62,15 +66,11 @@
*/
public void getPluginRequested( ClassLoader parent, URI uri, Object[]
args )
{
- if( m_monitors == null )
- {
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- RepositoryMonitor mon = (RepositoryMonitor) list.next();
- mon.getPluginRequested( parent, uri, args );
+ RepositoryMonitor monitor = (RepositoryMonitor) monitors[i];
+ monitor.getPluginRequested( parent, uri, args );
}
}

@@ -80,15 +80,11 @@
*/
public void establishedPluginClass( Class pluginClass )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- RepositoryMonitor mon = (RepositoryMonitor) list.next();
- mon.establishedPluginClass( pluginClass );
+ RepositoryMonitor monitor = (RepositoryMonitor) monitors[i];
+ monitor.establishedPluginClass( pluginClass );
}
}

@@ -99,15 +95,11 @@
*/
public void exceptionOccurred( String methodname, Exception e )
{
- if( m_monitors == null )
- {
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- RepositoryMonitor mon = (RepositoryMonitor) list.next();
- mon.exceptionOccurred( methodname, e );
+ RepositoryMonitor monitor = (RepositoryMonitor) monitors[i];
+ monitor.exceptionOccurred( methodname, e );
}
}

@@ -118,15 +110,11 @@
*/
public void pluginConstructorFound( Constructor constructor, Object[]
args )
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- RepositoryMonitor mon = (RepositoryMonitor) list.next();
- mon.pluginConstructorFound( constructor, args );
+ RepositoryMonitor monitor = (RepositoryMonitor) monitors[i];
+ monitor.pluginConstructorFound( constructor, args );
}
}

@@ -136,15 +124,11 @@
*/
public void pluginInstantiated( Object pluginInstance )
{
- if( m_monitors == null )
- {
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- RepositoryMonitor mon = (RepositoryMonitor) list.next();
- mon.pluginInstantiated( pluginInstance );
+ RepositoryMonitor monitor = (RepositoryMonitor) monitors[i];
+ monitor.pluginInstantiated( pluginInstance );
}
}

@@ -155,15 +139,11 @@
*/
public void classloaderConstructed( String type, ClassLoader classloader
)
{
- if( m_monitors == null )
+ Monitor[] monitors = getMonitors();
+ for( int i=0; i < monitors.length; i++ )
{
- return;
- }
- Iterator list = m_monitors.iterator();
- while( list.hasNext() )
- {
- RepositoryMonitor mon = (RepositoryMonitor) list.next();
- mon.classloaderConstructed( type, classloader );
+ RepositoryMonitor monitor = (RepositoryMonitor) monitors[i];
+ monitor.classloaderConstructed( type, classloader );
}
}

@@ -179,46 +159,10 @@
{
throw new IllegalArgumentException( "monitor must be
RepositoryMonitor type." );
}
- synchronized( this )
- {
- ArrayList list;
- if( m_monitors == null )
- {
- list = new ArrayList();
- }
- else
- {
- list = (ArrayList) m_monitors.clone();
- }
- list.add( monitor );
- m_monitors = list;
- }
- }
-
- /**
- * Remove a monitor from the set of monitors managed by this router.
- * @param monitor the monitor to remove
- */
- public void removeMonitor( Monitor monitor )
- {
- synchronized( this )
+ else
{
- if( m_monitors == null )
- {
- return;
- }
- ArrayList list = (ArrayList) m_monitors.clone();
- list.remove( monitor );
- if( list.size() == 0 )
- {
- m_monitors = null;
- }
- else
- {
- m_monitors = list;
- }
+ super.addMonitor( monitor );
}
}
-
}


Modified:
development/main/transit/handler/src/main/net/dpml/transit/monitors/Router.java
==============================================================================
---
development/main/transit/handler/src/main/net/dpml/transit/monitors/Router.java
(original)
+++
development/main/transit/handler/src/main/net/dpml/transit/monitors/Router.java
Tue Dec 14 17:53:53 2004
@@ -35,5 +35,6 @@
* @param monitor the monitor to remove
*/
void removeMonitor( Monitor monitor );
+
}




  • svn commit: r1179 - in development/main/transit/handler/src/main/net/dpml/transit: . adapter artifact monitors, mcconnell, 12/14/2004

Archive powered by MHonArc 2.6.24.

Top of Page