Skip to content

Commit

Permalink
Mvn-ize build and upgrade to log4j 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Bravo27 committed Aug 3, 2020
1 parent daf4dcd commit c5990c1
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 46 deletions.
42 changes: 16 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,6 @@ The `adapters.xml` file for the Basic Chat Demo, should look like:

<adapter_class>chat_demo.adapters.ChatMetadataAdapter</adapter_class>

<!-- Optional for ChatMetadataAdapter.
Configuration file for the Adapter's own logging.
Logging is managed through log4j. -->
<param name="log_config">adapters_log_conf.xml</param>
<param name="log_config_refresh_seconds">10</param>

<!-- Optional, managed by the inherited LiteralBasedProvider.
See LiteralBasedProvider javadoc. -->
<!--
Expand All @@ -74,12 +68,6 @@ The `adapters.xml` file for the Basic Chat Demo, should look like:

<adapter_class>chat_demo.adapters.ChatDataAdapter</adapter_class>

<!-- Optional for ChatDataAdapter.
Configuration file for the Adapter's own logging.
Leans on the Metadata Adapter for the configuration refresh.
Logging is managed through log4j. -->
<param name="log_config">adapters_log_conf.xml</param>

<!-- Optional for ChatDataAdapter.
Configuration flag for periodic flush of the snapshot.
Default: false. -->
Expand All @@ -100,6 +88,7 @@ You can easily expand your configurations using the generic template, `DOCS-SDKs
<br>
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.
Expand All @@ -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
Expand All @@ -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).
4 changes: 0 additions & 4 deletions lib/README.md

This file was deleted.

65 changes: 65 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.lightstreamer</groupId>
<artifactId>example-Chat-adapter-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>example-Chat-adapter-java</name>
<url>http://maven.apache.org</url>

<properties>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.source>1.8</maven.compiler.source>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>chat_demo.adapters.ChatMetadataAdapter</mainClass>
</configuration>
</plugin>

</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.lightstreamer</groupId>
<artifactId>ls-adapter-inprocess</artifactId>
<version>7.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.13.3</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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):
// <metadata_adapter_initialised_first>Y</metadata_adapter_initialised_first>
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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit c5990c1

Please sign in to comment.