Skip to content

Commit c5990c1

Browse files
committed
Mvn-ize build and upgrade to log4j 2
1 parent daf4dcd commit c5990c1

5 files changed

Lines changed: 87 additions & 46 deletions

File tree

README.md

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,6 @@ The `adapters.xml` file for the Basic Chat Demo, should look like:
4545

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

48-
<!-- Optional for ChatMetadataAdapter.
49-
Configuration file for the Adapter's own logging.
50-
Logging is managed through log4j. -->
51-
<param name="log_config">adapters_log_conf.xml</param>
52-
<param name="log_config_refresh_seconds">10</param>
53-
5448
<!-- Optional, managed by the inherited LiteralBasedProvider.
5549
See LiteralBasedProvider javadoc. -->
5650
<!--
@@ -74,12 +68,6 @@ The `adapters.xml` file for the Basic Chat Demo, should look like:
7468

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

77-
<!-- Optional for ChatDataAdapter.
78-
Configuration file for the Adapter's own logging.
79-
Leans on the Metadata Adapter for the configuration refresh.
80-
Logging is managed through log4j. -->
81-
<param name="log_config">adapters_log_conf.xml</param>
82-
8371
<!-- Optional for ChatDataAdapter.
8472
Configuration flag for periodic flush of the snapshot.
8573
Default: false. -->
@@ -100,6 +88,7 @@ You can easily expand your configurations using the generic template, `DOCS-SDKs
10088
<br>
10189
Please refer [here](https://lightstreamer.com/docs/ls-server/latest/General%20Concepts.pdf) for more details about Lightstreamer Adapters.
10290

91+
10392
## Install
10493
If you want to install a version of this demo in your local Lightstreamer Server, follow these steps:
10594
* 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
10897
* Launch Lightstreamer Server.
10998
* 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).
11099

100+
111101
## Build
112-
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:
113-
* Clone this project.
114-
* Get the `ls-adapter-interface.jar` file from the [latest Lightstreamer distribution](http://www.lightstreamer.com/download), and copy it into the `lib` folder.
115-
* 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.
116-
* Create the jars `LS_chat_metadata_adapter.jar` and `LS_chat_data_adapter.jar` created for something like these commands:
117-
```sh
118-
> mkdir tmp_classes/adapter tmp_classes/metadata
119-
> 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
120-
> jar cvf LS_chat_data_adapter.jar -C tmp_classes/adapter .
121-
> 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
122-
> jar cvf LS_chat_metadata_adapter.jar -C tmp_classes/metadata .
123-
```
124-
* 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.
125102

103+
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:
104+
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.
105+
For the sake of simplicity only the Maven case is detailed here.
106+
107+
### Maven
108+
109+
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.
110+
111+
Assuming Maven is installed and available in your path you can build the demo by running
112+
```sh
113+
mvn install dependency:copy-dependencies
114+
```
126115
## See Also
127116

128117
### Clients Using This Adapter
@@ -142,5 +131,6 @@ To build your own version of `LS_chat_metadata_adapter.jar` and `LS_chat_data_ad
142131

143132
## Lightstreamer Compatibility Notes
144133

145-
* Compatible with Lightstreamer SDK for Java In-Process Adapters since 6.0
134+
- Compatible with Lightstreamer SDK for Java In-Process Adapters since 7.3.
135+
- 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).
146136
- 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).

lib/README.md

Lines changed: 0 additions & 4 deletions
This file was deleted.

pom.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
5+
<groupId>com.lightstreamer</groupId>
6+
<artifactId>example-Chat-adapter-java</artifactId>
7+
<version>0.0.1-SNAPSHOT</version>
8+
<packaging>jar</packaging>
9+
10+
<name>example-Chat-adapter-java</name>
11+
<url>http://maven.apache.org</url>
12+
13+
<properties>
14+
<maven.compiler.target>1.8</maven.compiler.target>
15+
<maven.compiler.source>1.8</maven.compiler.source>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
</properties>
18+
19+
<build>
20+
<sourceDirectory>src</sourceDirectory>
21+
<plugins>
22+
<plugin>
23+
<groupId>org.apache.maven.plugins</groupId>
24+
<artifactId>maven-compiler-plugin</artifactId>
25+
<version>3.1</version>
26+
</plugin>
27+
<plugin>
28+
<groupId>org.codehaus.mojo</groupId>
29+
<artifactId>exec-maven-plugin</artifactId>
30+
<version>1.2.1</version>
31+
<executions>
32+
<execution>
33+
<goals>
34+
<goal>java</goal>
35+
</goals>
36+
</execution>
37+
</executions>
38+
<configuration>
39+
<mainClass>chat_demo.adapters.ChatMetadataAdapter</mainClass>
40+
</configuration>
41+
</plugin>
42+
43+
</plugins>
44+
</build>
45+
46+
<dependencies>
47+
<dependency>
48+
<groupId>junit</groupId>
49+
<artifactId>junit</artifactId>
50+
<version>3.8.1</version>
51+
<scope>test</scope>
52+
</dependency>
53+
<dependency>
54+
<groupId>com.lightstreamer</groupId>
55+
<artifactId>ls-adapter-inprocess</artifactId>
56+
<version>7.3.0</version>
57+
</dependency>
58+
<dependency>
59+
<groupId>org.apache.logging.log4j</groupId>
60+
<artifactId>log4j-core</artifactId>
61+
<version>2.13.3</version>
62+
</dependency>
63+
</dependencies>
64+
65+
</project>

src/src_chat/chat_demo/adapters/ChatDataAdapter.java renamed to src/main/java/com/lightstreamer/src_chat/chat_demo/adapters/ChatDataAdapter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
import java.util.concurrent.ExecutorService;
2828
import java.util.concurrent.Executors;
2929

30-
import org.apache.log4j.Logger;
31-
import org.apache.log4j.xml.DOMConfigurator;
30+
import org.apache.logging.log4j.LogManager;
31+
import org.apache.logging.log4j.Logger;
3232

3333
import com.lightstreamer.interfaces.data.DataProviderException;
3434
import com.lightstreamer.interfaces.data.FailureException;
@@ -110,7 +110,7 @@ public void init(Map params, File configDir) throws DataProviderException {
110110
// is executed after log configuration was completed, this parameter
111111
// must be present in the Adapter Set configuration (adapters.xml):
112112
// <metadata_adapter_initialised_first>Y</metadata_adapter_initialised_first>
113-
logger = Logger.getLogger("LS_demos_Logger.Chat");
113+
logger = LogManager.getLogger("LS_demos_Logger.Chat");
114114

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

src/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java renamed to src/main/java/com/lightstreamer/src_metadata/chat_demo/adapters/ChatMetadataAdapter.java

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import java.util.Map;
2121
import java.util.concurrent.ConcurrentHashMap;
2222

23-
import org.apache.log4j.Logger;
24-
import org.apache.log4j.xml.DOMConfigurator;
23+
import org.apache.logging.log4j.LogManager;
24+
import org.apache.logging.log4j.Logger;
2525

2626
import chat_demo.adapters.ChatDataAdapter;
2727

@@ -76,17 +76,7 @@ public void init(Map params, File configDir) throws MetadataProviderException {
7676
//Call super's init method to handle basic Metadata Adapter features
7777
super.init(params,configDir);
7878

79-
String logConfig = (String) params.get("log_config");
80-
if (logConfig != null) {
81-
File logConfigFile = new File(configDir, logConfig);
82-
String logRefresh = (String) params.get("log_config_refresh_seconds");
83-
if (logRefresh != null) {
84-
DOMConfigurator.configureAndWatch(logConfigFile.getAbsolutePath(), Integer.parseInt(logRefresh) * 1000);
85-
} else {
86-
DOMConfigurator.configure(logConfigFile.getAbsolutePath());
87-
}
88-
}
89-
logger = Logger.getLogger("LS_demos_Logger.Chat");
79+
logger = LogManager.getLogger("LS_demos_Logger.Chat");
9080

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

0 commit comments

Comments
 (0)