Browse Source

Initial populations

master^2
Bernarto P Tjahjono 3 years ago
parent
commit
bee21d279a
  1. 4
      .gitignore
  2. 157
      deployment_scripts/deployPeer.sh
  3. 136
      deployment_scripts/deployServer.sh
  4. 68
      deployment_scripts/revertPeer.sh
  5. 65
      deployment_scripts/revertServer.sh
  6. BIN
      project/bldb/lib/blpapi3.jar
  7. BIN
      project/bldb/lib/classmexer.jar
  8. BIN
      project/bldb/lib/cobra.jar
  9. BIN
      project/bldb/lib/jcs-1.3.3.1-RC.jar
  10. BIN
      project/bldb/lib/js-14.jar
  11. 502
      project/bldb/pom.xml
  12. 399
      project/bldb/src/main/java/com/fe/client/AbstractTeamOrgMgmt.java
  13. 545
      project/bldb/src/main/java/com/fe/client/AdminMgmt.java
  14. 222
      project/bldb/src/main/java/com/fe/client/Authenticated.java
  15. 247
      project/bldb/src/main/java/com/fe/client/ExecuteRMgmt.java
  16. 110
      project/bldb/src/main/java/com/fe/client/IExecAccessMgmt.java
  17. 1405
      project/bldb/src/main/java/com/fe/client/IExecMgmt.java
  18. 248
      project/bldb/src/main/java/com/fe/client/JspXHRRequest.java
  19. 226
      project/bldb/src/main/java/com/fe/client/LoginMgmt.java
  20. 96
      project/bldb/src/main/java/com/fe/client/MenuMgmt.java
  21. 2743
      project/bldb/src/main/java/com/fe/client/RFunctionMgmt.java
  22. 1041
      project/bldb/src/main/java/com/fe/client/SchedulerAPIServlet.java
  23. 4252
      project/bldb/src/main/java/com/fe/client/SchedulerMgmt.java
  24. 81
      project/bldb/src/main/java/com/fe/client/SchedulerReportClient.java
  25. 21
      project/bldb/src/main/java/com/fe/common/Constant.java
  26. 125
      project/bldb/src/main/java/com/fe/io/peer/PeerClient.java
  27. 72
      project/bldb/src/main/java/com/fe/io/server/ServerScheduler.java
  28. 60
      project/bldb/src/main/java/com/fe/lucene/FundamentalTickersCollector.java
  29. 252
      project/bldb/src/main/java/com/fe/lucene/LuceneCrawler.java
  30. 62
      project/bldb/src/main/java/com/fe/lucene/MarketCommodityCollector.java
  31. 76
      project/bldb/src/main/java/com/fe/lucene/MarketContractCollector.java
  32. 77
      project/bldb/src/main/java/com/fe/lucene/MarketSecurityCollector.java
  33. 79
      project/bldb/src/main/java/com/fe/lucene/MyIndexer.java
  34. 43
      project/bldb/src/main/java/com/fe/lucene/RecordDocument.java
  35. 45
      project/bldb/src/main/java/com/fe/lucene/SchedulerTokenCollector.java
  36. 258
      project/bldb/src/main/java/com/fe/lucene/SearchSession.java
  37. 96
      project/bldb/src/main/java/com/fe/lucene/SearchTokenCollector.java
  38. 55
      project/bldb/src/main/java/com/fe/lucene/TickerIndexRecord.java
  39. 55
      project/bldb/src/main/java/com/fe/lucene/TokenCollectorFactory.java
  40. 604
      project/bldb/src/main/java/com/fe/p2p/P2PServiceServlet.java
  41. BIN
      project/bldb/src/main/java/com/fe/p2p/peerbusy.gif
  42. 148
      project/bldb/src/main/java/com/fe/p2p/websocket/TomcatWSExecuteRService.java
  43. 86
      project/bldb/src/main/java/com/fe/p2p/websocket/cmd/Queue.java
  44. 164
      project/bldb/src/main/java/com/fe/scheduler/SchedulerInitServlet.java
  45. 166
      project/bldb/src/main/java/com/fe/scheduler/TemplateParser.java
  46. 28
      project/bldb/src/main/java/com/fe/scheduler/TestJob.java
  47. 1771
      project/bldb/src/main/java/com/fe/scheduler/balance/LoadBalancingLinkedQueue.java
  48. 4
      project/bldb/src/main/java/com/fe/scheduler/logmessages.properties
  49. 24
      project/bldb/src/main/java/com/fe/scheduler/scheduleralert.properties
  50. 94
      project/bldb/src/main/java/com/fe/servlet/AceModeRSyntax.java
  51. 151
      project/bldb/src/main/java/com/fe/servlet/FileUploader.java
  52. 157
      project/bldb/src/main/java/com/fe/servlet/P2PServletContextListener.java
  53. 101
      project/bldb/src/main/java/com/fe/servlet/RSyntaxServlet.java
  54. 54
      project/bldb/src/main/java/com/fe/svn/LogEntryHandler.java
  55. 63
      project/bldb/src/main/java/com/fe/svn/SVNDiffPush.java
  56. 32
      project/bldb/src/main/java/com/fe/svn/SVNIExecXML.java
  57. 30
      project/bldb/src/main/java/com/fe/svn/SVNSchedulerCommitInfo.java
  58. 398
      project/bldb/src/main/java/com/fe/svn/SVNSync.java
  59. 35
      project/bldb/src/main/java/com/fe/svn/SVNSync4RFunction.java
  60. 569
      project/bldb/src/main/java/com/fe/svn/SVNSyncFile.java
  61. 82
      project/bldb/src/main/java/com/fe/util/ImageLoader.java
  62. 55
      project/bldb/src/main/java/com/fe/util/PasswordService.java
  63. 59
      project/bldb/src/main/java/com/fe/util/ProxifyURL.java
  64. 139
      project/bldb/src/main/java/com/fe/util/RestartTomcat.java
  65. 35
      project/bldb/src/main/java/com/fe/util/StringPlaceHolder4ChildStrategy.java
  66. 335
      project/bldb/src/main/java/com/fe/util/WikiRFunctionManual.java
  67. 37
      project/bldb/src/main/resources/cache.ccf
  68. 23
      project/bldb/src/main/resources/com/fe/client/function_modified_alert.txt
  69. 24
      project/bldb/src/main/resources/com/fe/client/scheduler_modified_alert.txt
  70. 86
      project/bldb/src/main/resources/com/fe/config_unix.properties
  71. 98
      project/bldb/src/main/resources/com/fe/config_windows.properties
  72. 16
      project/bldb/src/main/resources/com/fe/p2p/pgadv.xml
  73. 4
      project/bldb/src/main/resources/com/fe/scheduler/logmessages.properties
  74. 15
      project/bldb/src/main/resources/com/fe/strategy_new_template.xml
  75. 47
      project/bldb/src/main/resources/com/fe/xml/mapping.xml
  76. 12
      project/bldb/src/main/resources/config_alarm.properties
  77. 7
      project/bldb/src/main/resources/config_auth.properties
  78. 2
      project/bldb/src/main/resources/config_db.properties
  79. 11
      project/bldb/src/main/resources/log4j.properties
  80. 40
      project/bldb/src/main/resources/log4j2.xml
  81. 78
      project/bldb/src/main/resources/quartz.properties
  82. 36
      project/bldb/src/main/resources/quartz_jobs.xml
  83. 24
      project/bldb/src/main/resources/scheduler_modified_alert.txt
  84. 25
      project/bldb/src/main/webapp/RELEASE-NOTES.txt
  85. 51
      project/bldb/src/main/webapp/WEB-INF/dwr.xml
  86. 97
      project/bldb/src/main/webapp/WEB-INF/urlrewrite.xml
  87. 168
      project/bldb/src/main/webapp/WEB-INF/web.xml
  88. 1
      project/bldb/src/main/webapp/ace/.git-ref
  89. 156
      project/bldb/src/main/webapp/ace/ChangeLog.txt
  90. 24
      project/bldb/src/main/webapp/ace/LICENSE
  91. 21
      project/bldb/src/main/webapp/ace/README.md
  92. BIN
      project/bldb/src/main/webapp/ace/demo/kitchen-sink/logo.png
  93. 47
      project/bldb/src/main/webapp/ace/demo/kitchen-sink/styles.css
  94. 39
      project/bldb/src/main/webapp/ace/editor.html
  95. 268
      project/bldb/src/main/webapp/ace/kitchen-sink-req.html
  96. 287
      project/bldb/src/main/webapp/ace/kitchen-sink.html
  97. 3442
      project/bldb/src/main/webapp/ace/kitchen-sink/demo.js
  98. 6040
      project/bldb/src/main/webapp/ace/kitchen-sink/docs/AsciiDoc.asciidoc
  99. 1544
      project/bldb/src/main/webapp/ace/kitchen-sink/docs/AsciiDoc.html
  100. 17
      project/bldb/src/main/webapp/ace/kitchen-sink/docs/Haxe.hx
  101. Some files were not shown because too many files have changed in this diff Show More

4
.gitignore vendored

@ -9,3 +9,7 @@ buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar
.settings
.classpath
.project
bin/

157
deployment_scripts/deployPeer.sh

@ -0,0 +1,157 @@
#******************************************************************************
#
# Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
# All rights reserved.
#
#******************************************************************************
#!/bin/bash
#Check these params value first :
P2PSERVER_PATH="/4EUtils/p2pserver"
STOP_COMMAND="stopPeer.sh"
START_COMMAND="startPeer.sh"
ERROR_LOG_PATH=$P2PSERVER_PATH"/logs"
P2P_PARENT_FOLDER="/4EUtils/"
P2P_PUBLIC_FOLDER="/mnt/public/Infrastructure/Linux_Unix/Current Version/R and Peer Software/Ubuntu_Peer/p2pserver/"
GIT_FOLDER_PATH="/git"
BACKUP_PARENT_PATH="/temp/scheduler_deployment_backup"
GITHUB_REPO_URL="https://4ecapkronos:2016gitcoDE@github.com/FourElementsCapital/Scheduler.git"
echo "*** SCHEDULER PEER DEPLOYMENT START ***"
set -e
if [ $# -lt 1 ]
then
echo "Error argument. Sample : ./deployPeer.sh 2.1.0"
exit 1
fi
v_out=$1
if [ $# -gt 1 ]
then
key="$2"
case $key in
-f|--fresh)
is_fresh="true"
shift # past argument
;;
*)
echo "Error argument. use -f or --fresh"
exit 1
;;
esac
fi
SCHEDULER_REPO_PATH=$GIT_FOLDER_PATH"/Scheduler"
SCHEDULER_RELEASE_PATH=$SCHEDULER_REPO_PATH"/release/"$v_out
BACKUP_PATH=$BACKUP_PARENT_PATH"/"$v_out
#echo "*. Check Scheduler local repository whether it's exist or not"
#if [ -d $SCHEDULER_REPO_PATH ]; then
# echo "Scheduler repo IS EXIST. PULLING from Github.."
# cd $SCHEDULER_REPO_PATH
# git pull $GITHUB_REPO_URL
#else
# echo "Scheduler repo IS NOT EXIST. CLONING from Github.."
# mkdir -p $GIT_FOLDER_PATH
# cd $GIT_FOLDER_PATH
# git clone $GITHUB_REPO_URL
#fi
#chmod -R 777 $GIT_FOLDER_PATH
echo "*. Check Scheduler release path "$SCHEDULER_RELEASE_PATH
cd $SCHEDULER_RELEASE_PATH
if [ "$is_fresh" == "true" ]
then
echo "*. Copy p2pfolder from public drive "
mkdir -p $P2P_PARENT_FOLDER
cp -R "$P2P_PUBLIC_FOLDER" $P2P_PARENT_FOLDER
fi
echo "*. Check Tomcat version and directory"
TOMCAT_7="/tomcat7"
TOMCAT_6="/tomcat6"
VAR_LIB_PATH="/var/lib"
VAR_LOG_PATH="/var/log"
TOMCAT_PATH=$VAR_LIB_PATH$TOMCAT_7
TOMCAT_WEB_PATH=$TOMCAT_PATH"/webapps"
TOMCAT_LOG_PATH=$VAR_LOG_PATH$TOMCAT_7
if [ ! -d $TOMCAT_PATH ]; then
if [ -d $VAR_LIB_PATH$TOMCAT_6 ]; then
TOMCAT_PATH=$VAR_LIB_PATH$TOMCAT_6
TOMCAT_WEB_PATH=$TOMCAT_PATH"/webapps"
TOMCAT_LOG_PATH=$VAR_LOG_PATH$TOMCAT_6
else
echo "Error : Neither tomcat 6 or 7 is installed !!"
exit 1
fi
fi
echo "Tomcat path : "$TOMCAT_PATH
echo "*. Stop Tomcat server"
cd $P2PSERVER_PATH
sh ./$STOP_COMMAND
if [ -z $is_fresh ]
then
echo "*. Create backup folder"
if [ -d $BACKUP_PATH ]
then
echo "ERROR : backup folder '"$BACKUP_PATH"' is already exist ! Please rename or remove it first. Note that it contains the BACKUP COPY of previous deployment."
exit 1
else
mkdir -p $BACKUP_PATH
fi
fi
if [ -z $is_fresh ]
then
echo "*. Backup current scheduler app"
cp -R $TOMCAT_WEB_PATH"/bldb" $BACKUP_PATH
fi
if [ -z $is_fresh ]
then
echo "*. Backup & clear tomcat log"
mkdir $BACKUP_PATH/log_tomcat
if [ "$(ls -A $TOMCAT_LOG_PATH)" ]
then
mv $TOMCAT_LOG_PATH/* $BACKUP_PATH/log_tomcat
fi
fi
if [ -z $is_fresh ]
then
echo "*. Backup & clear error log"
mkdir $BACKUP_PATH/log_error
if [ "$(ls -A $ERROR_LOG_PATH)" ]
then
mv $ERROR_LOG_PATH/* $BACKUP_PATH/log_error
fi
fi
echo "*. Deploy new scheduler app"
if [ -z $is_fresh ]
then
rm -R $TOMCAT_WEB_PATH"/bldb"
fi
cd $SCHEDULER_RELEASE_PATH
unzip -qq bldb.zip -d $TOMCAT_WEB_PATH
echo "*. Copy properties file"
cp -R $SCHEDULER_RELEASE_PATH"/properties/peer_unix/bldb" $TOMCAT_WEB_PATH
echo "*. Set access permission"
chmod -R 777 $TOMCAT_WEB_PATH"/bldb"
echo "*. Start Tomcat server"
cd $P2PSERVER_PATH
sh ./$START_COMMAND
echo "*** DEPLOYMENT SUCCESS ! ***"

136
deployment_scripts/deployServer.sh

@ -0,0 +1,136 @@
#******************************************************************************
#
# Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
# All rights reserved.
#
#******************************************************************************
#!/bin/bash
#Check these params value first :
P2PSERVER_PATH="/home/p2pserver"
STOP_COMMAND="stop.sh"
START_COMMAND="start.sh"
ERROR_LOG_PATH=$P2PSERVER_PATH"/logs"
SVN_PATH=$P2PSERVER_PATH"/4svntemp"
SVN_R_PATH=$P2PSERVER_PATH"/r_function_svntemp"
SVN_IEXEC_PATH=$P2PSERVER_PATH"/iexec_svn"
QUEUE_FILES=$P2PSERVER_PATH"/queue/queue1"
GIT_FOLDER_PATH="/git"
BACKUP_PARENT_PATH="/temp/scheduler_deployment_backup"
GITHUB_REPO_URL="https://4ecapkronos:2016gitcoDE@github.com/FourElementsCapital/Scheduler.git"
echo "*** SCHEDULER SERVER DEPLOYMENT START ***"
set -e
if [ $# -lt 1 ]
then
echo "Error argument. Sample : ./deployServer.sh 2.1.0"
exit 1
fi
v_out=$1
SCHEDULER_REPO_PATH=$GIT_FOLDER_PATH"/Scheduler"
SCHEDULER_RELEASE_PATH=$SCHEDULER_REPO_PATH"/release/"$v_out
BACKUP_PATH=$BACKUP_PARENT_PATH"/"$v_out
#echo "*. Check Scheduler local repository whether it's exist or not"
#if [ -d $SCHEDULER_REPO_PATH ]; then
# echo "Scheduler repo IS EXIST. PULLING from Github.."
# cd $SCHEDULER_REPO_PATH
# git pull $GITHUB_REPO_URL
#else
# echo "Scheduler repo IS NOT EXIST. CLONING from Github.."
# mkdir -p $GIT_FOLDER_PATH
# cd $GIT_FOLDER_PATH
# git clone $GITHUB_REPO_URL
#fi
#chmod -R 777 $GIT_FOLDER_PATH
echo "*. Check Scheduler release path "$SCHEDULER_RELEASE_PATH
cd $SCHEDULER_RELEASE_PATH
echo "*. Check Tomcat version and directory"
TOMCAT_7="/tomcat7"
TOMCAT_6="/tomcat6"
VAR_LIB_PATH="/var/lib"
VAR_LOG_PATH="/var/log"
TOMCAT_PATH=$VAR_LIB_PATH$TOMCAT_7
TOMCAT_WEB_PATH=$TOMCAT_PATH"/webapps"
TOMCAT_LOG_PATH=$VAR_LOG_PATH$TOMCAT_7
if [ ! -d $TOMCAT_PATH ]; then
if [ -d $VAR_LIB_PATH$TOMCAT_6 ]; then
TOMCAT_PATH=$VAR_LIB_PATH$TOMCAT_6
TOMCAT_WEB_PATH=$TOMCAT_PATH"/webapps"
TOMCAT_LOG_PATH=$VAR_LOG_PATH$TOMCAT_6
else
echo "Error : Neither tomcat 6 or 7 is installed !!"
exit 1
fi
fi
echo "Tomcat path : "$TOMCAT_PATH
echo "*. Stop Tomcat server"
cd $P2PSERVER_PATH
sh ./$STOP_COMMAND
echo "*. Create backup folder"
if [ -d $BACKUP_PATH ]
then
echo "ERROR : backup folder '"$BACKUP_PATH"' is already exist ! Please rename or remove it first. Note that it contains the BACKUP COPY of previous deployment."
exit 1
else
mkdir -p $BACKUP_PATH
fi
echo "*. Backup current scheduler app"
cp -R $TOMCAT_WEB_PATH"/bldb" $BACKUP_PATH
echo "*. Backup SVN files"
cp -R $SVN_PATH $BACKUP_PATH/svn
cp -R $SVN_R_PATH $BACKUP_PATH/svn_r
cp -R $SVN_IEXEC_PATH $BACKUP_PATH/svn_iexec
echo "*. Backup & clear tomcat log"
mkdir $BACKUP_PATH/log_tomcat
if [ "$(ls -A $TOMCAT_LOG_PATH)" ]
then
mv $TOMCAT_LOG_PATH/* $BACKUP_PATH/log_tomcat
fi
echo "*. Backup & clear error log"
mkdir $BACKUP_PATH/log_error
if [ "$(ls -A $ERROR_LOG_PATH)" ]
then
mv $ERROR_LOG_PATH/* $BACKUP_PATH/log_error
fi
echo "*. Retain superuser.pwd"
cp $BACKUP_PATH/log_error/superuser.pwd $ERROR_LOG_PATH
chmod 777 $ERROR_LOG_PATH"/superuser.pwd"
echo "*. Backup & clear queue files"
mkdir $BACKUP_PATH/queue
if [ "$(ls $QUEUE_FILES.* 2> /dev/null)" ]
then
mv $QUEUE_FILES.* $BACKUP_PATH/queue
fi
echo "*. Deploy new scheduler app"
rm -R $TOMCAT_WEB_PATH"/bldb"
cd $SCHEDULER_RELEASE_PATH
unzip -qq bldb.zip -d $TOMCAT_WEB_PATH
echo "*. Copy properties file"
cp -R $SCHEDULER_RELEASE_PATH"/properties/server_unix/bldb" $TOMCAT_WEB_PATH
echo "*. Set access permission"
chmod -R 777 $TOMCAT_WEB_PATH"/bldb"
echo "*** DEPLOYMENT SUCCESS ! ***"
echo "*** Please start Scheduler Server manually ! ***"

68
deployment_scripts/revertPeer.sh

@ -0,0 +1,68 @@
#******************************************************************************
#
# Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
# All rights reserved.
#
#******************************************************************************
#!/bin/bash
echo "*** SCHEDULER REVERT START ***"
set -e
if [ $# -lt 1 ]
then
echo "Error argument. Sample : ./revertPeer.sh 2.1.0"
exit 1
fi
v_out=$1
P2PSERVER_PATH="/4EUtils/p2pserver"
START_COMMAND="startPeer.sh"
STOP_COMMAND="stopPeer.sh"
BACKUP_PATH="/temp/scheduler_deployment_backup/"$v_out
echo "*. Check backup path "$BACKUP_PATH
cd $BACKUP_PATH
echo "*. Check Tomcat version and directory"
TOMCAT_7="/tomcat7"
TOMCAT_6="/tomcat6"
VAR_LIB_PATH="/var/lib"
VAR_LOG_PATH="/var/log"
TOMCAT_PATH=$VAR_LIB_PATH$TOMCAT_7
TOMCAT_WEB_PATH=$TOMCAT_PATH"/webapps"
if [ ! -d $TOMCAT_PATH ]; then
if [ -d $VAR_LIB_PATH$TOMCAT_6 ]; then
TOMCAT_PATH=$VAR_LIB_PATH$TOMCAT_6
TOMCAT_WEB_PATH=$TOMCAT_PATH"/webapps"
else
echo "Error : Neither tomcat 6 or 7 is installed !!"
exit 1
fi
fi
echo "Tomcat path : "$TOMCAT_PATH
echo "*. Stop Tomcat server"
cd $P2PSERVER_PATH
sh ./$STOP_COMMAND
echo "*. Remove Scheduler app"
rm -R $TOMCAT_WEB_PATH"/bldb"
echo "*. Copy files from backup"
cp -R $BACKUP_PATH"/bldb" $TOMCAT_WEB_PATH
echo "*. Set access permission"
chmod -R 777 $TOMCAT_WEB_PATH"/bldb"
echo "*. Start Tomcat server"
cd $P2PSERVER_PATH
sh ./$START_COMMAND
echo "*** REVERT SUCCESS ! ***"

65
deployment_scripts/revertServer.sh

@ -0,0 +1,65 @@
#******************************************************************************
#
# Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
# All rights reserved.
#
#******************************************************************************
#!/bin/bash
echo "*** SCHEDULER REVERT START ***"
set -e
if [ $# -lt 1 ]
then
echo "Error argument. Sample : ./revertServer.sh 2.1.0"
exit 1
fi
v_out=$1
P2PSERVER_PATH="/home/p2pserver"
START_COMMAND="start.sh"
STOP_COMMAND="stop.sh"
BACKUP_PATH="/temp/scheduler_deployment_backup/"$v_out
echo "*. Check backup path "$BACKUP_PATH
cd $BACKUP_PATH
echo "*. Check Tomcat version and directory"
TOMCAT_7="/tomcat7"
TOMCAT_6="/tomcat6"
VAR_LIB_PATH="/var/lib"
VAR_LOG_PATH="/var/log"
TOMCAT_PATH=$VAR_LIB_PATH$TOMCAT_7
TOMCAT_WEB_PATH=$TOMCAT_PATH"/webapps"
if [ ! -d $TOMCAT_PATH ]; then
if [ -d $VAR_LIB_PATH$TOMCAT_6 ]; then
TOMCAT_PATH=$VAR_LIB_PATH$TOMCAT_6
TOMCAT_WEB_PATH=$TOMCAT_PATH"/webapps"
else
echo "Error : Neither tomcat 6 or 7 is installed !!"
exit 1
fi
fi
echo "Tomcat path : "$TOMCAT_PATH
echo "*. Stop Tomcat server"
cd $P2PSERVER_PATH
sh ./$STOP_COMMAND
echo "*. Remove Scheduler app"
rm -R $TOMCAT_WEB_PATH"/bldb"
echo "*. Copy files from backup"
cp -R $BACKUP_PATH"/bldb" $TOMCAT_WEB_PATH
echo "*. Set access permission"
chmod -R 777 $TOMCAT_WEB_PATH"/bldb"
echo "*** REVERT SUCCESS ! ***"
echo "*** Please start Scheduler Server manually ! ***"

BIN
project/bldb/lib/blpapi3.jar

Binary file not shown.

BIN
project/bldb/lib/classmexer.jar

Binary file not shown.

BIN
project/bldb/lib/cobra.jar

Binary file not shown.

BIN
project/bldb/lib/jcs-1.3.3.1-RC.jar

Binary file not shown.

BIN
project/bldb/lib/js-14.jar

Binary file not shown.

502
project/bldb/pom.xml

@ -0,0 +1,502 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" 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>
<groupId>com.fe</groupId>
<artifactId>bldb</artifactId>
<version>1.0</version>
<packaging>war</packaging>
<name>A com.fourelementscapital Webapp</name>
<url>http://www.fourelementscapital.com</url>
<dependencies>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-alarm</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-auth</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-db</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-fileutils</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-r</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-scheduler-exception</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-scheduler-common</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-scheduler-p2p</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-scheduler-engines</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>com.fourelementscapital</groupId>
<artifactId>lib-scheduler-queue</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<!--
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.8.1</version>
</dependency>
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>apache-mime4j</artifactId>
<version>0.6</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-ant</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk14</artifactId>
<version>1.54</version>
</dependency>
<dependency>
<groupId>com.jolbox</groupId>
<artifactId>bonecp</artifactId>
<version>0.7.1.RELEASE</version>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.1</version>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.8.0</version>
</dependency>
<dependency>
<groupId>commons-cli</groupId>
<artifactId>commons-cli</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.3</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.2</version>
</dependency>
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>commons-modeler</groupId>
<artifactId>commons-modeler</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.3.1</version>
</dependency>
<dependency>
<groupId>concurrent</groupId>
<artifactId>concurrent</artifactId>
<version>1.3.4</version>
</dependency>
<dependency>
<groupId>com.googlecode.cqengine</groupId>
<artifactId>cqengine</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.directwebremoting</groupId>
<artifactId>dwr</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>12.0</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.9</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>7.0.42</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-coyote</artifactId>
<version>7.0.39</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxrpc-api</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>jcifs</groupId>
<artifactId>jcifs</artifactId>
<version>1.3.17</version>
</dependency>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.50</version>
</dependency>
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.6.0</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>net.jxta</groupId>
<artifactId>jxta-jxse</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.apache.lucene</groupId>
<artifactId>lucene-core</artifactId>
<version>2.4.1</version>
</dependency>
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mailapi</artifactId>
<version>1.4.3</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.12</version>
</dependency>
<dependency>
<groupId>be.cyberelf.nanoxml</groupId>
<artifactId>nanoxml</artifactId>
<version>2.2.3</version>
</dependency>
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.0.9.Final</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty</artifactId>
<version>6.1.26</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.1-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-contrib</artifactId>
<version>3.1-FINAL</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-scratchpad</artifactId>
<version>3.1-FINAL</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>1.7.7.1</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.6.1</version>
</dependency>
<!--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.1</version>
</dependency>
-->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.6.6</version>
</dependency>
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>smtp</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>org.tmatesoft.svnkit</groupId>
<artifactId>svnkit</artifactId>
<version>1.3.0.5847</version>
</dependency>
<dependency>
<groupId>org.tuckey</groupId>
<artifactId>urlrewrite</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>jaxp-api</artifactId>
<version>1.4.2</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.3</version>
</dependency>
<dependency>
<groupId>jfree</groupId>
<artifactId>jfreechart-swt</artifactId>
<version>1.0.17</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.19</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jcommon</artifactId>
<version>1.0.23</version>
</dependency>
<dependency>
<groupId>org.eclipse.swt</groupId>
<artifactId>org.eclipse.swt.win32.win32.x86</artifactId>
<version>4.3</version>
</dependency>
<dependency>
<groupId>org.eclipse.birt.runtime.3_7_1</groupId>
<artifactId>org.mozilla.javascript</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>net.bull.javamelody</groupId>
<artifactId>javamelody-core</artifactId>
<version>1.60.0</version>
</dependency>
<dependency>
<groupId>com.bloomberglp.blpapi</groupId>
<artifactId>blpapi</artifactId>
<version>3.2.2.0</version>
<systemPath>${pom.basedir}/lib/blpapi3.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.javamex.classmexer</groupId>
<artifactId>classmexer</artifactId>
<version>1.6.0</version>
<systemPath>${pom.basedir}/lib/classmexer.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>com.cobra</groupId>
<artifactId>cobra</artifactId>
<version>1.5.0</version>
<systemPath>${pom.basedir}/lib/cobra.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>org.mozilla.javascript.tools.shell</groupId>
<artifactId>js-14</artifactId>
<version>1.2.3</version>
<systemPath>${pom.basedir}/lib/js-14.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>org.apache.jcs</groupId>
<artifactId>jcs</artifactId>
<version>1.3.3.1</version>
<systemPath>${pom.basedir}/lib/jcs-1.3.3.1-RC.jar</systemPath>
<scope>system</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20090211</version>
</dependency>
</dependencies>
<properties>
<jdkLevel>1.8</jdkLevel>
</properties>
<build>
<finalName>bldb</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<includeEmptyDirs>true</includeEmptyDirs>
<webResources>
<resource>
<directory>lib</directory>
<targetPath>WEB-INF/lib</targetPath>
<includes>
<include>**/*.jar</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>

399
project/bldb/src/main/java/com/fe/client/AbstractTeamOrgMgmt.java

@ -0,0 +1,399 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.client;
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fe.common.Constant;
import com.fe.scheduler.TemplateParser;
import com.fourelementscapital.alarm.Alarm;
import com.fourelementscapital.alarm.AlarmType;
import com.fourelementscapital.alarm.ThemeVO;
import com.fourelementscapital.auth.UserThemeAccessPermission;
import com.fourelementscapital.db.AbstractTeamOrgDB;
import com.fourelementscapital.db.SchedulerDB;
/**
* This class is abstract and provide basic implementation for all Team Organization related moudles
* for example: Themes tag support on scheduler, R function *
* @author Administrator
*
*/
public abstract class AbstractTeamOrgMgmt extends Authenticated{
protected static String ACCESS_PRIVILEGE_RWX="RWX";
protected static String ACCESS_PRIVILEGE_RX="RX";
protected static String ACCESS_PRIVILEGE_R="R";
private Logger log = LogManager.getLogger(AbstractTeamOrgMgmt.class.getName());
/**
* this constructor to be used only for DWR, manual invoking to get the object using of this constructor will mis-behave
* @throws Exception
*/
public AbstractTeamOrgMgmt() throws Exception {
super();
}
/**
* this constructor will be used only when JSP or Httprequest request is available.
* @param request
* @throws Exception
*/
public AbstractTeamOrgMgmt(HttpServletRequest request) throws Exception {
super(request);
}
/**
* to be used in child class
* @param sdb
* @return
* @throws Exception
*/
protected Map getThemeAccessData(AbstractTeamOrgDB sdb) throws Exception {
UserThemeAccessPermission auth=getAuthenticatedUserObj(sdb);
HashMap rtn=new HashMap();
if(auth!=null){
rtn.put("rwx_tags",auth.getRwx());
rtn.put("rx_tags",auth.getRx());
rtn.put("r_tags",auth.getR());
}
String superuser=(String)getRequest().getSession().getAttribute(Constant.SESSION_LOGGED_SUPERUSER);
if(superuser!=null && !superuser.equals("")){
rtn.put("superuser",superuser);
}
return rtn;
}
/**
*
* @param scheduler_id
* @param sdb
* @return
* @throws Exception
*/
protected String getAccessPrivilege(int scheduler_id, AbstractTeamOrgDB sdb) throws Exception {
String rtn="";
UserThemeAccessPermission user=getAuthenticatedUserObj(sdb);
if(user!=null){
List<String> themes=sdb.getThemeTags(scheduler_id);
log.debug("themes:"+themes);
log.debug("user.getRwx():"+user.getRwx());
log.debug("user.getRx():"+user.getRx());
log.debug("user.getR():"+user.getR());
for(String ttag:themes){
if(user.getRwx().contains(ttag)) rtn=ACCESS_PRIVILEGE_RWX;
if(user.getRx().contains(ttag) && (!rtn.equals(ACCESS_PRIVILEGE_RWX) )) rtn=ACCESS_PRIVILEGE_RX;
if(user.getR().contains(ttag) && rtn.equals("")) rtn=ACCESS_PRIVILEGE_R;
}
if(themes.size()==0) rtn=ACCESS_PRIVILEGE_RWX;
}
log.debug("user:"+user);
log.debug("getAccessPrivilege:rtn:"+rtn);
String superuser=(String)getRequest().getSession().getAttribute(Constant.SESSION_LOGGED_SUPERUSER);
if(superuser!=null && !superuser.equals("")){
rtn=ACCESS_PRIVILEGE_RWX;
}
if(rtn.equals("")) rtn=null;
return rtn;
}
/**
* @deprecated
* @param notity_tags
* @param sdb
* @return
* @throws Exception
*/
protected ArrayList getNotifications(List notity_tags, AbstractTeamOrgDB sdb) throws Exception {
Map<String,String> priv_data=getThemeHirarchy(notity_tags,sdb);
ArrayList user_notification=new ArrayList();
for(Iterator<String> i=priv_data.keySet().iterator();i.hasNext();){
String ky=i.next();
if(priv_data.get(ky)!=null && priv_data.get(ky).equalsIgnoreCase("rwx")){
user_notification.add(ky);
}
}
return user_notification;
}
/**
*
* @param sdb
* @return
* @throws Exception
*/
protected boolean isAuthorizedUser(SchedulerDB sdb) throws Exception {
String user=getAuthenticatedUser();
if(user!=null){
Map u=sdb.getSVNUser4WikiUser(user);
if(u!=null && u.get("svn_username")!=null && u.get("svn_password")!=null
&& !((String)u.get("svn_username")).equals("") && !((String)u.get("svn_password")).equals("")
){
return true;
}else{
return false;
}
}else{
return false;
}
}
/**
*
* @param sdb
* @return
* @throws Exception
*/
protected String getAuthorizedUser(SchedulerDB sdb) throws Exception {
String user=getAuthenticatedUser();
log.debug("getAuthorizedUser() user:"+user);
if(user!=null){
Map u=sdb.getSVNUser4WikiUser(user);
if(u!=null && u.get("svn_username")!=null && u.get("svn_password")!=null
&& !((String)u.get("svn_username")).equals("") && !((String)u.get("svn_password")).equals("")
){
return (String)u.get("svn_username");
}else{
return null;
}
}else{
return null;
}
}
/**
*
* @param scheduler_id
* @param sdb
* @return
* @throws Exception
*/
protected Map getItemTags2(int scheduler_id,AbstractTeamOrgDB sdb) throws Exception {
//SchedulerDB sdb=SchedulerDB.getSchedulerDB();
//try{
HashMap h=new HashMap();
Vector tagids=sdb.getTagIds4Item(scheduler_id);
Vector tags=sdb.getTags();
Vector follow_tagids=sdb.getFollowTagIds4Item(scheduler_id);
ArrayList<String> themes=sdb.getThemeNames4Item(scheduler_id);
//Vector followers=sdb.getFollowers(scheduler_id);
Map priv_data=getThemeHirarchy(themes,sdb);
if(priv_data.get("theme")!=null){
priv_data.remove("theme");
}
List ftags=sdb.getFollowTags4Item(scheduler_id);
List user_notifications=ftags.size()>0?getNotifications(ftags,sdb):new ArrayList();
ArrayList all=new ArrayList(ftags);
all.addAll(themes);
h.put("tagids", tagids);
h.put("user_privileges",priv_data);
h.put("user_notifications",user_notifications);
h.put("follow_tagids",follow_tagids);
h.put("notice_escalated", getThemeHirarchy(all,sdb));
h.put("tags", tags);
h.putAll(priv_data);
//h.put("followers", followers);
return h;
//}catch(Exception e){
// ClientErrorMgmt.reportError(e, null);
// throw e;
//}finally{
// sdb.closeDB();
//}
}
/**
*
* @param item_id
* @param newtask_tags
* @param follow_tags
* @param atodb
* @param sdb
* @param name
* @param comment
* @param rev
* @param diff
* @param tempdata
* @param templ_file
* @throws Exception
*/
protected void updateAllItemTags(int item_id, List newtask_tags,List follow_tags,AbstractTeamOrgDB atodb,SchedulerDB sdb,String name, String comment,long rev,String diff, Map tempdata, String templ_file) throws Exception {
ArrayList<Integer> ids=new ArrayList();
for(Iterator i=newtask_tags.iterator();i.hasNext();){
String tid=(String)i.next();
ids.add(Integer.parseInt(tid));
}
atodb.updateItemTagIds(item_id, ids);
String owner_tag=null;
if(ids.size()>0){
owner_tag=atodb.getThemeTagName(ids.get(0));
}
ArrayList<Integer> fids=new ArrayList();
for(Iterator i=follow_tags.iterator();i.hasNext();){
String tid=(String)i.next();
fids.add(Integer.parseInt(tid));
}
atodb.updateFollwerTagIds(item_id, fids);
notifyLastModification(atodb,sdb,name,item_id,comment,rev,diff,tempdata,owner_tag,templ_file);
}
private void notifyLastModification(AbstractTeamOrgDB atdb,SchedulerDB sdb,String task_name,int item_id, String comments,long revision, String diff,Map hdata,String owner_tag, String templ_filename) throws Exception {
/*
SVNSync sync=new SVNSync();
String diff=null;
if(revision>=0){
diff=sync.getLastChanged(item_id);
}else {
diff="@@@No modification on script@@ there may be change on other than script for example trigger times, name and etc.. ";
}
*/
//String currentuser=new SchedulerMgmt(getRequest()).getAuthorizedUser(sdb);
String currentuser=getAuthorizedUser(sdb);
ArrayList<String> themes=atdb.getFollowTags4Item(item_id);
if(owner_tag!=null){
if(themes.contains(owner_tag)) themes.remove(owner_tag);
themes.add(0, owner_tag);
}
List<String> m_themes=atdb.getThemeNames4Item(item_id);
for(String t:m_themes){
if(!themes.contains(t)) themes.add(t);
}
//System.out.println("~~~~~~~~~~~~~~~~~~~~~~~~AbstractTeamOrgMgmt.notifyLastModification():themes"+themes);
String exc_user=currentuser+"@4ecap.com";
String content="";
//InputStream in=SendMail.class.getResourceAsStream("scheduler_modified_alert.txt");
InputStream in=AbstractTeamOrgMgmt.class.getResourceAsStream(templ_filename);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine;
while ((strLine = br.readLine()) != null) {
content+=(content.equals("")) ?strLine:"\n"+strLine;
}
br.close();
in.close();
//System.out.println("content:"+content);
TemplateParser pt=new TemplateParser(content,hdata);
String message=pt.parseTemplate();
String subject=pt.getSubject();
try{
// convert String array list to ThemeVO array list required by Alarm.sendAlarm() :
ArrayList<ThemeVO> themeList = new ArrayList<ThemeVO>();
for (int i=0; i<themes.size(); i++) {
themeList.add(new ThemeVO(themes.get(i)));
}
Alarm.sendAlarm( themeList, AlarmType.EMAIL, subject, message, false, true, false, null,exc_user);
}catch(Exception e){
log.error("Couldn't send scheduler update notification to themes "+themes+" the followings are error:");
e.printStackTrace();
}
}
protected Map getItemPrivilegeNotifications(ArrayList themes,ArrayList ftags,AbstractTeamOrgDB sdb) throws Exception {
Map priv_data=getThemeHirarchy(themes,sdb);
HashMap h=new HashMap();
//List user_notifications=getNotifications(ftags,sdb);
ArrayList all=new ArrayList(ftags);
all.addAll(themes);
List user_notifications=getNotifications(all,sdb);
h.put("user_notifications",user_notifications);
h.put("user_privileges",priv_data);
h.put("notice_escalated",getThemeHirarchy(all,sdb));
return h;
}
}

545
project/bldb/src/main/java/com/fe/client/AdminMgmt.java

@ -0,0 +1,545 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.client;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
import java.util.Vector;
import javax.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.directwebremoting.WebContextFactory;
import com.fe.util.PasswordService;
import com.fourelementscapital.db.ConstructQueryDB;
import com.fourelementscapital.db.ContractDB;
import com.fourelementscapital.db.SuperDB;
import com.fourelementscapital.db.UtilDB;
import com.fourelementscapital.db.vo.Contract;
import com.fourelementscapital.db.vo.Strategy;
import com.fourelementscapital.scheduler.error.ClientError;
/**
* This class methods can be accessed without authentication,
* this mgmt class provides method calls for authentication and certain
* calls outside authentication.
*/
public class AdminMgmt {
/**
* key for storing certain objections in the session
*/
protected static String LOGGED_IN_ATTRIBUTE="adminLoggedOn";
protected static String LOGGED_IN_USERNAME="adminLoggedUsername";
public static String DB_USER_PROPERTY_FILE="dbadmin.properties";
private HttpServletRequest request=null;
private Logger log = LogManager.getLogger(AdminMgmt.class.getName());
/**
* to be used outside DWR
* @param request
* @throws Exception
*/
public AdminMgmt(HttpServletRequest request) throws Exception{
this.request=request;
String usrat=(String)getRequest().getSession().getAttribute(AdminMgmt.LOGGED_IN_ATTRIBUTE);
if(usrat!=null && usrat.equalsIgnoreCase("true")){
}else{
//throw new Exception("You're not authorized to use this functionalities");
}
}
/**
* To be used only within DWR as it requires HttpRequest object.
* @throws Exception
*/
public AdminMgmt() throws Exception{
String usrat=(String)getRequest().getSession().getAttribute(AdminMgmt.LOGGED_IN_ATTRIBUTE);
if(usrat!=null && usrat.equalsIgnoreCase("true")){
}else{
//do nothing
}
}
/**
* Changing password of the authenticated user
* @param oldpassword
* @param newpassword
* @return
* @throws Exception
*/
public boolean changePassword(String oldpassword,String newpassword) throws Exception {
Properties prop = new Properties();
try {
prop.load(new FileInputStream(AdminMgmt.DB_USER_PROPERTY_FILE));
String encpwd=PasswordService.encrypt(oldpassword);
String encpwdnew=PasswordService.encrypt(newpassword);
boolean success=false;
if(prop.getProperty(getLoggedInUser())!=null){
if(prop.getProperty(getLoggedInUser().toLowerCase()).equals(encpwd)){
success=true;
}
}
if(!success){
throw new Exception("Invalid current password");
}else{
prop.setProperty(getLoggedInUser(), encpwdnew);
prop.store(new FileOutputStream(AdminMgmt.DB_USER_PROPERTY_FILE), null);
return true;
}
} catch (IOException e) {
throw e;
}
}
/**
* delete contract in the database
* @param db
* @param fieldtable
* @param contract
* @return
* @throws Exception
*/
public Map deleteContract(String db, String fieldtable, String contract) throws Exception {
try{
UtilDB udb=new SuperDB().getUtilDB(db);;
udb.connectDB(db);
udb.deleteContracts( udb.connection(), fieldtable,contract);
Vector contracts=udb.getUniqueContracts(udb.connection(), fieldtable);
udb.closeDB();
HashMap rtn=new HashMap();
rtn.put("contracts", contracts);
return rtn;
} catch (Exception e) {
ClientError.reportError(e, "db:"+db+",fieldtable:"+fieldtable);
throw e;
}
}
/**
* Get the field details for given database.
* @param db
* @param fieldtable
* @return
* @throws Exception
*/
public Map getFieldDetails(String db, String fieldtable) throws Exception {
try{
UtilDB udb=new SuperDB().getUtilDB(db);
udb.connectDB(db);
Vector contracts=udb.getUniqueContracts(udb.connection(), fieldtable);
udb.closeDB();
HashMap rtn=new HashMap();
rtn.put("contracts", contracts);
return rtn;
} catch (Exception e) {
ClientError.reportError(e, "db:"+db+",fieldtable:"+fieldtable);
throw e;
}
}
/**
*
* @param db
* @param fieldtable
* @return
* @throws Exception
*/
public boolean removeFieldTable(String db, String fieldtable) throws Exception {
try{
UtilDB udb=new SuperDB().getUtilDB(db);
udb.connectDB(db);
boolean result=udb.removeFieldTable(udb.connection(), fieldtable);
//boolean result=true;
udb.closeDB();
return result;
} catch (Exception e) {
ClientError.reportError(e, "db:"+db+",fieldtable:"+fieldtable);
throw e;
}
}
/**
*
* @param db
* @param fieldtable
* @param originalname
* @return
* @throws Exception
*/
public boolean renameFieldTable(String db, String fieldtable, String originalname) throws Exception {
try{
UtilDB udb=new SuperDB().getUtilDB(db);
udb.connectDB(db);
boolean result=udb.renameFieldTable(udb.connection(), fieldtable,originalname);
udb.closeDB();
return true;
} catch (Exception e) {
ClientError.reportError(e, "db:"+db+",fieldtable:"+fieldtable);
throw e;
}
}
/**
*
* @param db
* @param commodity
* @param contract
* @return
* @throws Exception
*/
public List getRecords4Contracts(String db, String commodity, String contract) throws Exception {
log.debug("getRecords4Contracts() called");
try{
UtilDB udb=new SuperDB().getUtilDB(db);
udb.connectDB(db);
List result=udb.getRecordCount4Contracts(udb.connection(), commodity, contract);
udb.closeDB();
return result;
} catch (Exception e) {
ClientError.reportError(e, "db:"+db+",commodity:"+commodity);
throw e;
}
}
/**
*
* @param dobj
* @param db
* @param tablename
* @param commodity
* @return
* @throws Exception
*/
public Vector getCommodityRawData(Map dobj,String db, String tablename, String commodity) throws Exception {
try{
UtilDB udb=new SuperDB().getUtilDB(db);
udb.connectDB(db);
String datequery = ConstructQueryDB.getConstructQueryDB().constructDateInputQuery(dobj);
Vector result=udb.getRawData(datequery,udb.connection(), tablename, commodity);
udb.closeDB();
return result;
} catch (Exception e) {
ClientError.reportError(e, "db:"+db+",commodity:"+commodity);
throw e;
}
}
/**
*
* @param dobj
* @param db
* @param fieldname
* @param commodity
* @return
* @throws Exception
*/
public Map getCommodityRawData2(Map dobj,String db, String fieldname, String commodity) throws Exception {
try{
UtilDB udb=new SuperDB().getUtilDB(db);
udb.connectDB(db);
String datequery = ConstructQueryDB.getConstructQueryDB().constructDateInputQuery(dobj);
//Vector result=udb.getRawData2(datequery,udb.connection(), fieldname, commodity);
Map result=udb.getRawData3(datequery,udb.connection(), fieldname, commodity);
udb.closeDB();
return result;
} catch (Exception e) {
ClientError.reportError(e, "db:"+db+",commodity:"+commodity);
throw e;
}
}
/**
*
* @param dobj
* @param db
* @param fieldname
* @param contract
* @param commodity
* @return
* @throws Exception
*/
public Map getCommodityRawData2Contrat(Map dobj,String db, String fieldname, String contract,String commodity) throws Exception {
try{
UtilDB udb=new SuperDB().getUtilDB(db);
udb.connectDB(db);
String datequery = ConstructQueryDB.getConstructQueryDB().constructDateInputQuery(dobj);
//Vector result=udb.getRawData2(datequery,udb.connection(), fieldname, commodity);
Map result=udb.getRawData2Contract(datequery,udb.connection(), fieldname, contract, commodity);
udb.closeDB();
return result;
} catch (Exception e) {
ClientError.reportError(e, "db:"+db+",commodity:"+commodity);
throw e;
}
}
/**
*
* @param db
* @param tablename
* @param date
* @param val
* @param sval
* @param cont
* @return
* @throws Exception
*/
public boolean addRawData(String db,String tablename,String date,String val, String sval, String cont ) throws Exception {
try{
Date d=new SimpleDateFormat("dd/MM/yyyy").parse(date);
Strategy contract=new Strategy();
contract.setCdate(d);
contract.setName(cont);
ContractDB cdb=new SuperDB().getContractDB(tablename,db);
cdb.connectDB(db);
if(cdb.checkSValueFieldTypeExist(cdb.connection()) && sval!=null && !sval.equals("") ){
contract.setSvalue(sval);
Vector<Strategy> records=new Vector();
records.add(contract);
cdb.addSValRecords(cdb.connection(), records);
}else{
contract.setValue(Double.parseDouble(val));
Vector<Contract> records=new Vector();
records.add(contract);
cdb.addRecords(cdb.connection(), records);
}
cdb.closeDB();
return true;
}catch(Exception e){
ClientError.reportError(e, null);
throw e;
}
}
/**
*
* @param db
* @param tablename
* @return
* @throws Exception
*/
public int checkTableDataType(String db,String tablename) throws Exception {
ContractDB cdb=new SuperDB().getContractDB(tablename,db);
try{
cdb.connectDB(db);
boolean issval=cdb.checkSValueFieldTypeExist(cdb.connection());
int rtn=0;
if(issval){
if(cdb.checkSValueField(cdb.connection())>0){
rtn=3; //database set to accepts numeric;
}else{
rtn=2; //database set to accepts sval
}
//override settings to acept both if the database is empty and sval field exist in the table.
if(cdb.countRecords(cdb.connection())<1){
rtn=0;
}
}else{
rtn=1; //database accepts only numeric
}
return rtn;
}catch(Exception e){
ClientError.reportError(e, null);
throw e;
}finally{
cdb.closeDB();
}
}
/**
*
* @param db
* @param tablename
* @param data
* @return
* @throws Exception
*/
public boolean deleteRawData(String db,String tablename, Map data) throws Exception {
UtilDB udb=new SuperDB().getUtilDB(db);
try{
log.debug("deleteRawData called, db:"+db+" tablename:"+tablename+ " data:"+data);
udb.connectDB(db);
if(data.get("contract")!=null && data.get("cdate1")!=null){
udb.deleteRawData(udb.connection(), tablename, data);
log.debug("delete method in utildb exec uted");
}
//udb.closeDB();
return true;
} catch (Exception e) {
ClientError.reportError(e, null);
throw e;
}finally{
udb.closeDB();
}
}
/**
*
* @param db
* @param tablename
* @param olddata
* @param newdata
* @return
* @throws Exception
*/
public boolean setUpdateRawData(String db,String tablename, Map olddata, Map newdata) throws Exception {
UtilDB udb=new SuperDB().getUtilDB(db);
try{
log.debug("setUpdateRawData called, db:"+db+" tablename:"+tablename+ " old:"+olddata+" new:"+newdata);
udb.connectDB(db);
if(olddata.get("contract")!=null && olddata.get("cdate1")!=null){
udb.updateRawData(udb.connection(), tablename, olddata, newdata);
log.debug("update method in utildb exec uted");
}
return true;
} catch (Exception e) {
ClientError.reportError(e, null);
throw e;
}finally{
udb.closeDB();
}
}
/**
*
* @param db
* @param commodity
* @return
* @throws Exception
*/
public boolean removCommodity(String db, String commodity) throws Exception {
try{
UtilDB udb=new SuperDB().getUtilDB(db);
udb.connectDB(db);
boolean result=udb.removeCommodityAndFields(udb.connection(), commodity);
udb.closeDB();
return result;
} catch (Exception e) {
ClientError.reportError(e, "db:"+db+",commodity:"+commodity);
throw e;
}
}
/**
*
* @return
* @throws Exception
*/
private String getLoggedInUser() throws Exception{
return (String)getRequest().getSession().getAttribute(AdminMgmt.LOGGED_IN_USERNAME);
}
/**
*
* @param db
* @return
* @throws Exception
*/
public Map getNodeInfo(String db) throws Exception {
TreeMap rtn=new TreeMap();
UtilDB udb=new SuperDB().getUtilDB(db);
udb.connectDB(db);
Map mar_c=udb.listAllCommoditiesAndFields(udb.connection());
if(mar_c.size()<=5000){
//avoid out of memory error
List mar_c_error=udb.listAllOrphanedAssets(udb.connection());
rtn.put(db+"_err", mar_c_error);
}
rtn.put(db, mar_c);
udb.closeDB();
return rtn;
}
private HttpServletRequest getRequest() throws Exception {
return (request == null && WebContextFactory.get()!=null) ? WebContextFactory.get().getHttpServletRequest() : request;
}
}

222
project/bldb/src/main/java/com/fe/client/Authenticated.java

@ -0,0 +1,222 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.client;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.directwebremoting.WebContextFactory;
import com.fe.common.Constant;
import com.fourelementscapital.auth.UserThemeAccessPermission;
import com.fourelementscapital.db.AbstractTeamOrgDB;
import com.fourelementscapital.db.InfrastructureDB;
import com.fourelementscapital.scheduler.error.ClientError;
/**
* This class is abstraction layer for the secured data, which means can be accessed only after logged in.
* Any class that exposes user privileged data should be extended from Authenticated class
* @author Rams
*
*/
public abstract class Authenticated {
private HttpServletRequest request=null;
public static String REMOTE_IP="$clientIpAddress";
private Logger log = LogManager.getLogger(Authenticated.class.getName());
public static final String SESS_AUTHENTICATED_USER="$$AuthenticatedUserObj";
/**
* No authentication, which means this constructed to be used internally within JVM.
* @param ignoreAuthentication
*/
protected Authenticated(boolean ignoreAuthentication){
}
/**
* Constructor for DWR
* @throws Exception
*/
public Authenticated() throws Exception {
if(getAuthenticatedUser()==null){
throw new Exception("SESSION LOGGED OUT: Access denied for this request");
}
try{
if(getRequest().getSession().getAttribute(REMOTE_IP)==null){
getRequest().getSession().setAttribute(REMOTE_IP, getRequest().getRemoteAddr());
}
}catch(Exception e){
log.error("Error while setting up session variable remote-ipaddress ");
}
}
/**
* This constructor to be used within JSP or interal call within java runtime.
* @param request
* @throws Exception
*/
public Authenticated(HttpServletRequest request) throws Exception {
this.request=request;
if(getAuthenticatedUser()==null){
throw new Exception("Requested user is not authenticated ");
}
try{
if(getRequest().getSession().getAttribute(REMOTE_IP)==null){
getRequest().getSession().setAttribute(REMOTE_IP, getRequest().getRemoteAddr());
}
}catch(Exception e){
log.error("Error while setting up session variable remote-ipaddress ");
}
}
protected UserThemeAccessPermission getAuthenticatedUserObj( AbstractTeamOrgDB sdb) throws Exception {
String currentuser=getAuthenticatedUser();
//String currentuser="ls"; //getAuthenticatedUser();
UserThemeAccessPermission auser=(UserThemeAccessPermission)getRequest().getSession().getAttribute(Authenticated.SESS_AUTHENTICATED_USER);
InfrastructureDB infrastructureDB = InfrastructureDB.getInfrastructureDB();
try{
if(auser==null){
infrastructureDB.connectDB();
Map<String,String> themes=infrastructureDB.getThemes4Users(currentuser);
auser = new UserThemeAccessPermission(currentuser);
auser.addPermissionWithThemes(themes);
getRequest().getSession().setAttribute(Authenticated.SESS_AUTHENTICATED_USER,auser);
}
} catch(Exception e) {
throw e;
} finally {
infrastructureDB.closeDB();
}
return auser;
}
/**
* Get authenticated user in any DWR call.
* @return
* @throws Exception
*/
protected String getAuthenticatedUser() throws Exception {
String ky=(String)getRequest().getSession().getAttribute(Constant.SESSION_LOGGED_USER);
String usr=null;
log.debug("getAuthenticatedUser ----ky:"+ky);
if((ky==null || (ky!=null && ky.equals(""))) ){
String user=null;
String pwd=null;
Cookie cookie[]=getRequest().getCookies();
if(cookie!=null){
for(int i=0;i<cookie.length;i++){
if(cookie[i].getName().equals("4eprevuser") && cookie[i].getValue()!=null) {
user=cookie[i].getValue();
}
if(cookie[i].getName().equals("4esessionuid") && cookie[i].getValue()!=null) {
pwd=cookie[i].getValue();
}
}
}
if(user!=null && pwd!=null){
LoginMgmt lm=new LoginMgmt();
log.debug("user:"+user+" pwd:"+pwd);
Map dt=lm.validateRememberedUser(user, pwd);
log.debug("dt:"+dt);
if((Boolean)dt.get("success")){
usr=user;
}
}
//usr=user;
}else{
usr=ky;
}
log.debug("getAuthenticatedUser ----@@@ky:"+ky);
//System.out.println("Authenticated.class: getAuthenticatedUser():"+usr);
if(usr!=null && usr.equals("")){
usr=null;
}
return usr;
}
protected void setRequest(HttpServletRequest request) throws Exception {
this.request=request;
}
protected HttpServletRequest getRequest() throws Exception {
return (request == null && WebContextFactory.get()!=null) ? WebContextFactory.get().getHttpServletRequest() : request;
}
protected Map getThemeHirarchy(List<String> themes, AbstractTeamOrgDB sdb) throws Exception {
//SchedulerDB sdb=SchedulerDB.getSchedulerDB();
InfrastructureDB infrastructureDB = InfrastructureDB.getInfrastructureDB();
try{
String th="";
HashMap rtn=new HashMap();
//StringTokenizer st=new StringTokenizer(themes,",");
//while(st.hasMoreTokens()){
for(String tkn: themes ){
//String tkn=st.nextToken();
th+=th.equals("")?"'"+tkn+"'":",'"+tkn+"'";
}
infrastructureDB.connectDB();
Map<String, String> data=!th.equals("")?infrastructureDB.getTeamOrg(th, getPermissionHierarchy()):new HashMap();
Map<String,String> user_privileges=UserThemeAccessPermission.replacePermissions(data);
return user_privileges;
}catch(Exception e){
ClientError.reportError(e, null);
e.printStackTrace();
throw e;
}finally{
//sdb.closeDB();
infrastructureDB.closeDB();
}
}
private List getPermissionHierarchy(){
ArrayList h=new ArrayList();
h.add("X");
h.add("M");
h.add("S");
h.add("B");
h.add("C");
h.add("U");
h.add("N");
return h;
}
}

247
project/bldb/src/main/java/com/fe/client/ExecuteRMgmt.java

@ -0,0 +1,247 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.client;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
import javax.servlet.http.HttpServletRequest;
import org.apache.jcs.JCS;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.directwebremoting.WebContextFactory;
import com.fourelementscapital.db.SchedulerDB;
import com.fourelementscapital.scheduler.balance.LoadBalancingQueue;
import com.fourelementscapital.scheduler.balance.executeR.LoadBalancingExecuteRQueue;
import com.fourelementscapital.scheduler.rscript.RScript;
/**
* Provides AJAX data for ExecuteR monitoring interface.
* The jsp file for this class executeR.jsp and javascript file executer.jsp
* @author Administrator
*
*/
public class ExecuteRMgmt {
private Logger log = LogManager.getLogger(ExecuteRMgmt.class.getName());
private HttpServletRequest request=null;
private static Semaphore refreshLock=new Semaphore(1,true);
private static final long TIMEOUT_MS=1000;
/**
* Semaphore lock and release machanism to make some the method calls exclusive to the current thread.
*/
private void acquireLock(){
try{
ExecuteRMgmt.refreshLock.tryAcquire(TIMEOUT_MS, TimeUnit.MILLISECONDS);
}catch(Exception e){ log.error("Error:"+e.getMessage()); }
}
private void releaseLock(){
try{ ExecuteRMgmt.refreshLock.release(); }catch(Exception e){ log.error("Error:"+e.getMessage()); }
}
/**
* for DWR call
* @throws Exception
*/
public ExecuteRMgmt() throws Exception {
}
/**
* for internal or jsp call
* @param request
* @throws Exception
*/
public ExecuteRMgmt(HttpServletRequest request) throws Exception {
}
/**
* get queue data in json format
* @return
* @throws Exception
*/
public Map getQueue() throws Exception {
acquireLock();
try{
HashMap rtn=new HashMap();
ArrayList<RScript> list2=new ArrayList();
LoadBalancingQueue queue=LoadBalancingQueue.getExecuteRScriptDefault();
Collection<RScript> queued=queue.getScriptQueue();
Collection<RScript> p1=queue.getScriptProcessingQueue();
ArrayList executing=new ArrayList();
for(RScript rs:p1){
//log.debug("p1:"+rs.getPeer());
executing.add(rs.getUid());
}
list2.addAll(p1);
list2.addAll(queued);
JCS gjcs=queue.getGroupedCache();
//just to retrieve so that, expired won't in the memory
int counter=0;
long totaldelay=0;
for(Object key: gjcs.getGroupKeys(LoadBalancingQueue.CACHE_GROUP_FINISHED)){
Long delay=(Long)gjcs.getFromGroup(key,LoadBalancingQueue.CACHE_GROUP_FINISHED);
if(delay!=null){
totaldelay=totaldelay+delay;
counter++;
}
}
log.debug("totaldelay:"+totaldelay+" counter:"+counter);
long ave_delay=(counter>0 && totaldelay>0)?(totaldelay/counter)/1000:0;
//just to retrieve so that, expired won't in the memory
for(Object key: gjcs.getGroupKeys(LoadBalancingQueue.CACHE_GROUP_TIMEOUT)){
gjcs.getFromGroup(key,LoadBalancingQueue.CACHE_GROUP_TIMEOUT);
}
Set finished=gjcs.getGroupKeys(LoadBalancingQueue.CACHE_GROUP_FINISHED);
Set timedout=gjcs.getGroupKeys(LoadBalancingQueue.CACHE_GROUP_TIMEOUT);
Set activePeers=gjcs.getGroupKeys(LoadBalancingQueue.CACHE_GROUP_ACTIVEPEERS);
//long perc=(memory/runtime.totalMemory())*100;
//perc=100-perc;
//log.debug("timedout:"+timedout.size());
//log.debug("finised:"+finished.size());
Map peerdata=null;
if(getRequest()!=null && getRequest().getSession()!=null && getRequest().getSession().getAttribute("peer_data")!=null){
peerdata=(Map)getRequest().getSession().getAttribute("peer_data");
}else{
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
try{
sdb.connectDB();
List<Map> pd=sdb.getPeersData();
peerdata=new HashMap();
for(Map record : pd){
String fname=(record.get("friendlyname")!=null && ((String)record.get("friendlyname")).equals(""))
?(String)record.get("friendlyname")
:(String)record.get("peername");
peerdata.put(record.get("peername"), record.get("friendlyname"));
}
if(getRequest()!=null){
getRequest().getSession().setAttribute("peer_data", peerdata);
}
}catch(Exception e){
log.error("Error:"+e.getMessage());
}finally{
sdb.closeDB();
}
}
rtn.put("queue", list2);
rtn.put("ave_delay", (ave_delay>0?ave_delay:0));
rtn.put("queued_count", queued.size());
rtn.put("executing", executing);
rtn.put("executing_count", p1.size());
rtn.put("active_peers", activePeers.size());
rtn.put("finished", finished);
rtn.put("timedout", timedout);
rtn.put("peernames",peerdata);
return rtn;
}catch(Exception e){
e.printStackTrace();
throw e;
}finally{
releaseLock();
}
}
/**
* remove failed item in the queue
* @param uid
* @throws Exception
*/
public void removeFromAllQueue(String uid) throws Exception {
try{
RScript rs=new RScript();
rs.setUid(uid);
LoadBalancingQueue queue=LoadBalancingQueue.getExecuteRScriptDefault();
queue.removeScriptFromAllQueue(rs);
}catch(Exception e){
e.printStackTrace();
}
}
/**
* returns the queue data in xml format
* @return
* @throws Exception
*/
public String getQueueXML() throws Exception {
Map data=getQueue();
String result="<result>";
for(Iterator<String> keys=data.keySet().iterator();keys.hasNext();){
String key=keys.next();
ArrayList a=new ArrayList();
a.add("ave_delay");
a.add("queued_count");
a.add("executing_count");
a.add("active_peers");
a.add("finished");
a.add("timedout");
if(a.contains(key)){
String val=data.get(key)+"";
//System.out.println("key:"+key+":"+data.get(key).getClass().getName()+" isCollection:"+(data.get(key) instanceof Collection) );
if(data.get(key) instanceof Collection) val=((Collection)data.get(key)).size()+"";
result+="<"+key.toLowerCase()+">"+val+"</"+key.toLowerCase()+">";
}
}
result+="</result>";
return result;
}
/**
* @deprecated
* @return
* @throws Exception
*/
public Map test_queueDebug() throws Exception {
LoadBalancingExecuteRQueue queue=(LoadBalancingExecuteRQueue)LoadBalancingQueue.getExecuteRScriptDefault();
return queue.debug_data();
}
private HttpServletRequest getRequest() throws Exception {
return (request == null && WebContextFactory.get()!=null) ? WebContextFactory.get().getHttpServletRequest() : request;
}
}

110
project/bldb/src/main/java/com/fe/client/IExecAccessMgmt.java

@ -0,0 +1,110 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.client;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.fourelementscapital.auth.UserThemeAccessPermission;
import com.fourelementscapital.db.InfrastructureDB;
import com.fourelementscapital.db.SchedulerDB;
public class IExecAccessMgmt extends Authenticated {
public IExecAccessMgmt() throws Exception {
super();
// TODO Auto-generated constructor stub
}
/**
* constructor for jsp
* @param request
* @throws Exception
*/
public IExecAccessMgmt(HttpServletRequest request) throws Exception {
super(request);
}
/**
* update user preference, this preference available on pressing + button on the menu bar
* @param key
* @param val
* @return
* @throws Exception
*/
public boolean checkUserPermission() throws Exception {
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
try{
sdb.connectDB();
UserThemeAccessPermission au = getAuthenticatedUserObj(sdb);
ArrayList fullaccess = au.getRwx();
ArrayList readexecaccess = au.getRx();
ArrayList readaccess = au.getR();
fullaccess.addAll(readexecaccess);
fullaccess.addAll(readaccess);
if(fullaccess.contains("iExec"))
return true;
else
return false;
}catch(Exception e){
e.printStackTrace();
throw e;
}
finally{
sdb.closeDB();
}
}
/**
* update user preference, this preference available on pressing + button on the menu bar
* @param key
* @param val
* @return
* @throws Exception
*/
public String checkUserPermissionNew(String application) throws Exception {
String access = "---";
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
InfrastructureDB infrastructureDB = InfrastructureDB.getInfrastructureDB();
try{
sdb.connectDB();
UserThemeAccessPermission au = getAuthenticatedUserObj(sdb);
infrastructureDB.connectDB();
List al = infrastructureDB.getAccessByAppAndUsername(application, au.toString());
for (int i=0; i<al.size(); i++) {
access = al.get(i) == null ? null : al.get(i).toString();
}
//return access;
}catch(Exception e){
e.printStackTrace();
throw e;
}
finally{
sdb.closeDB();
infrastructureDB.closeDB();
//return "---";
}
return access;
}
}

1405
project/bldb/src/main/java/com/fe/client/IExecMgmt.java

File diff suppressed because it is too large Load Diff

248
project/bldb/src/main/java/com/fe/client/JspXHRRequest.java

@ -0,0 +1,248 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.client;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.json.JSONArray;
import org.json.JSONObject;
import com.fourelementscapital.db.InfrastructureDB;
import com.fourelementscapital.db.RFunctionDB;
import com.fourelementscapital.db.SchedulerDB;
import com.fourelementscapital.scheduler.error.ClientError;
/**
* This class is used for making several XHR requests, for example jquery autocomplete and autosuggest feature.
* @author Administrator
*
*/
public class JspXHRRequest extends Authenticated {
/**
* make sure you are not passing null request, otherwise it won't work properly
* @param request
* @throws Exception
*/
public JspXHRRequest(HttpServletRequest request) throws Exception {
super(request);
}
/**
* Autocomplete search for scheduler name search on UI
* @return
* @throws Exception
*/
public String getXHRDataScheduler() throws Exception {
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
try{
sdb.connectDB();
JSONArray rtn=new JSONArray();
if( getRequest().getParameter("term")!=null){
if(getRequest().getParameter("term")!=null){
String kword=getRequest().getParameter("term");
List data=sdb.getAutoCompleteXHR(kword);
for(Iterator<Map> it=data.iterator();it.hasNext(); ){
Map record=it.next();
//System.out.println("SchedulerMgmt.getXHRDataScheduler():data:"+record);
rtn.put(record);
}
}
}
return rtn.toString();
}catch(Exception e){
ClientError.reportError(e, null);
throw e;
}finally{
sdb.closeDB();
}
}
/**
* Generic XHR data returned
* @return
* @throws Exception
*/
public String getXHRDataR() throws Exception {
RFunctionDB rfdb=RFunctionDB .getRFunctionDB();
try{
rfdb.connectDB();
JSONArray rtn=new JSONArray();
if( getRequest().getParameter("term")!=null){
if(getRequest().getParameter("term")!=null){
String kword=getRequest().getParameter("term");
List data=rfdb.autoCompleteFunctions(kword);
for(Iterator<Map> it=data.iterator();it.hasNext(); ){
Map record=it.next();
rtn.put(record);
}
}
}
return rtn.toString();
}catch(Exception e){
ClientError.reportError(e, null);
throw e;
}finally{
rfdb.closeDB();
}
}
/**
* Notification related data in JSON format.
* @return
* @throws Exception
*/
public String getNotificationData() throws Exception {
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
InfrastructureDB infrastructureDB = InfrastructureDB.getInfrastructureDB();
try{
sdb.connectDB();
JSONObject json=new JSONObject();
JSONArray rtn=new JSONArray();
infrastructureDB.connectDB();
List<String> themes = infrastructureDB.getThemeByUsernameAccess(getAuthenticatedUser());
List data=sdb.getFailedLast2Days(themes);
for(Iterator<Map> it=data.iterator();it.hasNext(); ){
Map record=it.next();
rtn.put(record);
}
json.put("failed_scripts", rtn);
return json.toString();
}catch(Exception e){
//ClientErrorMgmt.reportError(e, null);
//throw e;
//log.error("");
throw e;
}finally{
sdb.closeDB();
infrastructureDB.closeDB();
}
}
/**
* JSON formatted data.
* @return
* @throws Exception
*/
public String getJSON() throws Exception {
String callback=getRequest().getParameter("callback");
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
try{
sdb.connectDB();
JSONArray rtn=new JSONArray();
if( getRequest().getParameter("search_name")!=null || getRequest().getParameter("search_id")!=null){
String query="";
if(getRequest().getParameter("search_name")!=null){
String kword=getRequest().getParameter("search_name");
query = sdb.getTop20IdNameByNameQuery(kword);
}
if(getRequest().getParameter("search_id")!=null){
String kword=getRequest().getParameter("search_id");
query = sdb.getTop20IdNameByIdQuery(kword);
}
List data=sdb.getSingleColData(query);
for(Iterator it=data.iterator();it.hasNext(); ){
String rec=(String)it.next();
rtn.put(rec);
}
}
return callback+"("+rtn.toString()+");";
}catch(Exception e){
ClientError.reportError(e, null);
throw e;
}finally{
sdb.closeDB();
}
}
/**
* returns execution logs for the selected log item in the queue
* @param scheduler_id
* @param trigger_time
* @return
* @throws Exception
*/
public String getExecutionLogs(int scheduler_id, long trigger_time) throws Exception {
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
try{
sdb.connectDB();
JSONArray rtn=new JSONArray();
List list=sdb.getSchedulerExeLogs(scheduler_id,trigger_time);
rtn.put(list);
return rtn.toString();
}catch(Exception e){
ClientError.reportError(e, null);
throw e;
}finally{
sdb.closeDB();
}
}
/**
* List last 2 days failed details.
* @param scheduelr_id
* @param stat
* @return
* @throws Exception
*/
public String listLast2DaysFailedDetails(long scheduelr_id, String stat) throws Exception {
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
try{
sdb.connectDB();
String datequery= sdb.getHistoryQueueLogsDateQuery(scheduelr_id, stat);
Date now=new Date();
List list=sdb.listOfHistoryQueueLogs(now.getTime(),datequery);
JSONObject json=new JSONObject();
json.put("list", list);
return json.toString();
}catch(Exception e){
ClientError.reportError(e, null);
throw e;
}finally{
sdb.closeDB();
}
}
}

226
project/bldb/src/main/java/com/fe/client/LoginMgmt.java

@ -0,0 +1,226 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.client;
import java.net.URLDecoder;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.directwebremoting.WebContextFactory;
import org.directwebremoting.util.Logger;
import com.fe.common.Constant;
import com.fourelementscapital.auth.SuperUserAuthentication;
import com.fourelementscapital.auth.WikiAuthentication;
/**
* This class used authenticating the user.
* @author Administrator
*
*/
public class LoginMgmt {
private Logger log=Logger.getLogger(LoginMgmt.class);
/**
* for DWR call
*/
public LoginMgmt(){
}
/**
* for JSP or internal call
* @param request
*/
public LoginMgmt(HttpServletRequest request){
this.request=request;
}
//private static String dbname=Config.getString("db_wiki");
private HttpServletRequest request=null;
/**
* returns wiki database name for authentication and validation purpose
* @return
*/
//public static String getDBName() {
// return dbname;
//}
/**
* Login validation for given username and password
* @param user
* @param password
* @return
* @throws Exception
*/
public Map login(String user,String password) throws Exception {
HashMap rtn=new HashMap();
try{
//log.debug("connecting wiki db...db:"+wdb.getDriver(dbname)+" driver:");
//log.debug("connected catalog:"+wdb.connection().getCatalog());
boolean success= WikiAuthentication.validateUser(user, password);
if(!success){
rtn.put("message", "Invalid username or password");
}else{
HttpSession session=getRequest().getSession(true);
session.setMaxInactiveInterval(24*60*60); //1 day;
session.setAttribute(Constant.SESSION_LOGGED_USER, user);
boolean cookielogin=false;
session.setAttribute(Constant.SESSION_LOGGED_HEADER, getHeaders(getRequest(),cookielogin));
String pss=WikiAuthentication.getEncryptedPwd(user);
rtn.put("fesessionuid", pss);
}
rtn.put("loggedin", success);
return rtn;
}catch(Exception e){
e.printStackTrace();
throw e;
}
}
private Map getHeaders(HttpServletRequest req, boolean cookielogin) throws Exception {
HashMap rtn=new HashMap();
Enumeration<String> h=req.getHeaderNames();
while(h.hasMoreElements()){
String header=h.nextElement();
rtn.put(header, req.getHeader(header));
}
rtn.put(Constant.SESSION_LOGGED_HEADER_COOKIELOGIN, cookielogin);
rtn.put(Constant.SESSION_LOGGED_HEADER_IP,getRequest().getRemoteAddr());
return rtn;
}
/**
* Logging in as super user to over-ride some of the user privileged options
*
* @param user
* @param password
* @param newpassword
* @return
* @throws Exception
*/
public Map loginSuperUser(String user,String password,String newpassword) throws Exception {
HashMap rtn=new HashMap();
try{
boolean success=false;
if(user.equalsIgnoreCase("administrator") && newpassword!=null && !newpassword.equals("")){
success = SuperUserAuthentication.changePwd(password,newpassword);
}else{
success = SuperUserAuthentication.validateOrSet(password); //validation implementation to be done..
}
if(!success){
rtn.put("message", "Invalid username or password");
}else{
HttpSession session=getRequest().getSession(true);
session.setAttribute(Constant.SESSION_LOGGED_SUPERUSER, user);
}
rtn.put("loggedin", success);
return rtn;
}catch(Exception e){
e.printStackTrace();
throw e;
}
finally{
//wdb.closeDB();
}
}
/**
* validates remembered password on browser cookie, the password is stored in md5 hash value
* @param user
* @param password
* @return
* @throws Exception
*/
public Map validateRememberedUser(String user,String password) throws Exception {
HashMap rtn=new HashMap();
try{
boolean success=false;
String passcode=URLDecoder.decode(password);
log.debug("user:"+user+" passcode:"+passcode);
String pss=WikiAuthentication.getEncryptedPwd(user);
if(!passcode.equals(pss)){
rtn.put("message", "Invalid username or password");
}else{
success=true;
HttpSession session=getRequest().getSession(true);
session.setMaxInactiveInterval(24*60*60); //1 day;
session.setAttribute(Constant.SESSION_LOGGED_USER, user);
boolean cookielogin=true;
session.setAttribute(Constant.SESSION_LOGGED_HEADER, getHeaders(getRequest(),cookielogin));
//wdb.getEncryptedPwd(user_name)
//String pss=wdb.getEncryptedPwd(user);
rtn.put("fesessionuid", pss);
}
rtn.put("loggedin", success);
log.debug("rtn:"+rtn);
return rtn;
}catch(Exception e){
e.printStackTrace();
throw e;
}
}
/**
* a standard logout
* @throws Exception
*/
public void logout() throws Exception {
HttpSession session=getRequest().getSession();
session.removeAttribute(Constant.SESSION_LOGGED_USER);
session.invalidate();
}
private HttpServletRequest getRequest() throws Exception {
return (request == null && WebContextFactory.get()!=null) ? WebContextFactory.get().getHttpServletRequest() : request;
}
}

96
project/bldb/src/main/java/com/fe/client/MenuMgmt.java

@ -0,0 +1,96 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.client;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import com.fourelementscapital.db.SchedulerDB;
/**
* This class provides data for building menu on the web page.
*
*/
public class MenuMgmt extends Authenticated {
/**
* default constructor
* @throws Exception
*/
public MenuMgmt() throws Exception {
super();
}
/**
* constructor for jsp
* @param request
* @throws Exception
*/
public MenuMgmt(HttpServletRequest request) throws Exception {
super(request);
}
/**
* update user preference, this preference available on pressing + button on the menu bar
* @param key
* @param val
* @return
* @throws Exception
*/
public boolean updateUserPreference(String key, String val) throws Exception {
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
try{
String user=getAuthenticatedUser();
sdb.connectDB();
sdb.userPrefSaveOrUpdate(user, key, val);
return true;
}catch(Exception e){
e.printStackTrace();
throw e;
}
finally{
sdb.closeDB();
}
}
/**
* get user preference to set necessary settings in UI
* @return
* @throws Exception
*/
public Map getUserPref() throws Exception {
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
try{
String user=getAuthenticatedUser();
sdb.connectDB();
Map data=sdb.userPrefGetAll(user);
return data;
}catch(Exception e){
e.printStackTrace();
throw e;
}
finally{
sdb.closeDB();
}
}
}

2743
project/bldb/src/main/java/com/fe/client/RFunctionMgmt.java

File diff suppressed because it is too large Load Diff

1041
project/bldb/src/main/java/com/fe/client/SchedulerAPIServlet.java

File diff suppressed because it is too large Load Diff

4252
project/bldb/src/main/java/com/fe/client/SchedulerMgmt.java

File diff suppressed because it is too large Load Diff

81
project/bldb/src/main/java/com/fe/client/SchedulerReportClient.java

@ -0,0 +1,81 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.client;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fourelementscapital.scheduler.config.Config;
public class SchedulerReportClient {
private static String REPORTS_FOLDER="scheduler.report.folder";
private Logger log = LogManager.getLogger(SchedulerReportClient.class.getName());
private ArrayList<String> getFileNames() {
String folder=Config.getString(REPORTS_FOLDER);
ArrayList rtn=new ArrayList();
log.debug("folder:"+folder);
if(folder!=null && new File(folder).exists()){
File[] list=new File(folder).listFiles();
for(int i=0;i<list.length;i++){
rtn.add(list[i].getName());
log.debug("adding filename:"+list[i].getName());
}
}
Collections.sort(rtn );
return rtn;
}
public String generateMarkup(){
ArrayList<String> files=getFileNames();
String ul="";
String div="";
String folder=Config.getString(REPORTS_FOLDER);
int count=0;
for(String filename: files){
String filepart=filename.substring(0,filename.indexOf("."));
String ext=filename.substring(filename.indexOf(".")+1);
log.debug("filepart:"+filepart+" ext:"+ext);
if(ext.equalsIgnoreCase("png") || ext.equalsIgnoreCase("html") || ext.equalsIgnoreCase("htm")){
String id="scd_monitors-tabs-"+count;
String img_id="scd_monitors-tabs-img"+count;
ul+=(ul.equals(""))?"<ul>":"";
ul+="<li><a href=\"#"+id+"\">"+filepart+"</a></li>";
if(ext.equalsIgnoreCase("png") ){
div+="<div class=\"chromeScroll\" id=\""+id+"\"><img fileparam=\""+folder+filename+"\" src=\"image.jsp?file="+folder+filename+"&t="+new Date().getTime()+"\" id=\""+img_id+"\"></div>";
}else if(ext.equalsIgnoreCase("html") || ext.equalsIgnoreCase("htm")){
div+="<div class=\"chromeScroll\" id=\""+id+"\" style=\"overflow:hidden\">";
div+="<iframe fileparam=\""+folder+filename+"\" class=\"chromeScroll\" src=\"html.jsp?file="+folder+filename+"&t="+new Date().getTime()+"\" width=\"100%\" height=\"100%\" scrolling=\"yes\" style=\"border:0px\">";
div+="<p>Your browser does not support iframes.</p>";
div+="</iframe>";
div+="</div>";
}
}
count++;
}
ul+=(ul.equals(""))?"":"</ul>";
return ul+div;
}
}

21
project/bldb/src/main/java/com/fe/common/Constant.java

@ -0,0 +1,21 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.common;
public class Constant {
public final static String SESSION_LOGGED_USER="session^logged^user";
public final static String SESSION_LOGGED_HEADER="session^logged^header";
public final static String SESSION_LOGGED_HEADER_IP="sess_ip_address";
public final static String SESSION_LOGGED_HEADER_COOKIELOGIN="sess_cookielogin";
public final static String SESSION_LOGGED_SUPERUSER="session^logged^superuser";
}

125
project/bldb/src/main/java/com/fe/io/peer/PeerClient.java

@ -0,0 +1,125 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.io.peer;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
import java.util.Date;
import java.util.Timer;
import java.util.TimerTask;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fourelementscapital.scheduler.io.peer.PeerClientHandler;
public class PeerClient implements Runnable {
private final String host;
private final int port;
private static Timer timer=null;
private Logger log = LogManager.getLogger(PeerClient.class.getName());
public PeerClient(String host, int port) {
this.host = host;
this.port = port;
}
public void run() {
EventLoopGroup group = new NioEventLoopGroup(10);
try {
if(timer==null){
TimerTask tt=new TimerTask() {
public void run() {
String tname="peercleint_timer_"+(new Date().getTime()/1000);
ChannelHandlerContext chc=PeerClientHandler.getChannelHandler();
//System.out.println("PeerClient timer:"+chc);
if(chc!=null){
//System.out.println("PeerClient timer: active:"+chc.channel().isActive());
//System.out.println("PeerClient timer: open:"+chc.channel().isOpen());
if(!chc.channel().isOpen()){
Thread t=new Thread(new PeerClient(this.host,this.port),tname);
t.start();
}
}else{
Thread t=new Thread(new PeerClient(this.host,this.port),tname);
t.start();
}
}
private String host=null;
private int port=0;
public TimerTask init(String h,int p){
this.host = h;
this.port = p;
return this;
}
}.init(this.host, this.port);
//checks every 1 minute to see if a thread still running....
long freq=10*1000;
PeerClient.timer = new Timer("scheduler_con_monitor");
PeerClient.timer.scheduleAtFixedRate(tt,freq, freq);
}
Bootstrap b = new Bootstrap();
b.group(group)
.channel(NioSocketChannel.class)
.handler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline=ch.pipeline();
pipeline.addLast("decoder", new ObjectDecoder(ClassResolvers.cacheDisabled(null)));
pipeline.addLast("encoder", new ObjectEncoder());
// and then business logic.
pipeline.addLast("handler", new PeerClientHandler());
}
}
);
// Start the connection attempt.
//System.out.println("~~~~~~~~~PeerClient starting....");
log.debug("before bootstrap starting...");
Channel ch = b.connect(host, port).sync().channel();
//Read commands from the stdin.
//ChannelFuture lastWriteFuture = null;
//lastWriteFuture = ch.writeAndFlush(p);
//If user typed the 'bye' command, wait until the server closes
//the connection.
//ch.closeFuture().sync();
//Wait until all messages are flushed before closing the channel.
//if (lastWriteFuture != null) {
// lastWriteFuture.sync();
//}
//} catch(ConnectException ce){
//System.out.println("PeerClient() exception:~~~~~~~");
//ce.printStackTrace();
} catch(Exception e){
group.shutdownGracefully();
log.error("error while PeerClient:"+e.getMessage());
} finally {
//group.shutdownGracefully();
//System.out.println("PeerClient() finally:~~~~~~~");
}
}
}

72
project/bldb/src/main/java/com/fe/io/server/ServerScheduler.java

@ -0,0 +1,72 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.io.server;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.handler.codec.serialization.ClassResolvers;
import io.netty.handler.codec.serialization.ObjectDecoder;
import io.netty.handler.codec.serialization.ObjectEncoder;
import com.fourelementscapital.scheduler.io.server.ServerConnectionHandler;
public class ServerScheduler implements Runnable {
private int port;
public ServerScheduler(int port) {
this.port = port;
}
public void run() {
EventLoopGroup bossGroup = new NioEventLoopGroup(); // (1)
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap(); // (2)
b.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class) // (3)
.childOption(ChannelOption.TCP_NODELAY, true)
.childOption(ChannelOption.SO_KEEPALIVE, true)
.childHandler(new ChannelInitializer<SocketChannel>() { // (4)
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast(new ObjectEncoder(), new ObjectDecoder(ClassResolvers.cacheDisabled(null)), new ServerConnectionHandler());
}
});
b.bind(port).sync().channel().closeFuture().sync();
}catch(Exception e){
e.printStackTrace();
} finally {
workerGroup.shutdownGracefully();
bossGroup.shutdownGracefully();
}
}
public static void main(String[] args) throws Exception {
int port;
if (args.length > 0) {
port = Integer.parseInt(args[0]);
} else {
port = 8888;
}
}
}

60
project/bldb/src/main/java/com/fe/lucene/FundamentalTickersCollector.java

@ -0,0 +1,60 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import com.fourelementscapital.db.FlexiFieldDB;
public class FundamentalTickersCollector extends SearchTokenCollector {
public FundamentalTickersCollector(String tablename) {
super(tablename);
}
public void processTextTokens(String ticker) throws Exception {
FlexiFieldDB fldb=FlexiFieldDB.getFlexiFieldDB();
//ReferenceDB refdb=new ReferenceDB();
fldb.connectDB();
Vector<Map> fl_fdata=fldb.getFlexiFieldData4LuceneToken("fundamental_flexi_data" , "ticker", ticker);
String content=ticker+" ";
HashMap catfields=new HashMap();
for(Iterator<Map> i=fl_fdata.iterator();i.hasNext();){
Map record=i.next();
if(record.get("val")!=null){
String val=(String)record.get("val");
content+=" "+val;
if(record.get("fieldlabel")!=null){
catfields.put(record.get("fieldlabel")+"",val );
}
}
}
catfields.put("title",ticker);
super.rtn=content;
super.categoryfields.clear();
super.categoryfields.putAll(catfields);
fldb.closeDB();
//refdb.closeDB();
}
}

252
project/bldb/src/main/java/com/fe/lucene/LuceneCrawler.java

@ -0,0 +1,252 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.TreeMap;
import java.util.Vector;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fourelementscapital.scheduler.error.ClientError;
public class LuceneCrawler implements Runnable{
public static String INDEX_TABLE_SECURITY="market_securities";
public static String INDEX_TABLE_CONTRACT="market_contracts";
public static String INDEX_TABLE_COMMODITY="market_commodity";
public static String INDEX_TABLE_FUNDAMENTAL_TICKR="fundamental_ticker";
public static String INDEX_SCHEDULER="scheduler";
private String tablename;
private static ConcurrentLinkedQueue queue=new ConcurrentLinkedQueue();
private static Hashtable optimizedAccounts=new Hashtable();
private Logger log = LogManager.getLogger(LuceneCrawler.class.getName());
public LuceneCrawler(String tablename){
this.tablename=tablename;
}
private long indexid;
private LuceneCrawler(){
}
private static boolean threadExecuting=false;
public synchronized void index(String ticker) throws Exception {
//System.out.println("CandidateCrawler: added id:"+candidateid);
addToQueue(ticker,SearchSession.ACTION_INDEX);
}
private void addToQueue(String ticker, int action){
TickerIndexRecord uobj=new TickerIndexRecord();
uobj.setTicker(ticker);
uobj.setTablename(this.tablename);
uobj.setAction(action);
if(!LuceneCrawler.queue.contains(uobj)){
LuceneCrawler.queue.add(uobj);
}
if(!LuceneCrawler.threadExecuting){
LuceneCrawler.threadExecuting=true;
Thread th=new Thread(new LuceneCrawler());
th.start();
}
}
public void deleteIndex(String ticker) throws Exception {
addToQueue(ticker,SearchSession.ACTION_DELETE);
}
public void run() {
try{
//index creates a separate thread to index all queued items
//only one index will be running irrelevent of accounts or tablename
//once all queued items index, then after specified interval count in global.xml index will be optimized.
//this is to avoid big files being indexed very often that slows down the performance of the system.
//if no specificed optimization interval count is not specified then it is 1 by default (hard coded below)
while (!LuceneCrawler.queue.isEmpty()) {
TickerIndexRecord uobj =(TickerIndexRecord)LuceneCrawler.queue.poll();
//System.out.println("CandidateCrawler: indexing:"+uobj.getAccount()+":"+uobj.getRecordid());
MyIndexer myin=new MyIndexer(uobj.getTablename());
SearchSession ss=new SearchSession(myin);
SearchTokenCollector ctc=TokenCollectorFactory.getTokenCollector(uobj) ;//new CandidateTokenCollector(uobj.getAccount());
try{
//log.debug("add action:"+uobj.getAction()+" recordid:"+uobj.getRecordid()+" ac:"+uobj.getAccount()+" table:"+uobj.getTablename());
ss.action(uobj.getAction(),ctc,uobj.getTicker());
log.debug("added to searchsession");
if(SearchSession.ACTION_INDEX==uobj.getAction()){
//LuceneLog.log(LuceneLog.STATUS_SUCCESS, uobj.getAccount(), uobj.getDbname(), uobj.getRecordid(), "");
}else if(SearchSession.ACTION_DELETE==uobj.getAction()){
//LuceneLog.log(LuceneLog.STATUS_DELETED, uobj.getAccount(), uobj.getDbname(), uobj.getRecordid(), "");
}
}catch (Exception e){
ClientError.reportError(e, "Error while indexing, Action:"+uobj.getAction()+" id:"+uobj.getTicker()+" db:"+uobj.getTablename());
}
int count=1;
if(optimizedAccounts.containsKey(uobj.getTablename())){
TreeMap t=(TreeMap)optimizedAccounts.get(uobj.getTablename());
//log.debug("t:"+t+" uobj tablename:"+uobj.getDbname());
if(t.containsKey(uobj.getTablename())){
count=(Integer) t.get(uobj.getTablename());
//log.debug("count a:"+count);
count=count+1;
//log.debug("count b:"+count);
}
t.put(uobj.getTablename(), count);
}else{
TreeMap t=new TreeMap();
t.put(uobj.getTablename(),count);
optimizedAccounts.put(uobj.getTablename(),t);
}
log.debug("optimized accounts"+optimizedAccounts);
} //while loop
//for(int i=0;i<optimizeAccounts.size();i++){
int optcount=5;//default (if no entry found);
try{
//String opc=new GeneralConfiguration().getProperty(GeneralConfiguration.LUCENE_OPTIMIZATION_COUNT);
//optcount=Integer.parseInt(opc);
}catch(Exception e){}
Vector removeAccounts=new Vector();
for(Iterator i=optimizedAccounts.keySet().iterator();i.hasNext();){
String account=(String)i.next();
TreeMap table=(TreeMap)optimizedAccounts.get(account);
Vector removeTable=new Vector();
for(Iterator ia=table.keySet().iterator();ia.hasNext();){
String tablena=(String)ia.next();
Integer count=(Integer)table.get(tablena);
if(count>=optcount){
removeTable.add(tablena);
MyIndexer myin1=new MyIndexer(account);
SearchSession ss1=new SearchSession(myin1);
//LuceneLog.log(LuceneLog.STATUS_SUCCESS, account, tablena, 0, "*******Optimization started****");
ss1.action(SearchSession.ACTION_OPTIMIZE,null,null);
//LuceneLog.log(LuceneLog.STATUS_SUCCESS, account, tablena, 0, "*******Optimization ended********");
}
}
for(Iterator ia=removeTable.iterator();ia.hasNext();){
Object obj=ia.next();
table.remove(obj);
}
if(table.size()<=0){
removeAccounts.add(account);
}
}
for(Iterator ia=removeAccounts.iterator();ia.hasNext();){
Object obj=ia.next();
optimizedAccounts.remove(obj);
}
log.debug("optimized accounts at last:"+optimizedAccounts);
}catch(Exception e){
//System.out.println("CandidateCrawler: Error:"+e.getLocalizedMessage());
//e.printStackTrace();
ClientError.reportError(e, null);
//LuceneLog.log(LuceneLog.STATUS_FAILED, "", this.tablename, 0, "");
//throw e;
}finally{
LuceneCrawler.threadExecuting=false;
}
//meanwhile while optimizing if there were documents added to index.
//process the queue.
if(LuceneCrawler.queue.size()>0){
LuceneCrawler.threadExecuting=true;
Thread th=new Thread(new LuceneCrawler());
th.start();
}
}
public Hashtable getOptimizationQueueObj(){
return optimizedAccounts;
}
public String getOptimizationStatus(){
String rtn="";
for(Iterator i=optimizedAccounts.keySet().iterator();i.hasNext();){
String account=(String)i.next();
TreeMap table=(TreeMap)optimizedAccounts.get(account);
Vector removeTable=new Vector();
for(Iterator ia=table.keySet().iterator();ia.hasNext();){
String tablena=(String)ia.next();
Integer count=(Integer)table.get(tablena);
rtn+="Account:"+account+", table:"+tablena+", count:"+count+"\n";
}
}
return rtn;
}
public static int getQueueStat() throws Exception {
return queue.size();
}
}

62
project/bldb/src/main/java/com/fe/lucene/MarketCommodityCollector.java

@ -0,0 +1,62 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import com.fourelementscapital.db.FlexiFieldDB;
import com.fourelementscapital.db.ReferenceDB;
public class MarketCommodityCollector extends SearchTokenCollector {
public MarketCommodityCollector(String tablename) {
super(tablename);
}
public void processTextTokens(String ticker) throws Exception {
FlexiFieldDB fldb=FlexiFieldDB.getFlexiFieldDB();
//ReferenceDB refdb=new ReferenceDB();
fldb.connectDB();
Vector<Map> fl_fdata=fldb.getFlexiFieldData4LuceneToken("commodity_flexi_data" , "commodity", ticker);
String content=ticker+" ";
HashMap catfields=new HashMap();
for(Iterator<Map> i=fl_fdata.iterator();i.hasNext();){
Map record=i.next();
if(record.get("val")!=null){
String val=(String)record.get("val");
content+=" "+val;
if(record.get("fieldlabel")!=null){
catfields.put(record.get("fieldlabel")+"",val );
}
}
}
catfields.put("title",ticker);
super.rtn=content;
super.categoryfields.clear();
super.categoryfields.putAll(catfields);
fldb.closeDB();
//refdb.closeDB();
}
}

76
project/bldb/src/main/java/com/fe/lucene/MarketContractCollector.java

@ -0,0 +1,76 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import com.fourelementscapital.db.FlexiFieldDB;
import com.fourelementscapital.db.ReferenceDB;
public class MarketContractCollector extends SearchTokenCollector {
public MarketContractCollector(String tablename) {
super(tablename);
}
public void processTextTokens(String ticker) throws Exception {
//FlexiFieldDB fldb=new FlexiFieldDB();
ReferenceDB refdb=ReferenceDB.getReferenceDB();
refdb.connectDB();
//Vector<Map> fl_fdata=fldb.getFlexiFieldData4LuceneToken("commodity_flexi_data" , "commodity", ticker);
Vector bb_syncdata=refdb.getContractBBInfo(ticker);
String content=ticker+" ";
HashMap catfields=new HashMap();
/*
for(Iterator<Map> i=fl_fdata.iterator();i.hasNext();){
Map record=i.next();
if(record.get("val")!=null){
String val=(String)record.get("val");
content+=" "+val;
if(record.get("fieldlabel")!=null){
catfields.put(record.get("fieldlabel")+"",val );
}
}
}
*/
for(Iterator<Map> i=bb_syncdata.iterator();i.hasNext();){
Map record=i.next();
if(record.get("value")!=null){
String val=(String)record.get("value");
content+=" "+val;
if(record.get("friendly_name")!=null){
catfields.put(record.get("friendly_name")+"",val );
}
if(record.get("bb_fieldname")!=null){
catfields.put(record.get("bb_fieldname")+"",val );
}
}
}
catfields.put("title",ticker);
super.rtn=content;
super.categoryfields.clear();
super.categoryfields.putAll(catfields);
//fldb.closeDB();
refdb.closeDB();
}
}

77
project/bldb/src/main/java/com/fe/lucene/MarketSecurityCollector.java

@ -0,0 +1,77 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import com.fourelementscapital.db.FlexiFieldDB;
import com.fourelementscapital.db.ReferenceDB;
public class MarketSecurityCollector extends SearchTokenCollector {
public MarketSecurityCollector(String tablename) {
super(tablename);
}
public void processTextTokens(String ticker) throws Exception {
FlexiFieldDB fldb=FlexiFieldDB.getFlexiFieldDB();
ReferenceDB refdb=ReferenceDB.getReferenceDB();
fldb.connectDB();
refdb.connectDB();
Vector<Map> fl_fdata=fldb.getFlexiFieldData4LuceneToken("security_flexi_data" , "ticker", ticker);
Vector bb_syncdata=refdb.getSecurityBBInfo(ticker);
String content=ticker+" ";
HashMap catfields=new HashMap();
for(Iterator<Map> i=fl_fdata.iterator();i.hasNext();){
Map record=i.next();
if(record.get("val")!=null){
String val=(String)record.get("val");
content+=" "+val;
if(record.get("fieldlabel")!=null){
catfields.put(record.get("fieldlabel")+"",val );
}
}
}
for(Iterator<Map> i=bb_syncdata.iterator();i.hasNext();){
Map record=i.next();
if(record.get("value")!=null){
String val=(String)record.get("value");
content+=" "+val;
if(record.get("friendly_name")!=null){
catfields.put(record.get("friendly_name")+"",val );
}
if(record.get("bb_fieldname")!=null){
catfields.put(record.get("bb_fieldname")+"",val );
}
}
}
catfields.put("title",ticker);
super.rtn=content;
super.categoryfields.clear();
super.categoryfields.putAll(catfields);
fldb.closeDB();
refdb.closeDB();
}
}

79
project/bldb/src/main/java/com/fe/lucene/MyIndexer.java

@ -0,0 +1,79 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.io.File;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import com.fourelementscapital.scheduler.config.Config;
public class MyIndexer {
private Logger log = LogManager.getLogger(MyIndexer.class.getName());
private String filename=null;
private String account;
private String dbname;
private final int MAX_BUFFERED_DELETED_TERMS=20;
public MyIndexer(String dbname) {
this.dbname=dbname;
//this.filename=GlobalConfiguration.getConfig().getConfigValue(Preferences.GLOBAL_CONFIG_SEARCH_INDEX_FOLDER)+account+File.separator+tablename;
String root=Config.getString("lucene_index_folder");
this.filename=root+this.dbname;
if (!new File(this.filename).isDirectory()) {
new File(this.filename).mkdirs();
try{
IndexWriter iw= new IndexWriter(new File(this.filename), new StandardAnalyzer(), true,IndexWriter.MaxFieldLength.LIMITED);
iw.optimize();
iw.close();
log.info("Lucene Index created");
}catch(Exception e){
log.error("ERROR in creating index: MSG:"+e.getMessage());
}
}
}
public synchronized IndexReader getIndexReader() throws Exception {
return IndexReader.open(this.filename);
}
public synchronized IndexWriter getIndexWriter() throws Exception {
Directory idir=FSDirectory.getDirectory(new File(this.filename));
if(IndexWriter.isLocked(idir)){
//LuceneLog.log(LuceneLog.STATUS_FAILED, this.account, this.tablename, 0, "Forced to unlock the directory");
log.error("Forced to unclock index of file:"+this.filename);
IndexWriter.unlock(idir);
}
IndexWriter idx=new IndexWriter(new File(this.filename), new StandardAnalyzer(), false,IndexWriter.MaxFieldLength.LIMITED);
return idx;
}
public synchronized IndexSearcher getIndexSearcher() throws Exception {
return new IndexSearcher(this.filename);
}
}

43
project/bldb/src/main/java/com/fe/lucene/RecordDocument.java

@ -0,0 +1,43 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.io.File;
import java.util.Iterator;
import java.util.Map;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
public class RecordDocument {
public static Document Document(String content, String ticker, Map fields)
throws java.io.FileNotFoundException {
Document doc = new Document();
doc.add(new Field("content", content, Field.Store.YES, Field.Index.TOKENIZED));
doc.add(new Field("id", ticker, Field.Store.YES, Field.Index.UN_TOKENIZED));
//doc.add(new Field("ticker", ticker, Field.Store.YES, Field.Index.UN_TOKENIZED));
// doc.add(new Field("security", ticker, Field.Store.YES, Field.Index.UN_TOKENIZED));
//doc.add(new Field("contract", ticker, Field.Store.YES, Field.Index.UN_TOKENIZED));
//doc.add(new Field("commodity", ticker, Field.Store.YES, Field.Index.UN_TOKENIZED));
for(Iterator i=fields.keySet().iterator();i.hasNext();){
String key=(String)i.next();
if(key!=null && !key.equals("") && fields.get(key)!=null && fields.get(key)!=null && !fields.get(key).equals("") ){
doc.add(new Field(key, fields.get(key).toString(), Field.Store.YES, Field.Index.TOKENIZED));
}
}
return doc;
}
}

45
project/bldb/src/main/java/com/fe/lucene/SchedulerTokenCollector.java

@ -0,0 +1,45 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.util.Map;
import com.fourelementscapital.db.SchedulerDB;
public class SchedulerTokenCollector extends SearchTokenCollector {
public SchedulerTokenCollector(String tablename) {
super(tablename);
}
public void processTextTokens(String scheduler_id) throws Exception {
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
sdb.connectDB();
Map data=sdb.getScheduler(Integer.parseInt(scheduler_id));
super.categoryfields.clear();
super.categoryfields.putAll(data);
if(data.get("name")!=null){
super.categoryfields.put("title",data.get("name"));
super.rtn=(String)data.get("name");
}
sdb.closeDB();
}
}

258
project/bldb/src/main/java/com/fe/lucene/SearchSession.java

@ -0,0 +1,258 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
import java.util.Vector;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermEnum;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import com.fourelementscapital.db.vo.ValueObject;
public class SearchSession {
//private IndexWriter index;
//private IndexReader ir;
//private IndexSearcher searcher;
private Logger log = LogManager.getLogger(SearchSession.class.getName());
private int maxpage = 1000;
private MyIndexer myin;
public SearchSession(MyIndexer myin){
this.myin=myin;
}
//public SearchSession(IndexWriter index,IndexReader ir){
// this.index=index;
// this.ir=ir;
//}
//public SearchSession(IndexSearcher searcher) {
// this.searcher=searcher;
//}
public void setMaxPerPage(int mp){
this.maxpage=mp;
}
/*
public synchronized void addUpdate(long id, String content, Map fields) throws Exception {
if(this.ir==null || this.index==null) throw new Exception("IndexWriter or IndexReader is empty");
Term termid=new Term("id", ""+id);
TermEnum uidIter = ir.terms(termid);
Document doc=RecordDocument.Document(content, id, fields);
doc.add(new Field("updated",
DateTools.timeToString(new Date().getTime(), DateTools.Resolution.MINUTE),
Field.Store.YES, Field.Index.UN_TOKENIZED));
if(uidIter.next()){
index.updateDocument(termid, doc);
//update
}else{
doc.add(new Field("added",
DateTools.timeToString(new Date().getTime(), DateTools.Resolution.MINUTE),
Field.Store.YES, Field.Index.UN_TOKENIZED));
index.addDocument(doc);
//add
}
}
*/
public final static int ACTION_INDEX=1;
public final static int ACTION_DELETE=2;
public final static int ACTION_OPTIMIZE=3;
/**
* the one method for indexing and deleting because it should be synchronized, while doing this operation index will be locked.
*
* @param actiontype
* @param id
* @param content
* @param fields
* @throws Exception
*/
public synchronized void action(int actiontype,SearchTokenCollector ctc, String ticker) throws Exception {
synchronized (this) {
//System.out.println("action started:id"+id);
log.debug("action() invoked");
IndexReader ir=myin.getIndexReader();
IndexWriter index=myin.getIndexWriter();
try{
if(actiontype==ACTION_INDEX){
try{
ctc.processTextTokens(ticker);
}catch(Exception e){
e.printStackTrace();
throw new Exception("Error while processing at ticker:"+ticker+" Msg:"+e.getLocalizedMessage());
}
if(ctc.getString()!=null){
//candidate with this id already existing
String content=ctc.getString();
Map cfields=ctc.getCategoryFields();
log.debug("cfields:"+cfields);
log.debug("content:"+content);
Term termid=new Term("id", ""+ticker);
TermEnum uidIter = ir.terms(termid);
Document doc=RecordDocument.Document(content, ticker, cfields);
doc.add(new Field("updated",
DateTools.timeToString(new Date().getTime(), DateTools.Resolution.DAY),
Field.Store.YES, Field.Index.TOKENIZED));
//in-case of additional fields to be added to the index.
for(Iterator i=ctc.getAdditionalFields().iterator();i.hasNext();){
ValueObject v=(ValueObject)i.next();
if(v.getKey()!=null && !v.getKey().equals("") && v.getValue()!=null && !v.getValue().equals(""))
doc.add(new Field(v.getKey(), v.getValue(), Field.Store.YES, Field.Index.TOKENIZED));
}
if(uidIter.next()){
log.debug("updating document");
index.updateDocument(termid, doc);
//update
}else{
doc.add(new Field("added",
DateTools.timeToString(new Date().getTime(), DateTools.Resolution.DAY),
Field.Store.YES, Field.Index.TOKENIZED));
index.addDocument(doc);
//add
log.debug("adding document");
}
}else{
throw new Exception("No content collected at id:"+ticker+" Msg:");
}
}else if(actiontype==ACTION_DELETE){
if(ir==null || index==null) throw new Exception("IndexWriter or IndexReader is empty");
Term termid=new Term("id", ""+ticker);
TermEnum uidIter = ir.terms(termid);
if(uidIter.next()){
index.deleteDocuments(termid);
//update
log.debug("deleting document");
}
}else if(actiontype==ACTION_OPTIMIZE){
log.debug("optimizing indexwriter");
index.optimize();
}
}catch(Exception e){
//throw e;
throw new Exception("Error at id:"+ticker+" Msg:"+e.getMessage());
}finally{
ir.close();
index.close();
}
//System.out.println("action ended:id"+id+" ********");
}
}
private int totalHits=0;
public int getTotalHits(){
return this.totalHits;
}
public Vector results(String querystring /*, Session session */, int startindex ) throws Exception{
IndexSearcher searcher=this.myin.getIndexSearcher();
Vector rtn=null;
try{
Analyzer analyzer = new StandardAnalyzer();
QueryParser qp = new QueryParser("content", analyzer);
qp.setDefaultOperator(QueryParser.AND_OPERATOR);
Query query = qp.parse(querystring);
//Query query = QueryParser.parse(queryString, "contents", analyzer);
Hits hits = searcher.search(query);
this.totalHits=hits.length();
//System.out.println("hits legnth:"+hits.length());
if (hits.length() == 0) {
// System.out.println("SearchSession: no result found"+new Date());
}else{
rtn=new Vector();
int end=((startindex+maxpage)<=hits.length())?startindex+maxpage: hits.length();
for (int i = startindex; i < end ; i++) { // for each element
Document doc = hits.doc(i); //get the next document
//String highlighting=extractFragment(doc, query);
//LuceneResultItem li= new LuceneResultItem();
//li.setHtext(highlighting);
//try{
// li.setId(Long.parseLong(doc.get("id")));
//}catch(Exception e){}
//li.setScore(hits.score(i));
rtn.add(doc.get("id"));
}
}
}catch(Exception e){
throw e;
}finally{
searcher.close();
}
return rtn;
}
}

96
project/bldb/src/main/java/com/fe/lucene/SearchTokenCollector.java

@ -0,0 +1,96 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.Vector;
import com.fourelementscapital.db.vo.ValueObject;
public abstract class SearchTokenCollector {
protected String rtn="";
protected HashMap categoryfields=new HashMap();
protected Vector additionalField=new Vector();
private String tablename=null;
public SearchTokenCollector(String tablename){
this.tablename=tablename;
}
public String getTablename(){return this.tablename;}
protected String collectTokens(Map data) throws Exception {
String rtn="";
if(data!=null){
for(Iterator i=data.keySet().iterator();i.hasNext();){
String key=(String)i.next();
rtn+=(data.get(key)!=null)?" "+key+":"+data.get(key).toString():" ";
}
}
return rtn;
}
abstract void processTextTokens(String ticker) throws Exception;
public String getString(){
return this.rtn;
}
public Map getCategoryFields(){
return this.categoryfields;
}
protected void ignoreFields(Map data, String keys){
StringTokenizer st= new StringTokenizer(keys,",");
while(st.hasMoreTokens()){
String key=st.nextToken();
if(data.get(key)!=null){
data.remove(key);
}
}
}
protected Map getCategoryFields(Map data, Map datamap){
HashMap rtn=new HashMap();
for(Iterator i=datamap.keySet().iterator();i.hasNext();){
String key=(String)i.next();
if(data.get(key)!=null){
rtn.put(datamap.get(key), data.get(key));
}
}
return rtn;
}
protected void addFields(String fieldname,String fieldvalue){
ValueObject vo=new ValueObject();
vo.setKey(fieldname);
vo.setValue(fieldvalue);
additionalField.add(vo);
}
public Vector getAdditionalFields(){
return additionalField;
}
}

55
project/bldb/src/main/java/com/fe/lucene/TickerIndexRecord.java

@ -0,0 +1,55 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
public class TickerIndexRecord {
private String ticker;
private String tablename;
private int action;
public int getAction() {
return action;
}
public void setAction(int action) {
this.action = action;
}
public String getTablename() {
return tablename;
}
public void setTablename(String tablename) {
this.tablename = tablename;
}
public String getTicker() {
return ticker;
}
public void setTicker(String ticker) {
this.ticker = ticker;
}
public boolean equals(Object oth){
TickerIndexRecord other=(TickerIndexRecord)oth;
if(this.getTablename().equals(other.getTablename()) && this.getTicker()==other.getTicker()){
return true;
}else{
return false;
}
}
}

55
project/bldb/src/main/java/com/fe/lucene/TokenCollectorFactory.java

@ -0,0 +1,55 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.lucene;
public class TokenCollectorFactory {
private TokenCollectorFactory(){}
public static SearchTokenCollector getTokenCollector(TickerIndexRecord uio ){
try {
if(uio.getTablename().equals(LuceneCrawler.INDEX_TABLE_SECURITY)){
return new MarketSecurityCollector(uio.getTablename());
//return null;
}
if(uio.getTablename().equals(LuceneCrawler.INDEX_TABLE_CONTRACT)){
return new MarketContractCollector(uio.getTablename());
//return null;
}
if(uio.getTablename().equals(LuceneCrawler.INDEX_TABLE_COMMODITY)){
return new MarketCommodityCollector(uio.getTablename());
//return null;
}
if(uio.getTablename().equals(LuceneCrawler.INDEX_TABLE_FUNDAMENTAL_TICKR)){
return new FundamentalTickersCollector(uio.getTablename());
//return null;
}
if(uio.getTablename().equals(LuceneCrawler.INDEX_SCHEDULER)){
return new SchedulerTokenCollector(uio.getTablename());
//return null;
}
} catch (Exception e) {
// TODO Auto-generated catch block
//e.printStackTrace();
}
return null;
}
}

604
project/bldb/src/main/java/com/fe/p2p/P2PServiceServlet.java

@ -0,0 +1,604 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.p2p;
import java.io.File;
import java.io.FileInputStream;
import java.io.StringReader;
import java.io.StringWriter;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.StringTokenizer;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import net.jxta.discovery.DiscoveryService;
import net.jxta.pipe.InputPipe;
import net.jxta.protocol.PeerAdvertisement;
import net.jxta.protocol.PipeAdvertisement;
import org.apache.commons.digester.Digester;
import org.apache.commons.io.IOUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fe.io.peer.PeerClient;
import com.fe.io.server.ServerScheduler;
import com.fourelementscapital.db.RFunctionDB;
import com.fourelementscapital.db.SchedulerDB;
import com.fourelementscapital.db.SuperDB;
import com.fourelementscapital.db.UtilDB;
import com.fourelementscapital.db.vo.PeerPackage;
import com.fourelementscapital.scheduler.balance.ExecutingQueueCleaner;
import com.fourelementscapital.scheduler.config.Config;
import com.fourelementscapital.scheduler.group.RScriptScheduledTask;
import com.fourelementscapital.scheduler.p2p.MessageBean;
import com.fourelementscapital.scheduler.p2p.P2PAdvertisement;
import com.fourelementscapital.scheduler.p2p.P2PService;
import com.fourelementscapital.scheduler.p2p.listener.IncomingMessage;
public class P2PServiceServlet extends HttpServlet {
private static Thread jxtaInpThread=null;
private static Thread jxtaInpHelperThread=null;
private InputPipe inputPipe=null;
private static volatile boolean pipspin;
private static volatile boolean pipspinhelper;
private Timer timer=null;
private Logger log = LogManager.getLogger(P2PServiceServlet.class.getName());
public static final String helper_prefix="_helper";
private static String defaultP2PCache=""; // addition because there is a possibility that .cache folder cause an error when restarting .. bug when restarting (20140411)
@Override
public void init(ServletConfig servletConfig ) throws ServletException {
super.init(servletConfig);
start();
}
private void print(String pr) {
System.out.println("P2PServiceServlet:"+pr);
}
public void start() {
P2PService.removeCache(); // for the server
P2PService.setPeerStarted();
updatePeerName();
print("Peer updated");
startJxta();
print("starteed Jxta");
try {
capturePackageVersions();
} catch (Exception e1) {
log.error("!!!!! Error while capturing package information...");
}
try{
if(Config.getString("p2p.ignorejri")!=null && Config.getString("p2p.ignorejri").equalsIgnoreCase("true")){}else{
print("Before capturing r version");
RScriptScheduledTask.getRVersion();
}
print("end of start");
}catch(Exception e){
log.error("STARTUP ERROR:rJava support is not available on this peer");
}
}
public void startHelper() {
P2PService.removeCache(); //the .cache forlder will be locked when peer_helper is started
P2PService.setPeerStarted();
startHelperJxta();
}
public static boolean isJxtaInpThreadRunning(){
if(jxtaInpThread!=null && jxtaInpThread.isAlive())
return true;
else
return false;
}
private void startJxta(){
try {
System.out.println("starting network....................................");
//System.out.println("OS:"+System.getProperty("os.name"));
java.util.logging.Logger.getLogger("net.jxta").setLevel(Level.SEVERE);
//NetworkManager manager=P2PService.getManager();
//PeerGroup netPeerGroup = manager.getNetPeerGroup();
// get the discovery service
DiscoveryService discovery = P2PService.getDiscoveryService();
//PipeService pipeService = netPeerGroup.getPipeService();
long waittime = 10 * 1000L;
String computername=P2PService.getComputerName();
P2PAdvertisement ad=new P2PAdvertisement();
PeerAdvertisement mdadv = ad.getPeerAdvertisement(computername,P2PService.getPeerGroup());
discovery.publish(mdadv,DiscoveryService.NO_EXPIRATION,DiscoveryService.NO_EXPIRATION);
discovery.remotePublish(mdadv,DiscoveryService.NO_EXPIRATION);
jxtaInpThread=new Thread("Input poll") {
private Logger log = LogManager.getLogger(P2PServiceServlet.class.getName());
public void run() {
log.debug("jxtaInpThread run()11 ");
int sleepy=3000*60;
String computername=P2PService.getComputerName();
log.debug("computer name :"+computername);
P2PAdvertisement ad=new P2PAdvertisement();
log.debug("ad :"+ad);
PipeAdvertisement pipeAdv = ad.getPipeAdvertisement(computername,P2PService.getPeerGroup());
log.debug("creating input pipe advertisement ");
try{
inputPipe = P2PService.getPipeService().createInputPipe(pipeAdv, new IncomingMessage(null) );
//inputPipe = P2PService.getPipeService().createInputPipe(pipeAdv );
log.debug("waiting input pipe");
}catch(Exception e){
System.out.println("~~~~~~~~~~~~~FATAL Error P2PServiceServlet2$.run() on inputpipe service................");
e.printStackTrace();
}
P2PServiceServlet.pipspin=true;
while(P2PServiceServlet.pipspin) {
try {
sleep(sleepy);
}
catch(InterruptedException e) {log.error("Waiting thread intrupted...........");}
}
}
};
jxtaInpThread.start();
log.debug("jxtaInpThread started ");
TimerTask tt=new TimerTask() {
public void run() {
// System.out.format("Time's up!%n");
if(!jxtaInpThread.isAlive()){
//Logger log=Logger.getLogger(P2PServiceServlet.class);
//log.error("jxtaInpThread is not alive restarting the tread");
jxtaInpThread.start();
}
}
};
//checks every 1 minute to see if a thread still running....
long freq=90*1000;
timer = new Timer();
timer.scheduleAtFixedRate(tt,freq, freq);
TimerTask dbCleaner=new TimerTask() {
Logger log = LogManager.getLogger(P2PServiceServlet.class.getName());
public void run() {
int db_close_timeout = SuperDB.getDbCloseTimeout();
UtilDB udb=UtilDB.getUtilDB4SQLServer();
try{
SuperDB.killConnections(db_close_timeout);
Thread.sleep(300);
udb.connectDB(getUtilDBName());
ArrayList al=udb.showOldConnections(db_close_timeout,P2PService.getComputerName());
if(al != null && al.size()>0){
log.error("~~~~~~Killing "+al.size()+" physical connections in database after "+db_close_timeout+" minutes");
log.error("===While killing the following found left unclosed==");
log.error(SchedulerDB.collectStack4All());
log.error("=====");
udb.killConnections(al);
}
}catch(Exception e){
e.printStackTrace();
}finally{
try{
udb.closeDB();
}catch(Exception e){}
}
}
};
//checks every 5 minute to see if a thread still running....
long fivemins=60*1000*5;
Timer dbtimer = new Timer();
dbtimer.scheduleAtFixedRate(dbCleaner,fivemins, fivemins);
String tname="jett_thread_"+(new Date().getTime()/1000);
if(Config.getValue("load_balancing_server")!=null && Config.getValue("load_balancing_server").equals(P2PService.getComputerName())){
ExecutingQueueCleaner.clean(); //clean up the dead tasks in every 30 second.
}
/*
* launching NIO server
*
*/
if(Config.getValue("nio.server.mode")!=null && Config.getValue("nio.server.mode").trim().equalsIgnoreCase("true") &&
Config.getValue("nio.server.port")!=null && !Config.getValue("nio.server.port").trim().equals("")
){
int port=1818;
try{
port=Integer.parseInt(Config.getValue("nio.server.port"));
}catch(Exception e){}
Thread t=new Thread(new ServerScheduler(port),tname);
t.start();
System.out.println("--->ServerScheduler starting....in port:"+port);
}else{
if(Config.getValue("nio.server.address")!=null && !Config.getValue("nio.server.address").trim().equals("") &&
Config.getValue("nio.server.port")!=null && !Config.getValue("nio.server.port").trim().equals("")
){
System.out.println("--->PeerScheduler will start ...in IP:"+Config.getValue("nio.server.address")+" port:"+Config.getValue("nio.server.port"));
int port=1818;
String server=Config.getValue("nio.server.address");
try{
port=Integer.parseInt(Config.getValue("nio.server.port"));
}catch(Exception e){}
log.debug("server:"+server+" port:"+port+" tname:"+tname);
Thread t=new Thread(new PeerClient(server, port),tname);
log.debug("t:"+t);
t.start();
log.debug("started:");
//System.out.println("<---PeerScheduler starting...., "+server+":"+port);
}
}
}catch(Exception e){
e.printStackTrace();
}
}
private void startHelperJxta(){
try {
java.util.logging.Logger.getLogger("net.jxta").setLevel(Level.SEVERE);
DiscoveryService discovery = P2PService.getDiscoveryService();
long waittime = 10 * 1000L;
String computername=P2PService.getComputerName();
P2PAdvertisement ad=new P2PAdvertisement();
PeerAdvertisement mdadv = ad.getPeerAdvertisement(computername+helper_prefix,P2PService.getPeerGroup());
discovery.publish(mdadv,DiscoveryService.NO_EXPIRATION,DiscoveryService.NO_EXPIRATION);
discovery.remotePublish(mdadv,DiscoveryService.NO_EXPIRATION);
jxtaInpThread=new Thread("Input poll") {
private Logger log = LogManager.getLogger(P2PServiceServlet.class.getName());
public void run() {
int sleepy=3000*60;
String computername=P2PService.getComputerName();
P2PAdvertisement ad=new P2PAdvertisement();
PipeAdvertisement pipeAdv = ad.getPipeAdvertisement(computername+helper_prefix,P2PService.getPeerGroup());
try{
inputPipe = P2PService.getPipeService().createInputPipe(pipeAdv, new IncomingMessage(null) );
//inputPipe = P2PService.getPipeService().createInputPipe(pipeAdv );
log.debug("waiting input pipe");
}catch(Exception e){
System.out.println("~~~~~~~~~~~~~FATAL Error P2PServiceServlet2$.run() on inputpipe service................");
e.printStackTrace();
}
P2PServiceServlet.pipspin=true;
while(P2PServiceServlet.pipspin) {
try {
sleep(sleepy);
}
catch(InterruptedException e) {log.error("Waiting thread intrupted...........");}
}
}
};
jxtaInpThread.start();
TimerTask tt=new TimerTask() {
public void run() {
// System.out.format("Time's up!%n");
if(!jxtaInpThread.isAlive()){
//Logger log=Logger.getLogger(P2PServiceServlet.class);
//log.error("jxtaInpThread is not alive restarting the tread");
jxtaInpThread.start();
}
}
};
//checks every 1 minute to see if a thread still running....
long freq=90*1000;
timer = new Timer();
timer.scheduleAtFixedRate(tt,freq, freq);
TimerTask dbCleaner=new TimerTask() {
Logger log = LogManager.getLogger(P2PServiceServlet.class.getName());
public void run() {
int db_close_timeout = SuperDB.getDbCloseTimeout();
UtilDB udb=UtilDB.getUtilDB4SQLServer();
try{
SuperDB.killConnections(db_close_timeout);
Thread.sleep(300);
udb.connectDB(getUtilDBName());
ArrayList al=udb.showOldConnections(db_close_timeout,P2PService.getComputerName());
if(al != null && al.size()>0){
log.error("~~~~~~Killing "+al.size()+" physical connections in database after "+db_close_timeout+" minutes");
log.error("===While killing the following found left unclosed==");
log.error(SchedulerDB.collectStack4All());
log.error("=====");
udb.killConnections(al);
}
}catch(Exception e){
}finally{
try{
udb.closeDB();
}catch(Exception e){}
}
}
};
//checks every 5 minute to see if a thread still running....
long fivemins=60*1000*5;
Timer dbtimer = new Timer();
dbtimer.scheduleAtFixedRate(dbCleaner,fivemins, fivemins);
if(Config.getValue("load_balancing_server")!=null && Config.getValue("load_balancing_server").equals(P2PService.getComputerName())){
ExecutingQueueCleaner.clean(); //clean up the dead tasks in every 30 second.
}
}catch(Exception e){
e.printStackTrace();
}
}
private static MessageBean parseMessage(String msg) throws Exception {
Digester digester = new Digester();
digester.setValidating(false);
digester.addObjectCreate("message", MessageBean.class);
digester.addBeanPropertySetter("message/type");
digester.addBeanPropertySetter("message/command");
digester.addBeanPropertySetter("message/sender");
digester.addBeanPropertySetter("message/reply");
MessageBean ve= (MessageBean) digester.parse(new StringReader(msg));
return ve;
}
private void updatePeerName() {
SchedulerDB sdb=SchedulerDB.getSchedulerDB();
try{
String peername=P2PService.getComputerName();
sdb.connectDB();
sdb.updatePeersList(peername);
}catch(Exception e){
e.printStackTrace();
}finally{
try{
sdb.closeDB();
}catch(Exception e1){}
}
}
private void capturePackageVersions() throws Exception {
RFunctionDB rfdb=RFunctionDB .getRFunctionDB();
int loc=0;
try {
String peername=P2PService.getComputerName();
rfdb.connectDB();
loc=100;
LinkedHashMap<String , String> p=new LinkedHashMap<String, String>();
String rlib_path=System.getenv("R_HOME");
rlib_path+=rlib_path.endsWith(File.separator)?"library":File.separator+"library";
File[] libs=new File(rlib_path).listFiles();
int count=0;
ArrayList plist=new ArrayList();
loc=200;
for(int i=0;i<libs.length;i++){
File lib=new File(libs[i].getPath()+File.separator+"DESCRIPTION");
loc=300;
if(lib.exists()){
loc=400;
try{
StringWriter stringWriter = new StringWriter();
IOUtils.copy(new FileInputStream(lib), stringWriter);
StringTokenizer st=new StringTokenizer(stringWriter.toString(),"\n\r");
PeerPackage pp=new PeerPackage();
pp.setPackagename(libs[i].getName());
pp.setLastchecked(new Date());
loc=500;
while(st.hasMoreTokens()){
String line=st.nextToken();
if(line.startsWith("Version:") && line.split(":").length>1){
pp.setVersion(line.split(":")[1]);
}
}
plist.add(pp);
}catch(Exception e){
log.error("Error while getting info of package "+libs[i].getName());
}
}
}
rfdb.updatePeerPackage(peername, plist);
log.debug("peername:"+peername+" plist:"+plist);
}catch(Exception e){
log.error("Error ,MSG:"+e.getMessage()+" loc:"+loc);
//e.printStackTrace();
throw e;
}finally{
rfdb.closeDB();
}
}
/*
public void pipeMsgEvent(PipeMsgEvent event) {
Message msg;
try {
// Obtain the message from the event
//System.out.println("pipeMsgEvent() called");
msg = event.getMessage();
if (msg == null) {
System.out.println("Received an empty message");
return;
}
} catch (Exception e) {
e.printStackTrace();
return;
}
// get all the message elements
Message.ElementIterator en = msg.getMessageElements();
if (!en.hasNext()) {
return;
}
// get the message element in the name space PipeClient.MESSAGE_NAME_SPACE
MessageElement msgElement = msg.getMessageElement(null, P2PService.MESSAGE_NAME_SPACE);
P2PService.messages.add(msgElement.toString());
String message=msgElement.toString();
// Get message
*/
/*
if(message.startsWith("[REPLYTO:")){
String replytoPart=message.substring(0,"]");
PeerGroup netPeerGroup = P2PService.getPeerGroup();
PipeAdvertisement pipeAdv = new P2PAdvertisement().getPipeAdvertisement("Renee",netPeerGroup);
//OutgoingMessageCompose omc=new OutgoingMessageCompose(){
//};
OutgoingMessage ogM=new OutgoingMessage(null,"Your question will be answereed soon");
PipeService pipeService = P2PService.getPipeService();
try{
pipeService.createOutputPipe(pipeAdv,ogM);
}catch(Exception e){
e.printStackTrace();
}
}
*/
/*
if (msgElement.toString() == null) {
System.out.println("null msg received");
} else {
Date date = new Date(System.currentTimeMillis());
System.out.println("Message received at :" + date.toString());
System.out.println("Message created at :" + msgElement.toString());
}
}
*/
public void destroy() {
jxtaInpThread.interrupt();
P2PServiceServlet.pipspin=false;
if(timer!=null){
timer.cancel();
}
P2PService.stopNetwork();
}
private String getUtilDBName() {
//String db = "master";
//if ("mariadb".equalsIgnoreCase( SuperDB.getDbType() )) {
// db = "mysql";
//}
String db = "mysql";
return db;
}
}

BIN
project/bldb/src/main/java/com/fe/p2p/peerbusy.gif

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

148
project/bldb/src/main/java/com/fe/p2p/websocket/TomcatWSExecuteRService.java

@ -0,0 +1,148 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.p2p.websocket;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.http.HttpServletRequest;
import org.apache.catalina.websocket.MessageInbound;
import org.apache.catalina.websocket.StreamInbound;
import org.apache.catalina.websocket.WebSocketServlet;
import org.apache.catalina.websocket.WsOutbound;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fourelementscapital.scheduler.balance.LoadBalancingQueue;
import com.fourelementscapital.scheduler.rscript.RScript;
import com.fourelementscapital.scheduler.rscript.RScriptAsyncWebsocket;
public class TomcatWSExecuteRService extends WebSocketServlet {
private Logger log = LogManager.getLogger(TomcatWSExecuteRService.class.getName());
private final static Set<ChatMessageInbound> connections = new CopyOnWriteArraySet<ChatMessageInbound>();
@Override
protected StreamInbound createWebSocketInbound(String subProtocol, HttpServletRequest request) {
//System.out.println("TomcatWSServer.createWebSocketInbound()");
return new ChatMessageInbound(request.getRemoteHost());
}
private final class ChatMessageInbound extends MessageInbound {
private String ip;
public ChatMessageInbound(String ip) {
this.ip=ip;
}
protected void onOpen(WsOutbound outbound) {
connections.add(this);
//System.out.println("TomcatWSServer.onOpen()");
log.debug("connected...");
}
@Override
protected void onClose(int status) {
connections.remove(this);
log.debug("closed...");
//System.out.println("TomcatWSServer.onClose()");
}
@Override
protected void onBinaryMessage(ByteBuffer message) throws IOException {
throw new UnsupportedOperationException("Binary message not supported.");
}
@Override
protected void onTextMessage(CharBuffer message) throws IOException {
// Never trust the client
//String filteredMessage = String.format("%s: %s", nickname, HTMLFilter.filter(message.toString()));
//broadcast(message.toString());
//log.debug("msg received:"+message);
String s=message.toString();
Pattern pattern = Pattern.compile("^(.*?)~~(.*?)~~(.*?)$");
Matcher matcher = pattern.matcher(s);
//String id=s.replaceAll("^(.*?)~~(.*?)~~(.*?)$", "$1");
//String engine=s.replaceAll("^(.*?)~~(.*?)~~(.*?)$", "$2");
//String script=s.replaceAll("^(.*?)~~(.*?)~~(.*?)$", "$3");
//System.out.println("matcher.groupCount:"+matcher.groupCount());
//System.out.println("matcher.find():"+ matcher.find());
if(matcher.find() && matcher.groupCount()>2){
//String id=s.replaceAll("^(.*?)~~(.*?)~~(.*?)$", "$1");
//String engine=s.replaceAll("^(.*?)~~(.*?)~~(.*?)$", "$2");
//String script=s.replaceAll("^(.*?)~~(.*?)~~(.*?)$", "$3");
String id=matcher.group(1);
String engine=matcher.group(2);
String script=matcher.group(3);
//System.out.println("id:"+ id+" engine:"+engine);
//System.out.println("script:"+script);
//System.out.println("host:"+this.ip);
RScript rs=new RScript();
//set unique name from the parameter
rs.setUniquename(id);
rs.setRequesthost(this.ip);
rs.setTaskuid("direct_script");
if(engine!=null && engine.equalsIgnoreCase("rserve")){
rs.setTaskuid("direct_script_unix");
}
rs.setScript(script);
RScriptAsyncWebsocket listener=new RScriptAsyncWebsocket(id, this);
try{
LoadBalancingQueue.getExecuteRScriptDefault().addExecuteR(rs,listener);
}catch(Exception e){
log.error("error:"+e.getMessage());
}
}else{
String rtn="Script can't executed without ID or script body, format: unique-id~~script_content";
this.getWsOutbound().writeTextMessage(CharBuffer.wrap(rtn));
this.getWsOutbound().flush();
}
//System.out.println("id:"+id);
//System.out.println("script:"+script);
}
}
public static void broadcast(String message) {
for (ChatMessageInbound connection : connections) {
Logger log = LogManager.getLogger(TomcatWSExecuteRService.class.getName());
log.debug("# connections:"+connections.size());
log.debug("# Msg:"+message);
try {
CharBuffer buffer = CharBuffer.wrap(message);
connection.getWsOutbound().writeTextMessage(buffer);
} catch (IOException ignore) {
// Ignore
}
}
}
}

86
project/bldb/src/main/java/com/fe/p2p/websocket/cmd/Queue.java

@ -0,0 +1,86 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.p2p.websocket.cmd;
import java.util.Iterator;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import com.fourelementscapital.scheduler.balance.LoadBalancingQueue;
import com.fourelementscapital.scheduler.balance.executeR.LoadBalancingNewExecuteRQueue;
import com.fourelementscapital.scheduler.p2p.websocket.CommandAbstract;
import com.fourelementscapital.scheduler.queue.QueueStack;
import com.fourelementscapital.scheduler.queue.QueueStackManager;
public class Queue extends CommandAbstract {
@Override
public String executeValidCommand(CommandLine cmd, String command) {
String result="";
if(cmd.hasOption("o")){
//result="Not implemented yet";
LoadBalancingQueue leq=LoadBalancingQueue.getExecuteRScriptDefault();
if(leq instanceof LoadBalancingNewExecuteRQueue){
LoadBalancingNewExecuteRQueue leqnew=(LoadBalancingNewExecuteRQueue)leq;
try{
int q_size=leqnew.getScriptQueue().size();
int p_size=leqnew.getScriptProcessingQueue().size();
int o_size=leqnew.getAllScriptObjectsSize();
result+="Queued :"+q_size+"\n";
result+="Processing :"+p_size+"\n";
result+="Total Objects in Mem :"+o_size+"\n";
}catch(Exception e){
result+=" Error, e:"+e.getMessage();
}
}else{
result+="Current queue implementation doesn't support this feature";
}
}else{
//result=showHelp();
try{
Iterator<QueueStack> qst= QueueStackManager.getAllQueueStacks().iterator();
while(qst.hasNext()){
QueueStack qs=qst.next();
result+=qs.getPeername()+":"+qs.getUid()+" -----> "+(qs.isRunning()?"Busy":"Idle")+" "+qs.getSupportedtaskuids()+"\n";
}
if(result.equals("")){
result="No queue from peers";
}
}catch(Exception e){
result="Error, "+e.getMessage();
}
}
return result;
}
@Override
public Options getOptions() {
Options options = new Options();
//options.addOption("s", "show", false, "Show online peers");
//options.addOption("p", "peer", true, "Show queue stack of server side - example: -q 4ecappcsg2");
options.addOption("o", "queue-objects", false, "Show number of queued and processing objects");
return options;
}
@Override
public String getHeader() {
return "Show queue stacks and objects in the different queue in server side";
}
@Override
public String getFooter() {
return "";
}
}

164
project/bldb/src/main/java/com/fe/scheduler/SchedulerInitServlet.java

@ -0,0 +1,164 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.scheduler;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Properties;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fe.client.AdminMgmt;
import com.fe.util.PasswordService;
//import com.fe.data.BBSyncTrigger;
import com.fourelementscapital.scheduler.SchedulerEngine;
import com.fourelementscapital.scheduler.config.Config;
import com.fourelementscapital.scheduler.p2p.P2PService;
public class SchedulerInitServlet extends HttpServlet {
private Logger log = LogManager.getLogger(SchedulerInitServlet.class.getName());
private static String serverRoot=null;
public void init( ServletConfig servletConfig ) throws ServletException {
//System.out.println("~~~~~~~~~~~~~~~~~~~Servlet Initialized");
try{
serverRoot=servletConfig.getServletContext().getRealPath("");
System.out.println("------Server Root:"+serverRoot);
log.debug("p2p service started ");
String bbsy=Config.getString("bloomberg_synchronization");
if(false){
if(P2PService.getComputerName().equalsIgnoreCase("4ecapsvsg5") && !servletConfig.getServletContext().getRealPath("").contains("tomcat_beta")){
throw new ServletException ("scheduler doen't support dev mode");
}
}
//in production it should be moved to below the conditions, remove this and uncomment below.
//new SchedulerEngine().startSchedulerQueue();
//new BloombergDownloadJob().scheduleDownloadQueries();
if(Config.getValue("load_balancing_server")!=null && Config.getValue("load_balancing_server").equals(P2PService.getComputerName())){
new SchedulerEngine().startSchedulerQueue();
System.out.println("------Scheduer Queue started");
//new WSServer( 10008, new Draft_17() ).start();
System.out.println("------WebSocket Server started..");
}
if(false){
if(bbsy!=null & bbsy.equalsIgnoreCase("no")){
//under development
throw new Exception("Bloomberg Synchronization ignored, as it is not production server");
}
}
log.debug("init()");
if(Config.getValue("load_balancing_server")==null){
//shouldn't build any queue.
//new SchedulerEngine().startSchedulerQueue();
}
log.debug("init()1");
//new BloombergDownloadJob().scheduleDownloadQueries();
initAdminDefaultPwd();
//}catch(ServletException e1){
// throw e1;
}catch(Exception e){
e.printStackTrace();
log.error("####Error while scheduling bloomberg sync ERROR MSG:"+e.getMessage());
}
}
private void initAdminDefaultPwd() {
try{
Properties prop=new Properties();
prop.load(new FileInputStream(AdminMgmt.DB_USER_PROPERTY_FILE));
}catch(java.io.FileNotFoundException fnf){
try{
Properties prop = new Properties();
String password=PasswordService.encrypt("admin");
prop.setProperty("admin", password);
prop.store(new FileOutputStream(AdminMgmt.DB_USER_PROPERTY_FILE), null);
}catch(Exception ex1){}
}catch(Exception e){
//e.printStackTrace();
}
}
/*
private void addScheduledJobs(Vector<XMLScheduledJob> jobs,String confolder,String database) throws Exception{
log.debug(" Job size:"+jobs.size());
for(XMLScheduledJob sc:jobs){
if(sc.getDaysNumber()!=-1 && sc.getWeekdayNumber()!=-1 && sc.getHourNumber()!=-1 && sc.getMinuteNumber()!=-1 ) {
sc.setConfolder(confolder);
sc.setDatabase(database);
String jobname=sc.getWeekday()+sc.getHour()+sc.getMinute()+sc.getFilename()+"_"+database;
SchedulerFactory sf=new StdSchedulerFactory();
Scheduler scheduler=sf.getScheduler();
//JobDetail holds the definition for Jobs
JobDetail jobDetail = new JobDetail(jobname, Scheduler.DEFAULT_GROUP,BloombergSyncJob.class);
jobDetail.getJobDataMap().put("job",sc);
Trigger trigger = TriggerUtils.makeWeeklyTrigger("trigger4"+jobname,sc.getWeekdayNumber(),sc.getHourNumber(),sc.getMinuteNumber());
if(scheduler.getJobDetail(jobname,Scheduler.DEFAULT_GROUP )==null){
log.debug("job "+jobname+" added to scheduler");
scheduler.scheduleJob(jobDetail, trigger );
scheduler.start();
}else{
throw new Exception("Job "+jobname+" already added to scheduler");
}
}
}
}
*/
public static String getAppPath(){
if(serverRoot==null){
return "c:\\tomcat\\webapps\\bldb";
}else{
return serverRoot;
}
}
}

166
project/bldb/src/main/java/com/fe/scheduler/TemplateParser.java

@ -0,0 +1,166 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.scheduler;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
* Template parser
*/
public class TemplateParser {
private String subject=null;
private String template=null;
private Map data=null;
/**
* Constructor
* @param template template
* @param data data
*/
public TemplateParser(String template, Map data){
this.template=template;
this.data=data;
}
private Logger log = LogManager.getLogger(TemplateParser.class.getName());
/**
* Parse template, set subject
* @return message
*/
public String parseTemplate(){
String message=parseNewSubject(this.template);
message=replaceNewValues(message, this.data);
this.subject=replaceNewValues(this.subject, this.data);
return message;
}
/**
* Get subject
* @return subject
*/
public String getSubject(){
return this.subject;
}
/**
* Replace new values
* @param template template
* @param values values
* @return template with new values
*/
protected String replaceNewValues(final String template,
final Map<String, String> values){
if(template!=null){
final StringBuffer sb = new StringBuffer();
final Pattern pattern = Pattern.compile("\\[\\[(.*?)\\]\\]", Pattern.DOTALL);
final Matcher matcher = pattern.matcher(template);
while(matcher.find()){
final String key = matcher.group(1);
final Object replacement = values.get(key);
if(replacement == null){
matcher.appendReplacement(sb, "");
}else{
//matcher.appendReplacement(sb, replacement.toString());
matcher.appendReplacement(sb, Matcher.quoteReplacement(replacement.toString()));
}
// log.debug("key:"+key+" replacement:"+replacement);
}
//log.debug("~~~~~~~~~~~~ exiting replaceNewValues()1");
matcher.appendTail(sb);
//log.debug("~~~~~~~~~~~~ exiting replaceNewValues()2");
return sb.toString();
}else{
return "";
}
}
/*
protected String parseBody(final String template){
if(template!=null){
Pattern p1 = Pattern.compile("\\{\\{body\\}\\}(.*?)\\{\\{/body\\}\\}",Pattern.DOTALL);
final Matcher matcher = p1.matcher(template);
final StringBuffer sb = new StringBuffer();
String ke1y="";
if(matcher.find()){
ke1y = matcher.group(1);
matcher.appendReplacement(sb, "");
}
matcher.appendTail(sb);
if(ke1y!=null && !ke1y.equals("")){
//ke1y = ke1y.toString().replaceAll("\\<.*?\\>", "");
//ke1y = ke1y.replaceAll("\t|\n|\r|\f", "");
//ke1y= ke1y.replace("&nbsp;", " ");
if(!ke1y.trim().equals("")){
this.body=ke1y;
}
}
return sb.toString();
}else{
return "";
}
}
*/
/**
* Parse new subject
* @param template template
* @return template with new subject
*/
protected String parseNewSubject(final String template){
if(template!=null){
Pattern p1 = Pattern.compile("\\{\\{subject\\}\\}(.*?)\\{\\{/subject\\}\\}",Pattern.DOTALL);
final Matcher matcher = p1.matcher(template);
final StringBuffer sb = new StringBuffer();
String ke1y="";
if(matcher.find()){
ke1y = matcher.group(1);
matcher.appendReplacement(sb, "");
}
matcher.appendTail(sb);
if(ke1y!=null && !ke1y.equals("")){
ke1y = ke1y.toString().replaceAll("\\<.*?\\>", "");
ke1y = ke1y.replaceAll("\t|\n|\r|\f", "");
ke1y= ke1y.replace("&nbsp;", " ");
if(!ke1y.trim().equals("")){
this.subject=ke1y;
}
}
return sb.toString();
}else{
return "";
}
}
}

28
project/bldb/src/main/java/com/fe/scheduler/TestJob.java

@ -0,0 +1,28 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.scheduler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
public class TestJob implements Job {
private Logger log = LogManager.getLogger(TestJob.class.getName());
public void execute(JobExecutionContext context) throws JobExecutionException {
//System.out.println("~~~~~~~~~~~~~~~~~~~~"+context.getJobDetail().getName());
//log.debug("Job Executed:"+context.getJobDetail().getName());
log.debug("Job Excecuted:"+context.getJobDetail().getJobDataMap().get("p1"));
}
}

1771
project/bldb/src/main/java/com/fe/scheduler/balance/LoadBalancingLinkedQueue.java

File diff suppressed because it is too large Load Diff

4
project/bldb/src/main/java/com/fe/scheduler/logmessages.properties

@ -0,0 +1,4 @@
peer.sendtask.received=Task Received from server
peer.sendtask.noroom2execute=Task failed, no room for execution
peer.sendtask.unknown=Error occured, Msg:[error_message]

24
project/bldb/src/main/java/com/fe/scheduler/scheduleralert.properties

@ -0,0 +1,24 @@
#test environment
alert.subject=Slow moving of Scheduler Queue
casper.commandfile=C:\\casperjs\\batchbin\\casperjs.bat
script.queue_capture=Z:\\IT\\casperjs_scripts\\capture_queue.js
scheduler.url=http://4ecapsvsg2:8080/bldb/scheduler.jsp
screenshot.folder=\\\\10.153.64.10\\Public\\IT\\casperjs_scripts\\files\\
screenshot.folder.link=\\\\10.153.64.10\\Public\\IT\\casperjs_scripts\\files\\
ssh.enable=true
ssh.ipaddress=10.153.64.47
#enable only when ssh is true;
casper.commandfile=casperjs
script.queue_capture=/mnt/public/IT/casperjs_scripts/capture_queue.js
screenshot.folder=/mnt/public/IT/casperjs_scripts/files/

94
project/bldb/src/main/java/com/fe/servlet/AceModeRSyntax.java

@ -0,0 +1,94 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.servlet;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fourelementscapital.db.RFunctionDB;
public class AceModeRSyntax extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String realpath=request.getSession().getServletContext().getRealPath("");
//System.out.println("~~~~~~~~~~realpath:"+realpath);
//FileInputStream fin=null;
String fullpath=realpath+File.separator+"ace"+File.separator+"src"+File.separator+"mode-r.js";
response.setContentType("application/javascript");
BufferedReader in = new BufferedReader(new FileReader(fullpath));
String rtn="";
String str;
while ((str = in.readLine()) != null) {
rtn+=str+"\r\n";
}
RFunctionDB rfdb=RFunctionDB.getRFunctionDB();
String functionanames="";
try{
rfdb.connectDB();
List fnames=rfdb.listAllRFunctionNames();
for(Iterator i=fnames.iterator();i.hasNext();){
String fname=(String)i.next();
fname=""+fname+"";
functionanames+=functionanames.equals("")?fname: "|"+fname;
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
try{
rfdb.closeDB();
}catch(Exception e1){}
}
//rtn=replacePlaceHolders(rtn,"myfunctions","'getRACEUniverse','getContractReference','abc','eee'");
rtn=replacePlaceHolders(rtn,"myfunctions",functionanames);
in.close();
OutputStream out = response.getOutputStream();
out.write(rtn.getBytes());
out.flush();
}
private String replacePlaceHolders(String css,String holder, String value){
//Map<String, String> data = new HashMap<String, String>();
//...
Pattern p = Pattern.compile("\\[\\[([a-zA-Z.]+)\\]\\]");
Matcher m = p.matcher(css);
StringBuffer sb = new StringBuffer();
while (m.find()) {
String reg1 = m.group(1);
if(reg1.equals("myfunctions")){
m.appendReplacement(sb, Matcher.quoteReplacement(value == null ? "" : value));
}
}
m.appendTail(sb);
return sb.toString();
}
}

151
project/bldb/src/main/java/com/fe/servlet/FileUploader.java

@ -0,0 +1,151 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
/*
* Copyright 2010 Blue Lotus Software, LLC.
* Copyright 2010 John Yeary <jyeary@bluelotussoftware.com>.
* Copyright 2010 Allan O'Driscoll
*
* Dual Licensed MIT and GPL v.2
*
* The MIT License
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*
* The GNU General Public License (GPL) Version 2, June 1991
* This program is free software; you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation; version 2 of the License.
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with this program;
* if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.fe.servlet;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.List;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
/**
* Reads an <code>application/octet-stream</code> and writes it to a file.
* @author John Yeary <jyeary@bluelotussoftware.com>
* @author Allan O'Driscoll
* @version 1.0
*/
public class FileUploader extends HttpServlet {
private static final long serialVersionUID = 6748857432950840322L;
private static final String DESTINATION_DIR_PATH = "temp_files_uploaded";
private static String realPath;
/**
* {@inheritDoc}
* @param config
* @throws ServletException
*/
@Override
public void init(ServletConfig config) throws ServletException {
super.init(config);
realPath = getServletContext().getRealPath(DESTINATION_DIR_PATH) + "/";
}
/**
* Handles the HTTP <code>POST</code> method.
* @param request servlet request
* @param response servlet response
* @throws ServletException if a servlet-specific error occurs
* @throws IOException if an I/O error occurs
*/
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
PrintWriter writer = null;
InputStream is = null;
// FileOutputStream fos = null;
try {
writer = response.getWriter();
} catch (IOException ex) {
log(FileUploader.class.getName() + "has thrown an exception: " + ex.getMessage());
}
String filename = request.getHeader("X-File-Name");
try {
is = request.getInputStream();
//fos = new FileOutputStream(new File(realPath + filename));
//IOUtils.copy(is, fos);
List lines=IOUtils.readLines(is);
String txt="";
for(Iterator i=lines.iterator();i.hasNext();){
txt+=(String) i.next()+"\n";
//System.out.println(i.next());
//txt
}
response.setContentType("text/plain");
response.setStatus(response.SC_OK);
//writer.print("{success: true,txt:\""+txt+"\"}");
writer.print(txt);
} catch (FileNotFoundException ex) {
response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
writer.print("{success: false}");
log(FileUploader.class.getName() + "has thrown an exception: " + ex.getMessage());
} catch (IOException ex) {
response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
writer.print("{success: false}");
log(FileUploader.class.getName() + "has thrown an exception: " + ex.getMessage());
} finally {
try {
//fos.close();
is.close();
} catch (IOException ignored) {
}
}
writer.flush();
writer.close();
}
}

157
project/bldb/src/main/java/com/fe/servlet/P2PServletContextListener.java

@ -0,0 +1,157 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.servlet;
import java.util.Date;
import java.util.concurrent.ConcurrentLinkedQueue;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fe.client.Authenticated;
import com.fe.common.Constant;
import com.fe.p2p.P2PServiceServlet;
import com.fourelementscapital.db.BBSyncDB;
import com.fourelementscapital.scheduler.balance.ExecutingQueueCleaner;
import com.fourelementscapital.scheduler.p2p.P2PService;
public class P2PServletContextListener implements ServletContextListener,HttpSessionListener, ServletRequestListener {
private static long sessionid=0;
private Logger log = LogManager.getLogger(P2PServletContextListener.class.getName());
private static final String ATTRIBUTE_NAME = "com.example.SessionCounter";
//private Map<HttpSession, String> sessions = new ConcurrentHashMap<HttpSession, String>();
private static ConcurrentLinkedQueue<HttpSession> sessions=new ConcurrentLinkedQueue<HttpSession>();
public void contextDestroyed(ServletContextEvent event) {
BBSyncDB syncdb=BBSyncDB.getBBSyncDB();
try{
syncdb.connectDB();
syncdb.peerStopped(P2PService.getComputerName(), P2PServletContextListener.sessionid, new Date());
}catch(Exception e){
e.printStackTrace();
}finally{
try{syncdb.closeDB();}catch(Exception e){}
}
System.out.println("~~~~~~~~~~~~cleaning and stopping all running services.....");
new P2PServiceServlet().destroy();
ExecutingQueueCleaner.stop();
System.exit(0);
//if(RestartTomcat.proc!=null){
//RestartTomcat.proc.destroy();
//}
}
public void contextInitialized(ServletContextEvent event) {
// TODO Auto-generated method stub
sessionid=new Date().getTime();
BBSyncDB syncdb=BBSyncDB.getBBSyncDB();
try{
syncdb.connectDB();
syncdb.peerStarted(P2PService.getComputerName(), P2PServletContextListener.sessionid, new Date());
}catch(Exception e){
e.printStackTrace();
}finally{
try{syncdb.closeDB();}catch(Exception e){}
}
}
public void sessionCreated(HttpSessionEvent hse) {
HttpSession s=hse.getSession();
//String ip=(String)s.getAttribute(Authenticated.REMOTE_IP);
//log.debug("Session created:"+ip);
sessions.add(s);
}
public void sessionDestroyed(HttpSessionEvent hse) {
// TODO Auto-generated method stub
HttpSession s=hse.getSession();
String ip=(String)s.getAttribute(Authenticated.REMOTE_IP);
log.debug("Session before destroyed:"+sessions.size());
sessions.remove(s);
log.debug("Session after destroyed:"+sessions.size());
}
public void requestDestroyed(ServletRequestEvent arg0) {
// TODO Auto-generated method stub
}
public void requestInitialized(ServletRequestEvent event) {
// TODO Auto-generated method stub
//HttpServletRequest request = (HttpServletRequest) event.getServletRequest();
//HttpSession session = request.getSession();
//if (session.isNew()) {
// sessions.put(session, request.getRemoteAddr());
//}
}
//public static P2PServletContextListener getInstance(ServletContext context) {
// return (P2PServletContextListener) context.getAttribute(ATTRIBUTE_NAME);
//}
public static ConcurrentLinkedQueue<HttpSession> getSessions(){
return sessions;
}
public static HttpSession getActiveSessions(String user){
HttpSession rtn=null;
for(HttpSession sess: P2PServletContextListener.getSessions()){
if(sess.getAttribute(Constant.SESSION_LOGGED_USER)!=null && sess.getAttribute(Constant.SESSION_LOGGED_USER).equals(user)){
//System.out.println("invalidating session...."+sess.getId());
//sess.invalidate();
//sess.setMaxInactiveInterval(0);
rtn=sess;
}
}
return rtn;
}
//public int getCount(String remoteAddr) {
// return Collections.frequency(sessions.values(), remoteAddr);
//}
}

101
project/bldb/src/main/java/com/fe/servlet/RSyntaxServlet.java

@ -0,0 +1,101 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.servlet;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.fe.client.RFunctionMgmt;
import com.fourelementscapital.db.RFunctionDB;
public class RSyntaxServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String realpath=request.getSession().getServletContext().getRealPath("");
//System.out.println("~~~~~~~~~~realpath:"+realpath);
//FileInputStream fin=null;
String fullpath=realpath+File.separator+"editarea_0_8_2"+File.separator+"reg_syntax"+File.separator+"r.js";
response.setContentType("application/javascript");
BufferedReader in = new BufferedReader(new FileReader(fullpath));
String rtn="";
String str;
while ((str = in.readLine()) != null) {
rtn+=str+"\r\n";
}
RFunctionDB rfdb=RFunctionDB.getRFunctionDB();
String functionanames="";
try{
rfdb.connectDB();
List fnames=rfdb.listAllRFunctionNames();
for(Iterator i=fnames.iterator();i.hasNext();){
String fname=(String)i.next();
fname="'"+fname+"'";
functionanames+=functionanames.equals("")?fname: ","+fname;
}
}catch(Exception ex){
ex.printStackTrace();
}finally{
try{
rfdb.closeDB();
}catch(Exception e1){}
}
//rtn=replacePlaceHolders(rtn,"myfunctions","'getRACEUniverse','getContractReference','abc','eee'");
rtn=replacePlaceHolders(rtn,"myfunctions",functionanames);
in.close();
OutputStream out = response.getOutputStream();
out.write(rtn.getBytes());
out.flush();
}
private String replacePlaceHolders(String css,String holder, String value){
//Map<String, String> data = new HashMap<String, String>();
//...
Pattern p = Pattern.compile("\\[\\[([a-zA-Z.]+)\\]\\]");
Matcher m = p.matcher(css);
StringBuffer sb = new StringBuffer();
while (m.find()) {
String reg1 = m.group(1);
if(reg1.equals("myfunctions")){
m.appendReplacement(sb, Matcher.quoteReplacement(value == null ? "" : value));
}
}
m.appendTail(sb);
return sb.toString();
}
}

54
project/bldb/src/main/java/com/fe/svn/LogEntryHandler.java

@ -0,0 +1,54 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.svn;
import java.util.Vector;
import org.tmatesoft.svn.core.ISVNDirEntryHandler;
import org.tmatesoft.svn.core.ISVNLogEntryHandler;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
public class LogEntryHandler implements ISVNLogEntryHandler, ISVNDirEntryHandler{
private Vector<SVNLogEntry> messages=null;
private Vector<SVNDirEntry> dirmessages=null;
private boolean arrivalStarted=false;
public LogEntryHandler(){
this.messages=new Vector<SVNLogEntry>();
this.dirmessages=new Vector<SVNDirEntry>();
}
public void handleLogEntry(SVNLogEntry arg0) throws SVNException {
this.messages.add(arg0);
arrivalStarted=true;
}
public void handleDirEntry(SVNDirEntry arg0) throws SVNException {
this.dirmessages.add(arg0);
arrivalStarted=true;
}
public Vector<SVNLogEntry> getLogMessages() {
return (!arrivalStarted)?null:messages;
}
public Vector<SVNDirEntry> getLogDirMessages() {
return (!arrivalStarted)?null:dirmessages;
}
}

63
project/bldb/src/main/java/com/fe/svn/SVNDiffPush.java

@ -0,0 +1,63 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.svn;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.io.StringReader;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SVNDiffPush {
private HttpServletRequest request=null;
private HttpServletResponse response=null;
public SVNDiffPush(HttpServletRequest request, HttpServletResponse response) {
this.request=request;
this.response=response;
}
public void pushDiffWC() throws Exception {
try {
response.setHeader("Content-Disposition", "attachment; filename=comparison.diff");
response.setContentType("application/octet-stream");
if(this.request.getParameter("scheduler_id")!=null
&& !this.request.getParameter("revision").equals("")
){
int scheduler_id=Integer.parseInt(this.request.getParameter("scheduler_id"));
long revstart=Long.parseLong(this.request.getParameter("revision"));
SVNSync sync=new SVNSync();
String diff=sync.diffWC(scheduler_id, revstart);
OutputStream out = response.getOutputStream();
out.write(diff.getBytes());
out.flush();
}
//fin.close();
} catch (Exception e) {
e.printStackTrace();
response.setContentType("html/text");
response.setStatus(500);
}
}
}

32
project/bldb/src/main/java/com/fe/svn/SVNIExecXML.java

@ -0,0 +1,32 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.svn;
import com.fourelementscapital.scheduler.config.Config;
public class SVNIExecXML extends SVNSyncFile{
public SVNIExecXML(String user, String pwd){
super(user,pwd,Config.getString("svn_url_ie"),Config.getString("svn_local_path_ie"));
}
public SVNIExecXML(){
super(Config.getString("svn_url_ie"),Config.getString("svn_local_path_ie"));
}
public String getExtension() {
return ".xml";
}
}

30
project/bldb/src/main/java/com/fe/svn/SVNSchedulerCommitInfo.java

@ -0,0 +1,30 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.svn;
public class SVNSchedulerCommitInfo {
private long revision;
private int scheduler_id;
public long getRevision() {
return revision;
}
public void setRevision(long revision) {
this.revision = revision;
}
public int getScheduler_id() {
return scheduler_id;
}
public void setScheduler_id(int scheduler_id) {
this.scheduler_id = scheduler_id;
}
}

398
project/bldb/src/main/java/com/fe/svn/SVNSync.java

@ -0,0 +1,398 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.svn;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.StringReader;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.Vector;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.tmatesoft.svn.core.SVNCommitInfo;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNProperties;
import org.tmatesoft.svn.core.SVNProperty;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNCommitClient;
import org.tmatesoft.svn.core.wc.SVNDiffClient;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
import com.fourelementscapital.scheduler.config.Config;
public class SVNSync {
private Logger log = LogManager.getLogger(SVNSync.class.getName());
private String svnurl="svn://10.153.64.3/scheduler";
private String local="C:\\temp_repotest1\\sc3";
//private String user="svnrams";
//private String pwd="svnrams";
private File dstPath = null;
SVNClientManager cm=null;
public SVNSync(String user, String pwd){
init(user,pwd);
}
private void init(String user, String pwd) {
setupLibrary();
cm = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),user,pwd);
this.svnurl=Config.getString("svn_url");
this.local=Config.getString("svn_local_path");
this.dstPath = new File(this.local);
}
public SVNSync(){
String user=Config.getString("svn_user");
String pwd=Config.getString("svn_pwd");
init(user,pwd);
}
public long syncScript(int scheduler_id,String script, String message){
long revision=-1;
try {
SVNURL url = SVNURL.parseURIEncoded(this.svnurl);
/*
* SVN operations
*/
//SVNClientManager cm = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),user,pwd);
SVNUpdateClient uc = this.cm.getUpdateClient();
if(!SVNWCUtil.isVersionedDirectory(dstPath)){
uc.doCheckout(url, dstPath, SVNRevision.UNDEFINED, SVNRevision.HEAD, true);
uc.doUpdate(dstPath, SVNRevision.HEAD, true);
}else{
log.debug("~~~~~~"+dstPath.getPath()+" it is already working copy....");
}
/*
creating file
*/
String line;
BufferedReader reader = new BufferedReader(new StringReader(script));
StringBuffer sb=new StringBuffer();
File file=new File(local,"script_"+scheduler_id+".R");
BufferedWriter out = new BufferedWriter(new FileWriter(file));
while ((line = reader.readLine()) != null)
{
if(line!=null && line.equals("")){
out.write(line+"\n");
}
if(line!=null && !line.equals("")){
out.write(line+"\n");
}
}
out.close();
reader.close();
SVNWCClient wcc = this.cm.getWCClient();
try{
wcc.doInfo(file, SVNRevision.HEAD);
}catch(SVNException e){
if(e.getMessage().contains("is not under version control")){
wcc.doAdd(file, false, false, false, true);
log.debug("~~~~~ file:"+file+" is not under version control");
}else{
log.debug("~~~~~ file:"+file+" is under version control");
}
}
SVNCommitClient cc = cm.getCommitClient();
SVNCommitInfo info= cc.doCommit(new File[] {file}, false, message, false, true);
revision=info.getNewRevision();
//System.out.println("~~~~~~~~~~~~~~~SVNSync.syncScript() version:"+info.getNewRevision());
//System.out.println("~~~~~~~~~~~~~~~SVNSync.syncScript() toString:"+info.toString());
}catch(Exception e){
e.printStackTrace();
}
return revision;
}
public String getLastChanged(int scheduler_id) throws Exception {
String filename="script_"+scheduler_id+".R";
File file=new File(local,filename);
TreeSet<Long> rev=revisions(file);
Vector v=new Vector(rev);
String diff=null;
if(rev.size()>0 && v.indexOf(rev.last())>0){
long prev=(Long)v.get(v.indexOf(rev.last())-1);
diff=diff(scheduler_id,prev,rev.last().longValue());
if(diff!=null){
StringTokenizer st=new StringTokenizer(diff,"\n\r");
if(st.countTokens()>=4){
st.nextToken();st.nextToken();st.nextToken();st.nextToken();//st.nextToken();
diff="";
while(st.hasMoreTokens()){
diff+=st.nextToken()+"\n";
}
}
}
}
return diff;
}
public Vector<SVNLogEntry> log(int scheduler_id) throws Exception {
File file=new File(local,"script_"+scheduler_id+".R");
//Vector v=new Vector();
Vector v=null;
if(file.exists()){
SVNLogClient logc= this.cm.getLogClient();
long limit=250;
LogEntryHandler leh=new LogEntryHandler();
logc.doLog(new File[] {file}, SVNRevision.create(0),SVNRevision.create(0), SVNRevision.HEAD, true, true,limit,leh);
while(leh.getLogMessages()==null){
Thread.sleep(100);
}
v=leh.getLogMessages();
Thread.sleep(100);
}
return v;
}
public Vector<SVNDirEntry> logTest() throws Exception {
SVNLogClient logc= this.cm.getLogClient();
long limit=50;
LogEntryHandler leh=new LogEntryHandler();
SVNURL url = SVNURL.parseURIEncoded(this.svnurl);
//logc.doList(url, SVNRevision.create(0), SVNRevision.HEAD, true, true,leh);
//while(leh.getLogDirMessages()==null){
// Thread.sleep(100);
//}
//Vector v=leh.getLogMessages();
logc.doLog(url,new String[] {}, SVNRevision.create(0),SVNRevision.create(0), SVNRevision.HEAD, true, true,1,leh);
while(leh.getLogMessages()==null){
Thread.sleep(100);
}
Vector v=leh.getLogMessages();
Thread.sleep(100);
return v;
}
public String diff(int scheduler_id, long start, long end) throws Exception {
File file=new File(local,"script_"+scheduler_id+".R");
//File file1=new File(local,"script_"+scheduler_id+"_rev"+start+"_rev"+end+".diff");
String rtn=null;
if(file.exists()){
SVNDiffClient diffc= this.cm.getDiffClient();
//StringWriter sw=new StringWriter();
//BufferedWriter out = new BufferedWriter(sw);
//FileOutputStream fos=new FileOutputStream(file1) ;
ByteArrayOutputStream fos = new ByteArrayOutputStream( );
diffc.doDiff(file, SVNRevision.create(start),SVNRevision.create(start),SVNRevision.create(end), true, false,fos );
rtn=fos.toString();
}
return rtn;
}
public String diffWC(int scheduler_id, long rev) throws Exception {
File file=new File(local,"script_"+scheduler_id+".R");
//File file1=new File(local,"script_"+scheduler_id+"_rev"+start+"_rev"+end+".diff");
String rtn=null;
if(file.exists()){
SVNDiffClient diffc= this.cm.getDiffClient();
//StringWriter sw=new StringWriter();
//BufferedWriter out = new BufferedWriter(sw);
//FileOutputStream fos=new FileOutputStream(file1) ;
ByteArrayOutputStream fos = new ByteArrayOutputStream( );
diffc.doDiff(file, SVNRevision.create(rev),SVNRevision.create(rev),SVNRevision.HEAD, true, false,fos );
rtn=fos.toString();
}
return rtn;
}
public String getScript(int scheduler_id, long revision) throws Exception {
String filepath="script_"+scheduler_id+".R";
SVNRepository repository=this.cm.createRepository( SVNURL.parseURIEncoded(this.svnurl), false);
SVNNodeKind nodeKind = repository.checkPath( filepath , -1 );
if ( nodeKind == SVNNodeKind.NONE ) {
throw new Exception( "There is no entry at '" + this.svnurl + "'." );
} else if ( nodeKind == SVNNodeKind.DIR ) {
throw new Exception( "The entry at '" + this.svnurl + "' is a directory while a file was expected." );
//System.exit( 1 );
}
SVNProperties fileProperties = new SVNProperties( );
ByteArrayOutputStream baos = new ByteArrayOutputStream( );
repository.getFile( filepath , revision, fileProperties , baos );
Map fileProperties1=fileProperties.asMap();
String mimeType = (String)fileProperties1.get( SVNProperty.MIME_TYPE );
boolean isTextType = SVNProperty.isTextMimeType( mimeType );
/*
Iterator iterator = fileProperties1.keySet( ).iterator( );
while ( iterator.hasNext( ) ) {
String propertyName = ( String ) iterator.next( );
String propertyValue = ( String ) fileProperties1.get( propertyName );
// System.out.println( "File property: " + propertyName + "=" + propertyValue );
}
*/
String rtn=null;
if ( isTextType ) {
// System.out.println( "File contents:" );
//System.out.println( );
//baos.writeTo( System.out );
//baos.writeTo( sw );
rtn=baos.toString();
} else {
System.out.println( "Not a text file." );
}
return rtn;
}
/*
* Initializes the library to work with a repository via
* different protocols.
*/
private static void setupLibrary() {
/*
* For using over http:// and https://
*/
DAVRepositoryFactory.setup();
/*
* For using over svn:// and svn+xxx://
*/
SVNRepositoryFactoryImpl.setup();
/*
* For using over file:///
*/
FSRepositoryFactory.setup();
}
public TreeSet<Long> revisions( File file) throws Exception {
//File file=new File(local,"script_"+scheduler_id+FILE_EXTENSIION);
//Vector v=new Vector();
/*
TreeSet v=new TreeSet(new Comparator(){
public int compare(Object o1, Object o2) {
long i1=((Long)o1).longValue();
long i2=((Long)o2).longValue();
if(i1>i2) return -1;
else if(i1 > i2) return +1;
else return 0;
}
}); */
TreeSet v=new TreeSet();
if(file.exists()){
SVNLogClient logc= this.cm.getLogClient();
LogEntryHandler leh=new LogEntryHandler();
logc.doLog(new File[] {file}, SVNRevision.create(0),SVNRevision.create(0), SVNRevision.HEAD, true, true,0,leh);
while(leh.getLogMessages()==null){
Thread.sleep(100);
}
Vector logs=leh.getLogMessages();
Thread.sleep(100);
for(Iterator it=logs.iterator();it.hasNext(); ){
SVNLogEntry log=(SVNLogEntry)it.next();
v.add(log.getRevision());
}
}
return v;
}
}

35
project/bldb/src/main/java/com/fe/svn/SVNSync4RFunction.java

@ -0,0 +1,35 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.svn;
import com.fourelementscapital.scheduler.config.Config;
public class SVNSync4RFunction extends SVNSyncFile{
public SVNSync4RFunction(String user, String pwd){
super(user,pwd,Config.getString("svn_url_r"),Config.getString("svn_local_path_r"));
}
public SVNSync4RFunction(){
super(Config.getString("svn_url_r"),Config.getString("svn_local_path_r"));
}
public String getExtension() {
return ".r";
}
}

569
project/bldb/src/main/java/com/fe/svn/SVNSyncFile.java

@ -0,0 +1,569 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.svn;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileWriter;
import java.io.StringReader;
import java.util.Iterator;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeSet;
import java.util.Vector;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.tmatesoft.svn.core.SVNDirEntry;
import org.tmatesoft.svn.core.SVNException;
import org.tmatesoft.svn.core.SVNLogEntry;
import org.tmatesoft.svn.core.SVNNodeKind;
import org.tmatesoft.svn.core.SVNProperties;
import org.tmatesoft.svn.core.SVNProperty;
import org.tmatesoft.svn.core.SVNURL;
import org.tmatesoft.svn.core.internal.io.dav.DAVRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.fs.FSRepositoryFactory;
import org.tmatesoft.svn.core.internal.io.svn.SVNRepositoryFactoryImpl;
import org.tmatesoft.svn.core.io.SVNRepository;
import org.tmatesoft.svn.core.wc.SVNClientManager;
import org.tmatesoft.svn.core.wc.SVNCommitClient;
import org.tmatesoft.svn.core.wc.SVNDiffClient;
import org.tmatesoft.svn.core.wc.SVNLogClient;
import org.tmatesoft.svn.core.wc.SVNMoveClient;
import org.tmatesoft.svn.core.wc.SVNRevision;
import org.tmatesoft.svn.core.wc.SVNUpdateClient;
import org.tmatesoft.svn.core.wc.SVNWCClient;
import org.tmatesoft.svn.core.wc.SVNWCUtil;
import com.fourelementscapital.scheduler.config.Config;
public abstract class SVNSyncFile {
private Logger log = LogManager.getLogger(SVNSync4RFunction.class.getName());
private String svnurl=null ;//"svn://10.153.64.3/rfunctions_test";
private String local ;//="C:\\temp_repotest1\\rfunctions";
//private static String FILE_EXTENSIION=".r";
//private String user="svnrams";
//private String pwd="svnrams";
private File dstPath = null;
public abstract String getExtension();
SVNClientManager cm=null;
/*
private void init(String user, String pwd) {
setupLibrary();
cm = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),user,pwd);
this.svnurl=Config.getString("svn_url_r");
this.local=Config.getString("svn_local_path_r");
this.dstPath = new File(this.local);
}
*/
private void init(String user, String pwd, String svnurl, String svn_path) {
setupLibrary();
cm = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),user,pwd);
this.svnurl=svnurl;
this.local=svn_path;
this.dstPath = new File(this.local);
}
public SVNSyncFile(String user, String pwd, String svn_url, String local_path ){
init(user,pwd,svn_url,local_path);
}
public SVNSyncFile(String svn_url, String local_path ){
String user=Config.getString("svn_user");
String pwd=Config.getString("svn_pwd");
init(user,pwd,svn_url,local_path);
}
public void syncFile(String function_name,String script, String message){
try {
SVNURL url = SVNURL.parseURIEncoded(this.svnurl);
log.debug("this.svnurl:"+this.svnurl);
/*
* SVN operations
*/
//SVNClientManager cm = SVNClientManager.newInstance(SVNWCUtil.createDefaultOptions(true),user,pwd);
SVNUpdateClient uc = this.cm.getUpdateClient();
if(!SVNWCUtil.isVersionedDirectory(dstPath)){
uc.doCheckout(url, dstPath, SVNRevision.UNDEFINED, SVNRevision.HEAD, true);
uc.doUpdate(dstPath, SVNRevision.HEAD, true);
}else{
log.debug("~~~~~~"+dstPath.getPath()+" it is already working copy....");
}
/*
creating file
*/
String line;
BufferedReader reader = new BufferedReader(new StringReader(script));
StringBuffer sb=new StringBuffer();
File file=new File((local.endsWith(File.separator)? local:local+File.separator),function_name+getExtension());
BufferedWriter out = new BufferedWriter(new FileWriter(file));
while ((line = reader.readLine()) != null)
{
if(line!=null && line.equals("")){
out.write(line+"\n");
}
if(line!=null && !line.equals("")){
out.write(line+"\n");
}
}
out.close();
reader.close();
SVNWCClient wcc = this.cm.getWCClient();
try{
wcc.doInfo(file, SVNRevision.HEAD);
}catch(SVNException e){
if(e.getMessage().contains("is not under version control")){
wcc.doAdd(file, false, false, false, true);
log.debug("~~~~~ file:"+file+" is not under version control");
}else{
log.debug("~~~~~ file:"+file+" is under version control");
}
}
SVNCommitClient cc = cm.getCommitClient();
cc.doCommit(new File[] {file}, false, message, false, true);
}catch(Exception e){
e.printStackTrace();
}
}
public void deleteFile(String function_name){
try {
SVNURL url = SVNURL.parseURIEncoded(this.svnurl);
log.debug("this.svnurl:"+this.svnurl);
File file=new File((local.endsWith(File.separator)? local:local+File.separator),function_name+getExtension());
SVNWCClient wcc = this.cm.getWCClient();
try{
wcc.doDelete(file, true,false);
}catch(SVNException e){
log.error("Error occured while deleting, Error:"+e.getMessage());
}
SVNCommitClient cc = cm.getCommitClient();
cc.doCommit(new File[] {file}, false, "deleted", false, true);
}catch(Exception e){
e.printStackTrace();
}
}
public void renameFile(String old_function, String new_function,String script, String message){
try {
SVNURL url = SVNURL.parseURIEncoded(this.svnurl);
log.debug("this.svnurl:"+this.svnurl);
File n_file=new File((local.endsWith(File.separator)? local:local+File.separator),new_function+getExtension());
File o_file=new File((local.endsWith(File.separator)? local:local+File.separator),old_function+getExtension());
String line;
BufferedReader reader = new BufferedReader(new StringReader(script));
StringBuffer sb=new StringBuffer();
BufferedWriter out = new BufferedWriter(new FileWriter(o_file));
while ((line = reader.readLine()) != null)
{
if(line!=null && line.equals("")){
out.write(line+"\n");
}
if(line!=null && !line.equals("")){
out.write(line+"\n");
}
}
out.close();
reader.close();
SVNWCClient wcc = this.cm.getWCClient();
try{
wcc.doInfo(o_file, SVNRevision.HEAD);
}catch(SVNException e){
if(e.getMessage().contains("is not under version control")){
wcc.doAdd(o_file, false, false, false, true);
log.debug("~~~~~ file:"+n_file+" is not under version control");
}else{
log.debug("~~~~~ file:"+n_file+" is under version control");
}
}
SVNMoveClient mc = this.cm.getMoveClient();
mc.doMove(o_file, n_file);
SVNCommitClient cc = cm.getCommitClient();
cc.doCommit(new File[] {o_file,n_file}, false, message, false, true);
}catch(Exception e){
e.printStackTrace();
}
}
public Vector<SVNLogEntry> log(String function_name) throws Exception {
//File file=new File(local,"script_"+scheduler_id+FILE_EXTENSIION);
File file=new File((local.endsWith(File.separator)? local:local+File.separator),function_name+getExtension());
//Vector v=new Vector();
Vector v=null;
if(file.exists()){
SVNLogClient logc= this.cm.getLogClient();
long limit=250;
LogEntryHandler leh=new LogEntryHandler();
logc.doLog(new File[] {file}, SVNRevision.create(0),SVNRevision.create(0), SVNRevision.HEAD, false, true,limit,leh);
while(leh.getLogMessages()==null){
Thread.sleep(100);
}
v=leh.getLogMessages();
Thread.sleep(100);
}
return v;
}
public TreeSet<Long> revisions(String function_name) throws Exception {
//File file=new File(local,"script_"+scheduler_id+FILE_EXTENSIION);
File file=new File((local.endsWith(File.separator)? local:local+File.separator),function_name+getExtension());
//Vector v=new Vector();
/*
TreeSet v=new TreeSet(new Comparator(){
public int compare(Object o1, Object o2) {
long i1=((Long)o1).longValue();
long i2=((Long)o2).longValue();
if(i1>i2) return -1;
else if(i1 > i2) return +1;
else return 0;
}
}); */
TreeSet v=new TreeSet();
if(file.exists()){
SVNLogClient logc= this.cm.getLogClient();
LogEntryHandler leh=new LogEntryHandler();
logc.doLog(new File[] {file}, SVNRevision.create(0),SVNRevision.create(0), SVNRevision.HEAD, true, true,0,leh);
while(leh.getLogMessages()==null){
Thread.sleep(100);
}
Vector logs=leh.getLogMessages();
Thread.sleep(100);
for(Iterator it=logs.iterator();it.hasNext(); ){
SVNLogEntry log=(SVNLogEntry)it.next();
v.add(log.getRevision());
}
}
return v;
}
public Long firstRevision(String function_name) throws Exception {
TreeSet<Long> rev=revisions(function_name);
return rev.size()>0?rev.first():0;
}
public Long lastRevision(String function_name) throws Exception {
TreeSet<Long> rev=revisions(function_name);
return rev.size()>0?rev.last():0;
}
public String getWhatChanged(String function_name, Long c_rev) throws Exception {
TreeSet<Long> rev=revisions(function_name);
Vector v=new Vector(rev);
String diff=null;
if(v.indexOf(c_rev)>0){
long prev=(Long)v.get(v.indexOf(c_rev)-1);
diff=diff(function_name,prev,c_rev.longValue());
if(diff!=null){
StringTokenizer st=new StringTokenizer(diff,"\n\r");
if(st.countTokens()>=4){
st.nextToken();st.nextToken();st.nextToken();st.nextToken();//st.nextToken();
diff="";
while(st.hasMoreTokens()){
diff+=st.nextToken()+"\n";
}
}
}
}
return diff;
}
public String getLastChanged(String function_name) throws Exception {
TreeSet<Long> rev=revisions(function_name);
Vector v=new Vector(rev);
String diff=null;
if(rev.size()>0 && v.indexOf(rev.last())>0){
long prev=(Long)v.get(v.indexOf(rev.last())-1);
diff=diff(function_name,prev,rev.last().longValue());
if(diff!=null){
StringTokenizer st=new StringTokenizer(diff,"\n\r");
if(st.countTokens()>=4){
st.nextToken();st.nextToken();st.nextToken();st.nextToken();//st.nextToken();
diff="";
while(st.hasMoreTokens()){
diff+=st.nextToken()+"\n";
}
}
}
}
return diff;
}
public Vector<SVNDirEntry> logTest() throws Exception {
SVNLogClient logc= this.cm.getLogClient();
long limit=50;
LogEntryHandler leh=new LogEntryHandler();
SVNURL url = SVNURL.parseURIEncoded(this.svnurl);
//logc.doList(url, SVNRevision.create(0), SVNRevision.HEAD, true, true,leh);
//while(leh.getLogDirMessages()==null){
// Thread.sleep(100);
//}
//Vector v=leh.getLogMessages();
logc.doLog(url,new String[] {}, SVNRevision.create(0),SVNRevision.create(0), SVNRevision.HEAD, true, true,1,leh);
while(leh.getLogMessages()==null){
Thread.sleep(100);
}
Vector v=leh.getLogMessages();
Thread.sleep(100);
return v;
}
public String diff(String function_name, long start, long end) throws Exception {
//File file=new File(local,"script_"+scheduler_id+".R");
File file=new File((local.endsWith(File.separator)? local:local+File.separator),function_name+getExtension());
//File file1=new File(local,"script_"+scheduler_id+"_rev"+start+"_rev"+end+".diff");
String rtn=null;
if(file.exists()){
SVNDiffClient diffc= this.cm.getDiffClient();
//StringWriter sw=new StringWriter();
//BufferedWriter out = new BufferedWriter(sw);
//FileOutputStream fos=new FileOutputStream(file1) ;
ByteArrayOutputStream fos = new ByteArrayOutputStream( );
diffc.doDiff(file, SVNRevision.create(start),SVNRevision.create(start),SVNRevision.create(end), true, false,fos );
rtn=fos.toString();
}
return rtn;
}
public String diffWC(String function_name, long rev) throws Exception {
//File file=new File(local,"script_"+scheduler_id+".R");
//File file1=new File(local,"script_"+scheduler_id+"_rev"+start+"_rev"+end+".diff");
File file=new File((local.endsWith(File.separator)? local:local+File.separator),function_name+getExtension());
String rtn=null;
if(file.exists()){
SVNDiffClient diffc= this.cm.getDiffClient();
//StringWriter sw=new StringWriter();
//BufferedWriter out = new BufferedWriter(sw);
//FileOutputStream fos=new FileOutputStream(file1) ;
ByteArrayOutputStream fos = new ByteArrayOutputStream( );
diffc.doDiff(file, SVNRevision.create(rev),SVNRevision.create(rev),SVNRevision.HEAD, true, false,fos );
rtn=fos.toString();
}else{
throw new Exception("File:"+file.getPath()+" doesn't exist");
}
return rtn;
}
public String getScript(String function_name, long revision,String path) throws Exception {
SVNRepository repository=this.cm.createRepository( SVNURL.parseURIEncoded(this.svnurl), false);
String filepath=function_name+getExtension();
if(path!=null && !path.trim().equals("")){
if(path.indexOf(",")>=0){
StringTokenizer st=new StringTokenizer(path,",");
boolean found=false;
while(st.hasMoreTokens() && !found){
String thispath=st.nextToken();
SVNNodeKind nodeKind1 = repository.checkPath( thispath ,revision );
if(nodeKind1==SVNNodeKind.FILE){
filepath=thispath;
found=true;
}
}
}else{
filepath=path;
}
}
log.debug("filepath:"+filepath);
SVNNodeKind nodeKind = repository.checkPath( filepath ,revision );
if ( nodeKind == SVNNodeKind.NONE ) {
throw new Exception( "There is no entry at '" + this.svnurl + "'." );
} else if ( nodeKind == SVNNodeKind.DIR ) {
throw new Exception( "The entry at '" + this.svnurl + "' is a directory while a file was expected." );
//System.exit( 1 );
}
SVNProperties fileProperties = new SVNProperties( );
ByteArrayOutputStream baos = new ByteArrayOutputStream( );
repository.getFile( filepath , revision, fileProperties , baos );
Map fileProperties1=fileProperties.asMap();
String mimeType = (String)fileProperties1.get( SVNProperty.MIME_TYPE );
boolean isTextType = SVNProperty.isTextMimeType( mimeType );
/*
Iterator iterator = fileProperties1.keySet( ).iterator( );
while ( iterator.hasNext( ) ) {
String propertyName = ( String ) iterator.next( );
String propertyValue = ( String ) fileProperties1.get( propertyName );
// System.out.println( "File property: " + propertyName + "=" + propertyValue );
}
*/
String rtn=null;
if ( isTextType ) {
// System.out.println( "File contents:" );
//System.out.println( );
//baos.writeTo( System.out );
//baos.writeTo( sw );
rtn=baos.toString();
} else {
System.out.println( "Not a text file." );
}
return rtn;
}
/*
* Initializes the library to work with a repository via
* different protocols.
*/
private static void setupLibrary() {
/*
* For using over http:// and https://
*/
DAVRepositoryFactory.setup();
/*
* For using over svn:// and svn+xxx://
*/
SVNRepositoryFactoryImpl.setup();
/*
* For using over file:///
*/
FSRepositoryFactory.setup();
}
}

82
project/bldb/src/main/java/com/fe/util/ImageLoader.java

@ -0,0 +1,82 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.util;
import java.io.ByteArrayOutputStream;
import java.io.FileInputStream;
import java.io.OutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Image Loader
*/
public class ImageLoader {
private HttpServletRequest request=null;
private HttpServletResponse response=null;
/**
* Constructor
* @param request request
* @param response response
*/
public ImageLoader(HttpServletRequest request, HttpServletResponse response) {
this.request=request;
this.response=response;
}
/**
* Push Image
* @throws Exception
*/
public void pushImage() throws Exception {
try {
response.setHeader("Content-Disposition", "inline");
FileInputStream fin=null;
if(this.request.getParameter("file")!=null && !this.request.getParameter("file").equals("")){
fin = new FileInputStream(this.request.getParameter("file"));
if(this.request.getParameter("file").toLowerCase().endsWith(".svg")){
response.setContentType("image/svg+xml");
}else{
response.setContentType("image/png");
}
}else{
fin = new FileInputStream("/home/fileserv/Sharing/Public/Research/Monitors/SchedulerActivityMonitor.png");
response.setContentType("image/png");
}
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[1024];
int len;
while ((len = fin.read(buf)) > 0) {
// instead of writing to a ByteArrayOutputStream you can
// write to the FileOutputStream here (see the comments later
// after creating the byte[] variable called data
bos.write(buf, 0, len);
}
byte[] data = bos.toByteArray();
OutputStream out = response.getOutputStream();
out.write(data);
out.flush();
fin.close();
} catch (Exception e) {
//e.printStackTrace();
response.setContentType("html/text");
response.setStatus(500);
}
}
}

55
project/bldb/src/main/java/com/fe/util/PasswordService.java

@ -0,0 +1,55 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.util;
import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import sun.misc.BASE64Encoder;
/**
* Password encrypting
*/
public class PasswordService {
/**
* Private constructor
*/
private PasswordService()
{
}
/**
* Encrypt text
* @param plaintext plain text
* @return encrypted text
* @throws Exception
*/
public static synchronized String encrypt(String plaintext) throws Exception {
MessageDigest md = null;
try {
md = MessageDigest.getInstance("SHA"); //step 2
}catch(NoSuchAlgorithmException e) {
throw e;
}
try {
md.update(plaintext.getBytes("UTF-8")); //step 3
}catch(UnsupportedEncodingException e) {
throw e;
}
byte raw[] = md.digest(); //step 4
String hash = (new BASE64Encoder()).encode(raw); //step 5
return hash; //step 6
}
}

59
project/bldb/src/main/java/com/fe/util/ProxifyURL.java

@ -0,0 +1,59 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.util;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.fourelementscapital.scheduler.error.ClientError;
public class ProxifyURL {
private static HttpClient httpclient = new HttpClient();
private HttpServletRequest request;
private HttpServletResponse response;
private Logger log = LogManager.getLogger(ProxifyURL.class.getName());
public ProxifyURL(HttpServletRequest request, HttpServletResponse response){
this.request=request;
this.response=response;
}
public boolean isProxified(String url_prefix){
String queryString=this.request.getQueryString();
String tpf=this.request.getRequestURL().toString().replace(queryString,"");
log.debug("request url p:"+tpf);
return !tpf.equalsIgnoreCase(url_prefix);
}
public void proxifyGet(String url_prefix,String overwrite_qs) {
try{
String queryString=overwrite_qs==null?this.request.getQueryString():overwrite_qs;
String redirecting=url_prefix+"?"+queryString;
log.debug("redirecting to:"+redirecting);
GetMethod httpget = new GetMethod(redirecting);
int respo = httpclient.executeMethod(httpget);
//saveCookie(httpget);
this.response.getOutputStream().write(httpget.getResponseBody());
httpget.releaseConnection();
}catch(Exception e){
ClientError.reportError(e, null);
}
}
}

139
project/bldb/src/main/java/com/fe/util/RestartTomcat.java

@ -0,0 +1,139 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.util;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.util.Vector;
import com.fe.scheduler.SchedulerInitServlet;
import com.fourelementscapital.scheduler.peer.QueueFactory;
public class RestartTomcat {
private static Vector ignoredIds4Restart=new Vector();
public static void restartPeerLater(){
//thse 2 lines commented because, apart from scheduler task, there will be tasks also running, which will not have id.
//Vector executingIds=new QueueFactory().getExecutingIDs();
//if(executingIds.size()==0) {
int count=new QueueFactory().countExcTasksInPeer();
if(count==0) {
RestartTomcat.restartPeerNow();
}else{
Vector executingIds=new QueueFactory().getExecutingIDs();
System.out.println("RestartTomcat.java:: executingIds:"+executingIds+" ignoredIds4Restart:"+ignoredIds4Restart);
if(executingIds.containsAll(ignoredIds4Restart) && executingIds.size()==ignoredIds4Restart.size()){
RestartTomcat.restartPeerNow();
//System.out.println("RestartTomcat.java:: restarting now, it has killed id");
}
}
}
public static void restartPeerLater(int task_2b_killed){
//System.out.println("RestartTomcat.java:: restartPeerLater("+task_2b_killed+") called");
QueueFactory.setRestartRequested();
if(task_2b_killed>0){
ignoredIds4Restart.add(task_2b_killed);
}
RestartTomcat.restartPeerLater();
}
public static void restartPeerNow(){
try{
String tempDir = System.getProperty("java.io.tmpdir");
File file=new File(tempDir+File.separator+"restart.bat");
String line;
BufferedWriter out = new BufferedWriter(new FileWriter(file));
String service="Tomcat6";
out.write("net stop \""+service+"\" \n");
out.write("ping -n 8 localhost > nul\n");
// killing tasks in case of the related services are not stoppeed.
out.write("taskkill /f /t /im Rserve.exe \n");
out.write("taskkill /f /t /im tomcat6.exe \n");
out.write("ping -n 3 localhost > nul\n");
//copy the peer code from repository
out.write("xcopy \\\\4ecapsvsg2\\Public\\IT\\TomcatDev\\peer_classes\\. "+SchedulerInitServlet.getAppPath()+"\\WEB-INF /S /Y /D \n");
out.write("net start \""+service+"\"\n");
out.write("ping -n 3 localhost > nul\n");
out.write("EXIT \n");
out.close();
Runtime rt = Runtime.getRuntime();
String[] commandArgs = new String[]{"cmd", "/C", "start", file.getPath() };
// String[] commandArgs = new String[]{"cmd", "/C", file.getPath()};
Process proc = rt.exec(commandArgs);
}catch(Exception e){
e.printStackTrace();
}
}
public static void restartMainServer(){
try{
//String tempDir = System.getProperty("java.io.tmpdir");
//File file=new File(tempDir+File.separator+"restart.bat");
//String line;
//BufferedWriter out = new BufferedWriter(new FileWriter(file));
//out.write("rem restarting of service..\n");
//out.write("net stop \"Tomcat6\"\n");
//out.write("ping -n 5 localhost > nul\n");
//out.write("xcopy \\\\4ecapsvsg2\\Public\\IT\\TomcatDev\\peer_classes\\. "+SchedulerInitServlet.getAppPath()+"\\WEB-INF /S /Y \n");
//out.write("net start \"Tomcat6\"\n");
//out.close();
//Process p = Runtime.getRuntime().exec(file.getPath());
Runtime rt = Runtime.getRuntime();
String[] commandArgs = new String[]{"nohup", "/home/p2pserver/restart.sh", "&"};
Process proc = rt.exec(commandArgs);
}catch(Exception e){
e.printStackTrace();
}
}
}

35
project/bldb/src/main/java/com/fe/util/StringPlaceHolder4ChildStrategy.java

@ -0,0 +1,35 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.util;
import java.util.Map;
import java.util.Vector;
import com.fourelementscapital.fileutils.StringPlaceHolder;
public class StringPlaceHolder4ChildStrategy {
public static final String PATTERN = "\\{\\{(.*?)\\}\\}";
public static final String PATTERN_ATTR = "\\\"\\{\\{(.*?)\\}\\}\\\"";
public static Vector<String> getAttributePH(final String template) {
return StringPlaceHolder.getAttributePH(template, StringPlaceHolder4ChildStrategy.PATTERN_ATTR);
}
public static Vector<String> getElementPH(final String template) {
return StringPlaceHolder.getElementPH(template, StringPlaceHolder4ChildStrategy.PATTERN);
}
public static String parse(final String template, final Map values){
return StringPlaceHolder.parse(template, values, StringPlaceHolder4ChildStrategy.PATTERN);
}
}

335
project/bldb/src/main/java/com/fe/util/WikiRFunctionManual.java

@ -0,0 +1,335 @@
/******************************************************************************
*
* Copyright: Intellectual Property of Four Elements Capital Pte Ltd, Singapore.
* All rights reserved.
*
******************************************************************************/
package com.fe.util;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.httpclient.Cookie;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpState;
import org.apache.commons.httpclient.HttpStatus;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
/**
* Get RFunction Manual from Wiki
*/
public class WikiRFunctionManual {
private Logger log = LogManager.getLogger(WikiRFunctionManual.class.getName());
private String function;
private static HttpClient httpclient = new HttpClient();
//public WikiRFunctionManual(String function){
//this.function=function;
//}
/**
* Constructor
*/
public WikiRFunctionManual( ){
}
/**
* Get Wiki HTML (old)
* @param selector selector
* @return Wiki HTML
*/
public String getWikiHTML_old(String selector) throws Exception {
try{
httpclient.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
HttpState initialState = new HttpState();
initialState.addCookie(new Cookie(".4ecap.com", "mycookie", "stuff", "/", null, false));
initialState.addCookie(new Cookie(".4ecap.com", "4ecapwikidbUserName", "Rams", "/", null, false));
// initialState.addCookie(new Cookie(".4ecap.com", "4ecapwikidb_session", "", "/", null, false));
//initialState.addCookie(new Cookie(".4ecap.com", "4ecapwikidbLoggedOut", "", "/", null, false));
initialState.addCookie(new Cookie(".4ecap.com", "4ecapwikidbUserID", "4", "/", null, false));
httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(30000);
httpclient.setState(initialState);
GetMethod httpget = new GetMethod("http://wiki.4ecap.com/4ECwiki/"+this.function);
int respo = httpclient.executeMethod(httpget);
//saveCookie(httpget);
Document doc =Jsoup.parse( httpget.getResponseBodyAsString());
httpget.releaseConnection();
saveCookie(httpget);
if(doc.select("h1.firstHeading").text().trim().equals("Login Required")){
log.debug("~~~ logging in ~~~~~~~~");
//PostMethod method = new PostMethod("http://wiki.4ecap.com/4ecapwiki/index.php?title=Special:UserLogin&action=submitlogin&type=login");
PostMethod method = new PostMethod("http://wiki.4ecap.com/4ecapwiki/index.php?title=Special:UserLogin&wpCookieCheck=login");
method.getParams().setCookiePolicy(CookiePolicy.RFC_2109);
method.addParameter("wpName", "rams");
method.addParameter("wpPassword", "FECrams");
int returnCode = httpclient.executeMethod(method);
System.out.println("!!!!!!!!!!:"+method.getResponseBodyAsString());
//Header[] h=method.getResponseHeaders();
//for(int i=0;i<h.length;i++){
// System.out.println("name:"+h[i].getName()+" value:"+h[i].getValue());
//}
//System.out.println("!!!!!!!!!!:"+method.getResponseBodyAsString());
//if(returnCode==HttpStatus.SC_ACCEPTED){
saveCookie(method);
respo = httpclient.executeMethod(httpget);
doc =Jsoup.parse( httpget.getResponseBodyAsString());
//}
// System.out.println(":"+method.getResponseBodyAsString());
method.releaseConnection();
}else{
log.debug("~~~ already logged in~~~~~~~~");
}
//System.out.println("page"+content);
//HttpEntity entity = response.getEntity();
//System.out.println("content:"+doc.select("body"));
return doc.select(selector).toString() ;
}catch(Exception e){
e.printStackTrace();
throw e;
}
}
/**
* Get Wiki HTML
* @param wikiUsername wiki username
* @param wikiPassword wiki password
* @param wikiUrl wiki url
* @param function_name function name
* @return Wiki HTML
*/
public String getWikiHTML(String wikiUsername, String wikiPassword, String wikiUrl, String function_name) throws Exception {
try{
String rtn=null;
//String username=Config.getString("wiki.username");
//String password=Config.getString("wiki.password");
//String wikiurl=Config.getString("wiki.wikiurl");
String username=wikiUsername;
String password=wikiPassword;
String wikiurl=wikiUrl;
String url = wikiurl+"api.php?action=login&lgname="+username+"&lgpassword="+password+"&format=xml";
//System.out.println(">>> url : " + url);
//PostMethod method = new PostMethod("http://wiki.4ecap.com/4ecapwiki/api.php?action=login&lgname=Rams&lgpassword=FECrams");
PostMethod method = new PostMethod(url);
int returnCode = httpclient.executeMethod(method);
if(returnCode==HttpStatus.SC_OK){
//String st=getToken(method,"4ecapwikidbToken");
String st=getToken(method.getResponseBodyAsString());
log.debug("output:"+st);
PostMethod method1 = new PostMethod(wikiurl+"api.php?action=login&lgname="+username+"&lgpassword="+password+"&lgtoken="+st);
returnCode = httpclient.executeMethod(method1);
method1.releaseConnection();
if(returnCode ==HttpStatus.SC_OK){
PostMethod method2 = new PostMethod(wikiurl+"index.php?action=render&title="+function_name);
returnCode = httpclient.executeMethod(method2);
rtn=method2.getResponseBodyAsString();
method2.releaseConnection();
}
}
method.releaseConnection();
return rtn;
}catch(Exception e){
//e.printStackTrace();
throw e;
}
}
/**
* new wiki api pushes the token in body, earlier it used to be in header as cookie
* @param response
* @return token
*/
private String getToken(String response){
//Pattern p=Pattern.compile("^(.*?token=\")(.*?)(\".*?)$");
Pattern p=Pattern.compile("(token=\")(.*?)(\")"); //simplified
Matcher matcher = p.matcher(response);
String token=null;
if(matcher.find() && matcher.groupCount()>2){
token=matcher.group(2);
}
return token;
}
/**
* Get token
* @param method method
* @param tokenname token name
* @return token
*/
private String getToken2 (HttpMethod method, String tokenname) {
Header[] h=method.getResponseHeaders();
String rtn="";
for(int i=0;i<h.length;i++){
String headerName = h[i].getName();
String headerValue = h[i].getValue();
log.debug("header:"+headerName+" headerValue:"+headerValue);
if (headerName == null && headerValue == null) {
// No more headers
//break;
}
if ("Set-Cookie".equalsIgnoreCase(headerName)) {
// Parse cookie
String[] fields = headerValue.split(";\\s*");
String cookieValue = fields[0];
String[] cookieValues=cookieValue.split("=");
String expires = null;
String path = null;
String domain = null;
boolean secure = false;
// Parse each field
for (int j=1; j<fields.length; j++) {
if ("secure".equalsIgnoreCase(fields[j])) {
secure = true;
} else if (fields[j].indexOf('=') > 0) {
String[] f = fields[j].split("=");
if ("expires".equalsIgnoreCase(f[0])) {
expires = f[1];
} else if ("domain".equalsIgnoreCase(f[0])) {
domain = f[1];
} else if ("path".equalsIgnoreCase(f[0])) {
path = f[1];
}
}
}
//if(cookieValues.length==2 && cookieValues[0].equals("4ecapwikidbToken") ){
if(cookieValues.length==2 && cookieValues[0].equals(tokenname) ){
//httpclient.getState().addCookie(new Cookie(".4ecap.com", cookieValues[0], cookieValues[1], "/", null, false) );
rtn=cookieValues[1];
}
// Save the cookie...
}
}
return rtn;
}
/**
* Save cookie
* @param method method
*/
private void saveCookie(HttpMethod method) {
Header[] h=method.getResponseHeaders();
for(int i=0;i<h.length;i++){
String headerName = h[i].getName();
String headerValue = h[i].getValue();
if (headerName == null && headerValue == null) {
// No more headers
//break;
}
if ("Set-Cookie".equalsIgnoreCase(headerName)) {
// Parse cookie
String[] fields = headerValue.split(";\\s*");
String cookieValue = fields[0];
String[] cookieValues=cookieValue.split("=");
String expires = null;
String path = null;
String domain = null;
boolean secure = false;
// Parse each field
for (int j=1; j<fields.length; j++) {
if ("secure".equalsIgnoreCase(fields[j])) {
secure = true;
} else if (fields[j].indexOf('=') > 0) {
String[] f = fields[j].split("=");
if ("expires".equalsIgnoreCase(f[0])) {
expires = f[1];
} else if ("domain".equalsIgnoreCase(f[0])) {
domain = f[1];
} else if ("path".equalsIgnoreCase(f[0])) {
path = f[1];
}
}
}
if(cookieValues.length==2){
httpclient.getState().addCookie(new Cookie(".4ecap.com", cookieValues[0], cookieValues[1], "/", null, false) );
}
// Save the cookie...
}
}
Cookie[] cookies = httpclient.getState().getCookies();
for (int i = 0; i < cookies.length; i++) {
Cookie cookie = cookies[i];
System.err.println(
"Cookie: " + cookie.getName() +
", Value: " + cookie.getValue() +
//", IsPersistent?: " + cookie.isPersistent() +
", Expiry Date: " + cookie.getExpiryDate() +
//", Comment: " + cookie.getComment()+
", path: " + cookie.getPath()+
", domain: " + cookie.getDomain());
//cookie.setValue("My own value");
}
}
}

37
project/bldb/src/main/resources/cache.ccf

@ -0,0 +1,37 @@
# DEFAULT CACHE REGION
jcs.default=DC
jcs.default.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.default.cacheattributes.MaxObjects=1000
jcs.default.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.default.cacheattributes.UseMemoryShrinker=false
jcs.default.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.default.elementattributes.IsEternal=false
jcs.default.elementattributes.MaxLifeSeconds=21600
jcs.default.elementattributes.IdleTime=1800
jcs.default.elementattributes.IsSpool=true
jcs.default.elementattributes.IsRemote=true
jcs.default.elementattributes.IsLateral=true
# PRE-DEFINED CACHE REGIONS
jcs.region.testCache1=DC
jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
jcs.region.testCache1.cacheattributes.MaxObjects=1000
jcs.region.testCache1.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
jcs.region.testCache1.cacheattributes.UseMemoryShrinker=false
jcs.region.testCache1.cacheattributes.MaxMemoryIdleTimeSeconds=3600
jcs.region.testCache1.cacheattributes.ShrinkerIntervalSeconds=60
jcs.region.testCache1.cacheattributes.MaxSpoolPerRun=500
jcs.region.testCache1.elementattributes=org.apache.jcs.engine.ElementAttributes
jcs.region.testCache1.elementattributes.IsEternal=false
# AVAILABLE AUXILIARY CACHES
jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
jcs.auxiliary.DC.attributes.DiskPath=${user.dir}/jcs_swap
jcs.auxiliary.DC.attributes.MaxPurgatorySize=10000000
jcs.auxiliary.DC.attributes.MaxKeySize=1000000
jcs.auxiliary.DC.attributes.MaxRecycleBinSize=5000
jcs.auxiliary.DC.attributes.OptimizeAtRemoveCount=300000
jcs.auxiliary.DC.attributes.ShutdownSpoolTimeLimit=60

23
project/bldb/src/main/resources/com/fe/client/function_modified_alert.txt

@ -0,0 +1,23 @@
{{subject}}R Function [[function_name]] modified by [[current_user]]
{{/subject}}The following changes were made by [[current_user]] on R Function [[function_name]]
<div style='border:1px solid grey;padding:10px;margin-bottom:20px;'>
<pre>
[[diff]]
</pre>
</div>
User comments:
<div style='background-color:#e0e0e0;border:none;padding:10px; color:#0064EA;'>
[[comments]]
</div>
<div style='border:0px solid #b0b0b0;margin-top:10px;'>
<small style='font-size:.7em'>To stop this alert remove your name on "Notification of Changes" column on Themes and Notification tab of the function</small>
</div>

24
project/bldb/src/main/resources/com/fe/client/scheduler_modified_alert.txt

@ -0,0 +1,24 @@
{{subject}}R Function [[task_name]] modified by [[current_user]]
{{/subject}}The following changes were made by [[current_user]] on Scheduler Script [[task_name]] (ID [[scheduler_id]])
<div style='border:1px solid grey;padding:10px;margin-bottom:20px;'>
<pre>
[[diff]]
</pre>
</div>
User comments:
<div style='background-color:#e0e0e0;border:none;padding:10px; color:#0064EA;'>
[[comments]]
</div>
<div style='border:0px solid #b0b0b0;margin-top:10px;'>
<small style='font-size:.7em'>To stop this alert remove your name on "Notification of Changes" column on Themes and Notification tab of the script</small>
</div>

86
project/bldb/src/main/resources/com/fe/config_unix.properties

@ -0,0 +1,86 @@
#should be used only in test server
#db_testing_version=[Development snapshot & Live data ]
#production server color #EDF5FF //l.blue
#test server color #FBEFFB //l.red
#tab_body_bg=#FBEFFB
load_balancing_server=4ecapsvsg2
log_error_folder=/home/p2pserver/logs/
lucene_index_folder=/home/p2pserver/lucene/
log_error_to_console=yes
log_error_to_console_full=yes
r_script_init=/mnt/public/Libs/Rinit.r
r_function_source_folder=/home/fileserv/Sharing/Public/Libs/R Libs/4ECAPFunctions/
r_function_path_url_prefix=\\\\10.153.64.10\\Public\\Libs\\R Libs\\4ECAPFunctions
r_auto_source_inc_folder=/home/fileserv/Sharing/Public/Libs/
r_auto_source_inc_prefix=//10.153.64.10/Public/Libs/R Libs/4ECAPFunctions/
#follwing file will be updated whenever user change the order of the folder.
r_source_4e_function_file=/home/fileserv/Sharing/Public/Libs/source_R_editor_modifed.r
r_source_4e_function_file_path_perfix=\\\\\\\\10.153.64.10\\\\Public\\\\Libs\\\\
wiki.username=Rams
wiki.password=FECrams
wiki.wikiurl=https://wiki.4ecap.com/4ecapwiki/
#p2p.taskpip=taskpip11
#p2p.groupname=DiscoveryServer11
p2p.ignorejri=true
bloomberg.server.servletAPI.url=http://10.153.64.11:9090/bldb/schedulerAPI
iexec_source_folder=/home/p2pserver/iexec_source/
hsql.queue.datafile=/home/p2pserver/queue/queue2
scheduler.report.folder=Z:/Research/Monitors/Scheduler/MonitorTab/
package.repository.unix=/home/fileserv/Sharing/Public/Libs/R Libs/4ECAPPackageUNIX
package.repository.win=/home/fileserv/Sharing/Public/Libs/R Libs/4ECAPPackage
#not case sensitive
superuser.enable=rams,xavier,ls,be,andy,ari
#make this as NIO Server (ExecuteR Server)
#true or false
#nio.server.mode=true
#needed for peer to connect
#nio.server.address=10.153.64.45
#needed both by server and peer bind the port on server side and open port on peerside.
#nio.server.port=1818
svn_user=svn4Euser
svn_pwd=4ESVN052011
svn_url=svn://10.153.64.10/bldb
svn_local_path=/bldb
svn_user_r=svn4Euser
svn_pwd_r=4ESVN052011
svn_url_r=svn://10.153.64.10/rfunctions
svn_local_path_r=/rfunctions
svn_url_ie=svn://10.153.64.10/iexec
svn_local_path_ie=/iexec
#ignore phone alarm for these error codes
ignore.phone.alarm=2315,2317,2318,2319
#-------------------------------------------------------@deprecated---------------------------------------------------------------
#the followings are redundant and no longer being actively used.
rtrs_download_xml_reqfolder=smb://info:info@10.153.64.10/Public/IT/Reuters/Queries/
rtrs_download_xml_resfolder=smb://info:info@10.153.64.10/Public/IT/Reuters/Responses/
rtrs_download_xml_statusfolder=smb://info:info@10.153.64.10/Public/IT/Reuters/Status/
bloomberg_synchronization=no
#scheduler_services_on=rhinoscript,rhinoscript1,rscriptlowpriority
#scheduler_services_on=bb_download,rscript,rhinoscript,rscript4reuters,rscriptlowpriority,rscript4bb,rscript4rserve,rscript4rservelow,rscript4rserveunix
scheduler_services_on=rhinoscript1,rhinoscript4priority

98
project/bldb/src/main/resources/com/fe/config_windows.properties

@ -0,0 +1,98 @@
#should be used only in test server
#db_testing_version=[Development snapshot & Live data ]
#production server color #EDF5FF //l.blue
#test server color #FBEFFB //l.red
#tab_body_bg=#FBEFFB
load_balancing_server=4ecappcsg21
log_error_folder=c:\\tomcat\\bldb_logs\\
lucene_index_folder=c:\\tomcat\\index\\
log_error_to_console=yes
log_error_to_console_full=yes
r_script_init=c:\\rJava\\r_init.txt
r_function_source_folder=c:\\testing_data\\r_functions\\
r_function_path_url_prefix=\\\\10.153.64.10\\Public\\Libs\\R Libs\\test2remove_4ECAPFunctions
r_auto_source_inc_folder=//10.153.64.10/Public/Libs/R Libs/test2remove_4ECAPFunctions/Libs/
r_auto_source_inc_prefix=//10.153.64.10/Public/Libs/R Libs/4ECAPFunctions/
#follwing file will be updated whenever user change the order of the folder.
r_source_4e_function_file=//10.153.64.10/Public/Libs/source_R_editor_modifed_tmp_2delete.r
r_source_4e_function_file_path_perfix=\\\\\\\\10.153.64.10\\\\Public\\\\Libs\\\\
wiki.username=Scheduler
wiki.password=Wd2MMjh4eBy4xVEGz4PVMagWUPszdSqKhNSe25HkqzdbEQS47B
wiki.wikiurl=https://wiki.4ecap.com/4ecapwiki/
p2p.taskpip=taskpip22
p2p.groupname=DiscoveryServer22
#p2p.taskpip.helper=taskpip_helper22
p2p.cachepath=C:\\tomcat\\
#p2p.ignorejri=false
bloomberg.server.servletAPI.url=http://4ecapsvsg2:8080/bldb/schedulerAPI
iexec_source_folder=c:\\testing_data\\iexec\\
hsql.queue.datafile=c:\\rnd\\hsqldb-2.2.9\\scheduler_data\\queue
scheduler.report.folder=Z:/Research/Monitors/Scheduler/MonitorTab/
package.repository.unix=Z:\\Libs\\R Libs\\4ECAPPackageUNIX
package.repository.win=Z:\\Libs\\R Libs\\4ECAPPackage
#not case sensitive
superuser.enable=raMs,xavier,be,ls
#make this as NIO Server (ExecuteR Server)
#true or false
nio.server.mode=false
#needed for peer to connect
#nio.server.address=10.153.64.19
#needed both by server and peer bind the port on server side and open port on peerside.
#nio.server.port=1818
svn_user=svn4Euser
svn_pwd=4ESVN052011
svn_url=svn://10.153.64.10/scheduler_test
svn_local_path=C:\\temp_repotest1\\sc5
svn_user_r=svn4Euser
svn_pwd_r=4ESVN052011
svn_url_r=svn://10.153.64.10/rfunctions_test
svn_local_path_r=C:\\temp_repotest1\\rfunctions
#svn_url_ie=svn://10.153.64.10/iexec
#svn_local_path_ie=C:\\temp_repotest1\\iexec
svn_url_ie=svn://10.153.64.10/iexec
svn_local_path_ie=C:\\temp_repotest1\\iexec
#for peers executing R Engine and RServe scripts.
r_script_console_logs=\\\\10.153.64.10\\Public\\Logs\\scheduler_rscripts\\
log_executeR_folder=c:\\tomcat\\webapps\\bldb\\executeRlogs\\
peer_home=C:\\4E_Peer\\
#ignore.authentication=true
#ignore.authentication=false;
#p2p.nomulticast=true
p2p.nomulticast=false
#-------------------------------------------------------@deprecated---------------------------------------------------------------
#the followings are redundant and no longer being actively used.
rtrs_download_xml_reqfolder=smb://info:info@10.153.64.10/Public/IT/Reuters/Queries/
rtrs_download_xml_resfolder=smb://info:info@10.153.64.10/Public/IT/Reuters/Responses/
rtrs_download_xml_statusfolder=smb://info:info@10.153.64.10/Public/IT/Reuters/Status/
bloomberg_synchronization=no
scheduler_services_on=rhinoscript1,rhinoscript4priority

16
project/bldb/src/main/resources/com/fe/p2p/pgadv.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jxta:PGA>
<jxta:PGA xmlns:jxta="http://jxta.org">
<GID>
urn:jxta:uuid-2810413B3CC24DB483F4BAE601CF875002
</GID>
<MSID>
urn:jxta:uuid-29974C1D718F4E79A3A5E196818448850426E2ACBCB04EF6BF8F83B2A2C2E5CC06
</MSID>
<Name>
Tomcat Bridge Group
</Name>
<Desc>
Prototype app for demonstrating Tomcat Bridge Group
</Desc>
</jxta:PGA>

4
project/bldb/src/main/resources/com/fe/scheduler/logmessages.properties

@ -0,0 +1,4 @@
peer.sendtask.received=Task Received from server
peer.sendtask.noroom2execute=Task failed, no room for execution
peer.sendtask.unknown=Error occured, Msg:[error_message]

15
project/bldb/src/main/resources/com/fe/strategy_new_template.xml

@ -0,0 +1,15 @@
<!-- STRATEGY DESCRIPTION: -->
<STRATEGY name="[[name]]" expireonfullfill="true" automate="AUT1">
<QUANTITY>
</QUANTITY>
<PRICE>
</PRICE>
<MAXQUANTITY>
</MAXQUANTITY>
<MAXQTYPRICE>
</MAXQTYPRICE>
</STRATEGY>

47
project/bldb/src/main/resources/com/fe/xml/mapping.xml

@ -0,0 +1,47 @@
<mapping>
<scheduler>
<!--
valid settings
days=possitive numbers only i.e 2 is yesterday and today (last value of today)
hour: 00-23
minute: 00-59
weekday
-->
<!-- uncomment to activate scheduled job
<job days="2" hour="08" minute="20" weekday="MONDAY"/>
<job days="2" hour="08" minute="20" weekday="TUESDAY"/>
<job days="2" hour="08" minute="42" weekday="WEDNESDAY"/>
<job days="2" hour="08" minute="20" weekday="THURSDAY"/>
<job days="2" hour="08" minute="20" weekday="FRIDAY"/>
<job days="5" hour="08" minute="20" weekday="SATURDAY"/>
-->
</scheduler>
<commodity name="CL" bloombergmarketsector="Comdty">
<!--
Use comma for multiple tickers
-->
<ticker>
CLX8,CLZ8,CLF9,CLG9,CLH9,CLJ9,CLK9,CLM9,CLN9,
CLQ9,CLU9,CLV9,CLX9,CLZ9,CLF0
</ticker>
<field bloomberg="PX_LAST" sqlserver="Close Price"/>
<field bloomberg="PX_VOLUME" sqlserver="Volume"/>
<field bloomberg="OPEN_INT" sqlserver="Open Interest"/>
</commodity>
<commodity name="CL" bloombergmarketsector="Index">
<ticker>
NYM1CNCL
</ticker>
<field bloomberg="PX_LAST" sqlserver="Commercial Long"/>
</commodity>
</mapping>

12
project/bldb/src/main/resources/config_alarm.properties

@ -0,0 +1,12 @@
ignore.alarm=false
#imonitor.url=http://10.153.64.31:5001/iMonitor/Responder.aspx
imonitor.ip=10.153.64.31
imonitor.port=5655
#dump XML to file instead of sending it to iMonitor API
#alarm.dump=false
alarm.dump=true
alarm.dump.folder=/temp/scheduler-alarm/

7
project/bldb/src/main/resources/config_auth.properties

@ -0,0 +1,7 @@
database_wiki_connstring=jdbc:mysql://wiki.4ecap.com/4EwikiDB1?user=4ecremoteuser&password=4ecrmt2011
database_wiki_driver=com.mysql.jdbc.Driver
wiki_login_url=https://wiki.4ecap.com
#superuser_password_folder=/home/p2pserver/logs/
superuser_password_folder=c:\\tmp\\

2
project/bldb/src/main/resources/config_db.properties

@ -0,0 +1,2 @@
db_close_timeout=20
db_config_path=/mnt/public/Libs/.4E.config

11
project/bldb/src/main/resources/log4j.properties

@ -0,0 +1,11 @@
### This log4j.properties is to handle DWR (directwebremoting) only. DWR doesn't support log4j2. ###
### Without this, DWR will generate text to console (level:TRACE?). ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%4p %d{HH:mm:ss,SSS} %C - %m%n
log4j.rootLogger=ERROR
log4j.logger.org.directwebremoting=ERROR,stdout

40
project/bldb/src/main/resources/log4j2.xml

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="CONSOLE" target="SYSTEM_OUT">
<PatternLayout pattern="%4p %d{HH:mm:ss,SSS} %C - %m%n" />
</Console>
</Appenders>
<Loggers>
<Root level="ERROR">
<AppenderRef ref="CONSOLE"/>
</Root>
<Logger name="log4j.logger.com.fe" level="ERROR" additivity="false">
<Appender-ref ref="CONSOLE" />
</Logger>
<Logger name="log4j.logger.com.fourelementscapital.scheduler.config.Config" level="ERROR" additivity="false">
<Appender-ref ref="CONSOLE" />
</Logger>
<Logger name="log4j.logger.com.fe.client.SchedulerMgmt" level="ERROR" additivity="false">
<Appender-ref ref="CONSOLE" />
</Logger>
<Logger name="log4j.logger.com.fe.client.LoginMgmt" level="ERROR" additivity="false">
<Appender-ref ref="CONSOLE" />
</Logger>
<Logger name="log4j.logger.com.fe.scheduler.balance.hsqldb" level="ERROR" additivity="false">
<Appender-ref ref="CONSOLE" />
</Logger>
<Logger name="log4j.logger.net.bull.javamelody" level="ERROR" additivity="false">
<Appender-ref ref="CONSOLE" />
</Logger>
<Logger name="log4j.logger.org.quartz" level="ERROR" additivity="false">
<Appender-ref ref="CONSOLE" />
</Logger>
<Logger name="log4j.logger.org.lobobrowser" level="ERROR" additivity="false">
<Appender-ref ref="CONSOLE" />
</Logger>
<Logger name="log4j.logger.org.directwebremoting" level="ERROR" additivity="false">
<Appender-ref ref="CONSOLE" />
</Logger>
</Loggers>
</Configuration>

78
project/bldb/src/main/resources/quartz.properties

@ -0,0 +1,78 @@
#============================================================================
# Configure Main Scheduler Properties
#============================================================================
org.quartz.scheduler.instanceName = CakeNoteScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
#============================================================================
# Configure ThreadPool
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 12
org.quartz.threadPool.threadPriority = 5
#============================================================================
# Configure JobStore
#============================================================================
org.quartz.jobStore.misfireThreshold = 60000
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
#org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
#org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
#org.quartz.jobStore.useProperties = false
#org.quartz.jobStore.dataSource = myDS
#org.quartz.jobStore.tablePrefix = QRTZ_
#org.quartz.jobStore.isClustered = false
#============================================================================
# Configure Datasources
#============================================================================
#org.quartz.dataSource.myDS.driver = org.postgresql.Driver
#org.quartz.dataSource.myDS.URL = jdbc:postgresql://localhost/dev
#org.quartz.dataSource.myDS.user = jhouse
#org.quartz.dataSource.myDS.password =
#org.quartz.dataSource.myDS.maxConnections = 5
#============================================================================
# JobInitializationPlugin (xml declarative way to trigger jobs)
#============================================================================
#org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.JobInitializationPlugin
#org.quartz.plugin.jobInitializer.fileName = quartz_jobs.xml
#org.quartz.plugin.jobInitializer.overWriteExistingJobs = false
#org.quartz.plugin.jobInitializer.failOnFileNotFound = true
#============================================================================
# Configure JobStore
#============================================================================
#org.quartz.jobStore.misfireThreshold = 60000
#org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
#org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.MSSQLDelegate
#org.quartz.jobStore.useProperties = false
#org.quartz.jobStore.dataSource = myDS
#org.quartz.jobStore.tablePrefix = QRTZ_
#org.quartz.jobStore.isClustered = false
#org.quartz.jobStore.clusterCheckinInterval = 20000
#============================================================================
# Configure Datasources
#============================================================================
org.quartz.dataSource.myDS.driver = com.microsoft.sqlserver.jdbc.SQLServerDriver
org.quartz.dataSource.myDS.URL = jdbc:sqlserver://10.153.64.3:1433;databaseName=quartz_scheduler;integratedSecurity=false
org.quartz.dataSource.myDS.user = dbuser11
org.quartz.dataSource.myDS.password = dbuser11
org.quartz.dataSource.myDS.maxConnections = 5
org.quartz.dataSource.myDS.validationQuery=select 0 from dual

36
project/bldb/src/main/resources/quartz_jobs.xml

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<quartz xmlns="http://www.opensymphony.com/quartz/JobSchedulingData"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.opensymphony.com/quartz/JobSchedulingData
http://www.opensymphony.com/quartz/xml/job_scheduling_data_1_5.xsd"
version="1.5" overwrite-existing-jobs="true">
<job>
<job-detail1>
<name>testjob</name>
<group>CAKENOTE_GROUP</group>
<description>Basic test job</description>
<job-class>com.fe.scheduler.TestJob</job-class>
<job-data-map allows-transient-data="false">
<entry>
<key>param1</key>
<value>value1</value>
</entry>
<entry>
<key>param2</key>
<value>value2</value>
</entry>
</job-data-map>
</job-detail1>
<trigger1>
<simple>
<name>my-trigger</name>
<group>MYTRIGGER_GROUP</group>
<job-name>testjob</job-name>
<job-group>CAKENOTE_GROUP</job-group>
<!-- repeat indefinitely every 5 seconds -->
<repeat-count>-1</repeat-count>
<repeat-interval>5000</repeat-interval>
</simple>
</trigger1>
</job>
</quartz>

24
project/bldb/src/main/resources/scheduler_modified_alert.txt

@ -0,0 +1,24 @@
{{subject}}R Function [[task_name]] modified by [[current_user]]
{{/subject}}The following changes were made by [[current_user]] on Scheduler Script [[task_name]] (ID [[scheduler_id]])
<div style='border:1px solid grey;padding:10px;margin-bottom:20px;'>
<pre>
[[diff]]
</pre>
</div>
User comments:
<div style='background-color:#e0e0e0;border:none;padding:10px; color:#0064EA;'>
[[comments]]
</div>
<div style='border:0px solid #b0b0b0;margin-top:10px;'>
<small style='font-size:.7em'>To stop this alert remove your name on "Notification of Changes" column on Themes and Notification tab of the script</small>
</div>

25
project/bldb/src/main/webapp/RELEASE-NOTES.txt

@ -0,0 +1,25 @@
Release Notes for version 2.2.0
iTASK RELATED
==============
o :
Release Notes for version 2.1.0
iTASK RELATED
==============
o 7535 : Improve the handling of scheduler errors (Skip phone alert for error codes : 2315, 2317, 2318, 2319).
o 7569 : Port queries to MariaDB nomenclature, move queries to DAL.
o 7745 : If script name contains '&' then no alarm is sent to iMonitor (replace escape chars for XML).
o 7858 : Add release note.
o 8169 : Remove hardcoding of infrastructure from scheduler code and move it to config.
o 8195 : Move database timeout to config.
o 8207 : Optimize scheduler queries.
Release Notes for version 2.0.0
This is the original production version

51
project/bldb/src/main/webapp/WEB-INF/dwr.xml

@ -0,0 +1,51 @@
<!DOCTYPE dwr PUBLIC
"-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN"
"http://www.getahead.ltd.uk/dwr/dwr10.dtd">
<dwr>
<allow>
<create creator="new" javascript="AdminMgmt" scope="page">
<param name="class" value="com.fe.client.AdminMgmt"/>
</create>
<create creator="new" javascript="SchedulerMgmt" scope="page">
<param name="class" value="com.fe.client.SchedulerMgmt"/>
</create>
<create creator="new" javascript="RFunctionMgmt" scope="page">
<param name="class" value="com.fe.client.RFunctionMgmt"/>
</create>
<create creator="new" javascript="ExecuteRMgmt" scope="page">
<param name="class" value="com.fe.client.ExecuteRMgmt"/>
</create>
<create creator="new" javascript="IExecMgmt" scope="page">
<param name="class" value="com.fe.client.IExecMgmt"/>
</create>
<create creator="new" javascript="LoginMgmt" scope="page">
<param name="class" value="com.fe.client.LoginMgmt"/>
</create>
<create creator="new" javascript="MenuMgmt" scope="page">
<param name="class" value="com.fe.client.MenuMgmt"/>
</create>
<!-- convert match="com.fe.ValueObject" converter="bean"/ -->
<convert converter="bean" match="com.fourelementscapital.db.vo.*"/>
<convert match="java.lang.Exception" converter="exception"/>
<convert match="java.lang.StackTraceElement" converter="bean"/>
<convert match="com.fourelementscapital.scheduler.rscript.RScript" converter="bean"/>
<convert match="com.fourelementscapital.scheduler.pluggin.PlugginData" converter="bean"/>
<convert match="com.fourelementscapital.scheduler.engines.ScheduledTaskField" converter="bean"/>
</allow>
</dwr>

97
project/bldb/src/main/webapp/WEB-INF/urlrewrite.xml

@ -0,0 +1,97 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 3.2//EN"
"http://tuckey.org/res/dtds/urlrewrite3.2.dtd">
<!--
Configuration file for UrlRewriteFilter
http://tuckey.org/urlrewrite/
-->
<urlrewrite>
<rule>
<note>
The rule means that requests to /test/status/ will be redirected to /rewrite-status
the url will be rewritten.
</note>
<from>/test/status/</from>
<to type="redirect">%{context-path}/rewrite-status</to>
</rule>
<outbound-rule>
<note>
The outbound-rule specifies that when response.encodeURL is called (if you are using JSTL c:url)
the url /rewrite-status will be rewritten to /test/status/.
The above rule and this outbound-rule means that end users should never see the
url /rewrite-status only /test/status/ both in thier location bar and in hyperlinks
in your pages.
</note>
<from>/rewrite-status</from>
<to>/test/status/</to>
</outbound-rule>
<!--
INSTALLATION
in your web.xml add...
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
EXAMPLES
Redirect one url
<rule>
<from>/some/old/page.html</from>
<to type="redirect">/very/new/page.html</to>
</rule>
Redirect a directory
<rule>
<from>/some/olddir/(.*)</from>
<to type="redirect">/very/newdir/$1</to>
</rule>
Clean a url
<rule>
<from>/products/([0-9]+)</from>
<to>/products/index.jsp?product_id=$1</to>
</rule>
eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.
Browser detection
<rule>
<condition name="user-agent">Mozilla/[1-4]</condition>
<from>/some/page.html</from>
<to>/some/page-for-old-browsers.html</to>
</rule>
eg, will pass the request for /some/page.html on to /some/page-for-old-browsers.html only for older
browsers whose user agent srtings match Mozilla/1, Mozilla/2, Mozilla/3 or Mozilla/4.
Centralised browser detection
<rule>
<condition name="user-agent">Mozilla/[1-4]</condition>
<set type="request" name="browser">moz</set>
</rule>
eg, all requests will be checked against the condition and if matched
request.setAttribute("browser", "moz") will be called.
-->
</urlrewrite>

168
project/bldb/src/main/webapp/WEB-INF/web.xml

@ -0,0 +1,168 @@
<?xml version="1.0"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF 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.
-->
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<display-name>Welcome to Tomcat</display-name>
<description>
Welcome to Tomcat
</description>
<servlet>
<servlet-name>dwr-invoker</servlet-name>
<servlet-class>org.directwebremoting.servlet.DwrServlet</servlet-class>
<!--
<init-param>
<param-name>debug</param-name>
<param-value>false</param-value>
</init-param>
-->
<init-param>
<param-name>logLevel</param-name>
<param-value>ERROR</param-value>
</init-param>
<init-param>
<param-name>allowScriptTagRemoting</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>crossDomainSessionSecurity</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
<servlet>
<servlet-name>servletinit</servlet-name>
<servlet-class>com.fe.scheduler.SchedulerInitServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>p2pinit</servlet-name>
<servlet-class>com.fe.p2p.P2PServiceServlet</servlet-class>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet>
<servlet-name>SchedulerAPIServlet</servlet-name>
<servlet-class>com.fe.client.SchedulerAPIServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>rsyntax</servlet-name>
<servlet-class>com.fe.servlet.RSyntaxServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>fileuploader1</servlet-name>
<servlet-class>com.fe.servlet.FileUploader</servlet-class>
</servlet>
<servlet>
<servlet-name>ace_mode_r</servlet-name>
<servlet-class>com.fe.servlet.AceModeRSyntax</servlet-class>
</servlet>
<listener>
<listener-class>com.fe.servlet.P2PServletContextListener</listener-class>
</listener>
<servlet>
<servlet-name>TomcatWSServer</servlet-name>
<servlet-class>com.fourelementscapital.scheduler.p2p.websocket.TomcatWSServer</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TomcatWSServer</servlet-name>
<url-pattern>/ws/TomcatWSServer</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>TomcatWSExecuteRService</servlet-name>
<servlet-class>com.fe.p2p.websocket.TomcatWSExecuteRService</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TomcatWSExecuteRService</servlet-name>
<url-pattern>/ws/TomcatWSExecuteRService</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>TomcatWSConsole</servlet-name>
<servlet-class>com.fourelementscapital.scheduler.p2p.websocket.TomcatWSConsole</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TomcatWSConsole</servlet-name>
<url-pattern>/ws/TomcatWSConsole</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>dwr-invoker</servlet-name>
<url-pattern>/dwr/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>SchedulerAPIServlet</servlet-name>
<url-pattern>/schedulerAPI</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>fileuploader1</servlet-name>
<url-pattern>/fileuploader</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>rsyntax</servlet-name>
<url-pattern>/editarea_0_8_2/reg_syntax/r.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ace_mode_r</servlet-name>
<url-pattern>/ace/src/mode-r.js</url-pattern>
</servlet-mapping>
<filter>
<filter-name>monitoring</filter-name>
<filter-class>net.bull.javamelody.MonitoringFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>monitoring</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>net.bull.javamelody.SessionListener</listener-class>
</listener>
</web-app>

1
project/bldb/src/main/webapp/ace/.git-ref

@ -0,0 +1 @@
04917953ffdb7c700a64cc179b252fafeb0f0854

156
project/bldb/src/main/webapp/ace/ChangeLog.txt

@ -0,0 +1,156 @@
2012.09.17, Version 1.0.0
* New Features
- Multiple cursors and selections (https://c9.io/site/blog/2012/08/be-an-armenian-warrior-with-block-selection-on-steroids/)
- Fold buttons displayed in the gutter
- Indent Guides
- Completely reworked vim mode (Sergi Mansilla)
- Improved emacs keybindings
- Autoclosing of html tags (danyaPostfactum)
* 20 New language modes
- Coldfusion (Russ)
- Diff
- GLSL (Ed Mackey)
- Go (Davide Saurino)
- Haxe (Jason O'Neil)
- Jade (Garen Torikian)
- jsx (Syu Kato)
- LaTeX (James Allen)
- Less (John Roepke)
- Liquid (Bernie Telles)
- Lua (Lee Gao)
- LuaPage (Choonster)
- Markdown (Chris Spencer)
- PostgreSQL (John DeSoi)
- Powershell (John Kane)
- Sh (Richo Healey)
- SQL (Jonathan Camile)
- Tcl (Cristoph Hochreiner)
- XQuery (William Candillion)
- Yaml (Meg Sharkey)
* Live syntax checks
- for XQuery and JSON
* New Themes
- Ambiance (Irakli Gozalishvili)
- Dreamweaver (Adam Jimenez)
- Github (bootstraponline)
- Tommorrow themes (https://github.com/chriskempson/tomorrow-theme)
- XCode
* Many Small Enhancements and Bugfixes
2011.08.02, Version 0.2.0
* Split view (Julian Viereck)
- split editor area horizontally or vertivally to show two files at the same
time
* Code Folding (Julian Viereck)
- Unstructured code folding
- Will be the basis for language aware folding
* Mode behaviours (Chris Spencer)
- Adds mode specific hooks which allow transformations of entered text
- Autoclosing of braces, paranthesis and quotation marks in C style modes
- Autoclosing of angular brackets in XML style modes
* New language modes
- Clojure (Carin Meier)
- C# (Rob Conery)
- Groovy (Ben Tilford)
- Scala (Ben Tilford)
- JSON
- OCaml (Sergi Mansilla)
- Perl (Panagiotis Astithas)
- SCSS/SASS (Andreas Madsen)
- SVG
- Textile (Kelley van Evert)
- SCAD (Jacob Hansson)
* Live syntax checks
- Lint for CSS using CSS Lint <http://csslint.net/>
- CoffeeScript
* New Themes
- Crimson Editor (iebuggy)
- Merbivore (Michael Schwartz)
- Merbivore soft (Michael Schwartz)
- Solarized dark/light <http://ethanschoonover.com/solarized> (David Alan Hjelle)
- Vibrant Ink (Michael Schwartz)
* Small Features/Enhancements
- Lots of render performance optimizations (Harutyun Amirjanyan)
- Improved Ruby highlighting (Chris Wanstrath, Trent Ogren)
- Improved PHP highlighting (Thomas Hruska)
- Improved CSS highlighting (Sean Kellogg)
- Clicks which cause the editor to be focused don't reset the selection
- Make padding text layer specific so that print margin and active line
highlight are not affected (Irakli Gozalishvili)
- Added setFontSize method
- Improved vi keybindings (Trent Ogren)
- When unfocused make cursor transparent instead of removing it (Harutyun Amirjanyan)
- Support for matching groups in tokenizer with arrays of tokens (Chris Spencer)
* Bug fixes
- Add support for the new OSX scroll bars
- Properly highlight JavaScript regexp literals
- Proper handling of unicode characters in JavaScript identifiers
- Fix remove lines command on last line (Harutyun Amirjanyan)
- Fix scroll wheel sluggishness in Safari
- Make keyboard infrastructure route keys like []^$ the right way (Julian Viereck)
2011.02.14, Version 0.1.6
* Floating Anchors
- An Anchor is a floating pointer in the document.
- Whenever text is inserted or deleted before the cursor, the position of
the cursor is updated
- Usesd for the cursor and selection
- Basis for bookmarks, multiple cursors and snippets in the future
* Extensive support for Cocoa style keybindings on the Mac <https://github.com/ajaxorg/ace/issues/closed#issue/116/comment/767803>
* New commands:
- center selection in viewport
- remove to end/start of line
- split line
- transpose letters
* Refator markers
- Custom code can be used to render markers
- Markers can be in front or behind the text
- Markers are now stored in the session (was in the renderer)
* Lots of IE8 fixes including copy, cut and selections
* Unit tests can also be run in the browser
<https://github.com/ajaxorg/ace/blob/master/lib/ace/test/tests.html>
* Soft wrap can adapt to the width of the editor (Mike Ratcliffe, Joe Cheng)
* Add minimal node server server.js to run the Ace demo in Chrome
* The top level editor.html demo has been renamed to index.html
* Bug fixes
- Fixed gotoLine to consider wrapped lines when calculating where to scroll to (James Allen)
- Fixed isues when the editor was scrolled in the web page (Eric Allam)
- Highlighting of Python string literals
- Syntax rule for PHP comments
2011.02.08, Version 0.1.5
* Add Coffeescript Mode (Satoshi Murakami)
* Fix word wrap bug (Julian Viereck)
* Fix packaged version of the Eclipse mode
* Loading of workers is more robust
* Fix "click selection"
* Allow tokizing empty lines (Daniel Krech)
* Make PageUp/Down behavior more consistent with native OS (Joe Cheng)
2011.02.04, Version 0.1.4
* Add C/C++ mode contributed by Gastón Kleiman
* Fix exception in key input
2011.02.04, Version 0.1.3
* Let the packaged version play nice with requireJS
* Add Ruby mode contributed by Shlomo Zalman Heigh
* Add Java mode contributed by Tom Tasche
* Fix annotation bug
* Changing a document added a new empty line at the end

24
project/bldb/src/main/webapp/ace/LICENSE

@ -0,0 +1,24 @@
Copyright (c) 2010, Ajax.org B.V.
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of Ajax.org B.V. nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

21
project/bldb/src/main/webapp/ace/README.md

@ -0,0 +1,21 @@
Ace (Ajax.org Cloud9 Editor)
============================
Ace is a code editor written in JavaScript.
This repository has only generated files.
If you want to work on ace please go to https://github.com/ajaxorg/ace instead.
here you can find pre-built files for convenience of embedding.
it contains 4 versions
* [src](https://github.com/ajaxorg/ace-builds/tree/master/src) concatenated but not minified
* [src-min](https://github.com/ajaxorg/ace-builds/tree/master/src-min) concatenated and minified with uglify.js
* [src-noconflict](https://github.com/ajaxorg/ace-builds/tree/master/src-noconflict) uses ace.require instead of require
* [src-min-noconflict](https://github.com/ajaxorg/ace-builds/tree/master/src-min-noconflict) -
For a simple way of embedding ace into webpage see https://github.com/ajaxorg/ace-builds/blob/master/editor.html
To see ace in action go to [kitchen-sink-demo](http://ajaxorg.github.com/ace-builds/kitchen-sink.html), [scrollable-page-demo](http://ajaxorg.github.com/ace-builds/scrollable-page.html), or [minimal demo](http://ajaxorg.github.com/ace-builds/editor.html)

BIN
project/bldb/src/main/webapp/ace/demo/kitchen-sink/logo.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

47
project/bldb/src/main/webapp/ace/demo/kitchen-sink/styles.css

@ -0,0 +1,47 @@
/*PACKAGE
@import url(//fonts.googleapis.com/css?family=Droid+Sans+Mono);
PACKAGE*/
html {
height: 100%;
width: 100%;
overflow: hidden;
}
body {
overflow: hidden;
margin: 0;
padding: 0;
height: 100%;
width: 100%;
font-family: Arial, Helvetica, sans-serif, Tahoma, Verdana, sans-serif;
font-size: 12px;
background: rgb(14, 98, 165);
color: white;
}
#logo {
padding: 15px;
margin-left: 70px;
}
#editor {
position: absolute;
top: 0px;
left: 280px;
bottom: 0px;
right: 0px;
background: white;
}
#controls {
padding: 5px;
}
#controls td {
text-align: right;
}
#controls td + td {
text-align: left;
}

39
project/bldb/src/main/webapp/ace/editor.html

@ -0,0 +1,39 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Editor</title>
<style type="text/css" media="screen">
body {
overflow: hidden;
}
#editor {
margin: 0;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<pre id="editor">function foo(items) {
var i;
for (i = 0; i &lt; items.length; i++) {
alert("Ace Rocks " + items[i]);
}
}</pre>
<script src="src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/twilight");
editor.getSession().setMode("ace/mode/javascript");
</script>
</body>
</html>

268
project/bldb/src/main/webapp/ace/kitchen-sink-req.html

@ -0,0 +1,268 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ace Kitchen Sink</title>
<meta name="author" content="Fabian Jakobs">
<!--
Ace
version
commit
-->
<link rel="stylesheet" href="kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
</head>
<body>
<a href="http://ajaxorg.github.com/ace/" >
<img id="logo" src="kitchen-sink/logo.png">
</a>
<table id="controls">
<tr>
<td>
<label for="doc">Document</label>
</td><td>
<select id="doc" size="1">
</select>
</td>
</tr>
<tr>
<td >
<label for="mode">Mode</label>
</td><td>
<select id="mode" size="1">
</select>
</td>
</tr>
<tr>
<td>
<label for="split">Split</label>
</td><td>
<select id="split" size="1">
<option value="none">None</option>
<option value="below">Below</option>
<option value="beside">Beside</option>
</select>
</td>
</tr>
<tr>
<td >
<label for="theme">Theme</label>
</td><td>
<select id="theme" size="1">
<optgroup label="Bright">
<option value="ace/theme/chrome">Chrome</option>
<option value="ace/theme/clouds">Clouds</option>
<option value="ace/theme/crimson_editor">Crimson Editor</option>
<option value="ace/theme/dawn">Dawn</option>
<option value="ace/theme/dreamweaver">Dreamweaver</option>
<option value="ace/theme/eclipse">Eclipse</option>
<option value="ace/theme/github">GitHub</option>
<option value="ace/theme/solarized_light">Solarized Light</option>
<option value="ace/theme/textmate" selected="selected">TextMate</option>
<option value="ace/theme/tomorrow">Tomorrow</option>
<option value="ace/theme/xcode">XCode</option>
</optgroup>
<optgroup label="Dark">
<option value="ace/theme/ambiance">Ambiance</option>
<option value="ace/theme/chaos">Chaos</option>
<option value="ace/theme/clouds_midnight">Clouds Midnight</option>
<option value="ace/theme/cobalt">Cobalt</option>
<option value="ace/theme/idle_fingers">idleFingers</option>
<option value="ace/theme/kr_theme">krTheme</option>
<option value="ace/theme/merbivore">Merbivore</option>
<option value="ace/theme/merbivore_soft">Merbivore Soft</option>
<option value="ace/theme/mono_industrial">Mono Industrial</option>
<option value="ace/theme/monokai">Monokai</option>
<option value="ace/theme/pastel_on_dark">Pastel on dark</option>
<option value="ace/theme/solarized_dark">Solarized Dark</option>
<option value="ace/theme/twilight">Twilight</option>
<option value="ace/theme/tomorrow_night">Tomorrow Night</option>
<option value="ace/theme/tomorrow_night_blue">Tomorrow Night Blue</option>
<option value="ace/theme/tomorrow_night_bright">Tomorrow Night Bright</option>
<option value="ace/theme/tomorrow_night_eighties">Tomorrow Night 80s</option>
<option value="ace/theme/vibrant_ink">Vibrant Ink</option>
</optgroup>
</select>
</td>
</tr>
<tr>
<td>
<label for="fontsize">Font Size</label>
</td><td>
<select id="fontsize" size="1">
<option value="10px">10px</option>
<option value="11px">11px</option>
<option value="12px" selected="selected">12px</option>
<option value="14px">14px</option>
<option value="16px">16px</option>
<option value="20px">20px</option>
<option value="24px">24px</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="folding">Code Folding</label>
</td><td>
<select id="folding" size="1">
<option value="manual">manual</option>
<option value="markbegin" selected="selected">mark begin</option>
<option value="markbeginend">mark begin and end</option>
</select>
</td>
</tr>
<tr>
<td >
<label for="keybinding">Key Binding</label>
</td><td>
<select id="keybinding" size="1">
<option value="ace">Ace</option>
<option value="vim">Vim</option>
<option value="emacs">Emacs</option>
<option value="custom">Custom</option>
</select>
</td>
</tr>
<tr>
<td >
<label for="soft_wrap">Soft Wrap</label>
</td><td>
<select id="soft_wrap" size="1">
<option value="off">Off</option>
<option value="40">40 Chars</option>
<option value="80">80 Chars</option>
<option value="free">Free</option>
</select>
</td>
</tr>
<tr><td colspan="2">
<table id="more-controls">
<tr>
<td>
<label for="select_style">Full Line Selection</label>
</td><td>
<input type="checkbox" name="select_style" id="select_style" checked>
</td>
</tr>
<tr>
<td>
<label for="highlight_active">Highlight Active Line</label>
</td><td>
<input type="checkbox" name="highlight_active" id="highlight_active" checked>
</td>
</tr>
<tr>
<td >
<label for="show_hidden">Show Invisibles</label>
</td><td>
<input type="checkbox" name="show_hidden" id="show_hidden" checked>
</td>
</tr>
<tr>
<td >
<label for="display_indent_guides">Show Indent Guides</label>
</td><td>
<input type="checkbox" name="display_indent_guides" id="display_indent_guides" checked>
</td>
</tr>
<tr>
<td >
<label for="show_hscroll">Persistent HScroll</label>
</td><td>
<input type="checkbox" name="show_hscroll" id="show_hscroll">
</td>
</tr>
<tr>
<td >
<label for="animate_scroll">Animate scrolling</label>
</td><td>
<input type="checkbox" name="animate_scroll" id="animate_scroll">
</td>
</tr>
<tr>
<td >
<label for="show_gutter">Show Gutter</label>
</td><td>
<input type="checkbox" id="show_gutter" checked>
</td>
</tr>
<tr>
<td >
<label for="show_print_margin">Show Print Margin</label>
</td><td>
<input type="checkbox" id="show_print_margin" checked>
</td>
</tr>
<tr>
<td >
<label for="soft_tab">Use Soft Tab</label>
</td><td>
<input type="checkbox" id="soft_tab" checked>
</td>
</tr>
<tr>
<td >
<label for="highlight_selected_word">Highlight selected word</label>
</td>
<td>
<input type="checkbox" id="highlight_selected_word" checked>
</td>
</tr>
<tr>
<td >
<label for="enable_behaviours">Enable Behaviours</label>
</td>
<td>
<input type="checkbox" id="enable_behaviours">
</td>
</tr>
<tr>
<td >
<label for="fade_fold_widgets">Fade Fold Widgets</label>
</td>
<td>
<input type="checkbox" id="fade_fold_widgets">
</td>
</tr>
<tr>
<td >
<label for="highlight_token">Show token info</label>
</td>
<td>
<input type="checkbox" id="highlight_token">
</td>
</tr>
</table>
</td></tr>
</table>
</div>
</div>
</div>
<div id="editor-container"></div>
<script src="../demo/kitchen-sink/require.js"></script>
<script src="src/ace.js" data-ace-base="src"></script>
<script src="src/keybinding-vim.js"></script>
<script src="src/keybinding-emacs.js"></script>
<script src="kitchen-sink/demo.js"></script>
<script type="text/javascript" charset="utf-8">
require(["kitchen-sink/demo", "ace/ace"])
</script>
</body>
</html>

287
project/bldb/src/main/webapp/ace/kitchen-sink.html

@ -0,0 +1,287 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Ace Kitchen Sink</title>
<meta name="author" content="Fabian Jakobs">
<!--
Ace
version
commit
-->
<link href="./doc/site/images/favicon.ico" rel="icon" type="image/x-icon">
<link rel="stylesheet" href="kitchen-sink/styles.css" type="text/css" media="screen" charset="utf-8">
<script async="true" src="http://use.edgefonts.net/source-code-pro.js"></script>
</head>
<body>
<div id="optionsPanel" style="position:absolute;height:100%;width:260px">
<a href="http://ajaxorg.github.com/ace/" >
<img id="logo" src="kitchen-sink/logo.png">
</a>
<div style="position: absolute; overflow: hidden; top:80px; bottom:0">
<div style="width: 120%; height:100%; overflow-y: scroll">
<table id="controls">
<tr>
<td>
<label for="doc">Document</label>
</td><td>
<select id="doc" size="1">
</select>
</td>
</tr>
<tr>
<td >
<label for="mode">Mode</label>
</td><td>
<select id="mode" size="1">
</select>
</td>
</tr>
<tr>
<td>
<label for="split">Split</label>
</td><td>
<select id="split" size="1">
<option value="none">None</option>
<option value="below">Below</option>
<option value="beside">Beside</option>
</select>
</td>
</tr>
<tr>
<td >
<label for="theme">Theme</label>
</td><td>
<select id="theme" size="1">
<optgroup label="Bright">
<option value="ace/theme/chrome">Chrome</option>
<option value="ace/theme/clouds">Clouds</option>
<option value="ace/theme/crimson_editor">Crimson Editor</option>
<option value="ace/theme/dawn">Dawn</option>
<option value="ace/theme/dreamweaver">Dreamweaver</option>
<option value="ace/theme/eclipse">Eclipse</option>
<option value="ace/theme/github">GitHub</option>
<option value="ace/theme/solarized_light">Solarized Light</option>
<option value="ace/theme/textmate" selected="selected">TextMate</option>
<option value="ace/theme/tomorrow">Tomorrow</option>
<option value="ace/theme/xcode">XCode</option>
</optgroup>
<optgroup label="Dark">
<option value="ace/theme/ambiance">Ambiance</option>
<option value="ace/theme/chaos">Chaos</option>
<option value="ace/theme/clouds_midnight">Clouds Midnight</option>
<option value="ace/theme/cobalt">Cobalt</option>
<option value="ace/theme/idle_fingers">idleFingers</option>
<option value="ace/theme/kr_theme">krTheme</option>
<option value="ace/theme/merbivore">Merbivore</option>
<option value="ace/theme/merbivore_soft">Merbivore Soft</option>
<option value="ace/theme/mono_industrial">Mono Industrial</option>
<option value="ace/theme/monokai">Monokai</option>
<option value="ace/theme/pastel_on_dark">Pastel on dark</option>
<option value="ace/theme/solarized_dark">Solarized Dark</option>
<option value="ace/theme/twilight">Twilight</option>
<option value="ace/theme/tomorrow_night">Tomorrow Night</option>
<option value="ace/theme/tomorrow_night_blue">Tomorrow Night Blue</option>
<option value="ace/theme/tomorrow_night_bright">Tomorrow Night Bright</option>
<option value="ace/theme/tomorrow_night_eighties">Tomorrow Night 80s</option>
<option value="ace/theme/vibrant_ink">Vibrant Ink</option>
</optgroup>
</select>
</td>
</tr>
<tr>
<td>
<label for="fontsize">Font Size</label>
</td><td>
<select id="fontsize" size="1">
<option value="10px">10px</option>
<option value="11px">11px</option>
<option value="12px" selected="selected">12px</option>
<option value="13px">13px</option>
<option value="14px">14px</option>
<option value="16px">16px</option>
<option value="18px">18px</option>
<option value="20px">20px</option>
<option value="24px">24px</option>
</select>
</td>
</tr>
<tr>
<td>
<label for="folding">Code Folding</label>
</td><td>
<select id="folding" size="1">
<option value="manual">manual</option>
<option value="markbegin" selected="selected">mark begin</option>
<option value="markbeginend">mark begin and end</option>
</select>
</td>
</tr>
<tr>
<td >
<label for="keybinding">Key Binding</label>
</td><td>
<select id="keybinding" size="1">
<option value="ace">Ace</option>
<option value="vim">Vim</option>
<option value="emacs">Emacs</option>
<option value="custom">Custom</option>
</select>
</td>
</tr>
<tr>
<td >
<label for="soft_wrap">Soft Wrap</label>
</td><td>
<select id="soft_wrap" size="1">
<option value="off">Off</option>
<option value="40">40 Chars</option>
<option value="80">80 Chars</option>
<option value="free">Free</option>
</select>
</td>
</tr>
<tr><td colspan="2">
<table id="more-controls">
<tr>
<td>
<label for="select_style">Full Line Selection</label>
</td><td>
<input type="checkbox" name="select_style" id="select_style" checked>
</td>
</tr>
<tr>
<td>
<label for="highlight_active">Highlight Active Line</label>
</td><td>
<input type="checkbox" name="highlight_active" id="highlight_active" checked>
</td>
</tr>
<tr>
<td >
<label for="show_hidden">Show Invisibles</label>
</td><td>
<input type="checkbox" name="show_hidden" id="show_hidden" checked>
</td>
</tr>
<tr>
<td >
<label for="display_indent_guides">Show Indent Guides</label>
</td><td>
<input type="checkbox" name="display_indent_guides" id="display_indent_guides" checked>
</td>
</tr>
<tr>
<td >
<label for="show_hscroll">Persistent HScroll</label>
</td><td>
<input type="checkbox" name="show_hscroll" id="show_hscroll">
</td>
</tr>
<tr>
<td >
<label for="animate_scroll">Animate scrolling</label>
</td><td>
<input type="checkbox" name="animate_scroll" id="animate_scroll">
</td>
</tr>
<tr>
<td >
<label for="show_gutter">Show Gutter</label>
</td><td>
<input type="checkbox" id="show_gutter" checked>
</td>
</tr>
<tr>
<td >
<label for="show_print_margin">Show Print Margin</label>
</td><td>
<input type="checkbox" id="show_print_margin" checked>
</td>
</tr>
<tr>
<td >
<label for="soft_tab">Use Soft Tab</label>
</td><td>
<input type="checkbox" id="soft_tab" checked>
</td>
</tr>
<tr>
<td >
<label for="highlight_selected_word">Highlight selected word</label>
</td>
<td>
<input type="checkbox" id="highlight_selected_word" checked>
</td>
</tr>
<tr>
<td >
<label for="enable_behaviours">Enable Behaviours</label>
</td>
<td>
<input type="checkbox" id="enable_behaviours">
</td>
</tr>
<tr>
<td >
<label for="fade_fold_widgets">Fade Fold Widgets</label>
</td>
<td>
<input type="checkbox" id="fade_fold_widgets">
</td>
</tr>
<tr>
<td >
<label for="elastic_tabstops">Enable Elastic Tabstops</label>
</td>
<td>
<input type="checkbox" id="elastic_tabstops">
</td>
</tr>
<tr>
<td >
<label for="highlight_token">Show token info</label>
</td>
<td>
<input type="checkbox" id="highlight_token">
</td>
</tr>
<tr>
<td >
<label for="read_only">Read-only</label>
</td>
<td>
<input type="checkbox" id="read_only">
</td>
</tr>
</table>
</td></tr>
</table>
</div>
</div>
</div>
<div id="editor-container"></div>
<script src="src/ace.js" data-ace-base="src" type="text/javascript" charset="utf-8"></script>
<script src="src/keybinding-vim.js"></script>
<script src="src/keybinding-emacs.js"></script>
<script src="kitchen-sink/demo.js"></script>
<script type="text/javascript" charset="utf-8">
require("kitchen-sink/demo");
</script>
</body>
</html>

3442
project/bldb/src/main/webapp/ace/kitchen-sink/demo.js

File diff suppressed because it is too large Load Diff

6040
project/bldb/src/main/webapp/ace/kitchen-sink/docs/AsciiDoc.asciidoc

File diff suppressed because it is too large Load Diff

1544
project/bldb/src/main/webapp/ace/kitchen-sink/docs/AsciiDoc.html

File diff suppressed because it is too large Load Diff

17
project/bldb/src/main/webapp/ace/kitchen-sink/docs/Haxe.hx

@ -0,0 +1,17 @@
class Haxe
{
public static function main()
{
// Say Hello!
var greeting:String = "Hello World";
trace(greeting);
var targets:Array<String> = ["Flash","Javascript","PHP","Neko","C++","iOS","Android","webOS"];
trace("Haxe is a great language that can target:");
for (target in targets)
{
trace (" - " + target);
}
trace("And many more!");
}
}

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save