List of usage examples for javax.management MalformedObjectNameException getMessage
public String getMessage()
From source file:no.sr.ringo.persistence.jdbc.RingoDataSourceFactoryDbcpImpl.java
private PoolingDataSource getPoolingDataSource(JdbcConfiguration configuration, String connectURI, String userName, String password, Driver driver) { Properties properties = new Properties(); properties.put("user", userName); properties.put("password", password); // DBCP factory which will produce JDBC Driver instances ConnectionFactory driverConnectionFactory = new DriverConnectionFactory(driver, connectURI, properties); // DBCP Factory holding the pooled connection, which are created by the driver connection factory and held in the supplied pool ObjectName dataSourceJmxName; try {/*from w w w . ja v a 2s.c om*/ dataSourceJmxName = new ObjectName("no.difi.oxalis", "connectionPool", "OxalisDB"); } catch (MalformedObjectNameException e) { throw new IllegalStateException(e.getMessage(), e); } PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(driverConnectionFactory, dataSourceJmxName); if (configuration.getValidationQuery().isPresent()) { poolableConnectionFactory.setValidationQuery(configuration.getValidationQuery().get()); } // DBCP object pool holding our driver connections GenericObjectPool<PoolableConnection> genericObjectPool = new GenericObjectPool<PoolableConnection>( poolableConnectionFactory); poolableConnectionFactory.setPool(genericObjectPool); genericObjectPool.setMaxTotal(100); genericObjectPool.setMaxIdle(30); genericObjectPool.setMaxWaitMillis(10000); genericObjectPool.setTestOnBorrow(true); // Test the connection returned from the pool genericObjectPool.setTestWhileIdle(true); // Test idle instances visited by the pool maintenance thread and destroy any that fail validation genericObjectPool.setTimeBetweenEvictionRunsMillis(60 * 60 * 1000); // Test every hour // Creates the actual DataSource instance return new PoolingDataSource(genericObjectPool); }
From source file:eu.peppol.persistence.jdbc.OxalisDataSourceFactoryDbcpImpl.java
/** * Creates a DataSource with connection pooling as provided by Apache DBCP * * @return a DataSource/*from ww w . j a v a2 s. c o m*/ */ DataSource configureAndCreateDataSource(RepositoryConfiguration configuration) { log.debug("Configuring DataSource wrapped in a Database Connection Pool, using custom loader"); String jdbcDriverClassPath = configuration.getJdbcDriverClassPath(); log.debug("Loading JDBC Driver with custom class path: " + jdbcDriverClassPath); // Creates a new class loader, which will be used for loading our JDBC driver URLClassLoader urlClassLoader = getOxalisClassLoaderForJdbc(jdbcDriverClassPath); String className = configuration.getJdbcDriverClassName(); String connectURI = configuration.getJdbcConnectionUri().toString(); String userName = configuration.getJdbcUsername(); String password = configuration.getJdbcPassword(); log.debug("className=" + className); log.debug("connectURI=" + connectURI); log.debug("userName=" + userName); log.debug("password=" + password); // Loads the JDBC Driver in a separate class loader Driver driver = getJdbcDriver(jdbcDriverClassPath, urlClassLoader, className); Properties properties = new Properties(); properties.put("user", userName); properties.put("password", password); // DBCP factory which will produce JDBC Driver instances ConnectionFactory driverConnectionFactory = new DriverConnectionFactory(driver, connectURI, properties); // DBCP Factory holding the pooled connection, which are created by the driver connection factory and held in the supplied pool ObjectName dataSourceJmxName = null; try { dataSourceJmxName = new ObjectName("no.difi.oxalis", "connectionPool", "OxalisDB"); } catch (MalformedObjectNameException e) { throw new IllegalStateException(e.getMessage(), e); } PoolableConnectionFactory poolableConnectionFactory = new PoolableConnectionFactory(driverConnectionFactory, dataSourceJmxName); String validationQuery = configuration.getValidationQuery(); if (validationQuery != null) { poolableConnectionFactory.setValidationQuery(validationQuery); } // DBCP object pool holding our driver connections GenericObjectPool<PoolableConnection> genericObjectPool = new GenericObjectPool<PoolableConnection>( poolableConnectionFactory); poolableConnectionFactory.setPool(genericObjectPool); genericObjectPool.setMaxTotal(100); genericObjectPool.setMaxIdle(30); genericObjectPool.setMaxWaitMillis(10000); genericObjectPool.setTestOnBorrow(true); // Test the connection returned from the pool genericObjectPool.setTestWhileIdle(true); // Test idle instances visited by the pool maintenance thread and destroy any that fail validation genericObjectPool.setTimeBetweenEvictionRunsMillis(60 * 60 * 1000); // Test every hour // Creates the actual DataSource instance PoolingDataSource poolingDataSource = new PoolingDataSource(genericObjectPool); return poolingDataSource; }
From source file:org.hyperic.hq.plugin.jboss.jmx.ServerQuery.java
public void getAttributes(MBeanServerConnection mServer) throws PluginException { ObjectName name;/*from w ww .j a va 2 s .co m*/ try { name = new ObjectName(SERVER_NAME); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e.getMessage()); } getAttributes(mServer, name, ATTRS_SERVER); try { name = new ObjectName(SERVER_CONFIG_NAME); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e.getMessage()); } getAttributes(mServer, name, ATTRS_SERVER_CONFIG); try { name = new ObjectName(SERVER_INFO_NAME); } catch (MalformedObjectNameException e) { throw new IllegalArgumentException(e.getMessage()); } getAttributes(mServer, name, ATTRS_SERVER_INFO); //remove build id String fullVersion = getAttribute(ATTR_VERSION).substring(0, 5); setAttribute("version", fullVersion); //cprop defined in hq-plugin.xml String ver = fullVersion.substring(0, 3); setVersion(ver); setName(getAttribute(ATTR_SERVER_NAME)); setInstallPath(getAttribute(ATTR_HOMEDIR)); }
From source file:org.hyperic.hq.product.jmx.MxServerQuery.java
private void findServices(MBeanServerConnection mServer, MxServiceQuery query) throws PluginException { boolean isDebug = log.isDebugEnabled(); query.initialize();//from w ww . j a v a 2 s . c om Set services; ObjectName name; String mbeanClass = query.getMBeanClass(); String filter = query.getObjectNameFilter(); StringMatcher matcher = null; if (filter != null) { matcher = new StringMatcher(); if (filter.charAt(0) == '!') { matcher.setExcludes(filter.substring(1)); } else { matcher.setIncludes(filter); } } try { name = new ObjectName(query.getQueryName()); log.debug("[findServices] name=" + name); services = mServer.queryNames(name, null); log.debug("[findServices] services=(" + services.size() + ")" + services); } catch (MalformedObjectNameException e) { String msg = query.getQueryName() + ": " + e.getMessage(); throw new IllegalArgumentException(msg); } catch (RemoteException e) { throw new PluginException("Cannot connect to server", e); } catch (IOException e) { throw new PluginException("Cannot connect to server", e); } for (Iterator it = services.iterator(); it.hasNext();) { name = (ObjectName) it.next(); if ((matcher != null) && !matcher.matches(name.toString())) { if (isDebug) { log.debug("[" + name + "] !matches(" + matcher + ")"); } continue; } if (!query.apply(name)) { continue; } if (mbeanClass != null) { try { MBeanInfo info = mServer.getMBeanInfo(name); if (!info.getClassName().matches(mbeanClass)) { if (isDebug) { log.debug("[" + name + "] " + info.getClassName() + " !instanceof " + mbeanClass); } continue; } } catch (Exception e) { log.error("mServer.getMBeanInfo(" + name + "): " + e); continue; } } MxServiceQuery service = query.cloneInstance(); service.setObjectName(name); this.services.add(service); service.setParent(this); service.setServerQuery(this); service.getAttributes(mServer); } }
From source file:org.hyperic.hq.plugin.websphere.WebsphereCollector.java
protected final ObjectName newObjectNamePattern(String attrs) throws PluginException { try {//from ww w .j a v a2 s . co m return new ObjectName(this.domain + ":" + attrs + ",*"); } catch (MalformedObjectNameException e) { throw new PluginException(e.getMessage()); } }
From source file:org.hyperic.hq.plugin.jboss.jmx.ServerQuery.java
private void findServices(MBeanServerConnection mServer, ServiceQuery query) throws PluginException { query.initialize();/*from w ww. ja v a 2 s. c om*/ Set _services; ObjectName name; String mbeanClass = null; if (query instanceof GenericServiceQuery) { mbeanClass = ((GenericServiceQuery) query).getMBeanClass(); } try { name = new ObjectName(query.getQueryName()); _services = mServer.queryNames(name, null); log.debug("[findServices] " + name + " -> (" + mbeanClass + ") '" + _services.size() + "'"); } catch (MalformedObjectNameException e) { String msg = query.getQueryName() + ": " + e.getMessage(); throw new IllegalArgumentException(msg); } catch (RemoteException e) { throw new PluginException("Cannot connect to JBoss", e); } catch (IOException e) { throw new PluginException("Cannot connecto to JBoss", e); } for (Iterator it = _services.iterator(); it.hasNext();) { name = (ObjectName) it.next(); if (checkClass(mServer, name, mbeanClass)) { boolean apply = query.apply(name); log.debug("[findServices] " + (apply ? "+" : "-") + " name='" + name + "'"); if (apply) { ServiceQuery service = query.cloneInstance(); service.setObjectName(name); this.services.add(service); service.setParent(this); service.setServerQuery(this); service.getAttributes(mServer); } } } log.debug("***********************************************"); }
From source file:org.apache.geode.management.internal.cli.commands.CreateAlterDestroyRegionCommandsDUnitTest.java
private Callable<Boolean> newRegionMBeanIsCreated(final String regionPath) { return () -> { try {// w w w . j a va 2s .c om MBeanServer mbeanServer = MBeanJMXAdapter.mbeanServer; String queryExp = MessageFormat.format(ManagementConstants.OBJECTNAME__REGION_MXBEAN, regionPath, "*"); ObjectName queryExpON = new ObjectName(queryExp); return mbeanServer.queryNames(null, queryExpON).size() == 1; } catch (MalformedObjectNameException mone) { getLogWriter().error(mone); fail(mone.getMessage()); return false; } }; }
From source file:org.hyperic.hq.plugin.weblogic.jmx.WeblogicDiscover.java
public void find(MBeanServer mServer, WeblogicQuery query, List types) throws WeblogicDiscoverException { ObjectName scope;// w w w.ja v a 2s.co m try { scope = new ObjectName(domain + ":" + query.getScope() + ",*"); log.debug("[find] scope=" + scope); } catch (MalformedObjectNameException e) { // wont happen throw new IllegalArgumentException(e.getMessage()); } try { for (Iterator it = mServer.queryNames(scope, null).iterator(); it.hasNext();) { ObjectName obj = (ObjectName) it.next(); String name = obj.getKeyProperty("Name"); if (name != null) { if (name.startsWith("__") || (name.indexOf("uuid-") != -1)) // wierdo 9.1 stuff i.e __weblogic_admin_rmi_queue { continue; } } WeblogicQuery type = query.cloneInstance(); if (type.getAttributes(mServer, obj)) { types.add(type); WeblogicQuery[] childQueries = query.getChildQueries(); for (int i = 0; i < childQueries.length; i++) { WeblogicQuery childQuery = childQueries[i]; childQuery.setParent(type); childQuery.setVersion(type.getVersion()); find(mServer, childQuery, types); } } } } catch (Exception e) { throw new WeblogicDiscoverException(e); } }
From source file:eu.peppol.persistence.jdbc.OxalisDataSourceFactoryDbcpImplTest.java
private PoolingDataSource createPoolingDataSource(ConnectionFactory driverConnectionFactory) { PoolableConnectionFactory poolableConnectionFactory = null; try {//www .ja v a 2s. c o m poolableConnectionFactory = new PoolableConnectionFactory(driverConnectionFactory, new ObjectName("no.difi.oxalis", "connectionPool", "TestPool")); GenericObjectPool<PoolableConnection> pool = new GenericObjectPool<PoolableConnection>( poolableConnectionFactory); poolableConnectionFactory.setPool(pool); poolableConnectionFactory.setValidationQuery("select 1"); return new PoolingDataSource(pool); } catch (MalformedObjectNameException e) { throw new IllegalStateException("Unable to create poolable conneciton factory: " + e.getMessage(), e); } }
From source file:org.hyperic.hq.plugin.websphere.jmx.WebsphereRuntimeDiscoverer.java
private List discover(AdminClient mServer, String domain, WebSphereQuery query) throws PluginException { List res = new ArrayList(); boolean isApp = query instanceof ApplicationQuery; ObjectName scope;//from ww w .java2 s .c o m try { scope = new ObjectName(domain + ":" + query.getScope() + ",*"); } catch (MalformedObjectNameException e) { throw new PluginException(e.getMessage(), e); } Set beans; try { query.setMBeanServer(mServer); beans = mServer.queryNames(scope, null); } catch (ConnectorException e) { throw new PluginException(e.getMessage(), e); } for (Iterator it = beans.iterator(); it.hasNext();) { ObjectName obj = (ObjectName) it.next(); WebSphereQuery type = query.cloneInstance(); type.setName(obj.getKeyProperty("name")); type.setObjectName(obj); type.getAttributes(mServer, obj); if (type.apply()) { res.add(type); if (isApp) { for (WebSphereQuery moduleQuery : moduleQueries) { moduleQuery.setParent(type); res.addAll(discover(mServer, domain, moduleQuery)); } } } else { log.debug("[discover] MBean discarted. obj:'" + obj + "'"); } } return res; }