Java Reference
In-Depth Information
Once we have a
CustomData
object, we must “wrap” it in a
CustomData-
Holder
object as follows. The
CustomDataHolder
constructor accepts a
CustomData
parameter to be wrapped:
CustomDataHolder cdh = new CustomDataHolder (cd);
Alternatively, the public
value
field in the Holder class could be used to set the
value of the wrapped object:
CustomDataHolder cdh = new CustomDataHolder ();
cdh.value
=
cd;
Then we call the
demo()
method. We print out the contents of
cd
before and
after calling
demo()
to see what happens:
System.err.println ("Before calling demo():" +
"
\
ncd.someFloatValue ="+ cd.someFloatValue +
"
\
ncd.someIntegerValue ="+ cd.someIntegerValue);
// Call demo() to manipulate the CustomData within the
// (inout) CustomDataHolder parameter.
cor19.demo (cdh);
// Retrieve and print the modified CustomData from the
// holder.
cd = cdh.value;
System.err.println ("After demo():" +
"
\
ncd.someFloatValue
="
+ cd.someFloatValue +
"
\
ncd someIntegerValue
="
+ cd.someIntegerValue);
The complete expected output from the client is:
add(4,9) returns 32
hah() = 3.1416
Before setting, huh() = 0
After setting, huh() = 19
Before calling demo():
cd.someFloatValue = 12.0
cd.someIntegerValue =
−
13
After demo():
cd.someFloatValue = 24.0
cd.someIntegerValue =
−
39
Note that if we run the client again without restarting the server, the initial value
of
huh()
will be 19, not 0. Once the value in the servant is set, it remains set
until changed. For this reason, one must be careful when initializing attributes.
19.7 Running the CORBA example on two machines
The example above ran both client and server on the same machine. To run on two
different machines, the changes are very minimal. The name server,
orbd
, must
be started on the server machine, and the server machine name must be specified
Search WWH ::
Custom Search