-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNENaming.java
80 lines (68 loc) · 2.54 KB
/
NENaming.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import java.io.*;
import java.net.*;
import java.lang.reflect.*;
import java.util.*;
import java.lang.*;
import java.net.ServerSocket;
import java.net.Socket;
public class NENaming {
private static NEURLInfo parseURL (String url)
throws NEMalformattedURLException {
String host, name;
int port = NERegistry.REGISTRY_PORT;
if (! url.startsWith ("//")) throw new NEMalformattedURLException ();
String s = url.substring (2);
String[] hostAndStuff = s.split (":");
if (hostAndStuff.length < 2) throw new NEMalformattedURLException ();
host = hostAndStuff[0];
s = hostAndStuff[1];
String[] portAndName = s.split ("/", 2);
if (portAndName.length < 2) throw new NEMalformattedURLException ();
try {
port = Integer.parseInt (portAndName[0]);
name = portAndName[1];
}
catch (NumberFormatException e) {
port = NERegistry.REGISTRY_PORT;
name = s;
}
NEURLInfo info = new NEURLInfo ();
info.name = name;
info.host = host;
info.port = port;
return info;
}
public static NERemote lookup (String url)
throws NEMalformattedURLException, NERemoteException, NENotBoundException,
NEAccessException, NERegistryNotFoundException {
NEURLInfo info = parseURL (url);
NERegistry reg = NERegistryLocator.getRegistry (info.name, info.port);
return reg.lookup (info.name);
}
public static void bind (String url, NERemoteObjectReference object)
throws NEMalformattedURLException, NERemoteException, NEAlreadyBoundException,
NEAccessException, NERegistryNotFoundException {
NEURLInfo info = parseURL (url);
NERegistry reg = NERegistryLocator.getRegistry (info.name, info.port);
reg.bind (info.name, object);
}
public static void rebind (String url, NERemoteObjectReference object)
throws NEMalformattedURLException, NERemoteException, NEAccessException,
NERegistryNotFoundException {
NEURLInfo info = parseURL (url);
NERegistry reg = NERegistryLocator.getRegistry (info.name, info.port);
reg.rebind (info.name, object);
}
public static void unbind (String url)
throws NEMalformattedURLException, NERemoteException, NENotBoundException,
NEAccessException, NERegistryNotFoundException {
NEURLInfo info = parseURL (url);
NERegistry reg = NERegistryLocator.getRegistry (info.name, info.port);
reg.unbind (info.name);
}
private static class NEURLInfo {
public String host;
public String name;
public int port;
}
}