public static void fixAsEJB(ILaunchConfiguration config) {
    try {
      LaunchConfigurationInfo info =
          (LaunchConfigurationInfo) BeanUtils.invokeMethod(config, "getInfo");
      Map map = (Map) BeanUtils.getFieldValue(info, "fAttributes");

      String projectName = (String) map.get(ATTR_PROJECT_NAME);
      IJavaModel jModel = JavaCore.create(ResourcesPlugin.getWorkspace().getRoot());
      IJavaProject jp = jModel.getJavaProject(projectName);
      Assert.notNull(jp);

      File root = jp.getProject().getLocation().toFile();
      map.put("org.eclipse.jdt.launching.MAIN_TYPE", "jef.database.JefClassLoader");

      String arg = (String) map.get(ATTR_PROGRAM_ARGUMENTS);
      if (arg == null) {
        File openEjbFolder = findOpenEjbFolder();
        String projectPath = root.getAbsolutePath();
        String openEjbPath = openEjbFolder.getAbsolutePath();
        map.put(
            ATTR_PROGRAM_ARGUMENTS,
            "jef.ejb.server.OpenejbServer " + projectPath + " " + openEjbPath);
      }

    } catch (ReflectionException e) {
      e.printStackTrace();
    }
  }
 public static void fixAsWeb(ILaunchConfiguration config, IJavaProject jp) {
   try {
     LaunchConfigurationInfo info =
         (LaunchConfigurationInfo) BeanUtils.invokeMethod(config, "getInfo");
     Map map = (Map) BeanUtils.getFieldValue(info, "fAttributes");
     String projectName = (String) map.get(ATTR_PROJECT_NAME);
     List<String> l = (List<String>) map.get(ATTR_CLASSPATH);
     Object obj = map.get(ATTR_CLASSPATH);
     if (obj != null) {
       Object[] exists = null;
       if (obj.getClass().isArray()) {
         exists = (Object[]) obj;
       } else if (obj instanceof Collection) {
         exists = ((Collection) obj).toArray();
       }
       IClasspathEntry[] toAdd = getWebEntries();
       boolean flag1 = false, flag2 = false;
       for (Object o : exists) {
         String s = o.toString();
         if (s.indexOf("JEF_HOME/jef-jasper.jar") > -1) {
           flag1 = true;
         } else if (s.indexOf("JEF_HOME/jef-jetty-731.jar") > -1) {
           flag2 = true;
         }
       }
       if (!flag1 || !flag2) {
         map.put(
             ATTR_CLASSPATH,
             appendLaunchClasspath(l, projectName, config, toAdd, jp, 0)); // 指定添加类路径
       }
     } else {
       map.put(
           ATTR_CLASSPATH,
           appendLaunchClasspath(l, projectName, config, getWebEntries(), jp, 0)); // 指定添加类路径
     }
     map.put(ATTR_DEFAULT_CLASSPATH, false); // 指定不采用缺省类路径
     //			IFile f = jp.getProject().getFile("pom.xml");
     File root = jp.getProject().getLocation().toFile();
     String arg = (String) map.get(ATTR_PROGRAM_ARGUMENTS);
     map.put(ATTR_MAIN_TYPE_NAME, "jef.database.JefClassLoader");
     if (arg == null) {
       map.put(
           ATTR_PROGRAM_ARGUMENTS,
           "jef.http.server.JettyConsole -j \""
               + root.getAbsolutePath()
               + "\""
               + " -n "
               + jp.getElementName());
     } else if (arg.startsWith("jef.http.server.JettyConsole ")) {
     } else {
       map.put(
           ATTR_PROGRAM_ARGUMENTS,
           "jef.http.server.JettyConsole -j \"" + root.getAbsolutePath() + "\"" + arg);
     }
   } catch (ReflectionException e) {
     e.printStackTrace();
   }
 }
Example #3
0
  static String getJobGraph(ObjectName jobObjName) {
    Set<ObjectInstance> jobInstances = mBeanServer.queryMBeans(jobObjName, null);
    Iterator<ObjectInstance> jobIterator = jobInstances.iterator();
    ObjectInstance jobInstance = null;

    if (jobIterator.hasNext()) {
      jobInstance = jobIterator.next();
    }
    String gSnapshot = "";
    if (jobInstance != null) {
      ObjectName jobObjectName = jobInstance.getObjectName();
      MBeanInfo mBeanInfo = null;
      try {
        mBeanInfo = mBeanServer.getMBeanInfo(jobObjectName);
      } catch (IntrospectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (InstanceNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ReflectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
      /*
       * Now get the graph for the job
       */
      Set<String> operations = new HashSet<String>();
      for (MBeanOperationInfo operationInfo : mBeanInfo.getOperations()) {
        operations.add(operationInfo.getName());
        if (operationInfo.getName().equals("graphSnapshot")) {
          try {
            gSnapshot = (String) mBeanServer.invoke(jobObjectName, "graphSnapshot", null, null);
            // System.out.println(gSnapshot);
          } catch (InstanceNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (ReflectionException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          } catch (MBeanException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
        }
      }
    }
    return gSnapshot;
  }
  private void poolingSystemProperties() {
    try {
      ObjectName name = new ObjectName(ManagementFactory.OPERATING_SYSTEM_MXBEAN_NAME);

      while (true) {

        try {
          Thread.sleep(interval);
        } catch (InterruptedException e) {
        }

        Object systemLoad = mbeanServer.getAttribute(name, SYSTEM_LOAD);
        Long freePhysicalMemory = (Long) mbeanServer.getAttribute(name, FREE_PHYSICAL_MEM);
        Long freeSwapMemory = (Long) mbeanServer.getAttribute(name, FREE_SWAP_MEM);
        Long sharedMemory = (Long) mbeanServer.getAttribute(name, SHARED_MEM);

        Long totalSwapMemory = (Long) mbeanServer.getAttribute(name, TOTAL_SWAP_MEM);
        Long totalPhysicalMemory = (Long) mbeanServer.getAttribute(name, TOTAL_PHYSICAL_MEM);

        Double percentSwap = (double) ((freeSwapMemory * 100) / totalSwapMemory);
        Double percentPhysical = (double) ((freePhysicalMemory * 100 / totalPhysicalMemory));
        Long sharedMbyteMemory = sharedMemory / 1000000;

        Map<String, Object> status = new HashMap<String, Object>();

        status.put(SYSTEM_LOAD, systemLoad);
        status.put(FREE_PHYSICAL_MEM, percentPhysical);
        status.put(FREE_SWAP_MEM, percentSwap);
        status.put(SHARED_MEM, Double.parseDouble(sharedMbyteMemory.toString()));

        this.sendNotification(RESOURCE_STATUS_TYPE, status);
      }

    } catch (MalformedObjectNameException e) {
      e.printStackTrace();
    } catch (NullPointerException e) {
      e.printStackTrace();
    } catch (AttributeNotFoundException e) {
      e.printStackTrace();
    } catch (InstanceNotFoundException e) {
      e.printStackTrace();
    } catch (MBeanException e) {
      e.printStackTrace();
    } catch (ReflectionException e) {
      e.printStackTrace();
    }
  }
 public static void fix(ILaunchConfiguration configuration) {
   try {
     LaunchConfigurationInfo info =
         (LaunchConfigurationInfo) BeanUtils.invokeMethod(configuration, "getInfo");
     Map map = (Map) BeanUtils.getFieldValue(info, "fAttributes");
     String className = (String) map.get(ATTR_MAIN_TYPE_NAME);
     if (!className.equals("jef.database.JefClassLoader")) {
       map.put(ATTR_MAIN_TYPE_NAME, "jef.database.JefClassLoader");
       String args = (String) map.get(ATTR_PROGRAM_ARGUMENTS);
       if (args == null) {
         map.put(ATTR_PROGRAM_ARGUMENTS, className);
       } else {
         map.put(ATTR_PROGRAM_ARGUMENTS, StringUtils.join(new String[] {className, args}, " "));
       }
     }
   } catch (ReflectionException e) {
     e.printStackTrace();
   }
 }
Example #6
0
  private void doWaitForSpringApplication(MBeanServerConnection connection)
      throws IOException, MojoExecutionException, MojoFailureException {
    final SpringApplicationAdminClient client =
        new SpringApplicationAdminClient(connection, this.jmxName);
    try {
      execute(
          this.wait,
          this.maxAttempts,
          new Callable<Boolean>() {

            @Override
            public Boolean call() throws Exception {
              return (client.isReady() ? true : null);
            }
          });
    } catch (ReflectionException ex) {
      throw new MojoExecutionException("Unable to retrieve 'ready' attribute", ex.getCause());
    } catch (Exception ex) {
      throw new MojoFailureException("Could not invoke shutdown operation", ex);
    }
  }
Example #7
0
 /**
  * Registers a logger to the management server.
  *
  * @param logger A logger to be registered for management.
  */
 public static synchronized void register(Logger logger) {
   try {
     ManagementFactory.getPlatformMBeanServer()
         .createMBean(
             "com.hapiware.jmx.log4j.Logging",
             new ObjectName(LOGGING_NAME),
             new Object[] {logger.getLoggerRepository()},
             new String[] {"org.apache.log4j.spi.LoggerRepository"});
   } catch (MBeanException e) {
     e.printStackTrace();
   } catch (InstanceAlreadyExistsException e) {
     e.printStackTrace();
   } catch (NotCompliantMBeanException e) {
     e.printStackTrace();
   } catch (MalformedObjectNameException e) {
     e.printStackTrace();
   } catch (ReflectionException e) {
     e.printStackTrace();
   } catch (NullPointerException e) {
     e.printStackTrace();
   }
 }
  public void runJmx() throws IOException {

    propEnv.put(JMXConnector.CREDENTIALS, credentials);

    try {

      serviceURL = new JMXServiceURL(urlString);
      jmxConnector = JMXConnectorFactory.connect(serviceURL, propEnv);
      MBeanServerConnection connection = jmxConnector.getMBeanServerConnection();
      ObjectName objectName = new ObjectName("jboss.as:management-root=server");
      String serverState = (String) connection.getAttribute(objectName, "serverState");
      System.out.println("server Status is:= " + serverState);

    } catch (MalformedURLException e) {

      e.printStackTrace();
    } catch (MalformedObjectNameException e) {

      e.printStackTrace();
    } catch (IOException e) {

      e.printStackTrace();
    } catch (AttributeNotFoundException e) {

      e.printStackTrace();
    } catch (InstanceNotFoundException e) {

      e.printStackTrace();
    } catch (MBeanException e) {

      e.printStackTrace();
    } catch (ReflectionException e) {

      e.printStackTrace();
    } finally {
      jmxConnector.close();
    }
  }
  public static PRTGInterface getAndRegisterBean(String beanname) {
    // Find an agent from this JVM. Null argument will return
    // a list of all MBeanServer instances.
    MBeanServer server = ManagementFactory.getPlatformMBeanServer();

    ObjectName name = getJMXObjectName(getObjectName(beanname));
    PRTGInterface retVal = getBean(beanname);
    try {
      if (server.isRegistered(name)) {
        server.unregisterMBean(name);
      }
      // register the MBean
      server.registerMBean(retVal, name);

      // Invoke the printInfo operation on an
      // uninitialized MBean instance.
      Object result =
          server.invoke(
              name, // MBean name
              "printInfo", // operation name
              null, // no parameters
              null // void signature
              );
    } catch (InstanceNotFoundException e) {
      e.printStackTrace();
    } catch (MBeanException e) {
      e.getTargetException().printStackTrace();
    } catch (ReflectionException e) {
      e.printStackTrace();
    } catch (InstanceAlreadyExistsException e) {
      e.printStackTrace();
    } catch (NotCompliantMBeanException e) {
      e.printStackTrace();
    }
    return retVal;
  }
Example #10
0
  private void tryConnect(boolean requireRemoteSSL) throws IOException {
    if (jmxUrl == null && "localhost".equals(hostName) && port == 0) {
      // Monitor self
      this.jmxc = null;
      this.mbsc = ManagementFactory.getPlatformMBeanServer();
      this.server = Snapshot.newSnapshot(mbsc);
    } else {
      // Monitor another process
      if (lvm != null) {
        if (!lvm.isManageable()) {
          lvm.startManagementAgent();
          if (!lvm.isManageable()) {
            // FIXME: what to throw
            throw new IOException(lvm + "not manageable");
          }
        }
        if (this.jmxUrl == null) {
          this.jmxUrl = new JMXServiceURL(lvm.connectorAddress());
        }
      }
      Map<String, Object> env = new HashMap<String, Object>();
      if (requireRemoteSSL) {
        env.put("jmx.remote.x.check.stub", "true");
      }
      // Need to pass in credentials ?
      if (userName == null && password == null) {
        if (isVmConnector()) {
          // Check for SSL config on reconnection only
          if (stub == null) {
            checkSslConfig();
          }
          this.jmxc = new RMIConnector(stub, null);
          jmxc.connect(env);
        } else {
          this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
        }
      } else {
        env.put(JMXConnector.CREDENTIALS, new String[] {userName, password});
        if (isVmConnector()) {
          // Check for SSL config on reconnection only
          if (stub == null) {
            checkSslConfig();
          }
          this.jmxc = new RMIConnector(stub, null);
          jmxc.connect(env);
        } else {
          this.jmxc = JMXConnectorFactory.connect(jmxUrl, env);
        }
      }
      this.mbsc = jmxc.getMBeanServerConnection();
      this.server = Snapshot.newSnapshot(mbsc);
    }
    this.isDead = false;

    try {
      ObjectName on = new ObjectName(THREAD_MXBEAN_NAME);
      this.hasPlatformMXBeans = server.isRegistered(on);
      this.hasHotSpotDiagnosticMXBean =
          server.isRegistered(new ObjectName(HOTSPOT_DIAGNOSTIC_MXBEAN_NAME));
      // check if it has 6.0 new APIs
      if (this.hasPlatformMXBeans) {
        MBeanOperationInfo[] mopis = server.getMBeanInfo(on).getOperations();
        // look for findDeadlockedThreads operations;
        for (MBeanOperationInfo op : mopis) {
          if (op.getName().equals("findDeadlockedThreads")) {
            this.supportsLockUsage = true;
            break;
          }
        }

        on = new ObjectName(COMPILATION_MXBEAN_NAME);
        this.hasCompilationMXBean = server.isRegistered(on);
      }
    } catch (MalformedObjectNameException e) {
      // should not reach here
      throw new InternalError(e.getMessage());
    } catch (IntrospectionException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    } catch (InstanceNotFoundException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    } catch (ReflectionException e) {
      InternalError ie = new InternalError(e.getMessage());
      ie.initCause(e);
      throw ie;
    }

    if (hasPlatformMXBeans) {
      // WORKAROUND for bug 5056632
      // Check if the access role is correct by getting a RuntimeMXBean
      getRuntimeMXBean();
    }
  }
Example #11
0
  static String getJobsInfo(ObjectName jobObjName) {
    Set<ObjectInstance> jobInstances = mBeanServer.queryMBeans(jobObjName, null);

    Iterator<ObjectInstance> jobIterator = jobInstances.iterator();
    StringBuffer json = new StringBuffer("[");
    int counter = 0;
    while (jobIterator.hasNext()) {
      if (counter > 0) {
        json.append(",");
      }
      ObjectInstance jobInstance = jobIterator.next();
      ObjectName jobObjectName = jobInstance.getObjectName();
      MBeanInfo mBeanInfo = null;
      try {
        mBeanInfo = mBeanServer.getMBeanInfo(jobObjectName);
      } catch (IntrospectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (InstanceNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } catch (ReflectionException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }

      /*
       * Get the names of all the attributes
       */

      Set<String> names = new HashSet<String>();
      for (MBeanAttributeInfo attributeInfo : mBeanInfo.getAttributes()) {
        names.add(attributeInfo.getName());
      }
      // now construct the job json and add it to the string buffer
      StringBuffer s = new StringBuffer();
      s.append("{\"");
      Iterator<String> it = names.iterator();
      while (it.hasNext()) {
        String attr = it.next();
        s.append(attr);
        s.append("\":\"");
        try {
          s.append((String) mBeanServer.getAttribute(jobObjectName, attr));
        } catch (AttributeNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (InstanceNotFoundException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (MBeanException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (ReflectionException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
        s.append("\",\"");
      }
      // remove the trailing ,\
      s.deleteCharAt(s.length() - 1);
      s.deleteCharAt(s.length() - 1);
      json.append(s.toString() + "}");
      counter++;
    }
    json.append("]");
    String jsonString = json.toString();

    return jsonString;
  }
 private void renderEndPoints(
     String appRoot, IApplianceConfiguration config, IEndPoint[] endPoints, PrintWriter pw) {
   for (int i = 0; i < endPoints.length; i++) {
     IEndPoint endPoint = endPoints[i];
     IAppliance appliance = endPoint.getAppliance();
     String appliancePid = appliance.getPid();
     Integer endPointId = new Integer(endPoint.getId());
     boolean isAvailable = appliance.isAvailable();
     if (isAvailable) pw.println("<b>");
     else pw.println("<b><font color=\"gray\">");
     String name = null;
     ICategory category = null;
     ILocation location = null;
     if (config != null) {
       name = config.getName(endPointId);
       category = appliancesProxy.getCategory(config.getCategoryPid(endPointId));
       location = appliancesProxy.getLocation(config.getLocationPid(endPointId));
     }
     pw.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ENDPOINT");
     if (!appliance.isSingleton())
       pw.println(
           "&nbsp;(<a href=\""
               + appRoot
               + "/"
               + LABEL
               + "/config/"
               + appliancePid
               + "/"
               + endPointId
               + "\">Configuration</a>)");
     pw.println(
         "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ID: "
             + endPoint.getId()
             + "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;TYPE: "
             + endPoint.getType()
             + ((name != null) ? "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Name: " + name : "")
             + ((category != null)
                 ? "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Category: " + category.getName()
                 : "")
             + ((location != null)
                 ? "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Location: " + location.getName()
                 : ""));
     if (isAvailable)
       pw.println(
           "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
               + (endPointId > 0 ? "Clusters:" : "")
               + "</b><br/>");
     else
       pw.println(
           "<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"
               + (endPointId > 0 ? "Clusters:" : "")
               + "</b></font><br/>");
     try {
       IServiceCluster[] clusterArray = endPoint.getServiceClusters(IServiceCluster.SERVER_SIDE);
       if (clusterArray != null && clusterArray.length > 0) {
         renderClusterList(appRoot, appliancePid, endPointId, clusterArray, pw);
       }
       clusterArray = endPoint.getServiceClusters(IServiceCluster.CLIENT_SIDE);
       if (clusterArray != null && clusterArray.length > 0) {
         renderClusterList(appRoot, appliancePid, endPointId, clusterArray, pw);
       }
       String[] clusterNames = endPoint.getAdditionalClusterNames();
       if (clusterNames != null && clusterNames.length > 0) {
         renderClusterList(appRoot, appliancePid, endPoint, clusterNames, pw);
       }
       pw.println("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br/>");
     } catch (InstanceNotFoundException e) {
       e.printStackTrace();
     } catch (IntrospectionException e) {
       e.printStackTrace();
     } catch (ReflectionException e) {
       e.printStackTrace();
     }
   }
 }