示例#1
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;
  }
  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();
   }
 }
  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();
   }
 }
示例#6
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;
  }
示例#9
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;
  }
示例#10
0
 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();
     }
   }
 }