You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/04/17 17:23:49 UTC
svn commit: r1327141 - in
/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring:
./ JMXBasicDataSource.java JMXContainer.java JMXDeployer.java
Author: rmannibucau
Date: Tue Apr 17 15:23:48 2012
New Revision: 1327141
URL: http://svn.apache.org/viewvc?rev=1327141&view=rev
Log:
missed classes during last commit
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXBasicDataSource.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXContainer.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXDeployer.java
Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXBasicDataSource.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXBasicDataSource.java?rev=1327141&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXBasicDataSource.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXBasicDataSource.java Tue Apr 17 15:23:48 2012
@@ -0,0 +1,220 @@
+package org.apache.openejb.assembler.monitoring;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.sql.Statement;
+import javax.management.Description;
+import javax.management.ManagedAttribute;
+import javax.management.ManagedOperation;
+import javax.management.ObjectName;
+import org.apache.openejb.monitoring.DynamicMBeanWrapper;
+import org.apache.openejb.monitoring.LocalMBeanServer;
+import org.apache.openejb.monitoring.ObjectNameBuilder;
+
+// @MBean: don't put it since it is not a pojo
+@Description("describe a datasource pool")
+public class JMXBasicDataSource {
+ private transient final org.apache.commons.dbcp.BasicDataSource ds;
+
+ private transient ObjectName objectName;
+
+ public JMXBasicDataSource(final String name, final org.apache.commons.dbcp.BasicDataSource ds) {
+ this.ds = ds;
+
+ objectName = ObjectNameBuilder.uniqueName("datasources", name, ds);
+ try {
+ LocalMBeanServer.get().registerMBean(new DynamicMBeanWrapper(this), objectName);
+ } catch (Exception e) {
+ e.printStackTrace(); // TODO
+ }
+ }
+
+ public void unregister() {
+ try {
+ LocalMBeanServer.get().unregisterMBean(objectName);
+ } catch (Exception e) {
+ // ignored
+ }
+ }
+
+ @ManagedAttribute
+ @Description("The class loader instance to use to load the JDBC driver.")
+ public String getDriverClassName() {
+ return ds.getDriverClassName();
+ }
+
+ @ManagedAttribute
+ @Description("The connection URL to be passed to our JDBC driver to establish a connection.")
+ public String getUrl() {
+ return ds.getUrl();
+ }
+
+ @ManagedAttribute
+ @Description("The SQL query that will be used to validate connections from this pool before returning them to the caller.")
+ public String getValidationQuery() {
+ return ds.getValidationQuery();
+ }
+
+ @ManagedAttribute
+ @Description("The connection username to be passed to our JDBC driver to establish a connection.")
+ public String getUsername() {
+ return ds.getUsername();
+ }
+
+ @ManagedAttribute
+ @Description("Timeout in seconds before connection validation queries fail.")
+ public int getValidationQueryTimeout() {
+ return ds.getValidationQueryTimeout();
+ }
+
+ @ManagedAttribute
+ @Description("The initial number of connections that are created when the pool is started.")
+ public int getInitialSize() {
+ return ds.getInitialSize();
+ }
+
+ @ManagedAttribute
+ @Description("The maximum number of active connections that can be allocated from this pool at the same time,"
+ + " or negative for no limit.")
+ public int getMaxActive() {
+ return ds.getMaxActive();
+ }
+
+ @ManagedAttribute
+ @Description("The maximum number of connections that can remain idle in the pool, without extra ones being"
+ + "destroyed, or negative for no limit.")
+ public int getMaxIdle() {
+ return ds.getMaxIdle();
+ }
+
+ @ManagedAttribute
+ @Description("The minimum number of active connections that can remain idle in the pool, without extra ones"
+ + " being created when the evictor runs, or 0 to create none.")
+ public int getMinIdle() {
+ return ds.getMinIdle();
+ }
+
+ @ManagedAttribute
+ @Description("The minimum number of active connections that can remain idle in the pool, without extra ones"
+ + " being created when the evictor runs, or 0 to create none.")
+ public int getNumTestsPerEvictionRun() {
+ return ds.getNumTestsPerEvictionRun();
+ }
+
+ @ManagedAttribute
+ @Description("The minimum amount of time an object may sit idle in the pool before it is eligible for eviction"
+ + " by the idle object evictor (if any).")
+ public long getMinEvictableIdleTimeMillis() {
+ return ds.getMinEvictableIdleTimeMillis();
+ }
+
+ @ManagedAttribute
+ @Description("The number of milliseconds to sleep between runs of the idle object evictor thread.")
+ public long getTimeBetweenEvictionRunsMillis() {
+ return ds.getTimeBetweenEvictionRunsMillis();
+ }
+
+ @ManagedAttribute
+ @Description("The maximum number of open statements that can be allocated from the statement pool at the same time,"
+ + " or non-positive for no limit.")
+ public int getMaxOpenPreparedStatements() {
+ return ds.getMaxOpenPreparedStatements();
+ }
+
+ @ManagedAttribute
+ @Description("The maximum number of milliseconds that the pool will wait (when there are no available connections) "
+ + "for a connection to be returned before throwing an exception, or <= 0 to wait indefinitely.")
+ public long getMaxWait() {
+ return ds.getMaxWait();
+ }
+
+ @ManagedAttribute
+ @Description("The default auto-commit state of connections created by this pool.")
+ public boolean getDefaultAutoCommit() {
+ return ds.getDefaultAutoCommit();
+ }
+
+ @ManagedAttribute
+ @Description("Prepared statement pooling for this pool.")
+ public boolean getPoolPreparedStatements() {
+ return ds.isPoolPreparedStatements();
+ }
+
+ @ManagedAttribute
+ @Description("The indication of whether objects will be validated before being borrowed from the pool.")
+ public boolean getTestOnBorrow() {
+ return ds.getTestOnBorrow();
+ }
+
+ @ManagedAttribute
+ @Description("The indication of whether objects will be validated before being returned to the pool.")
+ public boolean getTestOnReturn() {
+ return ds.getTestOnReturn();
+ }
+
+ @ManagedAttribute
+ @Description("The indication of whether objects will be validated by the idle object evictor (if any).")
+ public boolean getTestWhileIdle() {
+ return ds.getTestWhileIdle();
+ }
+
+ @ManagedAttribute
+ @Description("The default \"catalog\" of connections created by this pool.")
+ public String getDefaultCatalog() {
+ return ds.getDefaultCatalog();
+ }
+
+ @ManagedAttribute
+ @Description("The default read-only state of connections created by this pool.")
+ public boolean getDefaultReadOnly() {
+ return ds.getDefaultReadOnly();
+ }
+
+ @ManagedAttribute
+ @Description("The default TransactionIsolation state of connections created by this pool.")
+ public int getDefaultTransactionIsolation() {
+ return ds.getDefaultTransactionIsolation();
+ }
+
+ @ManagedOperation
+ @Description("Execute the validation query.")
+ public String executeValidationQuery() {
+ final String query = ds.getValidationQuery();
+ if (query == null || query.trim().isEmpty()) {
+ return "no validation query defined";
+ }
+
+ final Connection conn;
+ try {
+ conn = ds.getConnection();
+ } catch (SQLException e) {
+ return e.getMessage();
+ }
+
+ Statement statement = null;
+ try {
+ statement = conn.createStatement();
+ if (statement.execute(query)) {
+ return "OK";
+ }
+ return "KO";
+ } catch (SQLException e) {
+ return e.getMessage();
+ } finally {
+ if (statement != null) {
+ try {
+ statement.close();
+ } catch (SQLException e) {
+ // no-op
+ }
+ }
+ if (conn != null) {
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ // no-op
+ }
+ }
+ }
+ }
+}
Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXContainer.java?rev=1327141&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXContainer.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXContainer.java Tue Apr 17 15:23:48 2012
@@ -0,0 +1,77 @@
+package org.apache.openejb.assembler.monitoring;
+
+import java.util.Map;
+import javax.management.Description;
+import javax.management.ManagedAttribute;
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.Container;
+import org.apache.openejb.assembler.classic.ContainerInfo;
+
+@Description("describe a container")
+public class JMXContainer {
+ private final Container container;
+ private final ContainerInfo info;
+
+ public JMXContainer(final ContainerInfo serviceInfo, final Container service) {
+ info = serviceInfo;
+ container = service;
+ }
+
+ @ManagedAttribute
+ @Description("Container id.")
+ public String getContainerId() {
+ return container.getContainerID().toString();
+ }
+
+ @ManagedAttribute
+ @Description("Container type.")
+ public String getContainerType() {
+ return container.getContainerType().name().toLowerCase().replace("_", " ");
+ }
+
+ @ManagedAttribute
+ @Description("Container managed beans.")
+ public String[] getManagedBeans() {
+ final BeanContext[] beans = container.getBeanContexts();
+ final String[] beanNames = new String[beans.length];
+ int i = 0;
+ for (BeanContext bc : beans) {
+ beanNames[i++] = new StringBuilder("bean-class: ").append(bc.getBeanClass().getName()).append(", ")
+ .append("ejb-name: ").append(bc.getEjbName()).append(", ")
+ .append("deployment-id: ").append(bc.getDeploymentID()).append(", ")
+ .toString();
+ }
+ return beanNames;
+ }
+
+ @ManagedAttribute
+ @Description("Container service.")
+ public String getService() {
+ return info.service;
+ }
+
+ @ManagedAttribute
+ @Description("Container class name.")
+ public String getClassName() {
+ return info.className;
+ }
+
+ @ManagedAttribute
+ @Description("Container factory method.")
+ public String getFactoryMethod() {
+ return info.factoryMethod;
+ }
+
+ @ManagedAttribute
+ @Description("Container properties.")
+ public String[] getProperties() {
+ final String[] properties = new String[info.properties.size()];
+ int i = 0;
+ for (Map.Entry<Object, Object> entry : info.properties.entrySet()) {
+ properties[i++] = new StringBuilder(entry.getKey().toString())
+ .append(" = ").append(entry.getValue().toString())
+ .toString();
+ }
+ return properties;
+ }
+}
Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXDeployer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXDeployer.java?rev=1327141&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXDeployer.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/monitoring/JMXDeployer.java Tue Apr 17 15:23:48 2012
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.openejb.assembler.monitoring;
+
+import java.util.Collection;
+import java.util.Properties;
+import javax.management.Description;
+import javax.management.MBean;
+import javax.management.ManagedAttribute;
+import javax.management.ManagedOperation;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import org.apache.openejb.assembler.Deployer;
+import org.apache.openejb.assembler.DeployerEjb;
+import org.apache.openejb.assembler.classic.AppInfo;
+import org.apache.openejb.core.LocalInitialContextFactory;
+
+@MBean
+@Description("OpenEJB Deployer")
+public class JMXDeployer {
+ @ManagedOperation
+ @Description("Deploy the specified application")
+ public String deploy(final String location) {
+ try {
+ deployer().deploy(location);
+ return "OK";
+ } catch (Exception e) {
+ return "ERR:" + e.getMessage();
+ }
+ }
+
+ @ManagedOperation
+ @Description("Undeploy the specified application")
+ public String undeploy(final String moduleId) {
+ try {
+ deployer().undeploy(moduleId);
+ return "OK";
+ } catch (Exception e) {
+ return "ERR:" + e.getMessage();
+ }
+ }
+
+ @ManagedAttribute
+ @Description("List available applications")
+ public String[] getDeployedApplications() {
+ try {
+ final Collection<AppInfo> apps = deployer().getDeployedApps();
+ final String[] appsNames = new String[apps.size()];
+ int i = 0;
+ for (AppInfo info : apps) {
+ appsNames[i++] = info.path;
+ }
+ return appsNames;
+ } catch (Exception e) {
+ return new String[] { "ERR:" + e.getMessage() };
+ }
+ }
+
+ private static Deployer deployer() throws NamingException {
+ final Properties p = new Properties();
+ p.setProperty(Context.INITIAL_CONTEXT_FACTORY, LocalInitialContextFactory.class.getName());
+
+ final ClassLoader oldCl = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(DeployerEjb.class.getClassLoader());
+ try {
+ return (Deployer) new InitialContext(p).lookup("openejb/DeployerBusinessRemote");
+ } finally {
+ Thread.currentThread().setContextClassLoader(oldCl);
+ }
+ }
+}