Initial populations
This commit is contained in:
+187
@@ -0,0 +1,187 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
|
||||
* All rights reserved.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
|
||||
package com.fourelementscapital.scheduler.config;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.Properties;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This class populates the configuration value from property file
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
public class Config {
|
||||
|
||||
|
||||
/**
|
||||
* Ignores authentication for the user
|
||||
*/
|
||||
public static final String CONFIG_IGNORE_AUTH="ignore.authentication";
|
||||
|
||||
/**
|
||||
* Number of maximum thread in Rserve
|
||||
*/
|
||||
public static final String CONFIG_NUMBEROF_RSERVE_THREADS="rserve.thread.size";
|
||||
|
||||
/**
|
||||
* Accepts anonymous users
|
||||
*/
|
||||
public static final String USER_ANONYMOUS="anonymous";
|
||||
|
||||
|
||||
/**
|
||||
* windows server/tomcat peer configuration file
|
||||
*/
|
||||
private static final String BUNDLE_NAME = "com.fe.config_windows"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* unix server/tomcat peer configuration file
|
||||
*/
|
||||
private static final String BUNDLE_NAME_UNIX = "com.fe.config_unix"; //$NON-NLS-1$
|
||||
|
||||
|
||||
/**
|
||||
* windows peer configuration
|
||||
*/
|
||||
private static final String PROPERTY_FILE_WIN = "peer_windows.properties"; //$NON-NLS-1$
|
||||
|
||||
/**
|
||||
* unix peer/server configuration file
|
||||
*/
|
||||
private static final String PROPERTY_FILE_UNIX = "peer_unix.properties"; //$NON-NLS-1$
|
||||
|
||||
|
||||
|
||||
public static String CONFIG_PROPERTY_LOCATION=null;
|
||||
|
||||
|
||||
/**
|
||||
* ignore p2p multicasting
|
||||
*/
|
||||
public static String P2P_NO_MULTICAST="p2p.nomulticast";
|
||||
|
||||
|
||||
/**
|
||||
* hsql data file property
|
||||
*/
|
||||
public static String HSQLDB_QUEUE_FILE="hsql.queue.datafile";
|
||||
|
||||
private static Properties confpro=null;
|
||||
|
||||
//private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle.getBundle(BUNDLE_NAME);
|
||||
|
||||
private Config() {
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the property value of specified key.
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getString(String key) {
|
||||
|
||||
|
||||
if(CONFIG_PROPERTY_LOCATION==null){
|
||||
try {
|
||||
//return RESOURCE_BUNDLE.getString(key);
|
||||
return getResourceBuddle().getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return '!' + key + '!';
|
||||
}
|
||||
}else{
|
||||
try {
|
||||
String ky= getPeerProperty(key);
|
||||
if(ky==null) throw new Exception();
|
||||
else return ky;
|
||||
} catch (Exception e) {
|
||||
return '!' + key + '!';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns the property value of specified key.
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static String getValue(String key) {
|
||||
|
||||
if(CONFIG_PROPERTY_LOCATION==null){
|
||||
try {
|
||||
|
||||
return getResourceBuddle().getString(key);
|
||||
} catch (MissingResourceException e) {
|
||||
return null;
|
||||
}
|
||||
}else{
|
||||
try {
|
||||
return getPeerProperty(key);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private static ResourceBundle resourceBundle=null;
|
||||
|
||||
private synchronized static ResourceBundle getResourceBuddle(){
|
||||
|
||||
if(resourceBundle==null){
|
||||
String os="win";
|
||||
resourceBundle= ResourceBundle.getBundle(BUNDLE_NAME); //windows
|
||||
if(System.getProperty("os.name").toLowerCase().equals("freebsd")) {
|
||||
resourceBundle=ResourceBundle.getBundle(BUNDLE_NAME_UNIX);
|
||||
os="freebsd";
|
||||
}
|
||||
if(System.getProperty("os.name").toLowerCase().contains("linux")) {
|
||||
resourceBundle=ResourceBundle.getBundle(BUNDLE_NAME_UNIX);
|
||||
os="linux";
|
||||
}
|
||||
LogManager.getLogger(Config.class.getName()).info("resourceBundle:"+resourceBundle+" os:"+os);
|
||||
}
|
||||
return resourceBundle;
|
||||
}
|
||||
|
||||
|
||||
private static String getPeerProperty(String key) throws Exception {
|
||||
try{
|
||||
if(confpro==null){
|
||||
String propertyfilename=PROPERTY_FILE_WIN;
|
||||
if(System.getProperty("os.name").toLowerCase().equals("freebsd"))
|
||||
propertyfilename=PROPERTY_FILE_UNIX;
|
||||
|
||||
if(System.getProperty("os.name").toLowerCase().contains("linux"))
|
||||
propertyfilename=PROPERTY_FILE_UNIX;
|
||||
|
||||
String folder=CONFIG_PROPERTY_LOCATION;
|
||||
folder=folder.endsWith(File.separator)?folder:folder+File.separator;
|
||||
confpro=new Properties();
|
||||
String filename=folder+"conf"+File.separator+propertyfilename;
|
||||
confpro.load(new FileInputStream(filename));
|
||||
}
|
||||
return confpro.getProperty(key);
|
||||
}catch(Exception e){
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+153
@@ -0,0 +1,153 @@
|
||||
/******************************************************************************
|
||||
*
|
||||
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
|
||||
* All rights reserved.
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
package com.fourelementscapital.scheduler.error;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
import com.fourelementscapital.scheduler.config.Config;
|
||||
|
||||
/**
|
||||
* This class handles error logging of the system.
|
||||
* <br>
|
||||
* <pre>
|
||||
* property to configure the folder "log_error_folder"
|
||||
* and also property that sends error log into console if a config property "log_error_to_console" is set to "yes"
|
||||
* </pre>
|
||||
* @author Rams Kannan
|
||||
*
|
||||
*/
|
||||
public class ClientError {
|
||||
|
||||
|
||||
private static String nextLineChar="\r\n";
|
||||
|
||||
/**
|
||||
* This method wil be invoked when there was error and the error log will be sent to an external file.
|
||||
* One log file per day will be created in this
|
||||
* <pre>
|
||||
* property to configure the folder "log_error_folder"
|
||||
* and also property that sends error log into console if a config property "log_error_to_console" is set to "yes"
|
||||
* </pre>
|
||||
* @param ex
|
||||
* @param msg
|
||||
*/
|
||||
public static void reportError(Exception ex, String msg){
|
||||
|
||||
|
||||
msg=(msg==null)?"":msg;
|
||||
|
||||
String root=Config.getString("log_error_folder");
|
||||
|
||||
Date d = new Date();
|
||||
String folder =root+"errorlogs";
|
||||
if (!new File(folder).isDirectory()) {
|
||||
new File(folder).mkdirs();
|
||||
}
|
||||
String fname=root+"errorlogs"+File.separator+"error"+new SimpleDateFormat("dd_MM_yyyy").format(d)+".log";
|
||||
File file=new File(fname);
|
||||
|
||||
try {
|
||||
boolean append = true;
|
||||
FileWriter fw = new FileWriter(file,append);
|
||||
|
||||
|
||||
SimpleDateFormat sd=new SimpleDateFormat("dd-MM-yyy h:mm:ss a");
|
||||
String logmessage="-------- "+sd.format(new Date())+" ------"+
|
||||
nextLineChar+collectErrorStack(ex,msg)+"***********************"+nextLineChar;
|
||||
|
||||
|
||||
|
||||
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
fw.append(logmessage+nextLineChar+" "+nextLineChar);
|
||||
fw.flush();
|
||||
fw.close();
|
||||
|
||||
|
||||
String consoleoutput=Config.getString("log_error_to_console");
|
||||
|
||||
if(consoleoutput!=null && consoleoutput.equalsIgnoreCase("yes")){
|
||||
System.out.println(logmessage);
|
||||
}
|
||||
//
|
||||
}
|
||||
catch (Exception ex1) {
|
||||
ex1.printStackTrace();
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private static String collectErrorStack(Exception ex,String msg) throws Exception {
|
||||
StackTraceElement[] stacks=ex.getStackTrace();
|
||||
String rtn="";
|
||||
if(msg!=null) rtn+=msg.trim()+nextLineChar;
|
||||
rtn+="ERROR MSG:"+ex.getMessage()+nextLineChar;
|
||||
int startat=0;
|
||||
for(int i=0;i<stacks.length;i++){
|
||||
if(stacks[i].getClassName().startsWith("com.fe.")){
|
||||
startat=i;
|
||||
}
|
||||
}
|
||||
int numbefore=4;
|
||||
startat=(startat>numbefore)?startat-numbefore:0;
|
||||
int counter=1;
|
||||
|
||||
|
||||
|
||||
String consoleoutputfull=Config.getString("log_error_to_console_full");
|
||||
|
||||
if(consoleoutputfull!=null && consoleoutputfull.equalsIgnoreCase("yes")){
|
||||
for(int i=startat;i<stacks.length;i++){
|
||||
//if((i>(startat+numbefore)) && !stacks[i].getClassName().startsWith("com.fe.")){
|
||||
|
||||
//}else{
|
||||
String space=" ";
|
||||
//for(int ab=0;ab<counter;ab++) space+=" "; counter++;
|
||||
if(stacks[i].getClassName().startsWith("com.fe.")){
|
||||
rtn+="->"+stacks[i].getClassName()+"."+stacks[i].getMethodName()+"()"+nextLineChar;;
|
||||
}else{
|
||||
rtn+=space+""+stacks[i].getClassName()+"."+stacks[i].getMethodName()+"()"+nextLineChar;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
}else{
|
||||
|
||||
for(int i=startat;i<stacks.length;i++){
|
||||
if((i>(startat+numbefore)) && !stacks[i].getClassName().startsWith("com.fe.")){
|
||||
|
||||
}else{
|
||||
String space="";
|
||||
for(int ab=0;ab<counter;ab++) space+=" "; counter++;
|
||||
if(stacks[i].getClassName().startsWith("com.fe.")){
|
||||
space+="->";
|
||||
}
|
||||
rtn+=space+""+stacks[i].getClassName()+"."+stacks[i].getMethodName()+"()"+nextLineChar;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return rtn;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user