├── .idea ├── .name ├── copyright │ └── profiles_settings.xml ├── vcs.xml ├── libraries │ ├── Maven__log4j_log4j_1_2_14.xml │ ├── Maven__com_jcraft_jsch_0_1_53.xml │ ├── Maven__org_kamranzafar_jtar_2_2.xml │ ├── Maven__com_google_code_gson_gson_2_4.xml │ ├── Maven__commons_io_commons_io_2_4.xml │ ├── Maven__com_nanohttpd_nanohttpd_2_1_1.xml │ ├── Maven__commons_lang_commons_lang_2_4.xml │ ├── Maven__com_github_willwarren_jscp_c3d34af219.xml │ └── Maven__org_fusesource_leveldbjni_leveldbjni_all_1_8.xml ├── modules.xml ├── compiler.xml ├── misc.xml └── uiDesigner.xml ├── jtalk-server-core ├── src │ └── main │ │ └── java │ │ └── com │ │ └── pddstudio │ │ └── jtalk │ │ └── core │ │ ├── values │ │ ├── ModuleStatus.java │ │ └── Log.java │ │ ├── configuration │ │ ├── IJTalkConfig.java │ │ ├── JTalkConfig.java │ │ └── CoreConfig.java │ │ ├── modules │ │ ├── IModuleCallback.java │ │ ├── BaseModule.java │ │ └── ModuleManager.java │ │ ├── JTCore.java │ │ ├── log │ │ └── JLog.java │ │ ├── tools │ │ └── JHelp.java │ │ ├── coremodules │ │ └── HTTPModule.java │ │ └── db │ │ └── Database.java ├── jtalk-server-core.iml └── pom.xml ├── jatlk-client-api ├── pom.xml └── jtalk-client-api.iml ├── jtalk-server-api ├── pom.xml └── jtalk-server-api.iml ├── jTalk.iml ├── pom.xml └── jtalk-tests ├── src └── main │ └── java │ └── com │ └── pddstudio │ └── jtalk │ └── testing │ └── JTCoreTesting.java ├── jtalk-tests.iml └── pom.xml /.idea/.name: -------------------------------------------------------------------------------- 1 | jTalk -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/values/ModuleStatus.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.values; 2 | 3 | /** 4 | * Created by pddstudio on 07.10.15. 5 | */ 6 | 7 | /** 8 | * Serves a module's status 9 | */ 10 | public enum ModuleStatus { 11 | UNKNOWN, 12 | READY, 13 | BUSY, 14 | IDLE, 15 | FAILED 16 | } 17 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/configuration/IJTalkConfig.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.configuration; 2 | 3 | /** 4 | * Created by pddstudio on 06.10.15. 5 | */ 6 | public interface IJTalkConfig { 7 | 8 | void onLoadConfiguration(); 9 | void onModuleLoaded(); 10 | void onModuleDestroyed(); 11 | void onCoreDestroyed(); 12 | String getConfigPath(); 13 | 14 | } 15 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/modules/IModuleCallback.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.modules; 2 | 3 | /** 4 | * Created by pddstudio on 07.10.15. 5 | */ 6 | 7 | import com.pddstudio.jtalk.core.values.ModuleStatus; 8 | 9 | /** 10 | * Interface used by {@link BaseModule} 11 | */ 12 | public interface IModuleCallback { 13 | ModuleStatus onModuleStart(); 14 | void onModuleStop(); 15 | ModuleStatus getModuleStatus(); 16 | String getModuleErrorReport(); 17 | } 18 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__log4j_log4j_1_2_14.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_jcraft_jsch_0_1_53.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_kamranzafar_jtar_2_2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_google_code_gson_gson_2_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_io_commons_io_2_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_nanohttpd_nanohttpd_2_1_1.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jatlk-client-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | jtalk 7 | com.pddstudio 8 | 1.0-SNAPSHOT 9 | 10 | 4.0.0 11 | 12 | jtalk-client 13 | pom 14 | 15 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__commons_lang_commons_lang_2_4.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jtalk-server-api/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | 8 | jtalk 9 | com.pddstudio 10 | 1.0-SNAPSHOT 11 | 12 | 13 | jtalk-server 14 | 1.0-SNAPSHOT 15 | 16 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__com_github_willwarren_jscp_c3d34af219.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /.idea/libraries/Maven__org_fusesource_leveldbjni_leveldbjni_all_1_8.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/values/Log.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.values; 2 | 3 | /** 4 | * Created by pddstudio on 07.10.15. 5 | */ 6 | 7 | /** 8 | * Enumeration for the status of a log message 9 | */ 10 | public enum Log { 11 | DEFAULT, 12 | INFO, 13 | WARNING, 14 | ERROR; 15 | 16 | public void printOnRelatedStream(String message) { 17 | switch (this) { 18 | case DEFAULT: 19 | case INFO: 20 | case WARNING: 21 | System.out.println(message); 22 | break; 23 | case ERROR: 24 | System.err.println(message); 25 | break; 26 | } 27 | } 28 | 29 | public String forLogMessage() { 30 | return "[" + name() + "]"; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/configuration/JTalkConfig.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.configuration; 2 | 3 | import com.pddstudio.jtalk.core.db.Database; 4 | import com.pddstudio.jtalk.core.log.JLog; 5 | import com.pddstudio.jtalk.core.values.Log; 6 | 7 | /** 8 | * Created by pddstudio on 06.10.15. 9 | */ 10 | public abstract class JTalkConfig implements IJTalkConfig { 11 | 12 | public abstract void onLoadConfiguration(); 13 | 14 | public abstract String getConfigPath(); 15 | 16 | public abstract void onModuleLoaded(); 17 | 18 | public void onModuleDestroyed() { 19 | 20 | } 21 | 22 | public void onCoreDestroyed() { 23 | JLog.print("Core determination incoming. Closing database connection.", Log.INFO); 24 | Database.getDatabase().close(); 25 | } 26 | 27 | public JTalkConfig() {} 28 | 29 | } 30 | -------------------------------------------------------------------------------- /jTalk.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /jatlk-client-api/jtalk-client-api.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /jtalk-server-api/jtalk-server-api.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/modules/BaseModule.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.modules; 2 | 3 | /** 4 | * Created by pddstudio on 07.10.15. 5 | */ 6 | 7 | /** 8 | * The base module class which all Modules inherit from 9 | */ 10 | public abstract class BaseModule implements IModuleCallback { 11 | 12 | // Abstract methods used to identify the module and deliver informations 13 | public abstract String getModuleName(); 14 | public abstract String getModuleDescription(); 15 | public abstract String getModuleAuthor(); 16 | public abstract String getModuleVersion(); 17 | 18 | /** 19 | * Returns the module's tag 20 | * @return Module's tag as String 21 | */ 22 | public String getModuleIdentifier() { 23 | return MODULE_TAG; 24 | } 25 | 26 | private String MODULE_TAG; 27 | 28 | public BaseModule(String moduleIdentifier) { 29 | this.MODULE_TAG = moduleIdentifier; 30 | } 31 | 32 | 33 | } 34 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.pddstudio 8 | jtalk 9 | pom 10 | 1.0-SNAPSHOT 11 | 12 | jatlk-client-api 13 | jtalk-server-api 14 | jtalk-server-core 15 | jtalk-tests 16 | 17 | 18 | 19 | 20 | 21 | org.apache.maven.plugins 22 | maven-jar-plugin 23 | 24 | 25 | 26 | true 27 | com.pddstudio.jtalk.testing.JTCoreTesting 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/JTCore.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core; 2 | 3 | import com.pddstudio.jtalk.core.configuration.JTalkConfig; 4 | import com.pddstudio.jtalk.core.coremodules.HTTPModule; 5 | import com.pddstudio.jtalk.core.db.Database; 6 | import com.pddstudio.jtalk.core.log.JLog; 7 | import com.pddstudio.jtalk.core.modules.ModuleManager; 8 | import com.pddstudio.jtalk.core.tools.JHelp; 9 | import com.pddstudio.jtalk.core.values.Log; 10 | 11 | /** 12 | * Created by pddstudio on 06.10.15. 13 | */ 14 | 15 | public class JTCore { 16 | 17 | /** 18 | * jTalk server core class 19 | */ 20 | 21 | private final JTalkConfig jTalkConfig; 22 | private final ModuleManager moduleManager; 23 | 24 | private static final String LAST_START = "JTCORE_LAST_START"; 25 | 26 | public JTCore(JTalkConfig jTalkConfig) { 27 | this.jTalkConfig = jTalkConfig; 28 | this.moduleManager = ModuleManager.start(); 29 | JLog.print("Starting JTCore...", Log.INFO); 30 | Database.getDatabase(); 31 | moduleManager.loadModule(new HTTPModule()); 32 | JLog.print("Last JTCore start: " + Database.getDatabase().get(LAST_START), Log.INFO); 33 | Database.getDatabase().save(LAST_START, JHelp.Date.getCurrentDateAndTime()); 34 | } 35 | 36 | public void destroy() { 37 | jTalkConfig.onCoreDestroyed(); 38 | moduleManager.destroy(); 39 | } 40 | 41 | } 42 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/configuration/CoreConfig.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.configuration; 2 | 3 | /** 4 | * This class serves the core config and required values 5 | */ 6 | public final class CoreConfig { 7 | 8 | /** 9 | * The root directory of JTalk and all it's files. 10 | */ 11 | public static final String JTALK_ROOT_DIR = "/opt/jTalk"; 12 | 13 | /** 14 | * JTalk's log directory 15 | */ 16 | public static final String JTALK_LOG_DIR = "/logs"; 17 | 18 | /** 19 | * JTalk's database directory 20 | */ 21 | public static final String JTALK_DB = "/database"; 22 | 23 | /** 24 | * JTalk's core db file name 25 | */ 26 | public static final String JTALK_CORE_DB_NAME = "/core.db"; 27 | 28 | /** 29 | * This sub class serves the required values for the JLog class. 30 | */ 31 | public static final class JLog { 32 | 33 | /** 34 | * Defines weather to create logs or not 35 | */ 36 | public static final boolean CREATE_LOG_FILES = true; 37 | 38 | /** 39 | * Defines weather to print the created log messages to the System.out or not. 40 | */ 41 | public static final boolean PRINT_LOGS = true; 42 | 43 | /** 44 | * Prefix for the database logfiles 45 | */ 46 | public static final String DATABASE_LOGFILE = JTALK_LOG_DIR + "/db_logs/db_log_"; 47 | 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /jtalk-tests/src/main/java/com/pddstudio/jtalk/testing/JTCoreTesting.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.testing; 2 | 3 | /** 4 | * Created by pddstudio on 07.10.15. 5 | */ 6 | 7 | import com.pddstudio.jtalk.core.JTCore; 8 | import com.pddstudio.jtalk.core.configuration.JTalkConfig; 9 | import com.pddstudio.jtalk.core.log.JLog; 10 | import com.pddstudio.jtalk.core.values.Log; 11 | 12 | import java.util.Scanner; 13 | 14 | /** 15 | * Used to test several JTalk core functions 16 | */ 17 | public class JTCoreTesting { 18 | 19 | private final JTalkConfig jTalkConfig = new JTalkConfig() { 20 | @Override 21 | public void onLoadConfiguration() { 22 | 23 | } 24 | 25 | @Override 26 | public String getConfigPath() { 27 | return null; 28 | } 29 | 30 | @Override 31 | public void onModuleLoaded() { 32 | JLog.print("JTCoreTesting:onModuleLoaded() completed.", Log.INFO); 33 | } 34 | }; 35 | 36 | private final JTCore jtCore; 37 | 38 | public JTCoreTesting() { 39 | jtCore = new JTCore(jTalkConfig); 40 | } 41 | 42 | public static void main(String[] args) { 43 | JTCoreTesting jtCoreTesting = new JTCoreTesting(); 44 | Scanner scanner = new Scanner(System.in); 45 | String input; 46 | while(scanner.hasNext()) { 47 | input = scanner.nextLine(); 48 | if(input.toLowerCase().equals("exit")) { 49 | jtCoreTesting.onExit(); 50 | } 51 | } 52 | 53 | } 54 | 55 | private void onExit() { 56 | System.out.println("onExit() called. Shutting down JTCore..."); 57 | jtCore.destroy(); 58 | System.out.println("Finished. Leaved main()."); 59 | System.exit(0); 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /jtalk-server-core/jtalk-server-core.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/log/JLog.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.log; 2 | 3 | import com.pddstudio.jtalk.core.JTCore; 4 | import com.pddstudio.jtalk.core.configuration.CoreConfig; 5 | import com.pddstudio.jtalk.core.tools.JHelp; 6 | import com.pddstudio.jtalk.core.values.Log; 7 | 8 | import java.util.Calendar; 9 | import java.util.GregorianCalendar; 10 | 11 | /** 12 | * Created by pddstudio on 06.10.15. 13 | */ 14 | 15 | /** 16 | * The Logger class used by {@link JTCore} and commons. 17 | */ 18 | public final class JLog { 19 | 20 | /** 21 | * Creates a new log message with {@link Log#DEFAULT} 22 | * @param logMessage 23 | */ 24 | public static void print(String logMessage) { 25 | addMessage(logMessage, Log.DEFAULT); 26 | } 27 | 28 | /** 29 | * Creates a new log message with the given {@link Log} value 30 | * @param logMessage 31 | * @param logType 32 | */ 33 | public static void print(String logMessage, Log logType) { 34 | addMessage(logMessage, logType); 35 | } 36 | 37 | private static void addMessage(String message, Log importance) { 38 | 39 | String logMessage = datePrefix() 40 | + importance.forLogMessage() 41 | + " : " 42 | + message; 43 | 44 | if(CoreConfig.JLog.PRINT_LOGS) { 45 | importance.printOnRelatedStream(logMessage); 46 | } 47 | 48 | if(CoreConfig.JLog.CREATE_LOG_FILES) { 49 | //TODO: write log to logfile 50 | } 51 | 52 | } 53 | 54 | /** 55 | * function to get the current system time in a formatted {@link String} 56 | * @return Current system date as formatted String: [YYYY-MM-DD | hh:mm:ss] 57 | */ 58 | private static String datePrefix() { 59 | return "[" + JHelp.Date.getCurrentDate() + "]"; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /jtalk-tests/jtalk-tests.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 24 | 25 | 31 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /jtalk-server-core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | jtalk 7 | com.pddstudio 8 | 1.0-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | jtalk-server-core 14 | jar 15 | 16 | 17 | 18 | jitpack.io 19 | https://jitpack.io 20 | 21 | 22 | 23 | 49 | 50 | 51 | 52 | com.jcraft 53 | jsch 54 | 0.1.53 55 | 56 | 57 | com.github.willwarren 58 | jscp 59 | c3d34af219 60 | 61 | 62 | com.google.code.gson 63 | gson 64 | 2.4 65 | 66 | 67 | com.nanohttpd 68 | nanohttpd 69 | 2.1.1 70 | 71 | 72 | org.fusesource.leveldbjni 73 | leveldbjni-all 74 | 1.8 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/modules/ModuleManager.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.modules; 2 | 3 | /** 4 | * Created by pddstudio on 07.10.15. 5 | */ 6 | 7 | import com.pddstudio.jtalk.core.log.JLog; 8 | import com.pddstudio.jtalk.core.values.Log; 9 | import com.pddstudio.jtalk.core.values.ModuleStatus; 10 | 11 | import java.util.HashMap; 12 | 13 | /** 14 | * The ModuleManager (un)registers modules which the {@link com.pddstudio.jtalk.core.JTCore} should load or determinate 15 | */ 16 | public class ModuleManager { 17 | 18 | private final HashMap moduleList; 19 | 20 | private ModuleManager() { 21 | moduleList = new HashMap(); 22 | JLog.print("ModuleManager initialized.", Log.INFO); 23 | } 24 | 25 | /** 26 | * Returns a new ModuleManager instance 27 | * @return ModuleManager instance 28 | */ 29 | public static ModuleManager start() { 30 | return new ModuleManager(); 31 | } 32 | 33 | /** 34 | * Called when the JTCore is about to shutdown. Disconnects all modules and saves relevant data. 35 | */ 36 | public void destroy() { 37 | if(moduleList.isEmpty()) { 38 | JLog.print("ModuleManager : No attached modules to disconnect. Skipping...", Log.INFO); 39 | } else { 40 | JLog.print("ModuleManager : Disconnecting all modules.", Log.INFO); 41 | for(BaseModule module : moduleList.values()) { 42 | JLog.print("Disconnecting Module : " + module.getModuleName() + " (Version: " + module.getModuleVersion() + ")", Log.INFO); 43 | module.onModuleStop(); 44 | moduleList.remove(module.getModuleIdentifier()); 45 | } 46 | } 47 | } 48 | 49 | /** 50 | * Loads the given BaseModule 51 | * @param module - The module which should be loaded 52 | */ 53 | public void loadModule(BaseModule module) { 54 | JLog.print("Trying to load Module: " + module.getModuleName() + " (Version: " + module.getModuleVersion() + ") [IDENT:" + module.getModuleIdentifier() + "]", Log.INFO); 55 | if(module.onModuleStart().equals(ModuleStatus.READY)) { 56 | JLog.print("Module successfully loaded!", Log.INFO); 57 | moduleList.put(module.getModuleIdentifier(), module); 58 | } else { 59 | JLog.print("An error occurred when trying to load module " + module.getModuleName() + " [STATUS: " + module.getModuleStatus().name() + "]", Log.ERROR); 60 | } 61 | } 62 | 63 | /** 64 | * Returns the Module object with the given identifier or null 65 | * @param moduleIdentifier - identifier for the module 66 | * @return The module or null 67 | */ 68 | public BaseModule getModule(String moduleIdentifier) { 69 | return moduleList.get(moduleIdentifier); 70 | } 71 | 72 | /** 73 | * Returns the number of modules attached to the ModuleManager 74 | * @return number of modules 75 | */ 76 | public int getModulesCount() { 77 | return moduleList.size(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/tools/JHelp.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.tools; 2 | 3 | /** 4 | * Created by pddstudio on 07.10.15. 5 | */ 6 | 7 | import java.util.Calendar; 8 | import java.util.GregorianCalendar; 9 | 10 | /** 11 | * Class which contains several helper methods used by JTalk and it's modules. 12 | */ 13 | public final class JHelp { 14 | 15 | public static class Date { 16 | 17 | /** 18 | * Returns the current system's date. 19 | * @return Date as String in YYYY-MM-DD format 20 | */ 21 | public static String getCurrentDate() { 22 | Calendar calendar = GregorianCalendar.getInstance(); 23 | StringBuilder stringBuilder = new StringBuilder(); 24 | stringBuilder.append(calendar.get(Calendar.YEAR)); 25 | stringBuilder.append("-"); 26 | int month = calendar.get(Calendar.MONTH); 27 | month++; 28 | if(month < 10) { 29 | stringBuilder.append("0"); 30 | } 31 | stringBuilder.append(month); 32 | stringBuilder.append("-"); 33 | if(calendar.get(Calendar.DAY_OF_MONTH) < 10) { 34 | stringBuilder.append("0"); 35 | } 36 | stringBuilder.append(calendar.get(Calendar.DAY_OF_MONTH)); 37 | return stringBuilder.toString(); 38 | } 39 | 40 | /** 41 | * Get the current system date and time as YYYY-MM-DD | hh:mm:ss 42 | * @return current system date and time as YYYY-MM-DD | hh:mm:ss 43 | */ 44 | public static String getCurrentDateAndTime() { 45 | Calendar calendar = GregorianCalendar.getInstance(); 46 | StringBuilder stringBuilder = new StringBuilder(); 47 | stringBuilder.append(calendar.get(Calendar.YEAR)); 48 | stringBuilder.append("-"); 49 | int month = calendar.get(Calendar.MONTH); 50 | month++; 51 | if(month < 10) { 52 | stringBuilder.append("0"); 53 | } 54 | stringBuilder.append(month); 55 | stringBuilder.append("-"); 56 | if(calendar.get(Calendar.DAY_OF_MONTH) < 10) { 57 | stringBuilder.append("0"); 58 | } 59 | stringBuilder.append(calendar.get(Calendar.DAY_OF_MONTH)); 60 | stringBuilder.append(" | "); 61 | if(calendar.get(Calendar.HOUR_OF_DAY) < 10) { 62 | stringBuilder.append("0"); 63 | } 64 | stringBuilder.append(calendar.get(Calendar.HOUR_OF_DAY)); 65 | stringBuilder.append(":"); 66 | if(calendar.get(Calendar.MINUTE) < 10) { 67 | stringBuilder.append("0"); 68 | } 69 | stringBuilder.append(calendar.get(Calendar.MINUTE)); 70 | stringBuilder.append(":"); 71 | if(calendar.get(Calendar.SECOND) < 10) { 72 | stringBuilder.append("0"); 73 | } 74 | stringBuilder.append(calendar.get(Calendar.SECOND)); 75 | return stringBuilder.toString(); 76 | } 77 | 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /jtalk-tests/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | jtalk 7 | com.pddstudio 8 | 1.0-SNAPSHOT 9 | 10 | 11 | 4.0.0 12 | 13 | jtalk-tests 14 | 15 | 31 | 32 | 33 | 34 | 35 | org.apache.maven.plugins 36 | maven-dependency-plugin 37 | 38 | 39 | copy-dependencies 40 | prepare-package 41 | 42 | copy-dependencies 43 | 44 | 45 | ${project.build.directory}/lib 46 | false 47 | false 48 | true 49 | 50 | 51 | 52 | 53 | 54 | org.apache.maven.plugins 55 | maven-jar-plugin 56 | 57 | 58 | 59 | true 60 | lib/ 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 75 | 76 | com.pddstudio 77 | jtalk-server 78 | 1.0-SNAPSHOT 79 | 80 | 81 | com.pddstudio 82 | jtalk-server-core 83 | 1.0-SNAPSHOT 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/coremodules/HTTPModule.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.coremodules; 2 | 3 | import com.pddstudio.jtalk.core.log.JLog; 4 | import com.pddstudio.jtalk.core.modules.BaseModule; 5 | import com.pddstudio.jtalk.core.values.Log; 6 | import com.pddstudio.jtalk.core.values.ModuleStatus; 7 | import fi.iki.elonen.NanoHTTPD; 8 | 9 | import java.io.IOException; 10 | 11 | /** 12 | * Created by pddstudio on 08.10.15. 13 | */ 14 | public class HTTPModule extends BaseModule { 15 | 16 | public static final String MODULE_IDENTIFIER = "TALK_CORE_HTTP_MODULE"; 17 | 18 | private static final String MODULE_NAME = "JTCore HTTP Module"; 19 | private static final String MODULE_DESC = "JTCore's internal HTTP Module. Required for serving external communication."; 20 | private static final String MODULE_AUTHOR = "Patrick J | PDDStudio"; 21 | private static final String MODULE_VERSION = "0.1DEV"; 22 | 23 | private HTTPServer httpServer; 24 | private ModuleStatus moduleStatus = ModuleStatus.UNKNOWN; 25 | 26 | public HTTPModule() { 27 | super(MODULE_IDENTIFIER); 28 | } 29 | @Override 30 | public String getModuleName() { 31 | return MODULE_NAME; 32 | } 33 | 34 | @Override 35 | public String getModuleDescription() { 36 | return MODULE_DESC; 37 | } 38 | 39 | @Override 40 | public String getModuleAuthor() { 41 | return MODULE_AUTHOR; 42 | } 43 | 44 | @Override 45 | public String getModuleVersion() { 46 | return MODULE_VERSION; 47 | } 48 | 49 | public ModuleStatus onModuleStart() { 50 | this.httpServer = new HTTPServer(9999); 51 | httpServer.startServer(); 52 | if(httpServer.hasFailure()) { 53 | moduleStatus = ModuleStatus.FAILED; 54 | } else { 55 | moduleStatus = ModuleStatus.READY; 56 | } 57 | return moduleStatus; 58 | } 59 | 60 | public void onModuleStop() { 61 | if(httpServer != null) { 62 | httpServer.stopServer(); 63 | moduleStatus = ModuleStatus.IDLE; 64 | } 65 | JLog.print(MODULE_NAME + ": Stopped module [" + moduleStatus.name() + "]", Log.INFO); 66 | } 67 | 68 | public ModuleStatus getModuleStatus() { 69 | return moduleStatus; 70 | } 71 | 72 | public String getModuleErrorReport() { 73 | if(httpServer != null && httpServer.hasFailure()) { 74 | return httpServer.getExceptionString(); 75 | } 76 | return "NO MESSAGE FOUND"; 77 | } 78 | 79 | private static class HTTPServer extends NanoHTTPD { 80 | 81 | private boolean hasException = false; 82 | private String exceptionString = ""; 83 | 84 | HTTPServer(int port) { 85 | super(port); 86 | } 87 | 88 | public void startServer() { 89 | try { 90 | HTTPServer.this.start(); 91 | } catch (IOException e) { 92 | hasException = true; 93 | exceptionString = e.getMessage(); 94 | } 95 | } 96 | 97 | @Override 98 | public Response serve(IHTTPSession session) { 99 | return new Response("I'm running."); 100 | //TODO: add API support for HTTPModule 101 | } 102 | 103 | public void stopServer() { 104 | HTTPServer.this.stop(); 105 | } 106 | 107 | public boolean hasFailure() { 108 | return hasException; 109 | } 110 | 111 | public String getExceptionString() { 112 | return exceptionString; 113 | } 114 | 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /jtalk-server-core/src/main/java/com/pddstudio/jtalk/core/db/Database.java: -------------------------------------------------------------------------------- 1 | package com.pddstudio.jtalk.core.db; 2 | 3 | import com.pddstudio.jtalk.core.configuration.CoreConfig; 4 | import com.pddstudio.jtalk.core.log.JLog; 5 | import com.pddstudio.jtalk.core.tools.JHelp; 6 | import com.pddstudio.jtalk.core.values.Log; 7 | import org.iq80.leveldb.*; 8 | import static org.fusesource.leveldbjni.JniDBFactory.*; 9 | import java.io.*; 10 | 11 | /** 12 | * Created by pddstudio on 06.10.15. 13 | */ 14 | 15 | /** 16 | * The Database class is used by JTalk's core. It saves and restores common values using LevelDB. 17 | */ 18 | public class Database { 19 | 20 | /** 21 | * This class is the wrapper for the LevelDB interface 22 | */ 23 | 24 | private static Database database; 25 | 26 | private static final String DATABASE_LOCATION = CoreConfig.JTALK_ROOT_DIR + CoreConfig.JTALK_DB + CoreConfig.JTALK_CORE_DB_NAME; 27 | private static final String DATABASE_LOGFILE = CoreConfig.JTALK_ROOT_DIR + CoreConfig.JTALK_LOG_DIR + CoreConfig.JLog.DATABASE_LOGFILE; 28 | 29 | DB db; 30 | 31 | private PrintWriter printWriter; 32 | private BufferedWriter bufferedWriter; 33 | private FileWriter fileWriter; 34 | 35 | Logger logger = new Logger() { 36 | public void log(String s) { 37 | //if(printWriter != null) printWriter.println(s); 38 | } 39 | }; 40 | 41 | private Database() { 42 | 43 | File databaseFile = new File(DATABASE_LOCATION); 44 | File databaseLogFile = new File(DATABASE_LOGFILE + JHelp.Date.getCurrentDate() + ".log"); 45 | 46 | if(!databaseLogFile.exists()) { 47 | JLog.print("Created log file for the database.", Log.INFO); 48 | } 49 | 50 | Options options = new Options(); 51 | options.createIfMissing(true); 52 | 53 | if(CoreConfig.JLog.CREATE_LOG_FILES) { 54 | try { 55 | fileWriter = new FileWriter(databaseLogFile, true); 56 | bufferedWriter = new BufferedWriter(fileWriter); 57 | printWriter = new PrintWriter(bufferedWriter); 58 | options.logger(logger); 59 | } catch (IOException e) { 60 | JLog.print("Failed to open the database log file:\n" + e.getMessage(), Log.WARNING); 61 | } 62 | } 63 | 64 | try { 65 | db = factory.open(databaseFile, options); 66 | JLog.print("Successfully opened the database connection.", Log.INFO); 67 | } catch (IOException e) { 68 | JLog.print("An error occurred when trying to open the database connection:\n" + e.getMessage(), Log.ERROR); 69 | } 70 | 71 | } 72 | 73 | /** 74 | * Returns the current Database instance. In case it's not initialized yet, it'll do this before returning. 75 | * @return the current {@link Database} instance 76 | */ 77 | public static Database getDatabase() { 78 | if(database == null) database = new Database(); 79 | return database; 80 | } 81 | 82 | /** 83 | * Function to close the current database connection. 84 | */ 85 | public void close() { 86 | try { 87 | db.close(); 88 | } catch (IOException e) { 89 | JLog.print("An error occurred when trying to close the database:\n" + e.getMessage(), Log.ERROR); 90 | } 91 | } 92 | 93 | /** 94 | * Saves a Key Pair value to the database. 95 | * @param key key value 96 | * @param value the value for the key 97 | */ 98 | public void save(String key, String value) { 99 | db.put(bytes(key), bytes(value)); 100 | } 101 | 102 | /** 103 | * Returns the value for the given key 104 | * @param key key value 105 | * @return Returns the value for the given key 106 | */ 107 | public String get(String key) { 108 | return asString(db.get(bytes(key))); 109 | } 110 | 111 | } 112 | -------------------------------------------------------------------------------- /.idea/uiDesigner.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | --------------------------------------------------------------------------------