-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStartServer.java
53 lines (41 loc) · 1.5 KB
/
StartServer.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
import FS.*;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.util.Properties;
import java.util.Scanner;
import java.io.BufferedReader;
public class StartServer {
public static void main(String args[]) {
try{
// create and initialize the ORB //// get reference to rootpoa & activate the POAManager
ORB orb = ORB.init(args, null);
POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
rootpoa.the_POAManager().activate();
// create servant and register it with the ORB
Server server = new Server();
server.setORB(orb);
// get object reference from the servant
org.omg.CORBA.Object ref = rootpoa.servant_to_reference(server);
FileSystem href = FileSystemHelper.narrow(ref);
org.omg.CORBA.Object objRef = orb.resolve_initial_references("NameService");
NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
// bind the Object Reference in Naming
String name = "FileSystem";
NameComponent path[] = ncRef.to_name( name );
ncRef.rebind(path, href);
System.out.println("Server ready and waiting ...");
// wait for invocations from clients
for (;;){
orb.run();
}
}
catch (Exception e) {
System.err.println("ERROR: " + e);
e.printStackTrace(System.out);
}
System.out.println("Server Exiting ...");
}
}