Skip to content
Open
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ infinispan-server-*
nohup.out

/build
/server/infinispan-server/
/server/
batch
CLAUDE.md
67 changes: 67 additions & 0 deletions documentation/asciidoc/topics/code_examples/admin-operations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
var infinispan = require('infinispan');

var connected = infinispan.client(
{port: 11222, host: '127.0.0.1'},
{
authentication: {
enabled: true,
saslMechanism: 'SCRAM-SHA-256',
userName: 'admin',
password: 'changeme'
}
}
);

connected.then(function (client) {

// Create a cache with a JSON configuration.
var cacheConfig = JSON.stringify({
'local-cache': {
encoding: { 'media-type': 'text/plain' }
}
});
var create = client.admin.createCache('myNewCache', cacheConfig);

// Get or create a cache (creates if it does not exist).
var getOrCreate = create.then(function() {
return client.admin.getOrCreateCache('myNewCache', cacheConfig);
});

// List all cache names.
var listNames = getOrCreate.then(function() {
return client.admin.cacheNames();
});
listNames.then(function(names) {
console.log('Cache names: ' + JSON.stringify(names));
});

// Remove a cache.
var remove = listNames.then(function() {
return client.admin.removeCache('myNewCache');
});

// Register a Protobuf schema.
var registerSchema = remove.then(function() {
return client.admin.registerSchema('person.proto',
'package example;\n' +
'message Person {\n' +
' required string name = 1;\n' +
'}\n');
});

// Remove a Protobuf schema.
var removeSchema = registerSchema.then(function() {
return client.admin.removeSchema('person.proto');
});

// Disconnect from {brandname} Server.
return removeSchema.then(function() {
return client.disconnect();
});

}).catch(function(error) {

// Log any errors.
console.log("Got error: " + error.message);

});
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
var infinispan = require('infinispan');

var connected = infinispan.client(
{port: 11222, host: '127.0.0.1'},
{
authentication: {
enabled: true,
saslMechanism: 'SCRAM-SHA-256',
userName: 'admin',
password: 'changeme'
}
}
);

connected.then(function (client) {

// Create a strong counter with an initial value of 0.
var create = client.counterCreate('my-counter', {
type: 'strong',
storage: 'PERSISTENT',
initialValue: 0
});

// Get the current counter value.
var get = create.then(function() {
return client.counterGet('my-counter');
});
get.then(function(value) {
console.log('Counter value: ' + value); // 0
});

// Add a value and return the new counter value.
var addAndGet = get.then(function() {
return client.counterAddAndGet('my-counter', 5);
});
addAndGet.then(function(value) {
console.log('After add: ' + value); // 5
});

// Set a value and return the previous counter value.
var getAndSet = addAndGet.then(function() {
return client.counterGetAndSet('my-counter', 10);
});
getAndSet.then(function(previous) {
console.log('Previous value: ' + previous); // 5
});

// Compare and swap: update only if the current value matches.
var cas = getAndSet.then(function() {
return client.counterCompareAndSwap('my-counter', 10, 20);
});
cas.then(function(value) {
console.log('After CAS: ' + value); // 20
});

// Reset the counter to its initial value.
var reset = cas.then(function() {
return client.counterReset('my-counter');
});

// Check if a counter is defined.
var isDefined = reset.then(function() {
return client.counterIsDefined('my-counter');
});
isDefined.then(function(defined) {
console.log('Is defined: ' + defined); // true
});

// Retrieve the counter configuration.
var getConfig = isDefined.then(function() {
return client.counterGetConfiguration('my-counter');
});
getConfig.then(function(config) {
console.log('Counter type: ' + config.type); // strong
});

// Remove the counter.
var remove = getConfig.then(function() {
return client.counterRemove('my-counter');
});

// Disconnect from {brandname} Server.
return remove.then(function() {
return client.disconnect();
});

}).catch(function(error) {

// Log any errors.
console.log("Got error: " + error.message);

});
6 changes: 2 additions & 4 deletions documentation/asciidoc/topics/proc_installing_clients.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

.Prerequisites

* Node.js version `12` or `14`.
* Node.js version `22` or `24`.
//Community content
ifdef::community[]
* {brandname} Server 9.4.x or later.
+
Use js-client `0.7` for {brandname} Server `8.2.x` to `9.3.x`.
* {brandname} Server 14.x or later.
endif::community[]
//Downstream content
ifdef::downstream[]
Expand Down
95 changes: 95 additions & 0 deletions documentation/asciidoc/topics/ref_client_usage.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,55 @@ include::code_examples/await-single-entries.js[]
include::code_examples/await-multiple-entries.js[]
----

== Performing admin operations

Use the `admin` property on the client to manage caches and Protobuf schemas on {brandname} Server.

Admin operations let you create and remove caches, list cache names, update configuration attributes, manage index schemas, and register or remove Protobuf schemas.

[NOTE]
====
Admin operations require the authenticated user to have administrative permissions on {brandname} Server.
====

[source,javascript,options="nowrap",subs=attributes+]
----
include::code_examples/admin-operations.js[]
----

.Available admin operations
[cols="1,3",options="header"]
|===
|Method |Description

|`createCache(name, config, opts)`
|Creates a cache with a JSON, XML, or YAML configuration. Use `opts.template` to create from a server template. Use `opts.flags` (e.g. `'VOLATILE'`) for non-persistent caches.

|`getOrCreateCache(name, config, opts)`
|Creates a cache if it does not already exist, otherwise returns the existing cache.

|`removeCache(name)`
|Removes a cache and all its data.

|`cacheNames()`
|Returns a list of all cache names on the server.

|`updateConfigurationAttribute(name, attribute, value)`
|Updates a mutable configuration attribute on a cache (e.g. `'memory.max-count'`).

|`reindex(name)`
|Rebuilds indexes for an indexed cache.

|`updateIndexSchema(name)`
|Updates the index schema for an indexed cache.

|`registerSchema(name, schema)`
|Registers or updates a Protobuf schema (`.proto` file) on the server.

|`removeSchema(name)`
|Removes a registered Protobuf schema from the server.
|===

== Running server-side scripts

You can add custom scripts to {brandname} Server and then run them from {hr_js} clients.
Expand Down Expand Up @@ -115,6 +164,52 @@ Use the `getWithMetadata` and `size` methods expire cache entries.
include::code_examples/ephemeral-data.js[]
----

== Using distributed counters

Distributed counters provide cluster-wide atomic counters that you can use to coordinate state across {brandname} Server nodes.
{brandname} supports two types of counters:

* **Strong counters** provide linearizable semantics with optional upper and lower bounds.
* **Weak counters** are more performant but offer weaker consistency guarantees.

[source,javascript,options="nowrap",subs=attributes+]
----
include::code_examples/distributed-counters.js[]
----

.Available counter operations
[cols="1,3",options="header"]
|===
|Method |Description

|`counterCreate(name, config)`
|Creates a counter. Config requires `type` (`'strong'` or `'weak'`), and optionally `storage`, `initialValue`, `upperBound`, `lowerBound` (strong), or `concurrencyLevel` (weak).

|`counterGet(name)`
|Returns the current counter value, or `undefined` if the counter does not exist.

|`counterAddAndGet(name, value)`
|Adds a value to the counter and returns the new value.

|`counterGetAndSet(name, value)`
|Sets a value and returns the previous value.

|`counterCompareAndSwap(name, expect, update)`
|Updates the counter to `update` only if the current value equals `expect`. Returns the value before the operation.

|`counterReset(name)`
|Resets the counter to its initial value.

|`counterIsDefined(name)`
|Returns `true` if the counter exists.

|`counterGetConfiguration(name)`
|Returns the counter configuration, or `undefined` if the counter does not exist.

|`counterRemove(name)`
|Removes the counter from the cluster.
|===

== Working with queries

Use the `query` method to perform queries on your caches.
Expand Down
46 changes: 46 additions & 0 deletions gen-asciidoc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/usr/bin/env bash

# Generates HTML documentation from AsciiDoc sources.
# Mirrors the asciidoctor-maven-plugin configuration used by
# the main Infinispan documentation build (documentation/pom.xml).

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
SRC_DIR="${SCRIPT_DIR}/documentation/asciidoc"
OUT_DIR="${SCRIPT_DIR}/out/docs"

mkdir -p "${OUT_DIR}"

asciidoctor \
--doctype book \
--backend html5 \
--safe-mode unsafe \
-a idprefix="" \
-a idseparator="-" \
-a sectanchors \
-a toc=left \
-a toclevels=3 \
-a numbered \
-a icons=font \
-a experimental \
-a source-highlighter=highlight.js \
-a highlightjs-theme=github \
-a imagesdir=../../topics/images \
-a stories=../stories \
-a topics=../topics \
-a community \
-a brandname=Infinispan \
-a fullbrandname=Infinispan \
-a brandshortname=infinispan \
-a hr_js="Hot Rod JS" \
-a doc_home=https://infinispan.org/documentation/ \
-a download_url=https://infinispan.org/download/ \
-a node_docs=https://docs.jboss.org/infinispan/hotrod-clients/javascript/1.0/apidocs/ \
-a server_docs=https://infinispan.org/docs/stable/titles/server/server.html \
-a code_tutorials=https://github.com/infinispan/infinispan-simple-tutorials/ \
-a query_docs=https://infinispan.org/docs/stable/titles/query/query.html \
-o "${OUT_DIR}/index.html" \
"${SRC_DIR}/titles/js_client.asciidoc"

echo "Documentation generated: ${OUT_DIR}/index.html"
Loading