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 Nov 9, 2020
1 parent 30a0659 commit 97bf578
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 41 deletions.
36 changes: 16 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,6 @@ The `adapters.xml` file for the *Round-Trip Demo*, should look like:

<adapter_class>roundtrip_demo.adapters.RoundTripMetadataAdapter</adapter_class>

<!-- Optional for RoundTripMetadataAdapter.
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 Down Expand Up @@ -88,24 +82,24 @@ If you want to install a version of the *Round-Trip Demo* in your local Lightstr

* 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.
* Make sure that Lightstreamer Server is not running.
* Get the `deploy.zip` file of the [latest release](https://github.com/Lightstreamer/Lightstreamer-example-RoundTrip-adapter-java/releases), unzip it, and copy the `RoundTrip` folder into the `adapters` folder of your Lightstreamer Server installation.
* Get the `deploy.zip` file of the [latest release](https://github.com/Lightstreamer/Lightstreamer-example-RoundTrip-adapter-java/releases), unzip it, and copy the `RoundTripDemo` folder into the `adapters` folder of your Lightstreamer Server installation.
* [Optional] Customize the logging settings in log4j configuration file: `RoundTripDemo/classes/log4j2.xml`.
* Launch Lightstreamer Server.
* Test the Adapter, launching the [Lightstreamer - Round-Trip Demo - HTML Client](https://github.com/Lightstreamer/Lightstreamer-example-RoundTrip-client-javascript) listed in [Clients Using This Adapter](https://github.com/Lightstreamer/Lightstreamer-example-RoundTrip-adapter-java#clients-using-this-adapter).

## Build

To build your own version of `LS_roundtrip_data_adapter.jar` and ` LS_roundtrip_metadata_adapter.jar`, instead of using the one provided in the `deploy.zip` file from the [Install](https://github.com/Lightstreamer/Lightstreamer-example-RoundTrip-adapter-java#install) section above, follow these steps:

* Download 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_roundtrip_metadata_adapter.jar` and `LS_roundtrip_data_adapter.jar` with commands like these:
```sh
> mkdir tmp_classes/data 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_data -d tmp_classes/data src/src_roundtrip/roundtrip_demo/adapters/RoundTripDataAdapter.java
> jar cvf LS_roundtrip_data_adapter.jar -C tmp_classes/data .
> javac -source 1.7 -target 1.7 -nowarn -g -classpath lib/log4j-1.2.17.jar;lib/ls-adapter-interface.jar;LS_roundtrip_data_adapter.jar -sourcepath src/src_metadata -d tmp_classes/metadata src/src_metadata/roundtrip_demo/adapters/RoundTripMetadataAdapter.java
> jar cvf LS_roundtrip_metadata_adapter.jar -C tmp_classes/metadata .
To build your own version of `example-RoundTrip-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-RoundTrip-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
Expand All @@ -126,5 +120,7 @@ To build your own version of `LS_roundtrip_data_adapter.jar` and ` LS_roundtrip_

## 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 Adapters version 6.0, please refer to [this tag](https://github.com/Lightstreamer/Lightstreamer-example-ChatTile-adapter-java/tree/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-RoundTrip-adapter-java/tree/for_Lightstreamer_5.1).
4 changes: 0 additions & 4 deletions lib/README.md

This file was deleted.

73 changes: 73 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<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-RoundTrip-adapter-java</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>example-RoundTrip-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>roundtrip_demo.adapters.RoundTripMetadataAdapter</mainClass>
</configuration>
</plugin>

</plugins>
</build>

<repositories>
<repository>
<id>Twitter</id>
<name>Twitter repository</name>
<url>https://maven.twttr.com/</url>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.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 @@ -20,9 +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 com.lightstreamer.adapters.metadata.LiteralBasedProvider;
import com.lightstreamer.interfaces.metadata.CreditsException;
Expand Down Expand Up @@ -64,17 +63,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.RoundTrip");
logger = LogManager.getLogger("LS_demos_Logger.RoundTrip");

// Read the Adapter Set name, which is supplied by the Server as a parameter
this.adapterSetId = (String) params.get("adapters_conf.id");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,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 @@ -89,7 +89,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.RoundTrip");
logger = LogManager.getLogger("LS_demos_Logger.RoundTrip");

// Read the Adapter Set name, which is supplied by the Server as a parameter
String adapterSetId = (String) params.get("adapters_conf.id");
Expand Down

0 comments on commit 97bf578

Please sign in to comment.