javax.management.ObjectName.getKeyPropertyListString()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(121)

本文整理了Java中javax.management.ObjectName.getKeyPropertyListString()方法的一些代码示例,展示了ObjectName.getKeyPropertyListString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ObjectName.getKeyPropertyListString()方法的具体详情如下:
包路径:javax.management.ObjectName
类名称:ObjectName
方法名:getKeyPropertyListString

ObjectName.getKeyPropertyListString介绍

暂无

代码示例

代码示例来源:origin: jmxtrans/jmxtrans

/**
 * Add results from a value of type objet name array.
 */
private void add(String attributeName, ImmutableList.Builder<String> valuePath, ObjectName[] objs) {
  ImmutableMap.Builder<String, Object> values = ImmutableMap.builder();
  for (ObjectName obj : objs) {
    values.put(obj.getCanonicalName(), obj.getKeyPropertyListString());
  }
  addNew(attributeName, valuePath, values.build());
}

代码示例来源:origin: jmxtrans/jmxtrans

/**
 * Create and add a new result.
 */
private void addNew(String attributeName, ImmutableList.Builder<String> valuePath, Object value) {
  accumulator.add(new Result(epoch, attributeName, className, objDomain, query.getResultAlias(), objectInstance.getObjectName().getKeyPropertyListString(), valuePath.build(), value));
}

代码示例来源:origin: hawtio/hawtio

/**
 * see: <code>org.apache.karaf.management.KarafMBeanServerGuard#getNameSegments(javax.management.ObjectName)</code>
 *
 * Assuming <strong>full</strong> {@link ObjectName} (not null, not containing wildcards and other funny stuff),
 * split objectName to elements used then co contruct ordered list of PIDs to check for MBean permissions.
 * @return
 */
static List<String> nameSegments(ObjectName objectName) {
  List<String> segments = new ArrayList<>();
  segments.add(objectName.getDomain());
  for (String s : objectName.getKeyPropertyListString().split(",")) {
    int index = s.indexOf('=');
    if (index < 0) {
      continue;
    }
    String key = objectName.getKeyProperty(s.substring(0, index));
    if (s.substring(0, index).equals("type")) {
      segments.add(1, key);
    } else {
      segments.add(key);
    }
  }
  return segments;
}

代码示例来源:origin: hawtio/hawtio

@SuppressWarnings("unchecked")
private void doQueryForMBeans(JMXSecurityMBean jmxSec, Map<String, Map<String, Object>> domains,
               Map<String, Map<String, Object>> rbacCache, Map<String, List<String>> queryForMBeans) throws Exception {
  TabularData dataForMBeans = jmxSec.canInvoke(queryForMBeans);
  Collection<?> results = dataForMBeans.values();
  for (Object cd : results) {
    ObjectName objectName = new ObjectName((String) ((CompositeData) cd).get("ObjectName"));
    boolean canInvoke = ((CompositeData) cd).get("CanInvoke") != null ? (Boolean) ((CompositeData) cd).get("CanInvoke") : false;
    Object mBeanInfoOrKey = domains.get(objectName.getDomain()).get(objectName.getKeyPropertyListString());
    Map<String, Object> mBeanInfo;
    if (mBeanInfoOrKey instanceof Map) {
      mBeanInfo = (Map<String, Object>) mBeanInfoOrKey;
    } else {
      mBeanInfo = rbacCache.get(mBeanInfoOrKey.toString());
    }
    if (mBeanInfo != null) {
      mBeanInfo.put("canInvoke", canInvoke);
    }
  }
}

代码示例来源:origin: hawtio/hawtio

@SuppressWarnings("unchecked")
private void doQueryForMBeanOperations(JMXSecurityMBean jmxSec, Map<String, Map<String, Object>> domains,
                    Map<String, Map<String, Object>> rbacCache, Map<String, List<String>> queryForMBeanOperations) throws Exception {
  TabularData dataForMBeanOperations = jmxSec.canInvoke(queryForMBeanOperations);
  Collection<?> results = dataForMBeanOperations.values();
  for (Object result : results) {
    CompositeData cd = (CompositeData) result;
    ObjectName objectName = new ObjectName((String) cd.get("ObjectName"));
    String method = (String) cd.get("Method");
    boolean canInvoke = cd.get("CanInvoke") != null ? (Boolean) cd.get("CanInvoke") : false;
    Object mBeanInfoOrKey = domains.get(objectName.getDomain()).get(objectName.getKeyPropertyListString());
    Map<String, Object> mBeanInfo;
    if (mBeanInfoOrKey instanceof Map) {
      mBeanInfo = (Map<String, Object>) mBeanInfoOrKey;
      LOG.trace("{} {} - {}", objectName, method, canInvoke);
    } else {
      mBeanInfo = rbacCache.get(mBeanInfoOrKey.toString());
      LOG.trace("{} {} - {} - {}", objectName, method, canInvoke, mBeanInfoOrKey.toString());
    }
    if (mBeanInfo != null) {
      decorateCanInvoke(mBeanInfo, method, canInvoke);
    }
  }
}

代码示例来源:origin: apache/geode

/**
 * This method will register an MBean in GemFire domain. Even if the client provides a domain name
 * it will be ignored and GemFire domain name will be used.
 *
 * This method checks the local Filter for registering the MBean. If filtered the MBean wont be
 * registered. Although the filter will remember the filtered MBean and register it once the
 * filter is removed.
 *
 * @return modified ObjectName
 */
public ObjectName registerMBean(Object object, ObjectName objectName, boolean isGemFireMBean) {
 ObjectName newObjectName = objectName;
 try {
  if (!isGemFireMBean) {
   String member = getMemberNameOrUniqueId(distMember);
   String objectKeyProperty = objectName.getKeyPropertyListString();
   newObjectName = ObjectName.getInstance(
     OBJECTNAME__PREFIX + objectKeyProperty + KEYVAL_SEPARATOR + "member=" + member);
  }
  if (isRegistered(newObjectName)) {
   return newObjectName;
  }
  mbeanServer.registerMBean(object, newObjectName);
  this.localGemFireMBean.put(newObjectName, object);
 } catch (InstanceAlreadyExistsException | NullPointerException | MalformedObjectNameException
   | NotCompliantMBeanException | MBeanRegistrationException e) {
  throw new ManagementException(e);
 }
 return newObjectName;
}

代码示例来源:origin: Netflix/servo

@Test
public void testOrderedTagsWithoutAppend() {
 ObjectNameMapper mapper = new OrderedObjectNameMapper(false,
   Arrays.asList("name", DataSourceType.KEY, "foo", "notPresentKey"));
 ObjectName name = mapper.createObjectName(TEST_DOMAIN, TEST_COUNTER);
 assertEquals(name.getDomain(), TEST_DOMAIN);
 assertEquals(name.getKeyPropertyListString(),
   String.format("name=testName,%s=COUNTER,foo=bar",
     DataSourceType.KEY));
}

代码示例来源:origin: Netflix/servo

@Test
public void testOrderedTagsWithAppend() {
 ObjectNameMapper mapper =
   new OrderedObjectNameMapper(true, "name",
     DataSourceType.KEY, "foo", "notPresentKey");
 ObjectName name = mapper.createObjectName(TEST_DOMAIN, TEST_COUNTER);
 assertEquals(name.getDomain(), TEST_DOMAIN);
 assertEquals(name.getKeyPropertyListString(),
   String.format("name=testName,%s=COUNTER,foo=bar,aaa=aaaVal,zzz=zzzVal",
     DataSourceType.KEY));
}

代码示例来源:origin: Netflix/servo

@Test
public void testOrderedTagsWithoutNameExplicitlyOrdered() {
 ObjectNameMapper mapper = new OrderedObjectNameMapper(true, "foo", DataSourceType.KEY);
 ObjectName name = mapper.createObjectName(TEST_DOMAIN, TEST_COUNTER);
 assertEquals(name.getDomain(), TEST_DOMAIN);
 assertEquals(name.getKeyPropertyListString(),
   String.format("foo=bar,%s=COUNTER,name=testName,aaa=aaaVal,zzz=zzzVal",
     DataSourceType.KEY));
}

代码示例来源:origin: javamelody/javamelody

result.add(domainNode);
final String keyPropertyListString = name.getKeyPropertyListString();
final String firstPropertyValue;
final int indexOf = keyPropertyListString.indexOf('=');

代码示例来源:origin: Netflix/servo

@Test
public void testInvalidCharactersSanitized() {
 ObjectName name =
   ObjectNameBuilder.forDomain("test*Domain&")
     .addProperty("foo%", "$bar")
     .build();
 assertEquals(name.getDomain(), "test_Domain_");
 assertEquals(name.getKeyPropertyListString(), "foo_=_bar");
}

代码示例来源:origin: Netflix/servo

@Test
public void testAddTagList() {
 ObjectName name =
   ObjectNameBuilder.forDomain("testDomain")
     .addProperties(BasicTagList.of("foo", "bar", "test", "stuff"))
     .build();
 assertEquals(name.getDomain(), "testDomain");
 assertEquals(name.getKeyPropertyListString(), "foo=bar,test=stuff");
}

代码示例来源:origin: Netflix/servo

@Test
public void testStandardMapping() {
 MonitorConfig config = MonitorConfig.builder("testName").withTag("foo", "bar").build();
 ObjectName name = DEFAULT_MAPPER.createObjectName(TEST_DOMAIN, new BasicCounter(config));
 assertEquals(name.getDomain(), TEST_DOMAIN);
 // note that this assumes that DataSourceType.KEY is greater than 'foo'
 // for String#compareTo purposes
 assertEquals(name.getKeyPropertyListString(),
   String.format("name=testName,foo=bar,%s=COUNTER",
     DataSourceType.KEY));
}

代码示例来源:origin: Netflix/servo

@Test
public void testTagByTag() {
 // Order will be in the order tags were added to the builder
 ObjectName name =
   ObjectNameBuilder.forDomain("testDomain")
     .addProperty(Tags.newTag("foo", "bar"))
     .addProperty(Tags.newTag("test", "stuff"))
     .build();
 assertEquals(name.getDomain(), "testDomain");
 assertEquals(name.getKeyPropertyListString(), "foo=bar,test=stuff");
}

代码示例来源:origin: hibernate/hibernate-orm

@Test
public void testHHH6635() throws Exception {
  MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
  Set<ObjectName> set = mBeanServer.queryNames( null, null );
  boolean mbeanfound = false;
  for ( ObjectName obj : set ) {
    if ( obj.getKeyPropertyListString().indexOf( "PooledDataSource" ) > 0 ) {
      mbeanfound = true;
      // see according c3p0 settings in META-INF/persistence.xml
      int actual_minPoolSize = (Integer) mBeanServer.getAttribute( obj, "minPoolSize" );
      assertEquals( 50, actual_minPoolSize );
      int actual_initialPoolSize = (Integer) mBeanServer.getAttribute( obj, "initialPoolSize" );
      assertEquals( 50, actual_initialPoolSize );
      int actual_maxPoolSize = (Integer) mBeanServer.getAttribute( obj, "maxPoolSize" );
      assertEquals( 800, actual_maxPoolSize );
      int actual_maxStatements = (Integer) mBeanServer.getAttribute( obj, "maxStatements" );
      assertEquals( 50, actual_maxStatements );
      int actual_maxIdleTime = (Integer) mBeanServer.getAttribute( obj, "maxIdleTime" );
      assertEquals( 300, actual_maxIdleTime );
      int actual_idleConnectionTestPeriod = (Integer) mBeanServer.getAttribute(
          obj,
          "idleConnectionTestPeriod"
      );
      assertEquals( 3000, actual_idleConnectionTestPeriod );
      break;
    }
  }
  assertTrue( "PooledDataSource BMean not found, please verify version of c3p0", mbeanfound );
}

代码示例来源:origin: Netflix/servo

@Test
public void testMultipleTags() throws MalformedObjectNameException {
 BasicCounter counter = new BasicCounter(
   MonitorConfig.builder("testName")
     .withTag("bbb", "foo")
     .withTag("aaa", "bar")
     .withTag("zzz", "test")
     .build());
 ObjectName name = DEFAULT_MAPPER.createObjectName(TEST_DOMAIN, counter);
 assertEquals(name.getDomain(), TEST_DOMAIN);
 assertEquals(name.getKeyPropertyListString(),
   String.format("name=testName,aaa=bar,bbb=foo,%s=COUNTER,zzz=test",
     DataSourceType.KEY));
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

public MBean(ObjectName objectName, MBeanInfo mBeanInfo) {
  _objectName = objectName;
  _mBeanInfo = mBeanInfo;
  _domainName = objectName.getDomain();
  _mBeanName = objectName.getKeyPropertyListString();
  _loaded = true;
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

public MBean(ObjectName objectName) {
  _objectName = objectName;
  _domainName = objectName.getDomain();
  _mBeanName = objectName.getKeyPropertyListString();
  _loaded = false;
  _mBeanInfo = null;
}

代码示例来源:origin: rhuss/jolokia

private String getKeyPropertyString(ObjectName pName) {
  return useCanonicalName ? pName.getCanonicalKeyPropertyListString() : pName.getKeyPropertyListString();
}

代码示例来源:origin: prometheus/jmx_exporter

public LinkedHashMap<String, String> getKeyPropertyList(ObjectName mbeanName) {
  LinkedHashMap<String, String> keyProperties = keyPropertiesPerBean.get(mbeanName);
  if (keyProperties == null) {
    keyProperties = new LinkedHashMap<String, String>();
    String properties = mbeanName.getKeyPropertyListString();
    Matcher match = PROPERTY_PATTERN.matcher(properties);
    while (match.lookingAt()) {
      keyProperties.put(match.group(1), match.group(2));
      properties = properties.substring(match.end());
      if (properties.startsWith(",")) {
        properties = properties.substring(1);
      }
      match.reset(properties);
    }
    keyPropertiesPerBean.put(mbeanName, keyProperties);
  }
  return keyProperties;
}

相关文章