diff --git a/pom.xml b/pom.xml index 1df1a91..7ec32e9 100644 --- a/pom.xml +++ b/pom.xml @@ -21,7 +21,7 @@ 4.0.0 org.wso2.carbon.connector org.wso2.carbon.connector.pcml - 1.0.6 + 1.0.7 bundle WSO2 Carbon - PCML Connector For AS400 http://wso2.org @@ -302,7 +302,7 @@ email-library compile - attached + single ${connector.name}-connector-${version} @@ -446,7 +446,7 @@ wso2-nexus WSO2 internal Repository - http://maven.wso2.org/nexus/content/groups/wso2-public/ + https://maven.wso2.org/nexus/content/groups/wso2-public/ true daily @@ -456,7 +456,7 @@ wso2.releases WSO2 internal Repository - http://maven.wso2.org/nexus/content/repositories/releases/ + https://maven.wso2.org/nexus/content/repositories/releases/ true daily @@ -466,7 +466,7 @@ wso2.snapshots Apache Snapshot Repository - http://maven.wso2.org/nexus/content/repositories/snapshots/ + https://maven.wso2.org/nexus/content/repositories/snapshots/ true daily @@ -480,12 +480,12 @@ nexus-releases WSO2 Release Distribution Repository - http://maven.wso2.org/nexus/service/local/staging/deploy/maven2/ + https://maven.wso2.org/nexus/service/local/staging/deploy/maven2/ wso2.snapshots Apache Snapshot Repository - http://maven.wso2.org/nexus/content/repositories/snapshots/ + https://maven.wso2.org/nexus/content/repositories/snapshots/ diff --git a/src/main/java/org/wso2/carbon/connector/pcml/AS400Constants.java b/src/main/java/org/wso2/carbon/connector/pcml/AS400Constants.java index b72b273..3ca1431 100644 --- a/src/main/java/org/wso2/carbon/connector/pcml/AS400Constants.java +++ b/src/main/java/org/wso2/carbon/connector/pcml/AS400Constants.java @@ -74,4 +74,6 @@ public class AS400Constants { // Default log file path. public static final String AS400_DEFAULT_LOG_PATH = CarbonUtils.getCarbonLogsPath() + File.separator + "pcml-connector-logs.log"; + // Parameters for enabling JMX. + public static final String AS400_JMX_ENABLED = "jmxEnabled"; } diff --git a/src/main/java/org/wso2/carbon/connector/pcml/AS400Initialize.java b/src/main/java/org/wso2/carbon/connector/pcml/AS400Initialize.java index 6c3ee8f..80f9c72 100644 --- a/src/main/java/org/wso2/carbon/connector/pcml/AS400Initialize.java +++ b/src/main/java/org/wso2/carbon/connector/pcml/AS400Initialize.java @@ -33,6 +33,13 @@ import java.io.IOException; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import javax.management.MalformedObjectNameException; +import javax.management.ObjectName; +import javax.management.MBeanServer; +import javax.management.InstanceAlreadyExistsException; +import javax.management.MBeanRegistrationException; +import javax.management.NotCompliantMBeanException; +import java.lang.management.ManagementFactory; /** * Creates AS400 instance for PCML connector. Authenticates if user ID and password are provided.

Allows to set @@ -44,6 +51,7 @@ public class AS400Initialize extends AbstractConnector { * node. The connections are stored in the memory. */ private static Map as400ConnectionPoolMap = new ConcurrentHashMap<>(); + private Boolean isJmxEnabled = false; /** * {@inheritDoc}

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 @@ -->