Allows to set
@@ -44,6 +51,7 @@ public class AS400Initialize extends AbstractConnector {
* node. The connections are stored in the memory.
*/
private static Map Creates an AS400 instance and store it in the message context as {@link
@@ -102,7 +110,24 @@ public void connect(MessageContext messageContext) throws ConnectException {
as400.authenticate(userID, password);
log.auditLog("Authentication success...");
}
+ String isJmxEnabled = (String) getParameter(messageContext, AS400Constants.AS400_JMX_ENABLED);
+ if (isJmxEnabled != null && !isJmxEnabled.isEmpty()) {
+ this.isJmxEnabled = Boolean.parseBoolean(isJmxEnabled);
+ if(this.isJmxEnabled) {
+ try {
+ ObjectName objectName = new ObjectName("org.wso2.carbon.connector.pcml:type=basic,name=as400");
+ MBeanServer server = ManagementFactory.getPlatformMBeanServer();
+ PCMLPoolMBean mbean = new PCMLPool(connectionPool, as400);
+ if(!server.isRegistered(objectName)) {
+ server.registerMBean(mbean, objectName);
+ }
+ } catch (MalformedObjectNameException | InstanceAlreadyExistsException |
+ MBeanRegistrationException | NotCompliantMBeanException e) {
+ log.auditError("Error while adding AS400ConnectionPoll to MBeanServer.");
+ }
+ }
+ }
} catch (AS400SecurityException as400SecurityException) {
String errorMessage = "Security or authorization error occurred: ";
AS400Utils.setExceptionToPayload(errorMessage, as400SecurityException, "100", messageContext);
diff --git a/src/main/java/org/wso2/carbon/connector/pcml/PCMLPool.java b/src/main/java/org/wso2/carbon/connector/pcml/PCMLPool.java
new file mode 100644
index 0000000..08398ca
--- /dev/null
+++ b/src/main/java/org/wso2/carbon/connector/pcml/PCMLPool.java
@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 LLC. 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.wso2.carbon.connector.pcml;
+
+import com.ibm.as400.access.AS400ConnectionPool;
+import com.ibm.as400.access.AS400;
+
+public class PCMLPool implements PCMLPoolMBean {
+
+ AS400ConnectionPool as400ConnectionPool;
+ AS400 as400;
+ int maxConnections;
+ long maxInactivity;
+ int maxLifetime;
+ int maxUseCount;
+ int maxUseTime;
+ boolean isRunMaintenance;
+ boolean isThreadUsed;
+ int cleanupInterval;
+ boolean pretestConnections;
+ int activeConnectionCount;
+
+ public PCMLPool(AS400ConnectionPool connectionPool, AS400 as400) {
+ this.as400ConnectionPool = connectionPool;
+ this.as400 = as400;
+ }
+
+ @Override
+ public int getMaxConnections() {
+ return this.as400ConnectionPool.getMaxConnections();
+ }
+
+ public long getMaxInactivity() {
+ return this.as400ConnectionPool.getMaxInactivity();
+ }
+
+ public long getMaxLifetime() {
+ return this.as400ConnectionPool.getMaxLifetime();
+ }
+
+ public int getMaxUseCount() {
+ return this.as400ConnectionPool.getMaxUseCount();
+ }
+
+ public long getMaxUseTime() {
+ return this.as400ConnectionPool.getMaxUseTime();
+ }
+
+ public boolean isRunMaintenance() {
+ return this.as400ConnectionPool.isRunMaintenance();
+ }
+
+ public boolean isThreadUsed() {
+ return this.as400ConnectionPool.isThreadUsed();
+ }
+
+ public long getCleanupInterval() {
+ return this.as400ConnectionPool.getCleanupInterval();
+ }
+
+ public boolean isPretestConnections() {
+ return this.as400ConnectionPool.isPretestConnections();
+ }
+
+ @Override
+ public int getActiveConnectionCount() {
+ return this.as400ConnectionPool.getActiveConnectionCount(as400.getSystemName(), as400.getUserId());
+ }
+}
diff --git a/src/main/java/org/wso2/carbon/connector/pcml/PCMLPoolMBean.java b/src/main/java/org/wso2/carbon/connector/pcml/PCMLPoolMBean.java
new file mode 100644
index 0000000..423726a
--- /dev/null
+++ b/src/main/java/org/wso2/carbon/connector/pcml/PCMLPoolMBean.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2024, WSO2 LLC. (http://www.wso2.org) All Rights Reserved.
+ *
+ * WSO2 LLC. 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.wso2.carbon.connector.pcml;
+
+public interface PCMLPoolMBean {
+
+ int getMaxConnections();
+
+ long getMaxInactivity();
+
+ long getMaxLifetime();
+
+ int getMaxUseCount();
+
+ long getMaxUseTime();
+
+ boolean isRunMaintenance();
+
+ boolean isThreadUsed();
+
+ long getCleanupInterval();
+
+ boolean isPretestConnections();
+
+ int getActiveConnectionCount();
+}
diff --git a/src/main/resources/config/init.xml b/src/main/resources/config/init.xml
index 5eef0bf..4169f07 100644
--- a/src/main/resources/config/init.xml
+++ b/src/main/resources/config/init.xml
@@ -18,6 +18,7 @@
-->