Package gnu.cajo

Class Cajo

java.lang.Object
gnu.cajo.Cajo
All Implemented Interfaces:
Grail

public final class Cajo extends Object implements 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 Classes
    Modifier and Type
    Class
    Description
    static 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
    Modifier and Type
    Field
    Description
    private final Vector
     
    private final Multicast
     
    private final Cajo.Registrar
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Cajo(int port, String serverHost, String clientHost)
    The constructor configures the network address settings.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    export(Object object)
    This method makes any object's public methods, whether instance or static, remotely invocable.
    protected void
     
    lookup(Class methodSetInterface)
    This method finds all remotely invocable objects, supporting the specified method set.
    static void
    main(String[] args)
    Technically this method is unrelated to the class, it is used to furnish library version information.
    static Object
    proxy(Object object)
    This method is used to allow clients to pass references to its own local objects, to other JVMs.
    proxy(Object reference, Class methodSetInterface)
    This method instantiates a Dynamic Proxy at the client, which implements the method set specified.
    void
    register(String hostname, int port)
    This method is used to manually collect remote registry entries.

    Methods inherited from class java.lang.Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • 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 startup
      serverHost - 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

      protected void finalize() throws Throwable
      Overrides:
      finalize in class Object
      Throws:
      Throwable
    • export

      public void export(Object object) throws IOException
      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 interface Grail
      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 created
      IOException - If the announcement datagram packet could not be sent
    • lookup

      public Object[] lookup(Class methodSetInterface) throws Exception
      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 interface Grail
      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

      public Object proxy(Object reference, Class methodSetInterface)
      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 interface Grail
      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 work
      methodSetInterface - 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

      public static Object proxy(Object object)
      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

      public void register(String hostname, int port) throws Exception
      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 JVM
      port - 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

      public static void main(String[] args) throws Exception
      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