コード例 #1
0
ファイル: Utils.java プロジェクト: juzipeek/MyReadingCode
 /** Try to convert a string value into a numerical value. */
 private static Number createNumberFromStringValue(String value) throws NumberFormatException {
   final String suffix = value.substring(value.length() - 1);
   if ("L".equalsIgnoreCase(suffix)) {
     return Long.valueOf(value.substring(0, value.length() - 1));
   }
   if ("F".equalsIgnoreCase(suffix)) {
     return Float.valueOf(value.substring(0, value.length() - 1));
   }
   if ("D".equalsIgnoreCase(suffix)) {
     return Double.valueOf(value.substring(0, value.length() - 1));
   }
   try {
     return Integer.valueOf(value);
   } catch (NumberFormatException e) {
     // OK: Ignore exception...
   }
   try {
     return Long.valueOf(value);
   } catch (NumberFormatException e1) {
     // OK: Ignore exception...
   }
   try {
     return Double.valueOf(value);
   } catch (NumberFormatException e2) {
     // OK: Ignore exception...
   }
   throw new NumberFormatException(
       "Cannot convert string value '" + value + "' into a numerical value");
 }
コード例 #2
0
  @Diagnostic(name = "Queue Size")
  public DiagnosticsResult queueSizes() throws JMSException, MalformedURLException {
    List<String> queueNameList = queueNamesList(diagnosticConfiguration.activeMqQueueNames());

    if (!queueNameList.isEmpty() && activeMQDiagnosticsClientConnector == null) {
      return new DiagnosticsResult(
          "ActiveMQ Queue Sizes", "activeMQDiagnosticsClientConnector bean not defined", Warn);
    }

    if (queueNameList.isEmpty()) {
      return new DiagnosticsResult(
          "ActiveMQ Queue Sizes", "No activeMQ.queueNames specified.", Warn);
    }

    List<DiagnosticsResult> results = new ArrayList<>();
    for (String queueName : queueNameList) {
      try {
        ObjectName objectNameRequest =
            new ObjectName(
                "org.apache.activemq:BrokerName=localhost,Type=Queue,Destination=" + queueName);
        Long queueSize =
            (Long)
                activeMQDiagnosticsClientConnector
                    .getObject()
                    .getAttribute(objectNameRequest, "QueueSize");
        if (queueSize == null) {
          results.add(new DiagnosticsResult("Queue Size for " + queueName, "Not Found!", Fail));
        } else {
          results.add(
              new DiagnosticsResult("Queue Size for " + queueName, queueSize.toString(), Success));
        }
      } catch (Exception e) {
        return new DiagnosticsResult(queueName, "Error occurred while connecting", Fail);
      }
    }
    return new DiagnosticsResult("ActiveMQ Queue Sizes", results);
  }