From c5990c125faafe1aa1a2b110c3974af5601e2f3f Mon Sep 17 00:00:00 2001 From: "giuseppe.corti" Date: Mon, 3 Aug 2020 16:01:25 +0200 Subject: [PATCH] Mvn-ize build and upgrade to log4j 2 --- README.md | 42 +++++------- lib/README.md | 4 -- pom.xml | 65 +++++++++++++++++++ .../chat_demo/adapters/ChatDataAdapter.java | 6 +- .../adapters/ChatMetadataAdapter.java | 16 +---- 5 files changed, 87 insertions(+), 46 deletions(-) delete mode 100644 lib/README.md create mode 100644 pom.xml rename src/{ => main/java/com/lightstreamer}/src_chat/chat_demo/adapters/ChatDataAdapter.java (98%) rename src/{ => main/java/com/lightstreamer}/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java (92%) diff --git a/README.md b/README.md index 85a8732..1851de3 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,6 @@ The `adapters.xml` file for the Basic Chat Demo, should look like: chat_demo.adapters.ChatMetadataAdapter - - adapters_log_conf.xml - 10 - - adapters_log_conf.xml - @@ -100,6 +88,7 @@ You can easily expand your configurations using the generic template, `DOCS-SDKs
Please refer [here](https://lightstreamer.com/docs/ls-server/latest/General%20Concepts.pdf) for more details about Lightstreamer Adapters. + ## Install If you want to install a version of this demo in your local Lightstreamer Server, follow these steps: * Download *Lightstreamer Server* (Lightstreamer Server comes with a free non-expiring demo license for 20 connected users) from [Lightstreamer Download page](http://www.lightstreamer.com/download.htm), and install it, as explained in the `GETTING_STARTED.TXT` file in the installation home directory. @@ -108,21 +97,21 @@ If you want to install a version of this demo in your local Lightstreamer Server * Launch Lightstreamer Server. * Test the Adapter, launching one of the clients listed in [Clients Using This Adapter](https://github.com/Lightstreamer/Lightstreamer-example-Chat-adapter-java#clients-using-this-adapter). + ## Build -To build your own version of `LS_chat_metadata_adapter.jar` and `LS_chat_data_adapter.jar`, instead of using the one provided in the `deploy.zip` file from the [Install](https://github.com/Lightstreamer/Lightstreamer-example-Chat-adapter-java#install) section above, follow these steps: -* Clone this project. -* Get the `ls-adapter-interface.jar` file from the [latest Lightstreamer distribution](http://www.lightstreamer.com/download), and copy it into the `lib` folder. -* Get the `log4j-1.2.17.jar` file from [Apache log4j](https://logging.apache.org/log4j/1.2/) and copy it into the `lib` folder. -* Create the jars `LS_chat_metadata_adapter.jar` and `LS_chat_data_adapter.jar` created for something like these commands: -```sh - > mkdir tmp_classes/adapter tmp_classes/metadata - > javac -source 1.7 -target 1.7 -nowarn -g -classpath lib/log4j-1.2.17.jar;lib/ls-adapter-interface.jar -sourcepath src/src_chat -d tmp_classes/adapter src/src_chat/chat_demo/adapters/ChatDataAdapter.java - > jar cvf LS_chat_data_adapter.jar -C tmp_classes/adapter . - > javac -source 1.7 -target 1.7 -nowarn -g -classpath lib/log4j-1.2.17.jar;lib/ls-adapter-interface.jar;LS_chat_data_adapter.jar -sourcepath src/src_metadata -d tmp_classes/metadata src/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java - > jar cvf LS_chat_metadata_adapter.jar -C tmp_classes/metadata . -``` -* Stop Lightstreamer Server; copy the just compiled LS_chat_metadata_adapter.jar in the adapters/Chat/lib folder of your Lightstreamer Server installation; restart Lightstreamer Server. +To build your own version of `example-Chat-adapter-java-0.0.1-SNAPSHOT.jar` instead of using the one provided in the `deploy.zip` file from the [Install](https://github.com/Lightstreamer/Lightstreamer-example-Chat-adapter-java#install) section above, you have two options: +either use [Maven](https://maven.apache.org/) (or other build tools) to take care of dependencies and building (recommended) or gather the necessary jars yourself and build it manually. +For the sake of simplicity only the Maven case is detailed here. + +### Maven + +You can easily build and run this application using Maven through the pom.xml file located in the root folder of this project. As an alternative, you can use an alternative build tool (e.g. Gradle, Ivy, etc.) by converting the provided pom.xml file. + +Assuming Maven is installed and available in your path you can build the demo by running +```sh + mvn install dependency:copy-dependencies +``` ## See Also ### Clients Using This Adapter @@ -142,5 +131,6 @@ To build your own version of `LS_chat_metadata_adapter.jar` and `LS_chat_data_ad ## Lightstreamer Compatibility Notes -* Compatible with Lightstreamer SDK for Java In-Process Adapters since 6.0 +- Compatible with Lightstreamer SDK for Java In-Process Adapters since 7.3. +- For a version of this example compatible with Lightstreamer SDK for Java In-Process Adapters version6.0, please refer to [this tag](https://github.com/Lightstreamer/Lightstreamer-example-Chat-adapter-java/releases/tag/pre_mvn). - For a version of this example compatible with Lightstreamer SDK for Java Adapters version 5.1, please refer to [this tag](https://github.com/Lightstreamer/Lightstreamer-example-Chat-adapter-java/releases/tag/for_Lightstreamer_5.1.2). diff --git a/lib/README.md b/lib/README.md deleted file mode 100644 index acc9ba5..0000000 --- a/lib/README.md +++ /dev/null @@ -1,4 +0,0 @@ -This folder should contain all the library files needed to compile the Chat Demo Adapter. Please drop here the: - - log4j-1.2.17.jar from [Apache log4j](https://logging.apache.org/log4j/1.2/); - ls-adapter-interface.jar from the /lib folder of latest Lightstreamer distribution. \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..78d6163 --- /dev/null +++ b/pom.xml @@ -0,0 +1,65 @@ + + 4.0.0 + + com.lightstreamer + example-Chat-adapter-java + 0.0.1-SNAPSHOT + jar + + example-Chat-adapter-java + http://maven.apache.org + + + 1.8 + 1.8 + UTF-8 + + + + src + + + org.apache.maven.plugins + maven-compiler-plugin + 3.1 + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + + + java + + + + + chat_demo.adapters.ChatMetadataAdapter + + + + + + + + + junit + junit + 3.8.1 + test + + + com.lightstreamer + ls-adapter-inprocess + 7.3.0 + + + org.apache.logging.log4j + log4j-core + 2.13.3 + + + + \ No newline at end of file diff --git a/src/src_chat/chat_demo/adapters/ChatDataAdapter.java b/src/main/java/com/lightstreamer/src_chat/chat_demo/adapters/ChatDataAdapter.java similarity index 98% rename from src/src_chat/chat_demo/adapters/ChatDataAdapter.java rename to src/main/java/com/lightstreamer/src_chat/chat_demo/adapters/ChatDataAdapter.java index 7741b3e..840e935 100644 --- a/src/src_chat/chat_demo/adapters/ChatDataAdapter.java +++ b/src/main/java/com/lightstreamer/src_chat/chat_demo/adapters/ChatDataAdapter.java @@ -27,8 +27,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import com.lightstreamer.interfaces.data.DataProviderException; import com.lightstreamer.interfaces.data.FailureException; @@ -110,7 +110,7 @@ public void init(Map params, File configDir) throws DataProviderException { // is executed after log configuration was completed, this parameter // must be present in the Adapter Set configuration (adapters.xml): // Y - logger = Logger.getLogger("LS_demos_Logger.Chat"); + logger = LogManager.getLogger("LS_demos_Logger.Chat"); // Read the Adapter Set name, which is supplied by the Server as a parameter String adapterSetId = (String) params.get("adapters_conf.id"); diff --git a/src/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java b/src/main/java/com/lightstreamer/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java similarity index 92% rename from src/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java rename to src/main/java/com/lightstreamer/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java index 5aac96f..d3454aa 100644 --- a/src/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java +++ b/src/main/java/com/lightstreamer/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java @@ -20,8 +20,8 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import chat_demo.adapters.ChatDataAdapter; @@ -76,17 +76,7 @@ public void init(Map params, File configDir) throws MetadataProviderException { //Call super's init method to handle basic Metadata Adapter features super.init(params,configDir); - String logConfig = (String) params.get("log_config"); - if (logConfig != null) { - File logConfigFile = new File(configDir, logConfig); - String logRefresh = (String) params.get("log_config_refresh_seconds"); - if (logRefresh != null) { - DOMConfigurator.configureAndWatch(logConfigFile.getAbsolutePath(), Integer.parseInt(logRefresh) * 1000); - } else { - DOMConfigurator.configure(logConfigFile.getAbsolutePath()); - } - } - logger = Logger.getLogger("LS_demos_Logger.Chat"); + logger = LogManager.getLogger("LS_demos_Logger.Chat"); // Read the Adapter Set name, which is supplied by the Server as a parameter this.adapterSetId = (String) params.get("adapters_conf.id");