User: d_jencks
Date: 02/04/14 19:48:51
Modified: src/main/org/jboss/mx/loading UnifiedClassLoader.java
UnifiedLoaderRepository.java
Added: src/main/org/jboss/mx/loading
UnifiedLoaderRepositoryMBean.java
Log:
Changed to use UnifiedLoaderRepository and UnifiedClassLoader from jbossmx. Removed
ServiceLibraries, UnifiedClassLoader, and MBeanClassLoader from jboss-system
Revision Changes Path
1.3 +47 -6 jmx/src/main/org/jboss/mx/loading/UnifiedClassLoader.java
Index: UnifiedClassLoader.java
===================================================================
RCS file: /cvsroot/jboss/jmx/src/main/org/jboss/mx/loading/UnifiedClassLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- UnifiedClassLoader.java 17 Mar 2002 20:32:09 -0000 1.2
+++ UnifiedClassLoader.java 15 Apr 2002 02:48:51 -0000 1.3
@@ -9,14 +9,16 @@
package org.jboss.mx.loading;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.io.InputStream;
-import java.util.Map;
import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.Map;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
/**
* A ClassLoader which loads classes from a single URL in conjunction with
@@ -29,7 +31,7 @@
* @author <a href="[EMAIL PROTECTED]">Christoph G. Jung</a>
* @author <a href="[EMAIL PROTECTED]">Scott Stark</a>
* @author <a href="[EMAIL PROTECTED]">Juha Lindfors</a>
- * @version <tt>$Revision: 1.2 $</tt>
+ * @version <tt>$Revision: 1.3 $</tt>
*
* <p><b>20010830 marc fleury:</b>
* <ul>
@@ -76,7 +78,7 @@
super(new URL[] {url}, UnifiedClassLoader.class.getClassLoader());
// FIXME: log it
- System.out.println("New UCL with url " + url);
+ //System.out.println("New jmx UCL with url " + url);
this.url = url;
}
@@ -100,6 +102,25 @@
}
/**
+ * UnifiedClassLoader constructor that can be used to
+ * register with a particular Loader Repository identified by ObjectName.
+ *
+ * @param url an <code>URL</code> value
+ * @param server a <code>MBeanServer</code> value
+ * @param repositoryName an <code>ObjectName</code> value
+ * @exception Exception if an error occurs
+ */
+ public UnifiedClassLoader(final URL url, final MBeanServer server, final
ObjectName repositoryName) throws Exception
+ {
+ this(url);
+ this.repository = (UnifiedLoaderRepository)server.invoke(repositoryName,
+ "registerClassLoader",
+ new Object[] {this},
+ new String[] {getClass().getName()});
+ }
+
+
+ /**
* Constructs a <tt>UnifiedClassLoader</tt> with given class definition.
*
* @param names class name
@@ -114,6 +135,16 @@
// Public --------------------------------------------------------
+
+ public void unregister()
+ {
+ if (repository != null)
+ {
+ repository.removeClassLoader(this);
+ } // end of if ()
+ }
+
+
public void addClass(String name, byte[] code)
{
classes.put(name, code);
@@ -231,6 +262,16 @@
return (url2 == null) ? false : url2.equals(url);
}
return false;
+ }
+
+ /**
+ * Return all library URLs associated with this UnifiedClassLoader
+ *
+ * <p>Do not remove this method without running the WebIntegrationTestSuite
+ */
+ public URL[] getAllURLs()
+ {
+ return repository.getURLs();
}
/**
1.2 +143 -17 jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository.java
Index: UnifiedLoaderRepository.java
===================================================================
RCS file:
/cvsroot/jboss/jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepository.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- UnifiedLoaderRepository.java 17 Mar 2002 10:30:31 -0000 1.1
+++ UnifiedLoaderRepository.java 15 Apr 2002 02:48:51 -0000 1.2
@@ -7,16 +7,26 @@
package org.jboss.mx.loading;
-import java.util.Set;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.net.URL;
-import java.net.URLClassLoader;
import EDU.oswego.cs.dl.util.concurrent.ConcurrentReaderHashMap;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+import javax.management.ListenerNotFoundException;
+import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
+import javax.management.Notification;
+import javax.management.NotificationBroadcasterSupport;
+import javax.management.NotificationFilter;
+import javax.management.NotificationListener;
+import javax.management.ObjectName;
+import javax.management.NotificationBroadcaster;
/**
@@ -27,13 +37,15 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Marc Fleury</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Ole Husgaard</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Juha Lindfors</a>.
- * @version $Revision: 1.1 $
+ * @version $Revision: 1.2 $
+ * just a hint... xdoclet not really used
+ * @jmx.name="JMImplementation:service=UnifiedLoaderRepository,name=Default"
*
*/
public class UnifiedLoaderRepository
extends LoaderRepository
+ implements NotificationBroadcaster, UnifiedLoaderRepositoryMBean
{
-
// Attributes ----------------------------------------------------
/**
@@ -82,12 +94,26 @@
*/
private long clToResourceSetMapVersion = 0;
+ /**
+ * sequenceNumber is used to mumber notifications.
+ *
+ */
+ private long sequenceNumber = 0;
+
+ /**
+ * We delegate our notification sending to a support object.
+ *
+ */
+ private final NotificationBroadcasterSupport broadcaster = new
NotificationBroadcasterSupport();
+
+ private MBeanNotificationInfo[] info;
+
// Public --------------------------------------------------------
/**
* Add a class to this repository. Allows a class to be added in
* byte code form stored inside this repository.
- /**
+ /**
* Load a class in this repository.
*
* @param name The name of the class
@@ -284,8 +310,10 @@
}
/** Iterates through the current class loaders and tries to find the
- given class name.
- @return the Class object for name if found, null otherwise.
+ * given class name.
+ * @return the Class object for name if found, null otherwise.
+ *
+ * @jmx.managed-operation
*/
public Class findClass(String name)
{
@@ -364,6 +392,7 @@
throw new Error("NYI");
}
+
public void addClassLoader(ClassLoader loader)
{
// if you come to us as UCL we send you straight to the orbit
@@ -384,8 +413,12 @@
}
else
-// addNonDelegatingClassLoader(loader);
- throw new RuntimeException("ULR only allows UCL to be added");
+ {
+ // addNonDelegatingClassLoader(loader);
+ //throw new RuntimeException("ULR only allows UCL to be added");
+ System.out.println("Tried to add non- URLClassLoader. Ignored");
+ } // end of else
+
}
private synchronized void addUnifiedClassLoader(UnifiedClassLoader cl)
@@ -401,15 +434,23 @@
classLoaders.add(cl);
// FIXME: log it
- System.out.println("Libraries adding UnifiedClassLoader " + cl.hashCode()
+ " key URL " + cl.getURL());
+ //System.out.println("UnifiedLoaderRepository adding UnifiedClassLoader "
+ cl.hashCode() + " key URL " + cl.getURL());
}
else
{
// FIXME: log it
- System.out.println("Libraries skipping duplicate UnifiedClassLoader for
key URL " + cl.getURL());
+ System.out.println("UnifiedLoaderRepository skipping duplicate
UnifiedClassLoader for key URL " + cl.getURL());
}
}
+ /**
+ * The removeClassLoader method removes a classloader from the
+ * UnifiedLoaderRepository and sends notifications for each class removed.
+ *
+ * @param cl a <code>ClassLoader</code> value
+ *
+ * @jmx.managed-operation
+ */
public synchronized void removeClassLoader(ClassLoader cl)
{
if (!classLoaders.contains(cl))
@@ -425,7 +466,13 @@
++clToClassSetMapVersion;
Set clClasses = (Set)clToClassSetMap.remove(cl);
-
+
+ //Notify that classes are about to be removed
+ for (Iterator iter = clClasses.iterator(); iter.hasNext();)
+ {
+ broadcaster.sendNotification(new Notification(CLASS_REMOVED, this,
getSequenceNumber(), (String)iter.next()));
+ }
+
for (Iterator iter = clClasses.iterator(); iter.hasNext();)
{
Object o = iter.next();
@@ -450,6 +497,85 @@
// log.trace("removing resource " + o + ", removed: " + o1);
}
}
+ }
+
+
+ /**
+ * registerClassLoader provides an mbean-accessible way to add a
+ * UnifiedClassloader, and sends a notification when it is added.
+ *
+ * @param ucl an <code>UnifiedClassLoader</code> value
+ * @return a <code>LoaderRepository</code> value
+ *
+ * @jmx.managed-operation
+ */
+ public LoaderRepository registerClassLoader(UnifiedClassLoader ucl)
+ {
+ addClassLoader(ucl);
+ broadcaster.sendNotification(new Notification(CLASSLOADER_ADDED, this,
getSequenceNumber(), null));
+ return this;
+ }
+
+ /**
+ * @jmx.managed-operation
+ */
+ public UnifiedLoaderRepository getInstance()
+ {
+ return this;
+ }
+
+ // implementation of javax.management.NotificationBroadcaster interface
+
+ /**
+ * addNotificationListener delegates to the broadcaster object we hold.
+ *
+ * @param listener a <code>NotificationListener</code> value
+ * @param filter a <code>NotificationFilter</code> value
+ * @param handback an <code>Object</code> value
+ * @exception IllegalArgumentException if an error occurs
+ */
+ public void addNotificationListener(NotificationListener listener,
NotificationFilter filter, Object handback) throws IllegalArgumentException
+ {
+ broadcaster.addNotificationListener(listener, filter, handback);
+ }
+
+ /**
+ *
+ * @return <description>
+ */
+ public MBeanNotificationInfo[] getNotificationInfo()
+ {
+ if (info == null)
+ {
+ info = new MBeanNotificationInfo[] {
+ new MBeanNotificationInfo(new String[] {"CLASSLOADER_ADDED"},
+ "javax.management.Notification",
+ "Notification that a classloader has been added
to the extensible classloader"),
+ new MBeanNotificationInfo(new String[] {"CLASS_REMOVED"},
+ "javax.management.Notification",
+ "Notification that a class has been removed from
the extensible classloader")
+
+ };
+ }
+ return info;
+ }
+
+ /**
+ * removeNotificationListener delegates to our broadcaster object
+ *
+ * @param listener a <code>NotificationListener</code> value
+ * @exception ListenerNotFoundException if an error occurs
+ */
+ public void removeNotificationListener(NotificationListener listener) throws
ListenerNotFoundException
+ {
+ broadcaster.removeNotificationListener(listener);
+ }
+
+
+
+ private synchronized long getSequenceNumber()
+ {
+ return sequenceNumber++;
}
}
1.1
jmx/src/main/org/jboss/mx/loading/UnifiedLoaderRepositoryMBean.java
Index: UnifiedLoaderRepositoryMBean.java
===================================================================
/*
* JBoss, the OpenSource J2EE webOS
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*
*/
package org.jboss.mx.loading;
import java.net.URL;
/**
* UnifiedLoaderRepositoryMBean.java
*
*
* Created: Sun Apr 14 13:04:04 2002
*
* @author <a href="mailto:[EMAIL PROTECTED]">David Jencks</a>
* @version
*/
public interface UnifiedLoaderRepositoryMBean
{
void removeClassLoader(ClassLoader cl);
LoaderRepository registerClassLoader(UnifiedClassLoader ucl);
UnifiedLoaderRepository getInstance();
URL[] getURLs();
Class findClass(String className);
}// UnifiedLoaderRepositoryMBean
_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development