summaryrefslogtreecommitdiff
path: root/java/demo/Ice/invoke/Client.java
diff options
context:
space:
mode:
authorDwayne Boone <dwayne@zeroc.com>2009-08-19 12:17:26 -0230
committerDwayne Boone <dwayne@zeroc.com>2009-08-19 12:17:26 -0230
commit98835323d82d8343140d49582586a4ce6ebb602e (patch)
tree6d500433765145e5eebebe4ffbab49ef077fe988 /java/demo/Ice/invoke/Client.java
parentFixed bug 4221 - Glacier2 router getCategoryForClient raises NullHandleException (diff)
downloadice-98835323d82d8343140d49582586a4ce6ebb602e.tar.bz2
ice-98835323d82d8343140d49582586a4ce6ebb602e.tar.xz
ice-98835323d82d8343140d49582586a4ce6ebb602e.zip
Bug 4212 - add use of ice_invoke_async to demo
Diffstat (limited to 'java/demo/Ice/invoke/Client.java')
-rw-r--r--java/demo/Ice/invoke/Client.java247
1 files changed, 201 insertions, 46 deletions
diff --git a/java/demo/Ice/invoke/Client.java b/java/demo/Ice/invoke/Client.java
index 8ab0ea28158..bd01e321545 100644
--- a/java/demo/Ice/invoke/Client.java
+++ b/java/demo/Ice/invoke/Client.java
@@ -11,6 +11,77 @@ import Demo.*;
public class Client extends Ice.Application
{
+ private class AMI_Object_ice_invokeI extends Ice.AMI_Object_ice_invoke
+ {
+ public void ice_response(boolean ok, byte[] outParams)
+ {
+ if(!ok)
+ {
+ System.out.println("Unknown user exception");
+ }
+ }
+
+ public void ice_exception(Ice.LocalException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ private class AMI_Object_ice_invokeGetValuesI extends Ice.AMI_Object_ice_invoke
+ {
+ public void ice_response(boolean ok, byte[] outParams)
+ {
+ if(!ok)
+ {
+ System.out.println("Unknown user exception");
+ }
+ else
+ {
+ //
+ // Unmarshal the results.
+ //
+ Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams);
+ Demo.CHolder c = new Demo.CHolder();
+ Demo.CHelper.read(in, c);
+ String str = in.readString();
+ in.readPendingObjects();
+ in.destroy();
+ System.out.println("Got string `" + str + "' and class: s.name=" + c.value.s.name +
+ ", s.value=" + c.value.s.value);
+ }
+ }
+
+ public void ice_exception(Ice.LocalException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ private class AMI_Object_ice_invokeThrowPrintFailureI extends Ice.AMI_Object_ice_invoke
+ {
+ public void ice_response(boolean ok, byte[] outParams)
+ {
+ Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams);
+ try
+ {
+ in.throwException();
+ }
+ catch(Demo.PrintFailure ex)
+ {
+ // Expected.
+ }
+ catch(Ice.UserException ex)
+ {
+ System.out.println("Unknown user exception");
+ }
+ in.destroy();
+ }
+
+ public void ice_exception(Ice.LocalException ex)
+ {
+ ex.printStackTrace();
+ }
+ }
private static void
menu()
{
@@ -49,9 +120,14 @@ public class Client extends Ice.Application
public int
run(String[] args)
{
- if(args.length > 0)
+ boolean async = false;
+ if(args.length == 1 && args[0].equals("--async"))
{
- System.err.println(appName() + ": too many arguments");
+ async = true;
+ }
+ else if(args.length > 0)
+ {
+ System.err.println("Usage: " + appName() + " [--async]");
return 1;
}
@@ -91,9 +167,17 @@ public class Client extends Ice.Application
//
// Invoke operation.
//
- if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, out.finished(), null))
+ if(async)
+ {
+ obj.ice_invoke_async(new AMI_Object_ice_invokeI(), "printString", Ice.OperationMode.Normal,
+ out.finished());
+ }
+ else
{
- System.out.println("Unknown user exception");
+ if(!obj.ice_invoke("printString", Ice.OperationMode.Normal, out.finished(), null))
+ {
+ System.out.println("Unknown user exception");
+ }
}
out.destroy();
@@ -110,9 +194,17 @@ public class Client extends Ice.Application
//
// Invoke operation.
//
- if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, out.finished(), null))
+ if(async)
{
- System.out.println("Unknown user exception");
+ obj.ice_invoke_async(new AMI_Object_ice_invokeI(), "printStringSequence",
+ Ice.OperationMode.Normal, out.finished());
+ }
+ else
+ {
+ if(!obj.ice_invoke("printStringSequence", Ice.OperationMode.Normal, out.finished(), null))
+ {
+ System.out.println("Unknown user exception");
+ }
}
out.destroy();
@@ -131,9 +223,17 @@ public class Client extends Ice.Application
//
// Invoke operation.
//
- if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, out.finished(), null))
+ if(async)
+ {
+ obj.ice_invoke_async(new AMI_Object_ice_invokeI(), "printDictionary", Ice.OperationMode.Normal,
+ out.finished());
+ }
+ else
{
- System.out.println("Unknown user exception");
+ if(!obj.ice_invoke("printDictionary", Ice.OperationMode.Normal, out.finished(), null))
+ {
+ System.out.println("Unknown user exception");
+ }
}
out.destroy();
@@ -149,9 +249,17 @@ public class Client extends Ice.Application
//
// Invoke operation.
//
- if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, out.finished(), null))
+ if(async)
{
- System.out.println("Unknown user exception");
+ obj.ice_invoke_async(new AMI_Object_ice_invokeI(), "printEnum", Ice.OperationMode.Normal,
+ out.finished());
+ }
+ else
+ {
+ if(!obj.ice_invoke("printEnum", Ice.OperationMode.Normal, out.finished(), null))
+ {
+ System.out.println("Unknown user exception");
+ }
}
out.destroy();
@@ -170,9 +278,17 @@ public class Client extends Ice.Application
//
// Invoke operation.
//
- if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, out.finished(), null))
+ if(async)
+ {
+ obj.ice_invoke_async(new AMI_Object_ice_invokeI(), "printStruct", Ice.OperationMode.Normal,
+ out.finished());
+ }
+ else
{
- System.out.println("Unknown user exception");
+ if(!obj.ice_invoke("printStruct", Ice.OperationMode.Normal, out.finished(), null))
+ {
+ System.out.println("Unknown user exception");
+ }
}
out.destroy();
@@ -198,9 +314,17 @@ public class Client extends Ice.Application
//
// Invoke operation.
//
- if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, out.finished(), null))
+ if(async)
{
- System.out.println("Unknown user exception");
+ obj.ice_invoke_async(new AMI_Object_ice_invokeI(), "printStructSequence",
+ Ice.OperationMode.Normal, out.finished());
+ }
+ else
+ {
+ if(!obj.ice_invoke("printStructSequence", Ice.OperationMode.Normal, out.finished(), null))
+ {
+ System.out.println("Unknown user exception");
+ }
}
out.destroy();
@@ -221,9 +345,17 @@ public class Client extends Ice.Application
//
// Invoke operation.
//
- if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, out.finished(), null))
+ if(async)
+ {
+ obj.ice_invoke_async(new AMI_Object_ice_invokeI(), "printClass", Ice.OperationMode.Normal,
+ out.finished());
+ }
+ else
{
- System.out.println("Unknown user exception");
+ if(!obj.ice_invoke("printClass", Ice.OperationMode.Normal, out.finished(), null))
+ {
+ System.out.println("Unknown user exception");
+ }
}
out.destroy();
@@ -234,23 +366,31 @@ public class Client extends Ice.Application
// Invoke operation.
//
Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder();
- if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, outParams))
+ if(async)
{
- System.out.println("Unknown user exception");
- continue;
+ obj.ice_invoke_async(new AMI_Object_ice_invokeGetValuesI(), "getValues",
+ Ice.OperationMode.Normal, null);
}
+ else
+ {
+ if(!obj.ice_invoke("getValues", Ice.OperationMode.Normal, null, outParams))
+ {
+ System.out.println("Unknown user exception");
+ continue;
+ }
- //
- // Unmarshal the results.
- //
- Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value);
- Demo.CHolder c = new Demo.CHolder();
- Demo.CHelper.read(in, c);
- String str = in.readString();
- in.readPendingObjects();
- in.destroy();
- System.out.println("Got string `" + str + "' and class: s.name=" + c.value.s.name +
- ", s.value=" + c.value.s.value);
+ //
+ // Unmarshal the results.
+ //
+ Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value);
+ Demo.CHolder c = new Demo.CHolder();
+ Demo.CHelper.read(in, c);
+ String str = in.readString();
+ in.readPendingObjects();
+ in.destroy();
+ System.out.println("Got string `" + str + "' and class: s.name=" + c.value.s.name +
+ ", s.value=" + c.value.s.value);
+ }
}
else if(line.equals("9"))
{
@@ -258,30 +398,45 @@ public class Client extends Ice.Application
// Invoke operation.
//
Ice.ByteSeqHolder outParams = new Ice.ByteSeqHolder();
- if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, outParams))
+ if(async)
{
- System.out.println("Expected exception");
- continue;
+ obj.ice_invoke_async(new AMI_Object_ice_invokeThrowPrintFailureI(), "throwPrintFailure",
+ Ice.OperationMode.Normal, null);
}
-
- Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value);
- try
+ else
{
- in.throwException();
+ if(obj.ice_invoke("throwPrintFailure", Ice.OperationMode.Normal, null, outParams))
+ {
+ System.out.println("Expected exception");
+ continue;
+ }
+
+ Ice.InputStream in = Ice.Util.createInputStream(communicator(), outParams.value);
+ try
+ {
+ in.throwException();
+ }
+ catch(Demo.PrintFailure ex)
+ {
+ // Expected.
+ }
+ catch(Ice.UserException ex)
+ {
+ System.out.println("Unknown user exception");
+ }
+ in.destroy();
}
- catch(Demo.PrintFailure ex)
+ }
+ else if(line.equals("s"))
+ {
+ if(async)
{
- // Expected.
+ obj.ice_invoke_async(new AMI_Object_ice_invokeI(), "shutdown", Ice.OperationMode.Normal, null);
}
- catch(Ice.UserException ex)
+ else
{
- System.out.println("Unknown user exception");
+ obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, null);
}
- in.destroy();
- }
- else if(line.equals("s"))
- {
- obj.ice_invoke("shutdown", Ice.OperationMode.Normal, null, null);
}
else if(line.equals("x"))
{