KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > rmi > RMIRegistryJob


1 package org.oddjob.rmi;
2
3 import java.rmi.registry.LocateRegistry JavaDoc;
4 import java.rmi.server.ExportException JavaDoc;
5
6 import org.oddjob.framework.SimpleJob;
7
8 /**
9  * @oddjob.description A job which creates an RMI registry. A registry can
10  * only be created once. If this job is re-run it will fail.
11  *
12  * @author Rob Gordon
13  */

14 public class RMIRegistryJob extends SimpleJob {
15
16     /** The default port */
17     public static final int DEFAULT_PORT = 1099;
18     
19     /**
20      * @oddjob.property
21      * @oddjob.description The port to use
22      * @oddjob.required Yes.
23      */

24     private int port = DEFAULT_PORT;
25
26     /**
27      * Set the port number to use.
28      *
29      * @param port The port number.
30      */

31     synchronized public void setPort(int port) {
32         this.port = port;
33     }
34
35     /**
36      * Get the port number.
37      *
38      * @return The port number.
39      */

40     synchronized public int getPort() {
41         return this.port;
42     }
43
44     /*
45      * (non-Javadoc)
46      * @see org.oddjob.jobs.AbstractJob#execute()
47      */

48     public int execute() throws Exception JavaDoc {
49         try {
50             LocateRegistry.createRegistry(getPort());
51         } catch (ExportException JavaDoc e) {
52             logger().debug("Registry probably created: " + e.getMessage());
53         }
54
55         return 0;
56     }
57 }
58
Popular Tags