Skip to content

Commit

Permalink
Merge pull request #3 from IsuruMaduranga/main
Browse files Browse the repository at this point in the history
Implement configuration handling for MI
  • Loading branch information
isudana authored Oct 31, 2023
2 parents 8f53f8b + 087a608 commit 26d8bcc
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 4 deletions.
2 changes: 1 addition & 1 deletion counter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<modelVersion>4.0.0</modelVersion>

<groupId>org.wso2.integration.transaction.counter</groupId>
<artifactId>transacton-count-handler</artifactId>
<artifactId>transaction-count-handler</artifactId>
<packaging>bundle</packaging>
<version>1.0.0</version>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,26 @@ public static enum ServerType {

// MI related constants
public static final String MI_CONFIG_CLASS = "org.wso2.config.mapper.ConfigParser";
public static final String MI_CONFIG_ROOT = "integration.transaction_counter";
public static final String MI_SERVER_ID = MI_CONFIG_ROOT + ".server_id";
public static final String MI_PRODUCER_THREAD_POOL_SIZE = MI_CONFIG_ROOT +
".producer_counting_thread_pool_size";
public static final String MI_RECORD_INTERVAL = MI_CONFIG_ROOT
+ ".producer_scheduled_interval";
public static final String MI_MAX_TRANSACTION_COUNT = MI_CONFIG_ROOT +
".max_transaction_count_per_record";
public static final String MI_MIN_TRANSACTION_COUNT = MI_CONFIG_ROOT +
".min_transaction_count_per_record";
public static final String MI_QUEUE_SIZE = MI_CONFIG_ROOT + ".record_queue_size";
public static final String MI_CONSUMER_COMMIT_INTERVAL = MI_CONFIG_ROOT
+ ".publisher_scheduled_interval";
public static final String MI_MAX_TRANSACTION_RECORDS_PER_COMMIT = MI_CONFIG_ROOT
+ ".publisher_max_batch_size";
public static final String MI_MAX_RETRY_COUNT = MI_CONFIG_ROOT + ".publisher_max_retries";
public static final String MI_STORE_CLASS = MI_CONFIG_ROOT + ".store_impl";
public static final String MI_SERVICE = MI_CONFIG_ROOT + ".service_url";
public static final String MI_SERVICE_USERNAME = MI_CONFIG_ROOT
+ ".service_username";
public static final String MI_SERVICE_PASSWORD = MI_CONFIG_ROOT
+ ".service_password";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,102 @@

package org.wso2.integration.transaction.counter.config;

import org.wso2.integration.transaction.counter.TransactionCounterConstants;
import org.wso2.integration.transaction.counter.exception.TransactionCounterConfigurationException;

import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.Objects;

public class MIConfigFetcher implements ConfigFetcher {

private static MIConfigFetcher instance = null;
private static HashMap<String, Object> configMap = new HashMap<>();
private final static HashMap<String, Object> configMap = new HashMap<>();

private MIConfigFetcher() throws TransactionCounterConfigurationException {
// To be implemented
try {
Class<?> configClass = Class.forName(TransactionCounterConstants.MI_CONFIG_CLASS);

@SuppressWarnings("unchecked")
HashMap<String, Object> configs = (HashMap<String, Object>) configClass
.getMethod("getParsedConfigs").invoke(null);

// Reading the config values
String temp;
Long tempLong;

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

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

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());

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());

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());

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());

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());

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());

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());

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());

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

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

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

configMap.put(TransactionCounterConstants.SERVER_ID, SERVER_ID);
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_STORE_CLASS, TRANSACTION_COUNT_STORE_CLASS);
configMap.put(TransactionCounterConstants.TRANSACTION_RECORD_QUEUE_SIZE, TRANSACTION_RECORD_QUEUE_SIZE);
configMap.put(TransactionCounterConstants.PRODUCER_THREAD_POOL_SIZE, PRODUCER_THREAD_POOL_SIZE);
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_RECORD_INTERVAL , TRANSACTION_COUNT_RECORD_INTERVAL);
configMap.put(TransactionCounterConstants.MAX_TRANSACTION_COUNT, MAX_TRANSACTION_COUNT);
configMap.put(TransactionCounterConstants.MIN_TRANSACTION_COUNT, MIN_TRANSACTION_COUNT);
configMap.put(TransactionCounterConstants.CONSUMER_COMMIT_INTERVAL, CONSUMER_COMMIT_INTERVAL);
configMap.put(TransactionCounterConstants.MAX_TRANSACTION_RECORDS_PER_COMMIT, MAX_TRANSACTION_RECORDS_PER_COMMIT);
configMap.put(TransactionCounterConstants.MAX_RETRY_COUNT, MAX_RETRY_COUNT);
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_SERVICE, TRANSACTION_COUNT_SERVICE);
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_SERVICE_USERNAME, TRANSACTION_COUNT_SERVICE_USERNAME);
configMap.put(TransactionCounterConstants.TRANSACTION_COUNT_SERVICE_PASSWORD, TRANSACTION_COUNT_SERVICE_PASSWORD);

} catch (ClassNotFoundException e) {
// This error won't be thrown here because it is already checked in TransactionCountConfig
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
throw new TransactionCounterConfigurationException(e);
} catch (ClassCastException e) {
throw new TransactionCounterConfigurationException("Error while parsing the config", e);
}
}

public static MIConfigFetcher getInstance() throws TransactionCounterConfigurationException {
Expand All @@ -40,6 +125,6 @@ public static MIConfigFetcher getInstance() throws TransactionCounterConfigurati

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

0 comments on commit 26d8bcc

Please sign in to comment.