1:
37:
38: package ;
39:
40: import ;
41:
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49: import ;
50: import ;
51: import ;
52: import ;
53: import ;
54: import ;
55: import ;
56:
57: public class RegistryImpl
58: extends UnicastRemoteObject implements Registry {
59:
60: private Hashtable bindings = new Hashtable();
61:
62: public RegistryImpl(int port) throws RemoteException {
63: this(port, RMISocketFactory.getSocketFactory(), RMISocketFactory.getSocketFactory());
64: }
65:
66: public RegistryImpl(int port, RMIClientSocketFactory cf, RMIServerSocketFactory sf) throws RemoteException {
67: super(new UnicastServerRef(new ObjID(ObjID.REGISTRY_ID), port, sf));
68:
69:
70: }
71:
72: public Remote lookup(String name) throws RemoteException, NotBoundException, AccessException {
73: Object obj = bindings.get(name);
74: if (obj == null) {
75: throw new NotBoundException(name);
76: }
77: return ((Remote)obj);
78: }
79:
80: public void bind(String name, Remote obj) throws RemoteException, AlreadyBoundException, AccessException {
81: if (bindings.containsKey(name)) {
82: throw new AlreadyBoundException(name);
83: }
84: bindings.put(name, obj);
85: }
86:
87: public void unbind(String name) throws RemoteException, NotBoundException, AccessException {
88: Object obj = bindings.remove(name);
89: if (obj == null) {
90: throw new NotBoundException(name);
91: }
92: }
93:
94: public void rebind(String name, Remote obj) throws RemoteException, AccessException {
95: bindings.put(name, obj);
96: }
97:
98: public String[] list() throws RemoteException, AccessException {
99: int size = bindings.size();
100: String[] strings = new String[size];
101: Enumeration e = bindings.keys();
102: for (int i = 0; i < size; i++) {
103: strings[i] = (String)e.nextElement();
104: }
105: return (strings);
106: }
107:
108: public static void version() {
109: System.out.println("rmiregistry ("
110: + System.getProperty("java.vm.name")
111: + ") "
112: + System.getProperty("java.vm.version"));
113: System.out.println("Copyright 2016 Free Software Foundation, Inc.");
114: System.out.println("This is free software; see the source for copying conditions. There is NO");
115: System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
116: System.exit(0);
117: }
118:
119: public static void help() {
120: System.out.println(
121: "Usage: rmiregistry [OPTION | PORT]\n" +
122: "\n" +
123: " --help Print this help, then exit\n" +
124: " --version Print version number, then exit\n");
125: System.exit(0);
126: }
127:
128: public static void main(String[] args) {
129: int port = Registry.REGISTRY_PORT;
130: if (args.length > 0) {
131: if (args[0].equals("--version")) {
132: version();
133: }
134: else if (args[0].equals("--help")) {
135: help();
136: }
137: try {
138: port = Integer.parseInt(args[0]);
139: }
140: catch (NumberFormatException _) {
141: System.err.println("Bad port number - using default");
142: }
143: }
144:
145: try {
146: Registry impl = LocateRegistry.createRegistry(port);
147: }
148: catch (RemoteException _) {
149: System.err.println("Registry failed");
150: }
151: }
152:
153: }