Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample code for standalone java client [PA-627] #703

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions clients/client-standalone/README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
How to run
----------

1. Build the project. </br>
For Windows
```
set JAVA_HOME=<jdk8 home path>
mvn clean install
```
For MacOS and Linux
```
export JAVA_HOME=<jdk8 home path>
mvn clean install
```
2. Start server
For Windows
```
set JAVA_HOME=<jdk17 home path>
start-server.bat
```
For MacOS and Linux
```
export JAVA_HOME=<jdk17 home path>
./start-server.sh
```
3. Start client

For Windows
```
set JAVA_HOME=<jdk8 home path>
start-client.bat
```
For MacOS and Linux
```
export JAVA_HOME=<jdk8 home path>
./start-client.sh
```
Binary file not shown.
112 changes: 112 additions & 0 deletions clients/client-standalone/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
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>
<packaging>jar</packaging>

<artifactId>client-standalone</artifactId>
<name>Clients - stanalone java client</name>
<groupId>book.hazelcast.client.stanalone</groupId>
<description>
Basic Stanalone Client
</description>

<parent>
<groupId>book.hazelcast.client</groupId>
<artifactId>clients</artifactId>
<version>0.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<jdk.version>8</jdk.version>
<maven.compiler.release>8</maven.compiler.release>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.7.1</version>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-enterprise</artifactId>
<version>${hazelcast.version}</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/server-lib</outputDirectory>
<destFileName>hazelcast-enterprise.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/test-artifacts</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<release>8</release>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
<version>${hazelcast.version}</version>
<scope>import</scope>
<type>pom</type>
<exclusions>
<exclusion>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-enterprise-java-client</artifactId>
<version>5.5.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/hazelcast-enterprise-java-client-5.5.0-SNAPSHOT.jar</systemPath>
</dependency>
</dependencies>
<repositories>
<repository>
<id>hazelcast-private-repository</id>
<name>Hazelcast Private Repository</name>
<url>https://repository.hazelcast.com/release/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
</repositories>
</project>
21 changes: 21 additions & 0 deletions clients/client-standalone/src/main/java/Client.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;

public class Client {

private Client() {
}

public static void main(String[] args) throws InterruptedException {
HazelcastInstance hazelcastClient = HazelcastClient.newHazelcastClient();
IMap<Integer, String> test = hazelcastClient.getMap("test");
for (int i=0; i < 1000000; i++) {
test.put(i, "item" + i);
System.out.println(test.get(i));
Thread.sleep(1000);
}
hazelcastClient.shutdown();
}

}
3 changes: 3 additions & 0 deletions clients/client-standalone/start-client.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

%JAVA_HOME%/bin/java -cp lib\*;target\classes Client
3 changes: 3 additions & 0 deletions clients/client-standalone/start-client.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

$JAVA_HOME/bin/java -cp /lib/*:target/classes Client
3 changes: 3 additions & 0 deletions clients/client-standalone/start-server.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

%JAVA_HOME%/binjava -cp target\server-lib\hazelcast-enterprise.jar com.hazelcast.core.server.HazelcastMemberStarter
3 changes: 3 additions & 0 deletions clients/client-standalone/start-server.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

$JAVA_HOME/bin/java -cp target\server-lib\hazelcast-enterprise.jar com.hazelcast.core.server.HazelcastMemberStarter
2 changes: 1 addition & 1 deletion clients/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
<module>client-near-cache</module>
<module>client-rest</module>
<module>client-statistics</module>
<module>client-standalone</module>
<module>user-code-deployment</module>
<module>client-labels</module>
<module>client-connection-strategy</module>
</modules>

<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
Expand Down