Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/icebox/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Gradle generated build files
bin
build
.gradle
62 changes: 62 additions & 0 deletions java/IceGrid/icebox/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# IceGrid IceBox

The IceGrid IceBox demo illustrates how to deploy an IceBox server with IceGrid.

## Ice prerequisites

- Install IceGrid. See [Ice service installation].

## Building the demo

The demo consists of three Gradle projects:

- **client** — the client application (uses the Gradle [application plugin]).
- **service** — the Greeter service implementation (uses the [java-library plugin]).
- **iceboxserver** — a launcher for the IceBox server (uses the Gradle [application plugin]).
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this iceboxserver? The IceGrid XML config doesn't use it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have this project for the distribution it creates, from the deployment:

        <option>--class-path</option>
        <option>iceboxserver/build/install/iceboxserver/lib/*</option>


> The `iceboxserver` project is a small Java application that starts the IceBox server (`com.zeroc.IceBox.Server`).
> At runtime, its classpath includes the Ice/IceBox libraries as well as the Greeter service JAR.

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
31 changes: 31 additions & 0 deletions java/IceGrid/icebox/client/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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 library as an implementation dependency.
implementation("com.zeroc:ice: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.icebox.client.Client")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) ZeroC, Inc.

package com.example.icegrid.icebox.client;

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

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 Greeter object hosted by the server. "greeter" is a stringified proxy with no
// addressing information, also known as a well-known proxy. It's specified by the <object> element in the
// IceGrid XML file. The IceGrid registry resolves this well-known proxy and returns the actual address
// (endpoint) of the server to this client.
var greeter = GreeterPrx.createProxy(communicator, "greeter");

// 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/icebox/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/icebox/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/icebox/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/icebox/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/icebox/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/icebox/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