-
Notifications
You must be signed in to change notification settings - Fork 216
Add IceGrid/icebox Java demo #625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| # Gradle generated build files | ||
| bin | ||
| build | ||
| .gradle |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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]). | ||
|
|
||
| > 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. | ||
pepone marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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 | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") | ||
| } |
36 changes: 36 additions & 0 deletions
36
java/IceGrid/icebox/client/src/main/java/com/example/icegrid/icebox/client/Client.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| servers/ | ||
| tmp/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| *.mdb | ||
| *.lock |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: