Exemplo n.º 1
0
 public static void testParseSemicolonDelimitedString() {
   String input = "one;two ; three; four ; five;six";
   List list = Util.parseStringList(input, ";");
   System.out.println("list: " + list);
   Assert.assertEquals(6, list.size());
   Assert.assertEquals("one", list.get(0));
   Assert.assertEquals("six", list.get(list.size() - 1));
 }
Exemplo n.º 2
0
 public static void testParseSemicolonDelimitedString2() {
   String input = "  myID1::subID1 ; myID2::mySubID2; myID3 ;myID4::blaSubID4";
   List list = Util.parseStringList(input, ";");
   System.out.println("list: " + list);
   Assert.assertEquals(4, list.size());
   Assert.assertEquals("myID1::subID1", list.get(0));
   Assert.assertEquals("myID4::blaSubID4", list.get(list.size() - 1));
 }
Exemplo n.º 3
0
    protected void handleJmx(Map<String, String> map, String input) {
      Map<String, Object> tmp_stats;
      int index = input.indexOf("=");
      if (index > -1) {
        List<String> list = null;
        String protocol_name = input.substring(index + 1);
        index = protocol_name.indexOf(".");
        if (index > -1) {
          String rest = protocol_name;
          protocol_name = protocol_name.substring(0, index);
          String attrs = rest.substring(index + 1); // e.g. "num_sent,msgs,num_received_msgs"
          list = Util.parseStringList(attrs, ",");

          // check if there are any attribute-sets in the list
          for (Iterator<String> it = list.iterator(); it.hasNext(); ) {
            String tmp = it.next();
            index = tmp.indexOf("=");
            if (index != -1) {
              String attrname = tmp.substring(0, index);
              String attrvalue = tmp.substring(index + 1);
              Protocol prot = prot_stack.findProtocol(protocol_name);
              Field field = prot != null ? Util.getField(prot.getClass(), attrname) : null;
              if (field != null) {
                Object value = MethodCall.convert(attrvalue, field.getType());
                if (value != null) prot.setValue(attrname, value);
              } else {
                // try to find a setter for X, e.g. x(type-of-x) or setX(type-of-x)
                ResourceDMBean.Accessor setter =
                    ResourceDMBean.findSetter(
                        prot, attrname); // Util.getSetter(prot.getClass(), attrname);
                if (setter != null) {
                  try {
                    Class<?> type =
                        setter instanceof ResourceDMBean.FieldAccessor
                            ? ((ResourceDMBean.FieldAccessor) setter).getField().getType()
                            : setter instanceof ResourceDMBean.MethodAccessor
                                ? ((ResourceDMBean.MethodAccessor) setter)
                                    .getMethod()
                                    .getParameterTypes()[0]
                                    .getClass()
                                : null;
                    Object converted_value = MethodCall.convert(attrvalue, type);
                    setter.invoke(converted_value);
                  } catch (Exception e) {
                    log.error("unable to invoke %s() on %s: %s", setter, protocol_name, e);
                  }
                } else log.warn(Util.getMessage("FieldNotFound"), attrname, protocol_name);
              }

              it.remove();
            }
          }
        }
        tmp_stats = dumpStats(protocol_name, list);
        if (tmp_stats != null) {
          for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) {
            Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue();
            String key = entry.getKey();
            map.put(key, tmp_map != null ? tmp_map.toString() : null);
          }
        }
      } else {
        tmp_stats = dumpStats();
        if (tmp_stats != null) {
          for (Map.Entry<String, Object> entry : tmp_stats.entrySet()) {
            Map<String, Object> tmp_map = (Map<String, Object>) entry.getValue();
            String key = entry.getKey();
            map.put(key, tmp_map != null ? tmp_map.toString() : null);
          }
        }
      }
    }