summaryrefslogtreecommitdiff
path: root/java/demo/IcePack
diff options
context:
space:
mode:
Diffstat (limited to 'java/demo/IcePack')
-rw-r--r--java/demo/IcePack/hello/Client.java333
-rw-r--r--java/demo/IcePack/hello/Server.java6
-rw-r--r--java/demo/IcePack/simple/Client.java47
-rw-r--r--java/demo/IcePack/simple/Server.java6
4 files changed, 175 insertions, 217 deletions
diff --git a/java/demo/IcePack/hello/Client.java b/java/demo/IcePack/hello/Client.java
index f2e73d43ff0..3f308bf8868 100644
--- a/java/demo/IcePack/hello/Client.java
+++ b/java/demo/IcePack/hello/Client.java
@@ -9,193 +9,182 @@
import Demo.*;
-public class Client
+public class Client extends Ice.Application
{
- private static void
+ private void
menu()
{
- System.out.println(
- "usage:\n" +
- "c: create a hello object\n" +
- "d: destroy the current hello object\n" +
- "s: set the current hello object\n" +
- "r: set the current hello object to a random hello object\n" +
- "S: show the name of the current hello object\n" +
- "t: send greeting\n" +
- "x: exit\n" +
- "?: help\n");
+ System.out.println(
+ "usage:\n" +
+ "c: create a hello object\n" +
+ "d: destroy the current hello object\n" +
+ "s: set the current hello object\n" +
+ "r: set the current hello object to a random hello object\n" +
+ "S: show the name of the current hello object\n" +
+ "t: send greeting\n" +
+ "x: exit\n" +
+ "?: help\n");
}
- private static int
- run(String[] args, Ice.Communicator communicator)
- throws Ice.UserException
+ public int
+ run(String[] args)
{
- Ice.Properties properties = communicator.getProperties();
+ try
+ {
+ IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator().stringToProxy("IcePack/Query"));
+ //
+ // Get an object implementing the HelloFactory interface.
+ //
+ HelloFactoryPrx factory = HelloFactoryPrxHelper.checkedCast(query.findObjectByType("::Demo::HelloFactory"));
- IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator.stringToProxy("IcePack/Query"));
+ //
+ // By default we create a Hello object named 'Foo'.
+ //
+ HelloPrx hello;
+ try
+ {
+ hello = factory.find("Foo");
+ }
+ catch(NameNotExistException ex)
+ {
+ hello = factory.create("Foo");
+ }
- //
- // Get an object implementing the HelloFactory interface.
- //
- HelloFactoryPrx factory = HelloFactoryPrxHelper.checkedCast(query.findObjectByType("::Demo::HelloFactory"));
+ menu();
- //
- // By default we create a Hello object named 'Foo'.
- //
- HelloPrx hello;
- try
- {
- hello = factory.find("Foo");
- }
- catch(NameNotExistException ex)
- {
- hello = factory.create("Foo");
- }
+ java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
- menu();
+ String line = null;
+ do
+ {
+ try
+ {
+ System.out.print("==> ");
+ System.out.flush();
+ line = in.readLine();
+ if(line == null)
+ {
+ break;
+ }
+ if(line.equals("t"))
+ {
+ hello.sayHello();
+ }
+ else if(line.equals("c"))
+ {
+ System.out.print("name: ");
+ System.out.flush();
+ String name = in.readLine();
+ if(name != null && name.length() > 0)
+ {
+ try
+ {
+ hello = factory.find(name);
+ System.out.println("Hello object named '" + name + "' already exists");
+ }
+ catch(NameNotExistException ex)
+ {
+ try
+ {
+ factory = HelloFactoryPrxHelper.checkedCast(
+ query.findObjectByType("::Demo::HelloFactory"));
+ hello = factory.create(name);
+ }
+ catch(IcePack.ObjectNotExistException e)
+ {
+ }
+ }
+ }
+ }
+ else if(line.equals("d"))
+ {
+ if(Ice.Util.identityToString(hello.ice_getIdentity()).equals("Foo"))
+ {
+ System.out.println("Can't delete the default Hello object named 'Foo'");
+ }
+ else
+ {
+ hello.destroy();
- java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
-
- String line = null;
- do
- {
- try
- {
- System.out.print("==> ");
- System.out.flush();
- line = in.readLine();
- if(line == null)
- {
- break;
- }
- if(line.equals("t"))
- {
- hello.sayHello();
- }
- else if(line.equals("c"))
- {
- System.out.print("name: ");
- System.out.flush();
- String name = in.readLine();
- if(name != null && name.length() > 0)
- {
- try
- {
- hello = factory.find(name);
- System.out.println("Hello object named '" + name + "' already exists");
- }
- catch(NameNotExistException ex)
- {
- factory = HelloFactoryPrxHelper.checkedCast(query.findObjectByType("::Demo::HelloFactory"));
- hello = factory.create(name);
- }
- }
- }
- else if(line.equals("d"))
- {
- if(Ice.Util.identityToString(hello.ice_getIdentity()).equals("Foo"))
- {
- System.out.println("Can't delete the default Hello object named 'Foo'");
- }
- else
- {
- hello.destroy();
-
- try
- {
- hello = factory.find("Foo");
- }
- catch(NameNotExistException ex)
- {
- hello = factory.create("Foo");
- }
- }
- }
- else if(line.equals("s"))
- {
- System.out.print("name: ");
- System.out.flush();
- String name = in.readLine();
- if(name != null && name.length() > 0)
- {
- try
- {
- hello = HelloPrxHelper.checkedCast(factory.find(name));
- }
- catch(NameNotExistException ex)
- {
- System.out.println("This name doesn't exist");
- }
- }
- }
- else if(line.equals("r"))
- {
- hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello"));
- }
- else if(line.equals("S"))
- {
- System.out.println(Ice.Util.identityToString(hello.ice_getIdentity()));
- }
- else if(line.equals("x"))
- {
- // Nothing to do
- }
- else if(line.equals("?"))
- {
- menu();
- }
- else
- {
- System.out.println("unknown command `" + line + "'");
- menu();
- }
- }
- catch(java.io.IOException ex)
- {
- ex.printStackTrace();
- }
- catch(Ice.LocalException ex)
- {
- ex.printStackTrace();
- }
- }
- while(!line.equals("x"));
-
- return 0;
+ try
+ {
+ hello = factory.find("Foo");
+ }
+ catch(NameNotExistException ex)
+ {
+ hello = factory.create("Foo");
+ }
+ }
+ }
+ else if(line.equals("s"))
+ {
+ System.out.print("name: ");
+ System.out.flush();
+ String name = in.readLine();
+ if(name != null && name.length() > 0)
+ {
+ try
+ {
+ hello = HelloPrxHelper.checkedCast(factory.find(name));
+ }
+ catch(NameNotExistException ex)
+ {
+ System.out.println("This name doesn't exist");
+ }
+ }
+ }
+ else if(line.equals("r"))
+ {
+ hello = HelloPrxHelper.checkedCast(query.findObjectByType("::Demo::Hello"));
+ }
+ else if(line.equals("S"))
+ {
+ System.out.println(Ice.Util.identityToString(hello.ice_getIdentity()));
+ }
+ else if(line.equals("x"))
+ {
+ // Nothing to do
+ }
+ else if(line.equals("?"))
+ {
+ menu();
+ }
+ else
+ {
+ System.out.println("unknown command `" + line + "'");
+ menu();
+ }
+ }
+ catch(java.io.IOException ex)
+ {
+ ex.printStackTrace();
+ }
+ catch(Ice.LocalException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+ while(!line.equals("x"));
+ }
+ catch(NameExistsException e)
+ {
+ e.printStackTrace();
+ return 1;
+ }
+ catch(IcePack.ObjectNotExistException e)
+ {
+ e.printStackTrace();
+ return 1;
+ }
+
+ return 0;
}
public static void
main(String[] args)
{
- int status = 0;
- Ice.Communicator communicator = null;
-
- try
- {
- Ice.Properties properties = Ice.Util.createProperties();
- properties.load("config");
- communicator = Ice.Util.initializeWithProperties(args, properties);
- status = run(args, communicator);
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- status = 1;
- }
-
- if(communicator != null)
- {
- try
- {
- communicator.destroy();
- }
- catch(Ice.LocalException ex)
- {
- ex.printStackTrace();
- status = 1;
- }
- }
-
- System.exit(status);
+ Client app = new Client();
+ int status = app.main("Client", args, "config");
+ System.exit(status);
}
}
diff --git a/java/demo/IcePack/hello/Server.java b/java/demo/IcePack/hello/Server.java
index b93391d9125..1ab34cda561 100644
--- a/java/demo/IcePack/hello/Server.java
+++ b/java/demo/IcePack/hello/Server.java
@@ -13,13 +13,9 @@ public class Server extends Ice.Application
run(String[] args)
{
Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello");
-
String id = communicator().getProperties().getProperty("Identity");
-
- Ice.Object object = new HelloFactoryI();
- adapter.add(object, Ice.Util.stringToIdentity(id));
+ adapter.add(new HelloFactoryI(), Ice.Util.stringToIdentity(id));
adapter.activate();
-
communicator().waitForShutdown();
return 0;
}
diff --git a/java/demo/IcePack/simple/Client.java b/java/demo/IcePack/simple/Client.java
index af3c0b605e7..5aa55e78994 100644
--- a/java/demo/IcePack/simple/Client.java
+++ b/java/demo/IcePack/simple/Client.java
@@ -9,9 +9,9 @@
import Demo.*;
-public class Client
+public class Client extends Ice.Application
{
- private static void
+ private void
menu()
{
System.out.println(
@@ -28,12 +28,12 @@ public class Client
"?: help\n");
}
- private static int
- run(String[] args, Ice.Communicator communicator)
+ public int
+ run(String[] args)
{
- Ice.Properties properties = communicator.getProperties();
+ Ice.Properties properties = communicator().getProperties();
- IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator.stringToProxy("IcePack/Query"));
+ IcePack.QueryPrx query = IcePack.QueryPrxHelper.checkedCast(communicator().stringToProxy("IcePack/Query"));
Ice.ObjectPrx base = null;
try
@@ -94,7 +94,7 @@ public class Client
}
else if(line.equals("f"))
{
- communicator.flushBatchRequests();
+ communicator().flushBatchRequests();
}
else if(line.equals("T"))
{
@@ -155,35 +155,8 @@ public class Client
public static void
main(String[] args)
{
- int status = 0;
- Ice.Communicator communicator = null;
-
- try
- {
- Ice.Properties properties = Ice.Util.createProperties();
- properties.load("config");
- communicator = Ice.Util.initializeWithProperties(args, properties);
- status = run(args, communicator);
- }
- catch(Ice.LocalException ex)
- {
- ex.printStackTrace();
- status = 1;
- }
-
- if(communicator != null)
- {
- try
- {
- communicator.destroy();
- }
- catch(Ice.LocalException ex)
- {
- ex.printStackTrace();
- status = 1;
- }
- }
-
- System.exit(status);
+ Client app = new Client();
+ int status = app.main("Client", args, "config");
+ System.exit(status);
}
}
diff --git a/java/demo/IcePack/simple/Server.java b/java/demo/IcePack/simple/Server.java
index d3c74cfc09b..6de00c95dcd 100644
--- a/java/demo/IcePack/simple/Server.java
+++ b/java/demo/IcePack/simple/Server.java
@@ -15,8 +15,7 @@ public class Server extends Ice.Application
Ice.ObjectAdapter adapter = communicator().createObjectAdapter("Hello");
String id = communicator().getProperties().getProperty("Identity");
- Ice.Object object = new HelloI();
- adapter.add(object, Ice.Util.stringToIdentity(id));
+ adapter.add(new HelloI(), Ice.Util.stringToIdentity(id));
adapter.activate();
communicator().waitForShutdown();
return 0;
@@ -26,6 +25,7 @@ public class Server extends Ice.Application
main(String[] args)
{
Server app = new Server();
- app.main("demo.IcePack.hello.Server", args);
+ int status = app.main("demo.IcePack.hello.Server", args);
+ System.exit(status);
}
}