01: package demo.imr;
02:
03: import java.io.*;
04:
05: import org.omg.CORBA.*;
06: import org.omg.PortableServer.*;
07:
08: import org.jacorb.util.*;
09:
10: public class Server extends SomeIfPOA {
11: public Server() {
12: }
13:
14: public void op() {
15: System.out.println("Server: Received call from client");
16: }
17:
18: public static void main(String[] args) {
19: if (args.length != 2) {
20: System.out
21: .println("Usage: jaco demo.imr.Server <ior_file> <timeout in secs>");
22: System.exit(1);
23: }
24:
25: System.setProperty("jacorb.implname", "imr_demo");
26: System.setProperty("jacorb.use_imr", "on");
27:
28: try {
29: long timeout = Integer.parseInt(args[1]) * 1000;
30: //init ORB
31: ORB orb = ORB.init(args, null);
32:
33: //get root POA
34: org.omg.PortableServer.POA root_poa = org.omg.PortableServer.POAHelper
35: .narrow(orb.resolve_initial_references("RootPOA"));
36:
37: //create necessary policies
38: org.omg.CORBA.Policy[] policies = new org.omg.CORBA.Policy[2];
39:
40: policies[0] = root_poa
41: .create_lifespan_policy(LifespanPolicyValue.PERSISTENT);
42: policies[1] = root_poa
43: .create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID);
44:
45: //create user POA with these policies
46: POA demo_poa = root_poa.create_POA("ImRDemoServerPOA",
47: root_poa.the_POAManager(), policies);
48:
49: //destroy policies
50: for (int i = 0; i < policies.length; i++)
51: policies[i].destroy();
52:
53: //instanciate implementation
54: Server s = new Server();
55:
56: //create object id
57: byte[] id = "imr_demo".getBytes();
58:
59: //activate object
60: demo_poa.activate_object_with_id(id, s);
61:
62: //make POA accept requests
63: root_poa.the_POAManager().activate();
64:
65: // create the object reference
66: org.omg.CORBA.Object obj = demo_poa.servant_to_reference(s);
67:
68: PrintWriter pw = new PrintWriter(new FileWriter(args[0]));
69:
70: // print stringified object reference to file
71: pw.println(orb.object_to_string(obj));
72:
73: pw.flush();
74: pw.close();
75:
76: // wait for requests
77: Thread.sleep(timeout);
78:
79: orb.shutdown(true);
80: } catch (Exception e) {
81: System.out.println(e);
82: }
83: }
84: }
|