diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2617deb --- /dev/null +++ b/LICENSE @@ -0,0 +1,29 @@ +BSD 3-Clause License + +Copyright (c) 2022, Automatic Controls Equipment Systems, Inc. +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are met: + +1. Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + +2. 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. + +3. Neither the name of the copyright holder 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 THE COPYRIGHT HOLDER OR CONTRIBUTORS 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..9c9902b --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# GarbageCollector + +WebCTRL is a trademark of Automated Logic Corporation. Any other trademarks mentioned herein are the property of their respective owners. + +## About + +This WebCTRL add-on invokes `System.gc()` every 5 minutes. Essentially, this hints that the JVM should run its garbage collector, freeing any excess memory. In some cases, this should improve performance of a WebCTRL server. \ No newline at end of file diff --git a/config/BUILD_DETAILS b/config/BUILD_DETAILS new file mode 100644 index 0000000..4abbd95 --- /dev/null +++ b/config/BUILD_DETAILS @@ -0,0 +1,18 @@ +JDK Version: +openjdk 18.0.2.1 2022-08-18 +OpenJDK Runtime Environment (build 18.0.2.1+1-1) +OpenJDK 64-Bit Server VM (build 18.0.2.1+1-1, mixed mode, sharing) + +Compilation Flags: +--release 8 + +Runtime Dependencies: +addonsupport-api-addon-1.7.0 +alarmmanager-api-addon-1.7.0 +bacnet-api-addon-1.8.007-20220318.0837r +directaccess-api-addon-1.7.0 +tomcat-embed-core-9.0.37 +webaccess-api-addon-1.7.0 +xdatabase-api-addon-1.7.0 + +Packaged Dependencies: diff --git a/config/COMPILE_FLAGS b/config/COMPILE_FLAGS new file mode 100644 index 0000000..782201d --- /dev/null +++ b/config/COMPILE_FLAGS @@ -0,0 +1 @@ +--release 8 diff --git a/ext/deploy.bat b/ext/deploy.bat new file mode 100644 index 0000000..b2bb55a --- /dev/null +++ b/ext/deploy.bat @@ -0,0 +1,57 @@ +@echo off +if "%WebCTRL%" EQU "" goto :bad +if "%addonFile%" EQU "" goto :bad +if "%certFile%" EQU "" goto :bad +if /i "%*" EQU "--help" ( + echo DEPLOY Copies the .addon archive and certificate file to the bound WebCTRL installation. + exit /b 0 +) +if "%*" NEQ "" ( + echo Unexpected parameter. + exit /b 1 +) +if not exist "%addonFile%" ( + echo Cannot deploy because !name!.addon does not exist. + exit /b 1 +) +echo Deploying... +if "!name!" EQU "AddonDevRefresher" ( + echo Cannot be used to self-deploy. + echo Deployment unsuccessful. + exit /b 1 +) +if not exist "%WebCTRL%\addons" mkdir "%WebCTRL%\addons" >nul 2>nul +copy /y "%certFile%" "%WebCTRL%\addons\%certFileName%" >nul +copy /y "%addonFile%" "%WebCTRL%\addons\!name!.update" >nul +if %ErrorLevel% NEQ 0 ( + echo Deployment unsuccessful. + exit /b 1 +) +set /a count=0 +:waitUpdate +timeout 1 /nobreak >nul +set /a count+=1 +if exist "%WebCTRL%\addons\!name!.update" ( + if "%count%" EQU "60" ( + echo Timeout occurred. + echo Deployment unsuccessful. + exit /b 1 + ) else ( + goto :waitUpdate + ) +) +if exist "%WebCTRL%\addons\!name!.addon" ( + echo Deployment successful. + exit /b 0 +) else ( + echo Deployment unsuccessful. + exit /b 1 +) + +:bad + echo This script should not be invoked as a stand-alone application. + echo You must use this file as an extension to addon-dev-script. + echo https://github.com/automatic-controls/addon-dev-script + echo Press any key to exit. + pause >nul +exit /b 1 \ No newline at end of file diff --git a/root/info.xml b/root/info.xml new file mode 100644 index 0000000..5bbf927 --- /dev/null +++ b/root/info.xml @@ -0,0 +1,6 @@ + + GarbageCollector + A simple WebCTRL add-on which invoked System.gc() every 5 minutes. + 1.0.0 + Automatic Controls Equipment Systems, Inc. + diff --git a/root/webapp/WEB-INF/web.xml b/root/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..dc786e3 --- /dev/null +++ b/root/webapp/WEB-INF/web.xml @@ -0,0 +1,29 @@ + + + + + + aces.webctrl.garbage.Initializer + + + + + WEB + /* + + + + + RoleFilterAJAX + com.controlj.green.addonsupport.web.RoleFilter + + roles + view_administrator_only + + + + RoleFilterAJAX + /* + + + diff --git a/src/aces/webctrl/garbage/Initializer.java b/src/aces/webctrl/garbage/Initializer.java new file mode 100644 index 0000000..a95e9ba --- /dev/null +++ b/src/aces/webctrl/garbage/Initializer.java @@ -0,0 +1,26 @@ +package aces.webctrl.garbage; +import javax.servlet.*; +public class Initializer implements ServletContextListener { + private volatile Thread thread; + private volatile boolean go = true; + @Override public void contextInitialized(ServletContextEvent sce){ + thread = new Thread(){ + @Override public void run(){ + while (go){ + try{ + System.gc(); + Thread.sleep(300000); + }catch(InterruptedException e){} + } + } + }; + thread.start(); + } + @Override public void contextDestroyed(ServletContextEvent sce){ + try{ + go = false; + thread.interrupt(); + thread.join(); + }catch(InterruptedException e){} + } +} \ No newline at end of file