Skip to content

Commit

Permalink
Merge pull request #27 from SanojPunchihewa/1.x.x
Browse files Browse the repository at this point in the history
[1.x.x] Adding JMX functionalities to the AS400 PCML Connector
  • Loading branch information
SanojPunchihewa authored Jan 29, 2024
2 parents 293eccd + 7118dd0 commit 6b22547
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.wso2.carbon.connector</groupId>
<artifactId>org.wso2.carbon.connector.pcml</artifactId>
<version>1.0.6</version>
<version>1.0.7</version>
<packaging>bundle</packaging>
<name>WSO2 Carbon - PCML Connector For AS400</name>
<url>http://wso2.org</url>
Expand Down Expand Up @@ -302,7 +302,7 @@
<id>email-library</id>
<phase>compile</phase>
<goals>
<goal>attached</goal>
<goal>single</goal>
</goals>
<configuration>
<finalName>${connector.name}-connector-${version}</finalName>
Expand Down Expand Up @@ -446,7 +446,7 @@
<repository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<url>https://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
Expand All @@ -456,7 +456,7 @@
<repository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/releases/</url>
<url>https://maven.wso2.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
Expand All @@ -466,7 +466,7 @@
<repository>
<id>wso2.snapshots</id>
<name>Apache Snapshot Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
<url>https://maven.wso2.org/nexus/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
Expand All @@ -480,12 +480,12 @@
<repository>
<id>nexus-releases</id>
<name>WSO2 Release Distribution Repository</name>
<url>http://maven.wso2.org/nexus/service/local/staging/deploy/maven2/</url>
<url>https://maven.wso2.org/nexus/service/local/staging/deploy/maven2/</url>
</repository>
<snapshotRepository>
<id>wso2.snapshots</id>
<name>Apache Snapshot Repository</name>
<url>http://maven.wso2.org/nexus/content/repositories/snapshots/</url>
<url>https://maven.wso2.org/nexus/content/repositories/snapshots/</url>
</snapshotRepository>
</distributionManagement>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
25 changes: 25 additions & 0 deletions src/main/java/org/wso2/carbon/connector/pcml/AS400Initialize.java
Original file line number Diff line number Diff line change
Expand Up @@ -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. <p> Allows to set
Expand All @@ -44,6 +51,7 @@ public class AS400Initialize extends AbstractConnector {
* node. The connections are stored in the memory.
*/
private static Map<String, AS400ConnectionPool> as400ConnectionPoolMap = new ConcurrentHashMap<>();
private Boolean isJmxEnabled = false;

/**
* {@inheritDoc} <p> Creates an AS400 instance and store it in the message context as {@link
Expand Down Expand Up @@ -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);
Expand Down
85 changes: 85 additions & 0 deletions src/main/java/org/wso2/carbon/connector/pcml/PCMLPool.java
Original file line number Diff line number Diff line change
@@ -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());
}
}
42 changes: 42 additions & 0 deletions src/main/java/org/wso2/carbon/connector/pcml/PCMLPoolMBean.java
Original file line number Diff line number Diff line change
@@ -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();
}
1 change: 1 addition & 0 deletions src/main/resources/config/init.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
-->
<template name="init" onError="fault" xmlns="http://ws.apache.org/ns/synapse">
<parameter name="systemName" description="The system name or hostname of the AS400 system."/>
<parameter name="jmxEnabled" description="jmx flag"/>
<parameter name="userID" description="The user ID for the AS400 system"/>
<parameter name="password" description="The password for the AS400 system"/>
<!--Connection Pool Properties-->
Expand Down

0 comments on commit 6b22547

Please sign in to comment.