|
Chapter 11 Updates |
Last Updated: 4 July 1999
This page contains links to the latest updates of the code and text to Chapter 11: The Java Shared Data Toolkit. This is currently a work in progress. I'm updating the code and text as I go. This is the text, the code should be following shortly.
| Return to top |
The main change that you should notice is that creating a ByteArray
has the same method signature as the other two objects. The old method that
required you to pass in an array of bytes (byte[]) has been marked
as deprecated. There was no need for that array of bytes so now you can remove
that argument.
Data class, you now have:
byte[] getDataAsBytes(); String getDataAsString(); Object getDataAsObject();As the method names suggest, these return data according to the various types. There are also corresponding setter methods as well. Now you just need to make sure that whatever variant is used on the sender is also used on the receivers.
Note that when you pass in an object, that object must be serializable. If not, then JSDT will silently fail (bummer, need to change this!).
Another annoyance from earlier versions was determining whether one of the
shared objects already had managers associated with them. Now the
Session has a bunch of methods that return a boolean indicating
if the named object was already managed. Prior to these, the only way to tell
was to create the object and then call the isManaged() method on
that object. If you were denied permission to join, then you were pretty well
stuffed. You can also check if the session is managed by using
SessionFactory.sessionManaged().
URLString class. This class now represents everything you need to
know about the URL. Also, that is now passed as the arguments to all of the
Session and Client methods that require URLs.
Included in this first cut of new functionality is better control. New methods
allow you to start a registry on something other than the default port. Of
course, you can also check for a registry already there too. A new feature is
the ability to forcibly stop the registry using the stop() method.
Again, like the other methods, this looks for the connection type and
optionally the port number.
In forthcoming versions of JSDT, it is expected that you will be able to add a registry manager along the same lines as the session and shared object managers. The idea of this is to allow authentication of people attempting to add or rebind objects within the registry that are not allowed.
For those applications that need to monitor everything at the session level, a new listener for changes in the registry may also be added.
| Return to top |
JSDTBankClient.java.
The following fixes are used to change the old java.lang.String
URL statements with the new URLString class.
Delete line 32 and replace it with
private static final String SESSION_TYPE = "socket"; private static final String SESSION_NAME = "McDuckBank";Delete lines 80-86 and replace with the following code:
URLString url =
URLString.createSessionURL(host, port, SESSION_TYPE, SESSION_NAME);
To bring the code up to date with the new ByteArray construction:
Remove old line 106 (new byte[]) as it is no longer needed.
Line 108 is now replaced with
balance = session.createByteArray(this, name, true);To deal with the different ways of retrieving information from shared objects we need to make the following change:
Line 272 now changes the method name to
msg = balance.getValueAsBytes();
Remove old line 53 (new byte[]) as it is no longer needed.
Line 54 is now replaced with
shared_array = session.createByteArray(this, name, true);
java.lang.String
URL statements with the new URLString class.
Replace line 26 with the following two lines:
private static final String SESSION_TYPE = "socket"; private static final String SESSION_NAME = "McDuckBank";then change line 71 to:
URLString url = URLString.createSessionURL("localhost",
port,
SESSION_TYPE,
SESSION_NAME);
Change line 87 to
byte[] msg = data.getDataAsBytes();
| Return to top |