[Mc4j-cvs] SF.net SVN: mc4j: [585] trunk/mc4j/modules/ems
                
                Brought to you by:
                
                    ghinkl
                    
                
            
            
        
        
        
    | 
      
      
      From: <gh...@us...> - 2007-08-31 17:32:06
      
     | 
| Revision: 585
          http://mc4j.svn.sourceforge.net/mc4j/?rev=585&view=rev
Author:   ghinkl
Date:     2007-08-31 10:32:02 -0700 (Fri, 31 Aug 2007)
Log Message:
-----------
Custom temp directory
Internal search for mbeanserver by default domain
Modified Paths:
--------------
    trunk/mc4j/modules/ems/build.xml
    trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/ConnectionFactory.java
    trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/settings/ConnectionSettings.java
    trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/classloader/ClassLoaderFactory.java
    trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/metadata/InternalVMTypeDescriptor.java
    trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/metadata/JBossConnectionTypeDescriptor.java
    trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/InternalVMProvider.java
Modified: trunk/mc4j/modules/ems/build.xml
===================================================================
--- trunk/mc4j/modules/ems/build.xml	2007-07-06 01:43:58 UTC (rev 584)
+++ trunk/mc4j/modules/ems/build.xml	2007-08-31 17:32:02 UTC (rev 585)
@@ -30,7 +30,7 @@
 
     <property name="module.jar" value="org-mc4j-ems.jar"/>
 
-    <property name="release.version" value="1.1.7"/>
+    <property name="release.version" value="1.2.0"/>
 
 
     <target
Modified: trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/ConnectionFactory.java
===================================================================
--- trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/ConnectionFactory.java	2007-07-06 01:43:58 UTC (rev 584)
+++ trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/ConnectionFactory.java	2007-08-31 17:32:02 UTC (rev 585)
@@ -59,7 +59,9 @@
 
     public static final String COPY_JARS_TO_TEMP = "mc4j.ems.CopyJarsToTemp";
 
+    public static final String JAR_TEMP_DIR = "mc4j.ems.JarTempDir";
 
+
     private boolean broadSearch = false;
     private int searchDepth = DEFAULT_SEARCH_DEPTH;
 
Modified: trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/settings/ConnectionSettings.java
===================================================================
--- trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/settings/ConnectionSettings.java	2007-07-06 01:43:58 UTC (rev 584)
+++ trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/settings/ConnectionSettings.java	2007-08-31 17:32:02 UTC (rev 585)
@@ -44,7 +44,7 @@
     private String principal;
     private String credentials;
 
-    private Properties advancedProperties;
+    private Properties advancedProperties = new Properties();
 
     private Properties controlProperties = new Properties();
 
Modified: trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/classloader/ClassLoaderFactory.java
===================================================================
--- trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/classloader/ClassLoaderFactory.java	2007-07-06 01:43:58 UTC (rev 584)
+++ trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/classloader/ClassLoaderFactory.java	2007-08-31 17:32:02 UTC (rev 585)
@@ -83,7 +83,7 @@
      * TODO GH: Implement a special classloader that can load classes from
      * within a jar inside another jar or perhaps just ship the impl jar separately...
      */
-    protected URL storeImplToTemp(String archiveResource) {
+    protected URL storeImplToTemp(String archiveResource, File tempDir) {
         try {
 
             if (jarCache.containsKey(archiveResource)) {
@@ -98,7 +98,7 @@
 
             // String tmpPath = System.getProperty("java.io.tmpdir");
 
-            File tmpFile = copyFileToTemp(archiveResource, is);
+            File tmpFile = copyFileToTemp(archiveResource, is, tempDir);
 
             jarCache.put(archiveResource, tmpFile);
 
@@ -111,11 +111,11 @@
         }
     }
 
-    private File copyFileToTemp(String archiveResource, InputStream is) throws IOException {
+    private File copyFileToTemp(String archiveResource, InputStream is, File directory) throws IOException {
         String jarName = new File(archiveResource).getName();
         jarName = jarName.substring(0, jarName.length() - 4);
 
-        File tmpFile = File.createTempFile(jarName, ".jar");
+        File tmpFile = File.createTempFile(jarName, ".jar", directory);
         tmpFile.deleteOnExit();
 
         log.trace("Copying jar [" + archiveResource + "] to temporary file [" + tmpFile.getAbsolutePath() + "]");
@@ -151,12 +151,12 @@
 */
 
 
-    public URL getCachedTempForFile(File file) throws MalformedURLException {
+    public URL getCachedTempForFile(File file, File directory) throws MalformedURLException {
         try {
             FileKey key = new FileKey(file);
             File result = tempJarCache.get(key);
             if (result == null) {
-                result = copyFileToTemp(file.getName(), new FileInputStream(file));
+                result = copyFileToTemp(file.getName(), new FileInputStream(file), directory);
                 tempJarCache.put(key, result);
             }
             return result.toURI().toURL();
@@ -175,15 +175,20 @@
 
 
     public ClassLoader buildClassLoader(ConnectionSettings settings) {
-        // TODO GH: Implement configurable system to point at jar instead of creating temporary version
 
+        String tempDirString = (String) settings.getControlProperties().get(ConnectionFactory.JAR_TEMP_DIR);
+        File tempDir = null;
+        if (tempDirString != null) {
+            tempDir = new File(tempDirString);
+        }
+
         List<URL> entries = new ArrayList<URL>();
 
         if (settings.getClassPathEntries() != null) {
             for (File file : settings.getClassPathEntries()) {
                 try {
                     if (Boolean.valueOf(settings.getControlProperties().getProperty(ConnectionFactory.COPY_JARS_TO_TEMP, "false"))) {
-                        entries.add(getCachedTempForFile(file));
+                        entries.add(getCachedTempForFile(file,tempDir));
                     } else {
                         entries.add(file.toURI().toURL());
                     }
@@ -193,9 +198,10 @@
             }
         }
 
+
         // Now load in the implementation jar
         // URL implURL = new URL(null, "deepjar://org-mc4j-ems-impl.jar", new Handler());
-        URL implURL = storeImplToTemp("org-mc4j-ems-impl.jar");
+        URL implURL = storeImplToTemp("org-mc4j-ems-impl.jar", tempDir);
 
         entries.add(implURL);
 
@@ -228,8 +234,8 @@
         if ((settings.getConnectionType() instanceof JSR160ConnectionTypeDescriptor) &&
             settings.getConnectionType().getConnectionClasspathEntries() == null &&
             Double.parseDouble(System.getProperty("java.version").substring(0, 3)) < 1.5) {
-            entries.add(storeImplToTemp("lib/jsr160-includes/mx4j.jar"));
-            entries.add(storeImplToTemp("lib/jsr160-includes/mx4j-remote.jar"));
+            entries.add(storeImplToTemp("lib/jsr160-includes/mx4j.jar", tempDir));
+            entries.add(storeImplToTemp("lib/jsr160-includes/mx4j-remote.jar", tempDir));
         }
 
         // TODO: Check if file exists, log warning if not
Modified: trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/metadata/InternalVMTypeDescriptor.java
===================================================================
--- trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/metadata/InternalVMTypeDescriptor.java	2007-07-06 01:43:58 UTC (rev 584)
+++ trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/metadata/InternalVMTypeDescriptor.java	2007-08-31 17:32:02 UTC (rev 585)
@@ -18,6 +18,8 @@
 
 public class InternalVMTypeDescriptor extends J2SE5ConnectionTypeDescriptor {
 
+    public static final String DEFAULT_DOMAIN_SEARCH = "mc4j.ems.DefaultDomainSearch";
+    
     public boolean isMEJBCompliant() {
         return false;
     }
Modified: trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/metadata/JBossConnectionTypeDescriptor.java
===================================================================
--- trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/metadata/JBossConnectionTypeDescriptor.java	2007-07-06 01:43:58 UTC (rev 584)
+++ trunk/mc4j/modules/ems/src/ems/org/mc4j/ems/connection/support/metadata/JBossConnectionTypeDescriptor.java	2007-08-31 17:32:02 UTC (rev 585)
@@ -88,7 +88,7 @@
             "lib/jboss-system.jar",
             "client/jbossall-client.jar",
             "client/log4j.jar",
-            "*/*/lib/jboss.jar",    
+            "*/*/lib/jboss.jar",
             "client/concurrent.jar",
             "client/jboss-jsr77-client.jar",
             // 3.2.3 jars
Modified: trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/InternalVMProvider.java
===================================================================
--- trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/InternalVMProvider.java	2007-07-06 01:43:58 UTC (rev 584)
+++ trunk/mc4j/modules/ems/src/ems-impl/org/mc4j/ems/impl/jmx/connection/support/providers/InternalVMProvider.java	2007-08-31 17:32:02 UTC (rev 585)
@@ -16,9 +16,11 @@
 
 package org.mc4j.ems.impl.jmx.connection.support.providers;
 
-import java.lang.management.ManagementFactory;
+import org.mc4j.ems.connection.support.metadata.InternalVMTypeDescriptor;
 
 import javax.management.MBeanServer;
+import javax.management.MBeanServerFactory;
+import java.lang.management.ManagementFactory;
 
 /**
  * Connect to the platform mbean server in the VM that EMS is running in.
@@ -30,8 +32,6 @@
 
    protected MBeanServer server;
 
-
-
    public MBeanServer getMBeanServer()
    {
       return this.server;
@@ -39,6 +39,25 @@
 
    protected void doConnect() throws Exception
    {
-      this.server = ManagementFactory.getPlatformMBeanServer();
+      String mbeanSearch =
+          (String) getConnectionSettings().getAdvancedProperties().get(
+              InternalVMTypeDescriptor.DEFAULT_DOMAIN_SEARCH);
+      MBeanServer foundServer = null;
+      if (mbeanSearch != null)
+      {
+          for (Object mbs : MBeanServerFactory.findMBeanServer(null))
+          {
+              if (mbeanSearch.equals(((MBeanServer)mbs).getDefaultDomain()))
+              {
+                  foundServer = (MBeanServer) mbs;
+              }
+          }
+      }
+
+      if (foundServer == null)
+      {
+          foundServer = ManagementFactory.getPlatformMBeanServer();
+      }
+      this.server = foundServer;
    }
 }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |