Skip to content
Merged
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
4 changes: 4 additions & 0 deletions java/IceGrid/query/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Gradle generated build files
bin
build
.gradle
55 changes: 55 additions & 0 deletions java/IceGrid/query/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# IceGrid Query

This demo shows how to use the Query object provided by the IceGrid registry to lookup a well-known object by type.

## Ice prerequisites

- Install IceGrid. See [Ice service installation].

## Building the demo

The demo has two Gradle projects, **client** and **server**, both using the [application plugin].

To build the demo, run:

```shell
./gradlew installDist
```

This creates a self-contained distribution under build/install/ for each application.
Each distribution includes:

- a bin/ directory with start scripts, and
- a lib/ directory containing the application JAR and all its runtime dependencies.

In our IceGrid deployment, we call java directly and set the class path to include everything in the distribution’s lib/
directory. This ensures both the server JAR and its dependencies (such as Ice) are available at runtime.

## Running the demo

First, start the IceGrid registry in its own terminal:

```shell
icegridregistry --Ice.Config=config.registry
```

Then, start the IceGrid node in its own terminal:

```shell
icegridnode --Ice.Config=config.node
```

Next, deploy the "GreeterHall" application in this IceGrid deployment:

```shell
icegridadmin --Ice.Config=config.admin -e "application add greeter-hall.xml"
```

Finally, run the client application:

```shell
./gradlew :client:run --quiet
```

[Application plugin]: https://docs.gradle.org/current/userguide/application_plugin.html
[Ice service installation]: https://github.com/zeroc-ice/ice/blob/main/NIGHTLY.md#ice-services
32 changes: 32 additions & 0 deletions java/IceGrid/query/client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) ZeroC, Inc.

plugins {
// Apply the application plugin to tell gradle this is a runnable Java application.
id("application")

// Apply the Slice-tools plugin to enable Slice compilation.
id("com.zeroc.slice-tools") version "3.8.+"

// Pull in our local 'convention plugin' to enable linting.
id("zeroc-linting")
}

dependencies {
// Add the Ice and IceGrid libraries as an implementation dependencies.
implementation("com.zeroc:ice:3.8.+")
implementation("com.zeroc:icegrid:3.8.+")
}

sourceSets {
main {
// Add the Greeter.ice file from the parent slice directory to the main source set.
slice {
srcDirs("../slice")
}
}
}

application {
// Specify the main entry point for the application.
mainClass.set("com.example.icegrid.query.client.Client")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright (c) ZeroC, Inc.

package com.example.icegrid.query.client;

import com.example.visitorcenter.GreeterPrx;
import com.zeroc.Ice.Communicator;
import com.zeroc.Ice.LocatorPrx;
import com.zeroc.Ice.ObjectPrx;
import com.zeroc.Ice.Util;
import com.zeroc.IceGrid.QueryPrx;

class Client {
public static void main(String[] args) {
// Create an Ice communicator. We'll use this communicator to create proxies and manage outgoing connections.
try (Communicator communicator = Util.initialize(args)) {

// Set the default locator of the new communicator. It's the address of the Locator hosted by our IceGrid
// registry. You can also set this proxy with the Ice.Default.Locator property.
communicator.setDefaultLocator(
LocatorPrx.createProxy(communicator, "IceGrid/Locator:tcp -h localhost -p 4061"));

// Create a proxy to the Query object hosted by the IceGrid registry. "IceGrid/Query" a well-known proxy,
// without addressing information.
QueryPrx query = QueryPrx.createProxy(communicator, "IceGrid/Query");

// Look up an object with type ::VisitorCenter::Greeter.
String greeterTypeId = GreeterPrx.ice_staticId(); // ::VisitorCenter::Greeter
ObjectPrx proxy = query.findObjectByType(greeterTypeId);

if (proxy == null) {
System.out.println(
String.format("The IceGrid registry doesn't know any object with type '%s'.", greeterTypeId));
} else {
// Cast the object proxy to a Greeter proxy.
GreeterPrx greeter = GreeterPrx.uncheckedCast(proxy);

// Send a request to the remote object and get the response.
String greeting = greeter.greet(System.getProperty("user.name"));
System.out.println(greeting);

// Send another request to the remote object. With the default configuration we use for this client,
// this request reuses the connection and reaches the same server, even when we have multiple
// replicated servers.
greeting = greeter.greet("alice");
System.out.println(greeting);
}
}
}
}
8 changes: 8 additions & 0 deletions java/IceGrid/query/config.admin
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Config file for icegridadmin

# A proxy to the Locator object hosted by the IceGrid registry.
Ice.Default.Locator=IceGrid/Locator:tcp -h localhost -p 4061

# Dummy username and password. They work because IceGrid is configured with the NullPermissionsVerifier.
IceGridAdmin.Username=foo
IceGridAdmin.Password=bar
18 changes: 18 additions & 0 deletions java/IceGrid/query/config.node
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Config file for icegridnode

# A proxy to the Locator object hosted by the IceGrid registry.
Ice.Default.Locator=IceGrid/Locator:tcp -h localhost -p 4061

# The name of this IceGrid node.
IceGrid.Node.Name=node1

# The endpoints of this node's object adapter. This object adapter receives requests from the IceGrid registry.
# We configure this object adapter to listen on an OS-assigned tcp port on the loopback interface since the IceGrid
# registry runs on the same host in this deployment.
IceGrid.Node.Endpoints=tcp -h 127.0.0.1

# The directory where the node stores the config files for the Ice servers it starts.
IceGrid.Node.Data=db/node

# Trace activation of Ice servers (3 = very verbose).
IceGrid.Node.Trace.Activator=3
22 changes: 22 additions & 0 deletions java/IceGrid/query/config.registry
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Config file for icegridregistry

# The endpoints of this registry's client object adapter. This object adapter receives requests from the clients.
# We configure it to listen on tcp port 4061, on all interfaces.
IceGrid.Registry.Client.Endpoints=tcp -p 4061

# The endpoints of this registry's server object adapter. This object adapter receives requests from the servers when
# they register/unregister themselves or their endpoints with the registry.
# We configure this object adapter to listen on an OS-assigned tcp port, on all interfaces.
IceGrid.Registry.Server.Endpoints=tcp

# The endpoints of this registry's internal object adapter. This object adapter receives requests from the IceGrid
# nodes.
# We configure this object adapter to listen on an OS-assigned tcp port, on the loopback interface since the IceGrid
# node runs on the same host in this deployment.
IceGrid.Registry.Internal.Endpoints=tcp -h 127.0.0.1

# The directory when the registry stores its LMDB database. This directory must exist and be writable by the registry.
IceGrid.Registry.LMDB.Path=db/registry

# The admin interface of the registry accepts any username/password combination.
IceGrid.Registry.AdminPermissionsVerifier=IceGrid/NullPermissionsVerifier
2 changes: 2 additions & 0 deletions java/IceGrid/query/db/node/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
servers/
tmp/
2 changes: 2 additions & 0 deletions java/IceGrid/query/db/registry/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*.mdb
*.lock
Binary file not shown.
7 changes: 7 additions & 0 deletions java/IceGrid/query/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.12.1-all.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading
Loading