Extremely Serious

Month: March 2021

Tomcat 8.5 Service Basic Management

Service Creation

  1. Open a cmd terminal and change the current directory to the following:

    %CATALINA_HOME%\bin

    In this directory you will find the following files:

    • tomcat8.exe
    • tomcat8w.exe
  2. Copy the file tomcat8w.exe to CustomTomcat8w.exe.

    tomcat8w.exe is in the following pattern:

    <SERVICE_NAME>w.exe

    This makes the default service name set to tomcat8. Copying it to CustomTomcat8w.exe makes a service name of CustomTomcat8.

  3. Set the basic properties of the CustomTomcat8 service using the following command:

    tomcat8.exe //IS//CustomTomcat8 --DisplayName="Apache Custom Tomcat 8" --Install="%CATALINA_HOME%\bin\tomcat8.exe" --StartMode=jvm --StopMode=jvm --StartClass=org.apache.catalina.startup.Bootstrap --StartParams=start --StopClass=org.apache.catalina.startup.Bootstrap --StopParams=stop --Description="Apache Custom Tomcat 8 by Ron"
  4. Set the classpath using the following command:

    tomcat8.exe //US//CustomTomcat8 --Classpath="%CATALINA_HOME%\bin\bootstrap.jar;%CATALINA_HOME%\bin\tomcat-juli.jar"
  5. Set the JVM to use using the following command:

    tomcat8.exe //US//CustomTomcat8 --Jvm="%JAVA_HOME%\jre\bin\server\jvm.dll"
  6. Set some JVM options using the following command:

    tomcat8.exe //US//CustomTomcat8 --JvmOptions="-Dcatalina.home=%CATALINA_HOME%;-Dcatalina.base=%CATALINA_HOME%"
  7. Set logging using the following command:

    tomcat8.exe //US//CustomTomcat8 --LogLevel="Info" --LogPrefix="custom_tomcat8_service-" --LogPath="%CATALINA_HOME%\logs" --StdOutput="auto" --StdError="auto" --PidFile="tomcat8.pid"
  8. Set JVM memory using the following command:

    tomcat8.exe //US//CustomTomcat8 --JvmMs=512 --JvmMx=1024

Service Post Creation

  1. Using the file explorer, find the directory specified by your CATALINA_HOME environment variable and add the LOCAL SERVICE group on the security. Also add the permissions Full Control and Modify to it.

    For example if your CATALINA_HOME is pointing to C:\dev\tools\apache-tomcat-8.5.64 directory, expect something like the following as an output:

  2. Using the file explorer, navigate to %CATALINA_HOME%\bin directory and double click the CustomTomcat8w.exe file. Click the Java tab and ensure that the Java Virtual Machine field was correctly set. If not, update it accordingly.

    For example if your JAVA_HOME is pointing to C:\Program Files\Java\jdk1.8.0_271 directory, ensure that the Java Virtual Machine field is pointing to the correct location of the jvm.dll.

Service Execution

  1. Open a cmd terminal and change the current directory to the following:

    %CATALINA_HOME%\bin
  2. Run the CustomTomcat8 service using the following command:

    tomcat8.exe //RS//CustomTomcat8

Service Termination

  1. Open a cmd terminal and change the current directory to the following:

    %CATALINA_HOME%\bin
  2. Stop the CustomTomcat8 service using the following command:

    tomcat8.exe //SS//CustomTomcat8

Service Removal

  1. Open a cmd terminal and change the current directory to the following:

    %CATALINA_HOME%\bin
  2. Remove the CustomTomcat8 service using the following command:

    tomcat8.exe //DS//CustomTomcat8

Windows Services App

After the service creation was completed and without any error, we can also manage the service using the windows services app. Just look for the value of the --DisplayName parameter (i.e. Apache Custom Tomcat 8) when setting the basic properties of the service. This is depicted as follows by the following snapshot:

Reference

Functional Programming with Gosu

First Class Citizen

An entity that can be passed around as an argument, returned from a function, modified and assigned to a variable.

First Class Function

A function that is treated as first class citizen.

Higher-Order Functions (HOF)

A function which takes function as an argument and/or that return a function.

Closure

A function that remembers its lexical scope even when the function is executed outside that lexical scope.

function greeterFn() : block() {
  var name="World" //name is a local variable created by init
  var greet = \-> print("Hello ${name}") //greet is an inner function 
                                         //that uses the variable declared 
                                         //in parent function.
  return greet
}

var greeter = greeterFn()
greeter()

Currying

The process of converting a function that takes multiple arguments into a function that takes them one at a time.

var sum = \ a : int, b : int -> a + b
print(sum(1,2))

var curriedSum = \ a : int -> \ b : int -> a + b
print(curriedSum(1)(2))

Function Composition

The act of putting two functions together to form a third function where the output of one function is the input of the other.

uses java.lang.Integer
uses java.lang.Double
uses java.lang.Math

var compose = \ output : block(out : Integer) : String, func : block(param: Double) : Integer -> \ arg : Double -> func(output(arg)) //Definition

var floorToString = compose(\ out -> out.toString(), \ param -> Math.floor(param)) //Usage

print(floorToString(121.212121))

Continuation

The part of the code that's yet to be executed.

uses java.lang.Double

var printAsString = \ num : Double -> print("Given ${num}")

var addOneAndContinue = \ num: Double, cc : block(___num : Double) -> {
  var result = num + 1
  cc(result)
}

addOneAndContinue(2, printAsString)

Purity

A function is pure if the return value is only determined by its input values, and does not produce side effects.

var greet = \ name: String -> print("Hello ${name}")
greet("World")

The following is not pure since it modifies state outside of the function:

var greeting : String
var greet = \ name: String -> {greeting ="Hello ${name}"}
greet("World")
print(greeting)

Side Effects

A function or expression is said to have a side if apart from returning a value, it interacts with (reads from or writes to) external mutable state.

var currentDate = java.util.Date.CurrentDate //Retrieves the date from the system.
print(currentDate)

gw.api.util.Logger.forCategory("side-effect").info('IO is a side effect!')

Idempotent

A function is idempotent if reapplying it to its result does not produce a different result.

print(java.lang.Math.abs(java.lang.Math.abs(10)))

Point-Free Style (Tacit Programming)

Write functions where the definition does not explicitly identify the arguments used. This style usually requires currying or other higher order functions.

uses java.lang.Integer

// Given
var map = \ fn : block(item : int) : int -> \ list : List<Integer> -> list.map<Integer>(\ item -> fn(item))
var add = \ a : int -> \ b : int -> a + b
var nums : List<Integer> = (0..5).toList()

// Not points-free - 'numbers' is an explicit argument
var incrementAll = \ numbers : List<Integer> -> map(add(1))(numbers)

print(incrementAll(nums))

// Points-free - The list is an implicit argument
var incrementAll2 = map(add(1))

print(incrementAll2(nums))

Predicate

A function that returns true or false for a given value.

var predicate = \ a : int -> a > 2

print((1..4).where(\ a -> predicate(a)))

Lambda

An anonymous function that can be treated like a value.

(\ a : int -> a + 1)(1)

Lambda can be assigned to a variable

var add1 = \ a : int -> a + 1
print(add1(1))

Reference

https://github.com/hemanth/functional-programming-jargon
https://en.wiktionary.org/wiki/second-class_object#English
https://en.wiktionary.org/wiki/third-class_object#English