Class ItemServer
- java.lang.Object
-
- gnu.cajo.utils.ItemServer
-
public class ItemServer extends java.lang.Object
These routines are used for server object construction. The objects can be utilized by remote clients to compose larger, cooperative, functionality. It can be used to bind all object servers for external access. A given application can bind as many objects as it wants.A security policy file, named "server.policy" will be loaded from the local directory. By default, the policy file need only allow the following permissions:
grant codeBase "file:${java.class.path}" { permission java.security.AllPermission; }; grant { permission java.net.SocketPermission "*:1024-", "accept"; permission java.net.SocketPermission "*", "connect"; };
This will allow the three things:
- The server codebase has full priviliges.
- Proxies can only create server sockets only on non-priviliged local ports.
- Proxies can only create client sockets to any remote port, on any host.
Remote
class needs configuration, it must be done before binding an object, since doing this will use the server's assigned name and port number. Configuration is accomplished by calling itsconfig
static method. Also, by default, acceptance of proxies is disabled.- Version:
- 1.0, 01-Nov-99 Initial release
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
ItemServer.JarClassLoader
-
Field Summary
Fields Modifier and Type Field Description private static java.util.HashMap
registries
private static java.rmi.registry.Registry
registry
-
Constructor Summary
Constructors Constructor Description ItemServer()
Deprecated.As only the static methods of this class are necessary now.ItemServer(java.lang.String host, int port, java.lang.String codebase)
Deprecated.Normally use of this constructor is not necessary, as the CodebaseServer class manages this property automatically when used.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
acceptProxies()
This method enables this VM to host proxies, and accept other mobile code, from other remote servers.static Remote
bind(java.lang.Object item, java.lang.String name)
This method remotes the provided object in the local rmiregistry.static Remote
bind(java.lang.Object item, java.lang.String name, java.lang.Object proxy)
This method is used to bind a proxy serving object in the defalut local registry.static Remote
bind(java.lang.Object item, java.lang.String name, java.lang.Object proxy, java.rmi.server.RMIServerSocketFactory ssf, java.rmi.server.RMIClientSocketFactory csf, int port)
This method is used to bind a proxy serving object with complete configurability.static Remote
bind(java.lang.String name, java.lang.String item, java.lang.String file)
This method is used to bind a server object, contained in its own jar file into this server's VM, for binding at runtime.static void
main(java.lang.String[] args)
The application loads either a zipped marshalled object (zedmob) from a URL, a file, or alternately, it will fetch a remote object reference from an rmiregistry.
-
-
-
Constructor Detail
-
ItemServer
public ItemServer()
Deprecated.As only the static methods of this class are necessary now.Nothing happens in the default constructor of this class. This is used when the server has its own internalCodebaseServer
instance running. To take advantage the client loading capability of the CodebaseServer, it must be running in the same instance of the server's VM.
-
ItemServer
public ItemServer(java.lang.String host, int port, java.lang.String codebase)
Deprecated.Normally use of this constructor is not necessary, as the CodebaseServer class manages this property automatically when used.This constructor sets the RMI codebase property for this VM instance. This is necessary if the server is serving proxies, or other types of classes, and is using a common, or remote, code base server.- Parameters:
host
- The public IP address or host name, on which the codebase is being served. It need not be the same physical machine as the object server.port
- The TCP port on which the codebase server is operating.codebase
- The path/filename of the jar file containing the codebase, relative to the working directory of the codebase server.
-
-
Method Detail
-
acceptProxies
public static void acceptProxies() throws java.lang.SecurityException
This method enables this VM to host proxies, and accept other mobile code, from other remote servers. Hosting mobile code can result in the overloading of this server VM, either accidentially, or maliciously. Therefore hosting should be done either in a trusted environment, or on a non-essential JVM. Hosting of mobile code is disabled by default.Note: accepting proxies may be disabled via a command line argument at the server's startup, in which case, this method will accomplish nothing. The loading of proxies can be prohibited when launching the server with the -Djava.security.manager switch. It installs a default SecurityManager, which will not allow the loading of proxies, or any other type of mobile code, and prohibits itself from being replaced by the application. Note: this is an extremely important command line switch; worth memorizing!
- Throws:
java.lang.SecurityException
- If a SecurityManager is already installed, and explicitly prohibits itself from being replaced.
-
bind
public static Remote bind(java.lang.Object item, java.lang.String name) throws java.io.IOException
This method remotes the provided object in the local rmiregistry. The registry will not be created until the binding of the first object, to allow the opportunity for theRemote
class' network settings to beconfigured
. Strictly speaking, it performs a rebind operation on the rmiregistry, to more easily allow the application to dynamically replace server objects at runtime, if necessary. Since the registry is not shared with other applications, checking for already bound objects is unnecessary.The provided object will first have its setItem method invoked with remote reference to itself, with which it can share with remote VMs, in an application specific manner (if it has one). Then it will have its startThread method invoked with no argument, to signal it to start its main processing thread (again, if it has one).
- Parameters:
item
- The object to be bound. It may be either local to the machine, or remote, it can even be a proxy from a remote object, if proxyacceptance
was enabled for this VM.name
- The name under which to bind the object reference in the local rmiregistry.- Returns:
- A remoted reference to the object within the context of this VM's settings.
- Throws:
java.io.IOException
- For network configuration related issues.
-
bind
public static Remote bind(java.lang.String name, java.lang.String item, java.lang.String file) throws java.lang.ClassNotFoundException, java.lang.InstantiationException, java.lang.IllegalAccessException, java.rmi.RemoteException
This method is used to bind a server object, contained in its own jar file into this server's VM, for binding at runtime. This plug-in object's codebase will be loaded into the master server's runtime, from the the object's jar file. The plug-in object's class will have its newInstance method invoked, to create the object for binding; therefore the plug-in object is required to have a no-arg constructor. The instantiated class is handled to the bind(object, name) method of this class, for final processing.This allows server objects to be modularised, into multiple standalone jar files. This method can be called several times, for objects in the same jar file. It can even be called with the file name of the running master server jar itself. This is to aid in the creation of server configuration scripts, containing the names of files, names of classes, and names under which to bind the server objects. I have left the file parser out, as there are two predominant approaches for this; .ini files for the Windows crowd, properties files, and XML files for the rest of the world. Feel free to devise your own format!
Now for an ultra important, super cool optimisation:
When compiling plug-in modules, make use of the javac -classpath yourpath/masterserver.jar option. This has a really great advantage:
It will prevent the needless recompilation of utility classes already contained in the master server. This can significantly reduce the size of your server plug-in object jars!
Note: plug-in objects typically do not support proxies. This is because the system rmi codebase property is typically set by the master server, to serve its own proxy jar file, when it has one. There can be only one codebase for a given JVM instance.- Parameters:
name
- The name to bind the loaded server object in the registry.item
- The name of the class from which to instantiate the object. Example: myclass.mypackage.MyServerObjectfile
- The absolute/relative path/filename where to find the jar file. Example: myitem.jar or plugins/myitem.jar or /usr/local/jar/myitem.jar- Returns:
- A remoted reference to the object within the context of this VM's settings.
- Throws:
java.lang.NullPointerException
- If the jar file referenced in the file argument could not be found in the filesystem.java.lang.ClassNotFoundException
- If the jar file referenced in the file argument did not contain the class specified in the item argument.java.lang.InstantiationException
- If the class file specified in the item argument was in an invalid, or in a corrupted format.java.lang.IllegalAccessException
- If the class specified in the item argument did not have a no-argument constructor.java.rmi.RemoteException
- If the registry did not yet exist, and could not be created.
-
bind
public static Remote bind(java.lang.Object item, java.lang.String name, java.lang.Object proxy) throws java.rmi.RemoteException, java.io.IOException
This method is used to bind a proxy serving object in the defalut local registry. It will remote a reference to the server object, and bind it under the name provided. If the proxy has a setItem method, it will be called with a remote reference to the serving object. Next it will have its setProxy method invoked, (again if it has one) with a MarshalledObject containing the proxy object. Finally the object will have its startThread method invoked (if it has one) with no argument, to signal it to start its main processing thread.- Parameters:
item
- The object to be bound. It may be either local to the machine, or remote, it can even be a proxy from a remote object, if proxyacceptance
was enabled for this VM.name
- The name under which to bind the object reference in the local rmiregistry.proxy
- The proxy object to be sent to requesting clients, it is normally encased in a java.rmi.MarshalledObject, for efficiency. If it is not when passed in, it will be, automatically.- Returns:
- A remoted reference to the object within the context of this VM's settings.
- Throws:
java.rmi.RemoteException
- If the registry could not be created.java.io.IOException
- If the provided proxy object is not serialisable.
-
bind
public static Remote bind(java.lang.Object item, java.lang.String name, java.lang.Object proxy, java.rmi.server.RMIServerSocketFactory ssf, java.rmi.server.RMIClientSocketFactory csf, int port) throws java.rmi.RemoteException, java.io.IOException
This method is used to bind a proxy serving object with complete configurability. It will remote a reference to the server object, and bind in it a local rmiregistry under the name ant the TCP port provided. If the proxy has a setItem method, it will be called with a remote reference to the serving object. Then it will have its setProxy method invoked, (if it has one) with a MarshalledObject containing the proxy object. The object will then have its startThread method invoked (again if it has one) with no argument, to signal it to start its main processing thread.- Parameters:
item
- The object to be bound. It may be either local to the machine, or remote, it can even be a proxy from a remote object, if proxyacceptance
was enabled for this VM.name
- The name under which to bind the object reference in the a local rmiregistry.proxy
- The proxy object to be sent to requesting clients, it is normally encased in a java.rmi.MarshalledObject, for efficiency. If it is not when passed in, it will be, automatically.ssf
- The custom RMIServerSocketFactory to be used by the registry, typically something using strong cryptography. This value can be null, to indicate using the default socket factory for the JVM.csf
- The custom RMIClientSocketFactory to be used by the registry, typically something using strong cryptography. This value can be null, to indicate using the default socket factory for the JVM.port
- The TCP port on which both this registry, and the binding object will accept connections. This value can be zero, to indicate using the default registry settings for the JVM.Note: a given port will only support one given set of socket factories, the first ones bound.
- Returns:
- A remoted reference to the object within the context of this VM's settings.
- Throws:
java.rmi.RemoteException
- If the registry could not be created.java.io.IOException
- If the provided proxy object is not serialisable.
-
main
public static void main(java.lang.String[] args) throws java.lang.Exception
The application loads either a zipped marshalled object (zedmob) from a URL, a file, or alternately, it will fetch a remote object reference from an rmiregistry. It uses thegetitem
method of theRemote
class. The application startup will be announced over a defaultMulticast
object. The remote interface to the object will be bound under the name "main" in the local rmiregistry using the localbind
method.The startup can take up to six optional configuration parameters, which must be in order, progressing from most important, to most least:
- args[0] The URL where to get the object: file:// http:// ftp:// /path/file, path/file or alternatively; //[host][:port]/[name] -- the host port and name are optional, if omitted the host is presumed local, the port 1099, and the name proxy. If no arguments are provided, this will be assumed to be ///main.
- args[1] The optional external client host name, if using NAT.
- args[2] The optional external client port number, if using NAT.
- args[3] The optional internal client host name, if multi home/NIC.
- args[4] The optional internal client port number, if using NAT.
- args[5] The optional URL where to get a proxy object: file://
http:// ftp:// ..., //host:port/name (rmiregistry), /path/name
(serialized), or path/name (class). It will be passed into the loaded
object as the sole argument to its setItem method.
- Throws:
java.lang.Exception
-
-