first commit

This commit is contained in:
2026-01-19 16:57:29 +07:00
parent 0668d07d0c
commit 740b241b71
8 changed files with 246 additions and 7 deletions

View File

@@ -1,15 +1,26 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="ClassName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="ConstPropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="EnumEntryName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="FunctionName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="GrazieInspection" enabled="false" level="GRAMMAR_ERROR" enabled_by_default="false" />
<inspection_tool class="GrazieStyle" enabled="false" level="STYLE_SUGGESTION" enabled_by_default="false" />
<inspection_tool class="InconsistentCommentForJavaParameter" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="LocalVariableName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="ObjectPrivatePropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="ObjectPropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PackageName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PrivatePropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="PropertyName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="ReplaceUntilWithRangeUntil" enabled="true" level="WEAK WARNING" enabled_by_default="true" />
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
<option name="processCode" value="true" />
<option name="processLiterals" value="true" />
<option name="processComments" value="true" />
</inspection_tool>
<inspection_tool class="TestFunctionName" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
</profile>
</component>

View File

@@ -0,0 +1,73 @@
package ActiveMQ
import jakarta.jms.BytesMessage
import jakarta.jms.Connection
import jakarta.jms.MapMessage
import jakarta.jms.Message
import jakarta.jms.MessageConsumer
import jakarta.jms.MessageListener
import jakarta.jms.Queue
import jakarta.jms.Session
import jakarta.jms.TextMessage
import org.apache.activemq.ActiveMQConnectionFactory
import org.tinylog.Logger
import java.util.function.Consumer
@Suppress("unused")
class ActiveMQClient(BrokerURL: String, username: String, password: String, queueName: String) {
private lateinit var connection: Connection
private lateinit var session: Session
private lateinit var destination : Queue
private lateinit var consumer: MessageConsumer
var MessageConsumer : Consumer<Message>?= null
init{
try{
connection = ActiveMQConnectionFactory(BrokerURL, username, password).createConnection()
connection.start()
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE)
destination = session.createQueue(queueName)
consumer = session.createConsumer(destination)
consumer.messageListener = MessageListener { message ->
MessageConsumer?.accept(message)
when (message) {
is TextMessage -> Logger.info { "Received Text Message : ${message.text}" }
is BytesMessage -> {
val length = message.bodyLength.toInt()
val byteArray = ByteArray(length)
message.readBytes(byteArray)
Logger.info { "Received Bytes Message of length : $length" }
}
is MapMessage -> {
val mapNames = message.mapNames
val mapContent = mutableMapOf<String, Any?>()
while (mapNames.hasMoreElements()) {
val key = mapNames.nextElement() as String
val value = message.getObject(key)
mapContent[key] = value
}
Logger.info { "Received Map Message : $mapContent" }
}
else -> Logger.warn { "Received Unknown Message Type" }
}
}
Logger.info { "ActiveMQ Connection created to Broker : $BrokerURL" }
} catch (e : Exception){
Logger.error { "Failed to create connection, Message : ${e.message}" }
}
}
fun Stop(){
try{
consumer.close()
session.close()
connection.close()
Logger.info { "Connection closed to Broker" }
} catch (e : Exception){
Logger.error { "Failed to close connection, Message : ${e.message}" }
}
}
}

View File

@@ -1,2 +0,0 @@
class ActiveMQClient {
}

View File

@@ -1,5 +1,30 @@
import ActiveMQ.ActiveMQClient
import Other.Config
import Web.WebUI
import database.MySQLInjector
import java.util.function.Consumer
//TIP To <b>Run</b> code, press <shortcut actionId="Run"/> or
// click the <icon src="AllIcons.Actions.Execute"/> icon in the gutter.
fun main() {
val config = Config()
config.Load()
val webUI = WebUI(config)
val activeclient = ActiveMQClient(
config.ActiveMQ_BrokerURL,
config.ActiveMQ_Username,
config.ActiveMQ_Password,
config.ActiveMQ_QueueName
)
val mysql = MySQLInjector(config)
activeclient.MessageConsumer = Consumer{ message ->
}
Runtime.getRuntime().addShutdownHook(Thread {
webUI.Stop()
activeclient.Stop()
mysql.Stop()
})
}

View File

@@ -1,2 +0,0 @@
class MySQLInjector {
}

121
src/Other/Config.kt Normal file
View File

@@ -0,0 +1,121 @@
package Other
import org.tinylog.Logger
import java.io.FileInputStream
import java.io.FileNotFoundException
import java.io.FileOutputStream
import java.nio.file.Files
import java.time.LocalDateTime
import java.util.Properties
import kotlin.io.path.Path
@Suppress("unused")
class Config {
private val prop = Properties()
private val filename = "config.properties"
var WebPort : Int
get() = prop.getProperty("webport").toInt()
set(value) {prop.setProperty("webport", value.toString())}
var ActiveMQ_BrokerURL : String
get() = prop.getProperty("activemq_brokerurl")
set(value) {prop.setProperty("activemq_brokerurl", value)}
var ActiveMQ_Username : String
get() = prop.getProperty("activemq_username")
set(value) {prop.setProperty("activemq_username", value)}
var ActiveMQ_Password : String
get() = prop.getProperty("activemq_password")
set(value) {prop.setProperty("activemq_password", value)}
var ActiveMQ_QueueName : String
get() = prop.getProperty("activemq_queuename")
set(value) {prop.setProperty("activemq_queuename", value)}
var MySQL_AAS1 : String
get() = prop.getProperty("mysql_aas1")
set(value) {prop.setProperty("mysql_aas1", value)}
var MySQL_AAS2 : String
get() = prop.getProperty("mysql_aas2")
set(value) {prop.setProperty("mysql_aas2", value)}
var MySQL_AAS3 : String
get() = prop.getProperty("mysql_aas3")
set(value) {prop.setProperty("mysql_aas3", value)}
var MySQL_AAS1_Username : String
get() = prop.getProperty("mysql_aas1_username")
set(value) {prop.setProperty("mysql_aas1_username", value)}
var MySQL_AAS1_Password : String
get() = prop.getProperty("mysql_aas1_password")
set(value) {prop.setProperty("mysql_aas1_password", value)}
var MySQL_AAS2_Username : String
get() = prop.getProperty("mysql_aas2_username")
set(value) {prop.setProperty("mysql_aas2_username", value)}
var MySQL_AAS2_Password : String
get() = prop.getProperty("mysql_aas2_password")
set(value) {prop.setProperty("mysql_aas2_password", value)}
var MySQL_AAS3_Username : String
get() = prop.getProperty("mysql_aas3_username")
set(value) {prop.setProperty("mysql_aas3_username", value)}
var MySQL_AAS3_Password : String
get() = prop.getProperty("mysql_aas3_password")
set(value) {prop.setProperty("mysql_aas3_password", value)}
fun Load(){
try{
if (Files.isRegularFile(Path(filename))){
prop.load(FileInputStream(filename))
if (!prop.contains("webport")) throw Exception("Invalid config file: missing 'webport'")
if (!prop.contains("activemq_brokerurl")) throw Exception("Invalid config file: missing 'activemq_brokerurl'")
if (!prop.contains("activemq_username")) throw Exception("Invalid config file: missing 'activemq_username'")
if (!prop.contains("activemq_password")) throw Exception("Invalid config file: missing 'activemq_password'")
if (!prop.contains("activemq_queuename")) throw Exception("Invalid config file: missing 'activemq_queuename'")
if (!prop.contains("mysql_aas1")) throw Exception("Invalid config file: missing 'mysql_aas1'")
if (!prop.contains("mysql_aas2")) throw Exception("Invalid config file: missing 'mysql_aas2'")
if (!prop.contains("mysql_aas3")) throw Exception("Invalid config file: missing 'mysql_aas3'")
if (!prop.contains("mysql_aas1_username")) throw Exception("Invalid config file: missing 'mysql_aas1_username'")
if (!prop.contains("mysql_aas1_password")) throw Exception("Invalid config file: missing 'mysql_aas1_password'")
if (!prop.contains("mysql_aas2_username")) throw Exception("Invalid config file: missing 'mysql_aas2_username'")
if (!prop.contains("mysql_aas2_password")) throw Exception("Invalid config file: missing 'mysql_aas2_password'")
if (!prop.contains("mysql_aas3_username")) throw Exception("Invalid config file: missing 'mysql_aas3_username'")
if (!prop.contains("mysql_aas3_password")) throw Exception("Invalid config file: missing 'mysql_aas3_password'")
Logger.info { "Configuration loaded from config.properties" }
} else throw FileNotFoundException("Config file not found")
} catch (e: FileNotFoundException){
Logger.error(e) { "Config file not found, Message : ${e.message}" }
CreateDefault()
Save()
}
catch (e: Exception){
Logger.error(e) { "Error while loading config, Message : ${e.message}" }
CreateDefault()
Save()
}
}
fun Save(){
// save prop to file "save.properties"
// comment is save date and time
val comment = "Configuration saved on ${LocalDateTime.now()}"
try{
prop.store(FileOutputStream(filename), comment)
Logger.info { "Configuration saved to config.properties" }
} catch (ex: Exception){
Logger.error(ex) { "Error while saving config, Message : ${ex.message}" }
}
}
fun CreateDefault(){
prop.clear()
prop.setProperty("webport", "7000")
prop.setProperty("activemq_brokerurl", "tcp://localhost:61616")
prop.setProperty("activemq_username", "admin")
prop.setProperty("activemq_password", "admin")
prop.setProperty("activemq_queuename", "TEST.QUEUE")
prop.setProperty("mysql_aas1", "jdbc:mysql://192.168.10.10:3306/aas")
prop.setProperty("mysql_aas2", "jdbc:mysql://192.168.10.11:3306/aas")
prop.setProperty("mysql_aas3"," jdbc:mysql://192.168.10.12:3306/aas")
prop.setProperty("mysql_aas1_username","admin")
prop.setProperty("mysql_aas1_password","admin")
prop.setProperty("mysql_aas2_username","admin")
prop.setProperty("mysql_aas2_password","admin")
prop.setProperty("mysql_aas3_username","admin")
prop.setProperty("mysql_aas3_password","admin")
Logger.info {"Default configuration created" }
}
}

View File

@@ -1,13 +1,16 @@
package Web
import Other.Config
import io.javalin.Javalin
@Suppress("unused")
/**
* Start WebUI Server
*/
class WebUI(listenport: Int) {
var app : Javalin = Javalin.create { config ->
class WebUI(config: Config) {
private var app : Javalin = Javalin.create { config ->
config.staticFiles.add("/html")
}.start(listenport)
}.start(config.WebPort)
/**
* Stop WebUI Server

View File

@@ -0,0 +1,10 @@
package database
import Other.Config
class MySQLInjector(config: Config) {
fun Stop(){
}
}