Skip to content

Commit

Permalink
initial doc tidy-up
Browse files Browse the repository at this point in the history
  • Loading branch information
sshanks-kx committed Nov 8, 2023
1 parent c0aee17 commit 8ddf963
Show file tree
Hide file tree
Showing 7 changed files with 175 additions and 142 deletions.
143 changes: 9 additions & 134 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
![Travis (.com) branch](https://img.shields.io/travis/com/kxsystems/javakdb/master) [![Coverage](https://sonarcloud.io/api/project_badges/measure?project=KxSystems_javakdb&metric=coverage)](https://sonarcloud.io/dashboard?id=KxSystems_javakdb) <a href="https://sonarcloud.io/dashboard?id=KxSystems_javakdb"><img src="https://sonarcloud.io/images/project_badges/sonarcloud-white.svg" width="125"></a>


KDB+ IPC interface for the Java programming language. This will allow your application to
kdb+ IPC interface for the Java programming language. This will allow your application to

- query kdb+
- subscribe to a kdb+ publisher
Expand All @@ -19,145 +19,20 @@ Latest release can be downloaded [here](https://github.com/KxSystems/javakdb/rel

## Documentation

:open_file_folder: Documentation is in the [`docs`](docs/README.md) folder.
:point_right: Documentation is in the [`docs`](docs/README.md) folder.

## Building from source
## API Reference

Java 1.8 (and above) is recommended. Please ensure that your `JAVA_HOME` environment variable is set to the version of Java you have installed (or the one preferred if you have multiple versions).

You will also need [Apache Maven](https://maven.apache.org/) installed. Run the following to check you have it set up and configured correctly

```bash
mvn -version
```

In order to build the library, run the following within the directory where the `pom.xml` file is located (from the downloaded source).

```bash
mvn clean compile
```

If you wish to deploy the library to your machines local repository, in order to be used by other maven projects on your machine, run the following

```bash
mvn clean install
```

Please refer to the [Apache Maven documentation](https://maven.apache.org/guides/index.html) for further details

## Code examples

Supplied with the code is a series of code examples. The following describes each with an example of how to run from Maven (note: Maven is not required to run the applications, but used here for convenience).

`mvn clean install` should be performed prior to running.

### GridViewer

Creates a Swing GUI that presents the contents of a KDB+ table (Flip). It shows the mapping of the Flip class to a Swing TableModel. The contents of the table are some random data that we instruct KDB+ to generate.

Prerequisite:

- a kdb+ server running on port 5010 on your machine i.e. `q -p 5010`


Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.GridViewer"
```

### QueryResponse

Instructs the remote kdb+ process to execute q code (kdb+ native language) and receives the result. The same principle can be used to execute q functions. Example of a sync request.

Prerequisite:

- a kdb+ server running on port 5010 on your machine i.e. `q -p 5010`


Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.QueryResponse"
```


### SerializationOnly

Example of code that can be used to serialize/deserialize a Java type (array of ints) to kdb+ format.

Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.SerializationOnly"
```

### Server

Creates a Java app that listens on TCP port 5010, which a kdb+ process can communicate with. It will echo back sync messages and discard async messages. The following is an example of running kdb+ from the same machine (i.e. running the q executable and typing commands at the q prompt) that will communicate with the Java server.

```q
q
q)h:hopen `::5010
q)h"hello"
q)neg[h]"hello"
```

Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.Server"
HTML docs can be generated via running
```

### Feed

Example of creating an update function remotely (to capture table inserts), along with table creation and population of the table.
Table population has an example of single-row inserts (lower latency) and bulk inserts (better throughput and resource utilization).

Prerequisites:

- a kdb+ server running on port 5010 on your machine i.e. `q -p 5010`.
- as this example depends on a `.u.upd` function being defined and a table name `mytable` pre-existing, you may wish to run the following within the kdb+ server (in normal environments, these table and function definitions should be pre-created by your kdb+ admin).

```q
q).u.upd:{[tbl;row] insert[tbl](row)}
q)mytable:([]time:`timespan$();sym:`symbol$();price:`float$();size:`long$())
mvn -pl javakdb javadoc:javadoc
```

## Building From Source

Run command:
:point_right: [`Building guide`](docs/build.md)

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.Feed"
```

### TypesMapping

Example app that creates each of the kdb+ types in Java, and communicates with kdb+ to check that the type has been correctly matched with its q type (kdb+ default language). Prints the Java type and corresponding q type.

Prerequisite:

- a kdb+ server running on port 5010 on your machine i.e. `q -p 5010`.


Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.TypesMapping"
```

### Subscriber

Example app that subscribes to real-time updates from a table that is maintained in kdb+.

Prerequisite:

- a kdb+ server running on port 5010 on your machine. The instance must have the `.u.sub` function defined. An example of `.u.sub` can be found in [KxSystems/kdb-tick](https://github.com/KxSystems/kdb-tick), an example tickerplant. You can execute this tickerplant process by running `q tick.q` (the default port is set to 5010).

Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.Subscriber"
```
## Code Examples

:point_right: [`Examples`](docs/examples.md)

36 changes: 28 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,22 +146,22 @@ Kdb+ types are mapped to and from Java types by this driver, and the example [`T
| [C| (10)char vector| a| ,"a"|
| java.lang.String| (-11)symbol| 42| &#96;42|
| [Ljava.lang.String| (11)symbol vector| 42| ,&#96;42|
| java.sql.Timestamp| (-12)timestamp| 2017-07-07 15:22:38.976| 2017.07.07D15:22:38.976000000|
| [Ljava.sql.Timestamp| (12)timestamp vector| 2017-07-07 15:22:38.976| ,2017.07.07D15:22:38.976000000|
| java.time.Instant| (-12)timestamp| 2017-07-07 15:22:38.976| 2017.07.07D15:22:38.976000000|
| [Ljava.time.Instant| (12)timestamp vector| 2017-07-07 15:22:38.976| ,2017.07.07D15:22:38.976000000|
| kx.c\$Month| (-13)month| 2000-12| 2000.12m|
| [Lkx.c\$Month| (13)month vector| 2000-12| ,2000.12m|
| java.sql.Date| (-14)date| 2017-07-07| 2017.07.07|
| [Ljava.sql.Date| (14)date vector| 2017-07-07| ,2017.07.07|
| java.util.Date| (-15)datetime| Fri Jul 07 15:22:38 GMT+03:00 2017| 2017.07.07T15:22:38.995|
| [Ljava.util.Date| (15)datetime vector| Fri Jul 07 15:22:38 GMT+03:00 2017| ,2017.07.07T15:22:38.995|
| java.time.LocalDate| (-14)date| 2017-07-07| 2017.07.07|
| [Ljava.time.LocalDate| (14)date vector| 2017-07-07| ,2017.07.07|
| java.util.LocalDateTime| (-15)datetime| Fri Jul 07 15:22:38 GMT+03:00 2017| 2017.07.07T15:22:38.995|
| [Ljava.util.LocalDateTime| (15)datetime vector| Fri Jul 07 15:22:38 GMT+03:00 2017| ,2017.07.07T15:22:38.995|
| kx.c\$Timespan| (-16)timespan| 15:22:38.995000000| 0D15:22:38.995000000|
| [Lkx.c\$Timespan| (16)timespan vector| 15:22:38.995000000| ,0D15:22:38.995000000|
| kx.c\$Minute| (-17)minute| 12:22| 12:22|
| [Lkx.c\$Minute| (17)minute vector| 12:22| ,12:22|
| kx.c\$Second| (-18)second| 12:22:38| 12:22:38|
| [Lkx.c\$Second| (18)second vector| 12:22:38| ,12:22:38|
| java.sql.Time| (-19)time| 15:22:38| 15:22:38.995|
| [Ljava.sql.Time| (19)time vector| 15:22:38| ,15:22:38.995|
| java.time.LocalTime| (-19)time| 15:22:38| 15:22:38.995|
| [Ljava.time.LocalTime| (19)time vector| 15:22:38| ,15:22:38.995|


## Timezone
Expand Down Expand Up @@ -284,5 +284,25 @@ java -Djavax.net.ssl.trustStore=./keystore -Djavax.net.ssl.keyStore=./keystore k

To troubleshoot SSL, supply `-Djavax.net.debug=ssl` on the command line when invoking your Java application.

## UDS (unix domain sockets)

kdb+ can use UDS for comms, see [here](https://code.kx.com/q/wp/ipc/#unix-domain-socket) for details.

Java ipc requires java version 16 or greater, OS support & client/server residing on same machine.
Java reference [here](https://inside.java/2021/02/03/jep380-unix-domain-sockets-channels/)

example of client connection when kdb+ listening on 5010
```java
c=new c("/tmp/kx.5010",System.getProperty("user.name")+":mypassword");
```

example of creating server when kdb+ connecting with h:hopen`:unix://1234
```java
java.net.UnixDomainSocketAddress address = java.net.UnixDomainSocketAddress.of("/tmp/kx.1234");
ServerSocketChannel serverChannel = ServerSocketChannel.open(java.net.StandardProtocolFamily.UNIX);
serverChannel.bind(address);
// pass serverChannel to c contructor to wait til new client connection occurs
```



23 changes: 23 additions & 0 deletions docs/build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Building Java kdb+ ipc interface from source

Java 1.8 (and above) is recommended. Please ensure that your `JAVA_HOME` environment variable is set to the version of Java you have installed (or the one preferred if you have multiple versions).

You will also need [Apache Maven](https://maven.apache.org/) installed. Run the following to check you have it set up and configured correctly

```bash
mvn -version
```

In order to build the library, run the following within the directory where the `pom.xml` file is located (from the downloaded source).

```bash
mvn clean compile
```

If you wish to deploy the library to your machines local repository, in order to be used by other maven projects on your machine, run the following

```bash
mvn clean install
```

Please refer to the [Apache Maven documentation](https://maven.apache.org/guides/index.html) for further details
115 changes: 115 additions & 0 deletions docs/examples.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
# java ipc examples for kdb+

Supplied with the code is a series of code examples. The following describes each with an example of how to run from Maven (note: Maven is not required to run the applications, but used here for convenience).

`mvn clean install` should be performed prior to running.

## GridViewer

Creates a Swing GUI that presents the contents of a KDB+ table (Flip). It shows the mapping of the Flip class to a Swing TableModel. The contents of the table are some random data that we instruct KDB+ to generate.

Prerequisite:

- a kdb+ server running on port 5010 on your machine i.e. `q -p 5010`


Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.GridViewer"
```

## QueryResponse

Instructs the remote kdb+ process to execute q code (kdb+ native language) and receives the result. The same principle can be used to execute q functions. Example of a sync request.

Prerequisite:

- a kdb+ server running on port 5010 on your machine i.e. `q -p 5010`


Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.QueryResponse"
```


## SerializationOnly

Example of code that can be used to serialize/deserialize a Java type (array of ints) to kdb+ format.

Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.SerializationOnly"
```

## Server

Creates a Java app that listens on TCP port 5010, which a kdb+ process can communicate with. It will echo back sync messages and discard async messages. The following is an example of running kdb+ from the same machine (i.e. running the q executable and typing commands at the q prompt) that will communicate with the Java server.

```q
q
q)h:hopen `::5010
q)h"hello"
q)neg[h]"hello"
```

Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.Server"
```

## Feed

Example of creating an update function remotely (to capture table inserts), along with table creation and population of the table.
Table population has an example of single-row inserts (lower latency) and bulk inserts (better throughput and resource utilization).

Prerequisites:

- a kdb+ server running on port 5010 on your machine i.e. `q -p 5010`.
- as this example depends on a `.u.upd` function being defined and a table name `mytable` pre-existing, you may wish to run the following within the kdb+ server (in normal environments, these table and function definitions should be pre-created by your kdb+ admin).

```q
q).u.upd:{[tbl;row] insert[tbl](row)}
q)mytable:([]time:`timespan$();sym:`symbol$();price:`float$();size:`long$())
```


Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.Feed"
```

## TypesMapping

Example app that creates each of the kdb+ types in Java, and communicates with kdb+ to check that the type has been correctly matched with its q type (kdb+ default language). Prints the Java type and corresponding q type.

Prerequisite:

- a kdb+ server running on port 5010 on your machine i.e. `q -p 5010`.


Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.TypesMapping"
```

## Subscriber

Example app that subscribes to real-time updates from a table that is maintained in kdb+.

Prerequisite:

- a kdb+ server running on port 5010 on your machine. The instance must have the `.u.sub` function defined. An example of `.u.sub` can be found in [KxSystems/kdb-tick](https://github.com/KxSystems/kdb-tick), an example tickerplant. You can execute this tickerplant process by running `q tick.q` (the default port is set to 5010).

Run command:

```bash
mvn exec:java -pl javakdb-examples -Dexec.mainClass="com.kx.examples.Subscriber"
```

File renamed without changes.
File renamed without changes
File renamed without changes.

0 comments on commit 8ddf963

Please sign in to comment.