Skip to content

Commit

Permalink
Merge pull request #15 from IsuruMaduranga/main
Browse files Browse the repository at this point in the history
Set default values for configuration params
  • Loading branch information
isudana authored Dec 8, 2023
2 parents 6e4776e + 503e436 commit 8e2ef8a
Show file tree
Hide file tree
Showing 7 changed files with 190 additions and 197 deletions.
62 changes: 54 additions & 8 deletions counter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.wso2.integration.transaction.counter</groupId>
<artifactId>transaction-counter</artifactId>
<version>1.0.0</version>
</parent>

<groupId>org.wso2.integration.transaction.counter</groupId>
<version>1.0.0</version>
<artifactId>transaction-count-handler</artifactId>
<packaging>bundle</packaging>
<name>WSO2 Integration Transaction Counting Handler</name>
Expand Down Expand Up @@ -56,6 +52,57 @@
</dependency>
</dependencies>

<scm>
<connection>scm:git:https://github.com/wso2/integration-transaction-counter.git</connection>
<developerConnection>scm:git:https://github.com/wso2/integration-transaction-counter.git</developerConnection>
<url>https://github.com/wso2/integration-transaction-counter.git/</url>
<tag>HEAD</tag>
</scm>

<profiles>
<profile>
<id>deploy</id>
</profile>
</profiles>

<repositories>
<repository>
<id>wso2-nexus</id>
<name>WSO2 internal Repository</name>
<url>https://maven.wso2.org/nexus/content/groups/wso2-public/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
<repository>
<id>wso2.releases</id>
<name>WSO2 internal Repository</name>
<url>https://maven.wso2.org/nexus/content/repositories/releases/</url>
<releases>
<enabled>true</enabled>
<updatePolicy>daily</updatePolicy>
<checksumPolicy>ignore</checksumPolicy>
</releases>
</repository>
</repositories>

<distributionManagement>
<repository>
<id>wso2.releases</id>
<name>WSO2 Releases Repository</name>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
<url>https://maven.wso2.org/nexus/content/repositories/releases/</url>
<layout>default</layout>
</repository>
</distributionManagement>

<build>
<plugins>
<plugin>
Expand All @@ -72,8 +119,7 @@
org.wso2.integration.transaction.counter.*,
</Export-Package>
<Import-Package>
org.apache.synapse.core,
*;resolution:=optional
org.apache.synapse.core, *;resolution:=optional
</Import-Package>
</instructions>
</configuration>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,20 @@ public static enum ServerType {
+ ".service_username";
public static final String MI_SERVICE_PASSWORD = MI_CONFIG_ROOT
+ ".service_password";

// Default values
public static final String DEFAULT_SERVER_ID = "default";
public static final String DEFAULT_TRANSACTION_COUNT_STORE_CLASS =
"org.wso2.integration.transaction.counter.store.TransactionRecordStoreImpl";
public static final int DEFAULT_TRANSACTION_RECORD_QUEUE_SIZE = 1000;
public static final int DEFAULT_PRODUCER_THREAD_POOL_SIZE = 10;
public static final int DEFAULT_TRANSACTION_COUNT_RECORD_INTERVAL = 10;
public static final double DEFAULT_MAX_TRANSACTION_COUNT = 20;
public static final double DEFAULT_MIN_TRANSACTION_COUNT = 5;
public static final int DEFAULT_CONSUMER_COMMIT_INTERVAL = 10;
public static final int DEFAULT_MAX_TRANSACTION_RECORDS_PER_COMMIT = 100;
public static final int DEFAULT_MAX_RETRY_COUNT = 3;
public static final String DEFAULT_TRANSACTION_COUNT_SERVICE = "https://localhost:8080/transactions/records";
public static final String DEFAULT_TRANSACTION_COUNT_SERVICE_USERNAME = "admin";
public static final String DEFAULT_TRANSACTION_COUNT_SERVICE_PASSWORD = "admin";
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Objects;

public class APIMConfigFetcher implements ConfigFetcher {

Expand All @@ -48,67 +47,79 @@ private APIMConfigFetcher() throws TransactionCounterConfigurationException {

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_SERVER_ID);
String SERVER_ID = Objects.requireNonNull( temp, "Server ID cannot be null");
String SERVER_ID = temp;

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_STORE_CLASS);
String TRANSACTION_COUNT_STORE_CLASS = Objects.requireNonNull(
temp, "Transaction count store class cannot be null");
String TRANSACTION_COUNT_STORE_CLASS = temp;

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_QUEUE_SIZE);
temp = Objects.requireNonNull(temp, "Transaction record queue size cannot be null");
Integer TRANSACTION_RECORD_QUEUE_SIZE = Integer.parseInt(temp);
Integer TRANSACTION_RECORD_QUEUE_SIZE = null;
if (temp != null) {
TRANSACTION_RECORD_QUEUE_SIZE = Integer.parseInt(temp);
}

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_PRODUCER_THREAD_POOL_SIZE);
temp = Objects.requireNonNull(temp, "Producer thread pool size cannot be null");
Integer PRODUCER_THREAD_POOL_SIZE = Integer.parseInt(temp);
Integer PRODUCER_THREAD_POOL_SIZE = null;
if (temp != null) {
PRODUCER_THREAD_POOL_SIZE = Integer.parseInt(temp);
}

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_RECORD_INTERVAL);
temp = Objects.requireNonNull(temp, "Transaction count record interval cannot be null");
Integer TRANSACTION_COUNT_RECORD_INTERVAL = Integer.parseInt(temp);
Integer TRANSACTION_COUNT_RECORD_INTERVAL = null;
if (temp != null) {
TRANSACTION_COUNT_RECORD_INTERVAL = Integer.parseInt(temp);
}

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_MAX_TRANSACTION_COUNT);
temp = Objects.requireNonNull(temp, "Max transaction count cannot be null");
Double MAX_TRANSACTION_COUNT = Double.parseDouble(temp);
Double MAX_TRANSACTION_COUNT = null;
if (temp != null) {
MAX_TRANSACTION_COUNT = Double.parseDouble(temp);
}

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_MIN_TRANSACTION_COUNT);
temp = Objects.requireNonNull(temp, "Min transaction count cannot be null");
Double MIN_TRANSACTION_COUNT = Double.parseDouble(temp);
Double MIN_TRANSACTION_COUNT = null;
if (temp != null) {
MIN_TRANSACTION_COUNT = Double.parseDouble(temp);
}

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_CONSUMER_COMMIT_INTERVAL);
temp = Objects.requireNonNull(temp, "Consumer commit interval cannot be null");
Integer CONSUMER_COMMIT_INTERVAL = Integer.parseInt(temp);
Integer CONSUMER_COMMIT_INTERVAL = null;
if (temp != null) {
CONSUMER_COMMIT_INTERVAL = Integer.parseInt(temp);
}

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_MAX_TRANSACTION_RECORDS_PER_COMMIT);
temp = Objects.requireNonNull(temp, "Max transaction records per commit cannot be null");
Integer MAX_TRANSACTION_RECORDS_PER_COMMIT = Integer.parseInt(temp);
Integer MAX_TRANSACTION_RECORDS_PER_COMMIT = null;
if (temp != null) {
MAX_TRANSACTION_RECORDS_PER_COMMIT = Integer.parseInt(temp);
}

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_MAX_RETRY_COUNT);
temp = Objects.requireNonNull(temp, "Max retry count cannot be null");
Integer MAX_RETRY_COUNT = Integer.parseInt(temp);
Integer MAX_RETRY_COUNT = null;
if (temp != null) {
MAX_RETRY_COUNT = Integer.parseInt(temp);
}

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_SERVICE);
String TRANSACTION_COUNT_SERVICE = Objects.requireNonNull(temp,
"Transaction count service cannot be null");
String TRANSACTION_COUNT_SERVICE = temp;

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_SERVICE_USERNAME);
String TRANSACTION_COUNT_SERVICE_USERNAME = Objects.requireNonNull(temp,
"Transaction count service username cannot be null");
String TRANSACTION_COUNT_SERVICE_USERNAME = temp;

temp = (String) getFirstProperty.invoke(apiManagerConfiguration,
TransactionCounterConstants.GATEWAY_SERVICE_PASSWORD);
String TRANSACTION_COUNT_SERVICE_PASSWORD = Objects.requireNonNull(temp,
"Transaction count service password cannot be null");
String TRANSACTION_COUNT_SERVICE_PASSWORD = temp;

configMap.put(TransactionCounterConstants.SERVER_ID, SERVER_ID);
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_STORE_CLASS, TRANSACTION_COUNT_STORE_CLASS);
Expand Down Expand Up @@ -142,6 +153,9 @@ public static ConfigFetcher getInstance() throws TransactionCounterConfiguration

@Override
public String getConfigValue(String key) {
if (configMap.get(key) == null) {
return null;
}
return configMap.get(key).toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,55 +43,67 @@ private MIConfigFetcher() throws TransactionCounterConfigurationException {
Long tempLong;

temp = (String) configs.get(TransactionCounterConstants.MI_SERVER_ID);
String SERVER_ID = Objects.requireNonNull( temp, "Server ID cannot be null");
String SERVER_ID = temp;

temp = (String) configs.get(TransactionCounterConstants.MI_STORE_CLASS);
String TRANSACTION_COUNT_STORE_CLASS = Objects.requireNonNull(temp,
"Transaction count store class cannot be null");
String TRANSACTION_COUNT_STORE_CLASS = temp;

tempLong = (Long) configs.get(TransactionCounterConstants.MI_QUEUE_SIZE);
Objects.requireNonNull(tempLong, "Transaction record queue size cannot be null");
Integer TRANSACTION_RECORD_QUEUE_SIZE = Integer.parseInt(tempLong.toString());
Integer TRANSACTION_RECORD_QUEUE_SIZE = null;
if (tempLong != null) {
TRANSACTION_RECORD_QUEUE_SIZE = Integer.parseInt(tempLong.toString());
}

tempLong = (Long) configs.get(TransactionCounterConstants.MI_PRODUCER_THREAD_POOL_SIZE);
Objects.requireNonNull(tempLong, "Producer thread pool size cannot be null");
Integer PRODUCER_THREAD_POOL_SIZE = Integer.parseInt(tempLong.toString());
Integer PRODUCER_THREAD_POOL_SIZE = null;
if (tempLong != null) {
PRODUCER_THREAD_POOL_SIZE = Integer.parseInt(tempLong.toString());
}

tempLong = (Long) configs.get(TransactionCounterConstants.MI_RECORD_INTERVAL);
Objects.requireNonNull(tempLong, "Transaction count record interval cannot be null");
Integer TRANSACTION_COUNT_RECORD_INTERVAL = Integer.parseInt(tempLong.toString());
Integer TRANSACTION_COUNT_RECORD_INTERVAL = null;
if (tempLong != null) {
TRANSACTION_COUNT_RECORD_INTERVAL = Integer.parseInt(tempLong.toString());
}

tempLong = (Long) configs.get(TransactionCounterConstants.MI_MAX_TRANSACTION_COUNT);
Objects.requireNonNull(tempLong, "Max transaction count cannot be null");
Double MAX_TRANSACTION_COUNT = Double.parseDouble(tempLong.toString());
Double MAX_TRANSACTION_COUNT = null;
if (tempLong != null) {
MAX_TRANSACTION_COUNT = Double.parseDouble(tempLong.toString());
}

tempLong = (Long) configs.get(TransactionCounterConstants.MI_MIN_TRANSACTION_COUNT);
Objects.requireNonNull(tempLong, "Min transaction count cannot be null");
Double MIN_TRANSACTION_COUNT = Double.parseDouble(tempLong.toString());
Double MIN_TRANSACTION_COUNT = null;
if (tempLong != null) {
MIN_TRANSACTION_COUNT = Double.parseDouble(tempLong.toString());
}

tempLong = (Long) configs.get(TransactionCounterConstants.MI_CONSUMER_COMMIT_INTERVAL);
Objects.requireNonNull(tempLong, "Consumer commit interval cannot be null");
Integer CONSUMER_COMMIT_INTERVAL = Integer.parseInt(tempLong.toString());
Integer CONSUMER_COMMIT_INTERVAL = null;
if (tempLong != null) {
CONSUMER_COMMIT_INTERVAL = Integer.parseInt(tempLong.toString());
}

tempLong = (Long) configs.get(TransactionCounterConstants.MI_MAX_TRANSACTION_RECORDS_PER_COMMIT);
Objects.requireNonNull(tempLong, "Max transaction records per commit cannot be null");
Integer MAX_TRANSACTION_RECORDS_PER_COMMIT = Integer.parseInt(tempLong.toString());
Integer MAX_TRANSACTION_RECORDS_PER_COMMIT = null;
if (tempLong != null) {
MAX_TRANSACTION_RECORDS_PER_COMMIT = Integer.parseInt(tempLong.toString());
}

tempLong = (Long) configs.get(TransactionCounterConstants.MI_MAX_RETRY_COUNT);
Objects.requireNonNull(tempLong, "Max retry count cannot be null");
Integer MAX_RETRY_COUNT = Integer.parseInt(tempLong.toString());
Integer MAX_RETRY_COUNT = null;
if (tempLong != null) {
MAX_RETRY_COUNT = Integer.parseInt(tempLong.toString());
}

temp = (String) configs.get(TransactionCounterConstants.MI_SERVICE);
String TRANSACTION_COUNT_SERVICE = Objects.requireNonNull(temp,
"Transaction count service cannot be null");
String TRANSACTION_COUNT_SERVICE = temp;

temp = (String) configs.get(TransactionCounterConstants.MI_SERVICE_USERNAME);
String TRANSACTION_COUNT_SERVICE_USERNAME = Objects.requireNonNull(temp,
"Transaction count service username cannot be null");
String TRANSACTION_COUNT_SERVICE_USERNAME = temp;

temp = (String) configs.get(TransactionCounterConstants.MI_SERVICE_PASSWORD);
String TRANSACTION_COUNT_SERVICE_PASSWORD = Objects.requireNonNull(temp,
"Transaction count service password cannot be null");
String TRANSACTION_COUNT_SERVICE_PASSWORD = temp;

configMap.put(TransactionCounterConstants.SERVER_ID, SERVER_ID);
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_STORE_CLASS, TRANSACTION_COUNT_STORE_CLASS);
Expand Down Expand Up @@ -125,6 +137,9 @@ public static MIConfigFetcher getInstance() throws TransactionCounterConfigurati

@Override
public String getConfigValue(String key) {
if (configMap.get(key) == null) {
return null;
}
return configMap.get(key).toString();
}
}
Loading

0 comments on commit 8e2ef8a

Please sign in to comment.