JVM SDK released

The JVM is the runtime environment for Java-based applications.

Lire cet article en Français

 

We can write programs that run in the JVM (Java Virtual Machine) with a multitude of different languages.

 

Today, Java and Kotlin are the two languages most used by Android developers, and like Google, many now prefer Kotlin.

 

It's not too late to refactor your Java application ;)

 

You can follow our migration guide here if you are currently using our Java SDK, which is now deprecated in favor of the SDK JVM :

 

Entirely written in Kotlin, it allows us to easily call Java code as well.

 

 

This language was written by JetBrains, well known for its numerous IDEs such as IntellIJ Idea, CLion or Webstorm.

Some interesting features of Kotlin

 

  • Null Pointer Safety : Limits the risk of NullPointerException by distinguishing null references from those that are not.
  • Scope Functions : Copies the object on which it is called and performs operations.
  • Default arguments : Limits the number of overloads to write.
  • Named parameters : Freely change the order in which they are called.
  • Full Java interoperability : It runs on the JVM and uses Java libraries and tools.
  • Extensions functions : Add methods to classes without modifying their source code.

Show me the code!

 

The JAR is available on Maven: https://bintray.com/maven/kuzzleio/sdk-jvm

You can now add it to your classpath:


Maven:

<dependency>
<groupId>io.kuzzle</groupId>
<artifactId>sdk-jvm</artifactId>
<version>1.0.1</version>
<type>pom</type>
</dependency>

 

Gradle:

implementation 'io.kuzzle:sdk-jvm:1.0.1'

 

Ivy:

<dependency org='io.kuzzle' name='sdk-jvm' rev='1.0.1'>
<artifact name='sdk-jvm' ext='pom' ></artifact>
</dependency>

 

Login to your Kuzzle instance now!

First you need to instantiate the SDK by choosing the communication protocol. Only the WebSocket is available for the moment, but HTTP support will arrive very soon.

 

Here is the Kotlin code:

val ws = WebSocket("kuzzle");
val kuzzle = Kuzzle(ws).apply {
connect()
};

 

Now you can start communicating with Kuzzle via the API. The structure of our SDKs is modelled on our API with a division into controllers and actions.
Here is an example of authentication with
auth:login:

 

// Login with username "Yoann"
kuzzle.authController.login("local", ConcurrentHashMap<String, Any?>().apply {
put("username", "Yoann")
put("password", "thisarticleisfire")
}).get()

// The SDK instance is now authenticated

 

Or to create a new document with document:create :

 

val document: ConcurrentHashMap<String, Any?> = ConcurrentHashMap<String, Any?>().apply {
put("firstname", "Yoann")
put("type", "alien")
}
val result: ConcurrentHashMap<String, Any?> =
kuzzle
.documentController
.create("nyc-open-data", "yellow-taxi", document)
.get();

 

Our documentation, written in Kotlin and Java, is available here.

You can also consult our Getting Started Kotlin and Java.

Future developments

 

In the near future we plan to develop support for the HTTP protocol, which is very important for mobile development, so as not to drain the battery through a persistent WebSocket connection.
There is also still work to be done on the documentation to make it more accessible, notably by writing Getting Started and new guides.
Finally, as the Kuzzle API is constantly being enriched with new actions, we will also have work to integrate them into the current SDK.

If you have any questions about the SDK, you can ask the core-team on Stackoverflow or come and discuss it with the community on Discord: http://join.discord.kuzzle.io.

 

Yoann Abbes

Related posts