aries-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cschnei...@apache.org
Subject svn commit: r1796859 - in /aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc: RecoverableDataSource.java RecoverableDataSourceMBean.java internal/ManagedDataSourceFactory.java
Date Tue, 30 May 2017 13:18:17 GMT
Author: cschneider
Date: Tue May 30 13:18:16 2017
New Revision: 1796859

URL: http://svn.apache.org/viewvc?rev=1796859&view=rev
Log:
ARIES-1276: Add monitoring capability via MBean to Aries Transaction JDBC

Added:
    aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSourceMBean.java
Modified:
    aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java
    aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/ManagedDataSourceFactory.java

Modified: aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java?rev=1796859&r1=1796858&r2=1796859&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java
(original)
+++ aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSource.java
Tue May 30 13:18:16 2017
@@ -43,7 +43,7 @@ import java.sql.SQLFeatureNotSupportedEx
  *
  * @org.apache.xbean.XBean
  */
-public class RecoverableDataSource implements DataSource {
+public class RecoverableDataSource implements DataSource, RecoverableDataSourceMBean {
 
     private CommonDataSource dataSource;
     private AriesTransactionManager transactionManager;
@@ -63,6 +63,7 @@ public class RecoverableDataSource imple
     private boolean backgroundValidation = false;
     private int backgroundValidationMilliseconds = 600000;
 
+    private ConnectionManagerFactory cm;
     private DataSource delegate;
 
     /**
@@ -217,7 +218,7 @@ public class RecoverableDataSource imple
         mcf.setPassword(password);
         mcf.init();
 
-        ConnectionManagerFactory cm = new ConnectionManagerFactory();
+        cm = new ConnectionManagerFactory();
         cm.setManagedConnectionFactory(mcf.getConnectionFactory());
         cm.setTransactionManager(transactionManager);
         cm.setAllConnectionsEqual(allConnectionsEquals);
@@ -241,6 +242,87 @@ public class RecoverableDataSource imple
         }
     }
 
+    /**
+     * @org.apache.xbean.DestroyMethod
+     */
+    public void stop() throws Exception {
+        if (cm != null) {
+            cm.destroy();
+        }
+    }
+
+    //---------------------------
+    // MBean implementation
+    //---------------------------
+
+    public String getName() {
+        return name;
+    }
+
+    public String getExceptionSorter() {
+        return exceptionSorter;
+    }
+
+    public String getUsername() {
+        return username;
+    }
+
+    public String getPassword() {
+        return password;
+    }
+
+    public boolean isAllConnectionsEquals() {
+        return allConnectionsEquals;
+    }
+
+    public int getConnectionMaxIdleMinutes() {
+        return connectionMaxIdleMinutes;
+    }
+
+    public int getConnectionMaxWaitMilliseconds() {
+        return connectionMaxWaitMilliseconds;
+    }
+
+    public String getPartitionStrategy() {
+        return partitionStrategy;
+    }
+
+    public boolean isPooling() {
+        return pooling;
+    }
+
+    public int getPoolMaxSize() {
+        return poolMaxSize;
+    }
+
+    public int getPoolMinSize() {
+        return poolMinSize;
+    }
+
+    public boolean isValidateOnMatch() {
+        return validateOnMatch;
+    }
+
+    public boolean isBackgroundValidation() {
+        return backgroundValidation;
+    }
+
+    public int getBackgroundValidationMilliseconds() {
+        return backgroundValidationMilliseconds;
+    }
+
+    public String getTransaction() {
+        return transaction;
+    }
+
+    public int getConnectionCount() {
+        return cm.getPoolingSupport().getConnectionCount();
+    }
+
+    public int getIdleConnectionCount() {
+        return cm.getPoolingSupport().getIdleConnectionCount();
+    }
+
     //---------------------------
     // DataSource implementation
     //---------------------------

Added: aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSourceMBean.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSourceMBean.java?rev=1796859&view=auto
==============================================================================
--- aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSourceMBean.java
(added)
+++ aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/RecoverableDataSourceMBean.java
Tue May 30 13:18:16 2017
@@ -0,0 +1,56 @@
+/*
+ * 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.aries.transaction.jdbc;
+
+public interface RecoverableDataSourceMBean {
+
+    String getName();
+
+    String getExceptionSorter();
+
+    String getUsername();
+
+    String getPassword();
+
+    boolean isAllConnectionsEquals();
+
+    int getConnectionMaxIdleMinutes();
+
+    int getConnectionMaxWaitMilliseconds();
+
+    String getPartitionStrategy();
+
+    boolean isPooling();
+
+    int getPoolMaxSize();
+
+    int getPoolMinSize();
+
+    boolean isValidateOnMatch();
+
+    boolean isBackgroundValidation();
+
+    int getBackgroundValidationMilliseconds();
+
+    String getTransaction();
+
+    int getConnectionCount();
+
+    int getIdleConnectionCount();
+}

Modified: aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/ManagedDataSourceFactory.java
URL: http://svn.apache.org/viewvc/aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/ManagedDataSourceFactory.java?rev=1796859&r1=1796858&r2=1796859&view=diff
==============================================================================
--- aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/ManagedDataSourceFactory.java
(original)
+++ aries/trunk/transaction/transaction-jdbc/src/main/java/org/apache/aries/transaction/jdbc/internal/ManagedDataSourceFactory.java
Tue May 30 13:18:16 2017
@@ -19,6 +19,7 @@
 package org.apache.aries.transaction.jdbc.internal;
 
 import org.apache.aries.transaction.AriesTransactionManager;
+import org.apache.aries.transaction.jdbc.RecoverableDataSource;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.Constants;
 import org.osgi.framework.ServiceReference;
@@ -40,7 +41,7 @@ public class ManagedDataSourceFactory {
     private final Map<String, Object> properties;
 
     private ServiceRegistration<DataSource> registration;
-    private ConnectionManagerFactory cm;
+    private RecoverableDataSource ds;
 
     public ManagedDataSourceFactory(ServiceReference reference,
                                     AriesTransactionManager transactionManager) {
@@ -104,39 +105,32 @@ public class ManagedDataSourceFactory {
         if (isXaDataSource) {
             props.put("aries.xa.aware", "true");
         }
+        props.put("jmx.objectname", "org.apache.aries.transaction:type=jdbc,name=" + getResourceName());
         props.put(Constants.SERVICE_RANKING, getInt(Constants.SERVICE_RANKING, 0) + 1000);
 
-        AbstractMCFFactory mcf = isXaDataSource ? new XADataSourceMCFFactory() : new DataSourceMCFFactory();
-        mcf.setDataSource(dataSource);
-        mcf.setExceptionSorterAsString(getString("aries.xa.exceptionSorter", "all"));
-        mcf.setUserName(getString("aries.xa.username", null));
-        mcf.setPassword(getString("aries.xa.password", null));
-        mcf.init();
-
-        cm = new ConnectionManagerFactory();
-        cm.setManagedConnectionFactory(mcf.getConnectionFactory());
-        cm.setTransactionManager(transactionManager);
-        cm.setAllConnectionsEqual(getBool("aries.xa.allConnectionsEquals", true));
-        cm.setConnectionMaxIdleMinutes(getInt("aries.xa.connectionMadIdleMinutes", 15));
-        cm.setConnectionMaxWaitMilliseconds(getInt("aries.xa.connectionMaxWaitMilliseconds",
5000));
-        cm.setPartitionStrategy(getString("aries.xa.partitionStrategy", null));
-        cm.setPooling(getBool("aries.xa.pooling", true));
-        cm.setPoolMaxSize(getInt("aries.xa.poolMaxSize", 10));
-        cm.setPoolMinSize(getInt("aries.xa.poolMinSize", 0));
-        cm.setValidateOnMatch(getBool("aries.xa.validateOnMatch", true));
-        cm.setBackgroundValidation(getBool("aries.xa.backgroundValidation", false));
-        cm.setBackgroundValidationMilliseconds(getInt("aries.xa.backgroundValidationMilliseconds",
600000));
-        cm.setTransaction(getString("aries.xa.transaction", isXaDataSource ? "xa" : "local"));
-        cm.setName(getResourceName());
-        cm.init();
+        ds = new RecoverableDataSource();
+        ds.setDataSource(dataSource);
+        ds.setExceptionSorter(getString("aries.xa.exceptionSorter", "all"));
+        ds.setUsername(getString("aries.xa.username", null));
+        ds.setPassword(getString("aries.xa.password", null));
+
+        ds.setTransactionManager(transactionManager);
+        ds.setAllConnectionsEquals(getBool("aries.xa.allConnectionsEquals", true));
+        ds.setConnectionMaxIdleMinutes(getInt("aries.xa.connectionMadIdleMinutes", 15));
+        ds.setConnectionMaxWaitMilliseconds(getInt("aries.xa.connectionMaxWaitMilliseconds",
5000));
+        ds.setPartitionStrategy(getString("aries.xa.partitionStrategy", null));
+        ds.setPooling(getBool("aries.xa.pooling", true));
+        ds.setPoolMaxSize(getInt("aries.xa.poolMaxSize", 10));
+        ds.setPoolMinSize(getInt("aries.xa.poolMinSize", 0));
+        ds.setValidateOnMatch(getBool("aries.xa.validateOnMatch", true));
+        ds.setBackgroundValidation(getBool("aries.xa.backgroundValidation", false));
+        ds.setBackgroundValidationMilliseconds(getInt("aries.xa.backgroundValidationMilliseconds",
600000));
+        ds.setTransaction(getString("aries.xa.transaction", isXaDataSource ? "xa" : "local"));
+        ds.setName(getResourceName());
+        ds.start();
 
         BundleContext context = reference.getBundle().getBundleContext();
-        DataSource ds = (DataSource) mcf.getConnectionFactory().createConnectionFactory(cm.getConnectionManager());
         registration = context.registerService(DataSource.class, ds, props);
-
-        if (isXaDataSource) {
-            Recovery.recover(getResourceName(), (XADataSource) dataSource, transactionManager);
-        }
     }
 
     public void unregister() throws Exception {
@@ -144,8 +138,8 @@ public class ManagedDataSourceFactory {
             registration.unregister();
             registration = null;
         }
-        if (cm != null) {
-            cm.destroy();
+        if (ds != null) {
+            ds.stop();
         }
     }
 



Mime
View raw message