|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectgnu.cajo.utils.ItemServer
public class ItemServer
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:
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 its config
static method. Also, by default, acceptance of proxies is disabled.
Constructor Summary | |
---|---|
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 | |
---|---|
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. |
static void |
unbind(java.lang.String name)
This method makes a bound object unable to be found by any new clients. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public ItemServer()
CodebaseServer
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.
public ItemServer(java.lang.String host, int port, java.lang.String codebase)
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 |
---|
public static void acceptProxies() throws java.lang.SecurityException
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!
java.lang.SecurityException
- If a SecurityManager is already installed, and
explicitly prohibits itself from being replaced.public static Remote bind(java.lang.Object item, java.lang.String name) throws java.io.IOException
Remote
class' network settings to be configured
. 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).
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 proxy
acceptance
was enabled for this VM.name
- The name under which to bind the object reference in the
a local rmiregistry. If an object is already bound under this name, this
object will replace it.
java.io.IOException
- For network configuration related issues.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 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.
name
- The name under which to bind the object reference in the
a local rmiregistry. If an object is already bound under this name, this
object will replace it.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
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.public static Remote bind(java.lang.Object item, java.lang.String name, java.lang.Object proxy) throws java.rmi.RemoteException, java.io.IOException
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 proxy
acceptance
was enabled for this VM.name
- The name under which to bind the object reference in the
a local rmiregistry. If an object is already bound under this name, this
object will replace it.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.
java.rmi.RemoteException
- If the registry could not be created.
java.io.IOException
- If the provided proxy object is not serialisable.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
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 proxy
acceptance
was enabled for this VM.name
- The name under which to bind the object reference in the
a local rmiregistry. If an object is already bound under this name, this
object will replace it.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.
java.rmi.RemoteException
- If the registry could not be created.
java.io.IOException
- If the provided proxy object is not serialisable.public static void unbind(java.lang.String name)
name
- The name under which the object can be found on this serverpublic static void main(java.lang.String[] args) throws java.lang.Exception
getitem
method of the Remote
class. The
application startup will be announced over a default
Multicast
object. The remote interface to the object
will be bound under the name "main" in the local rmiregistry using the
local bind
method.
The startup can take up to six optional configuration parameters, which must be in order, progressing from most important, to most least:
java.lang.Exception
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |