Package gnu.cajo
Class Cajo
java.lang.Object
gnu.cajo.Cajo
- All Implemented Interfaces:
Grail
This class implements the Generic Standard Interface for the cajo library.
It is designed to work with all JRE's: 1.3 and higher.
- Version:
- 1.0, 21-Aug-07
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final class
This internal use only helper class automatically removes unresponsive server references from the internal queue.static final class
This internal use only helper class maintains a registry of exported objects.static final class
This internal use only helper class scans an exported object to see if it has methods matching the client method set. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method makes any object's public methods, whether instance or static, remotely invocable.protected void
finalize()
Object[]
This method finds all remotely invocable objects, supporting the specified method set.static void
Technically this method is unrelated to the class, it is used to furnish library version information.static Object
This method is used to allow clients to pass references to its own local objects, to other JVMs.This method instantiates a Dynamic Proxy at the client, which implements the method set specified.void
This method is used to manually collect remote registry entries.
-
Field Details
-
multicast
-
items
-
registrar
-
-
Constructor Details
-
Cajo
public Cajo(int port, String serverHost, String clientHost) throws UnknownHostException, IOException The constructor configures the network address settings. If a machine is operating behind a Network Adress Translating router (NAT), the internal and external addresses are requried. If not, then both addresses can be the same, or null arguments can be used.- Parameters:
port
- The TCP port to be used for communications, for servers canonically it is the IANA assigned cajo port of 1198, for clients it can be any value, including 0, meaining chosen from any unused port available at the time of startupserverHost
- The local network interface on which the item will will be remotely invokable. Typically it is specified when the server has multiple phyisical network interfaces, or is multi-homed, i.e. having multiple logical network interfaces. The value can be null, which will make the item accessible on all network interfaces, this is identical to providing the special port address "0.0.0.0".clientHost
- The host name, or IP address the remote client will use to communicate with this server. If null, it will be the same as serverHost resolution. This would need to be explicitly specified if the server is operating behind NAT; i.e. when the server's subnet IP address is not the same as its address outside the subnet.
-
-
Method Details
-
finalize
-
export
This method makes any object's public methods, whether instance or static, remotely invocable. As the object being remoted is already instantiated, there is no artificial requirement for it to implement a no-arg constructor. If not all methods are safe to be made remotely invocable, then wrap the object with a special-case decorator.Note: if an object is exported more than once, it will be registered each time, you generally do not want to do this. Also, if you plan to use the register method, to contact remote registries directly, it is highly advisible to export all objects prior to doing so.
- Specified by:
export
in interfaceGrail
- Parameters:
object
- The POJO to be made remotely invocable, i.e. there is no requirement for it to implement any special interfaces, nor to be derived from any particular class- Throws:
RemoteException
- If the internal registry could not be createdIOException
- If the announcement datagram packet could not be sent
-
lookup
This method finds all remotely invocable objects, supporting the specified method set. The method set is a client defined interface. It specifies the method signatures required.- Specified by:
lookup
in interfaceGrail
- Parameters:
methodSetInterface
- The interface of methods that remote objects are required to support- Returns:
- An array of remote object references, specific to the framework, implementing the specified method collection
- Throws:
Exception
- For any network or framework specific reasons
java.lang.IllegalArgumentException - when the provided class is not a Java interface
-
proxy
This method instantiates a Dynamic Proxy at the client, which implements the method set specified. This allows a remote object reference to be used in a semantically identical fashion as if it were local. The proxies can, if the service object reference is serialisable, be freely passed between JVMs, or persisted to storage for later use.- Specified by:
proxy
in interfaceGrail
- Parameters:
reference
- A reference to a remote object returned by the lookup method of this interface, though actually, any object reference implementing the client method set would workmethodSetInterface
- The set (or subset) of public methods, static or instance, that the object reference implements- Returns:
- An object implementing the method set interface provided.
-
proxy
This method is used to allow clients to pass references to its own local objects, to other JVMs. Normally all arguments are passed by value, meaning copies are sent to the remote JVM. Sometimes however, what is needed is for all users to have a reference to the same object instance, on which to perform operations.- Parameters:
object
- The local client object for which a pass-by-reference is sought- Returns:
- A proxy object, implementing all of the interfaces of the wrapped object argument, it will even work in the local context
-
register
This method is used to manually collect remote registry entries. The specific addresses or host names of the remote JVMs must be known. It is used to reach JVMs that for some reason are not accessible by UDP. The method will also share all of its references. Note: you will generally want to export all of your service objects first, before making calls to register.- Parameters:
hostname
- The address or domain name of a remote grail JVMport
- The TCP port on which the object is being shared, canonically it 1198- Throws:
Exception
- Various types, related to network related errors: invalid host name, host unavailable, host unreachable, etc...
-
main
Technically this method is unrelated to the class, it is used to furnish library version information. It provides an execution point called when the library jar is executed. It simply copies the contents of the internal readme.txt file to the console.- Throws:
Exception
-