Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. package server;
  2. import java.util.Properties;
  3.  
  4. import org.omg.CosNaming.NamingContextExt;
  5. import org.omg.CosNaming.NamingContextExtHelper;
  6. import org.omg.PortableServer.IdAssignmentPolicyValue;
  7. // import org.omg.PortableServer.LifespanPolicyValue;
  8. import org.omg.PortableServer.POA;
  9. import org.omg.PortableServer.POAHelper;
  10. import org.omg.PortableServer.ThreadPolicyValue;
  11.  
  12. public class Server_AOM {
  13.  
  14. public static void main(String[] args) {
  15.  
  16. Properties props = System.getProperties();
  17. props.setProperty("org.omg.CORBA.ORBClass", "com.sun.corba.se.internal.POA.POAORB");
  18. props.setProperty("org.omg.CORBA.ORBSingletonClass", "com.sun.corba.se.internal.corba.ORBSingleton");
  19.  
  20. // Para el nameservice
  21. props.put("org.omg.CORBA.ORBInitialHost", "localhost");
  22. props.put("org.omg.CORBA.ORBInitialPort", "1050");
  23.  
  24. try {
  25. // Initialize the ORB.
  26. org.omg.CORBA.ORB orb = org.omg.CORBA.ORB.init(args, props);
  27.  
  28. // get a reference to the root POA
  29. org.omg.CORBA.Object obj = orb.resolve_initial_references("RootPOA");
  30. POA poaRoot = POAHelper.narrow(obj);
  31.  
  32. // Create policies for our persistent POA
  33. org.omg.CORBA.Policy[] policies = {
  34. // poaRoot.create_lifespan_policy(LifespanPolicyValue.PERSISTENT),
  35. poaRoot.create_id_assignment_policy(IdAssignmentPolicyValue.USER_ID),
  36. poaRoot.create_thread_policy(ThreadPolicyValue.ORB_CTRL_MODEL)
  37. };
  38.  
  39. // Create myPOA with the right policies
  40. POA poa = poaRoot.create_POA("EchoServerImpl_poa", poaRoot.the_POAManager(), policies);
  41.  
  42. // Create the servant
  43. EchoServerImpl servant = new EchoServerImpl();
  44.  
  45. // Activate the servant with the ID on myPOA
  46. byte[] objectId = "AnyObjectID".getBytes();
  47. poa.activate_object_with_id(objectId, servant);
  48.  
  49. // Activate the POA manager
  50. poaRoot.the_POAManager().activate();
  51.  
  52. // Get a reference to the servant and write it down.
  53. obj = poa.servant_to_reference(servant);
  54.  
  55. // ---- Uncomment below to enable Naming Service access. ----
  56.  
  57. org.omg.CORBA.Object ncobj = orb.resolve_initial_references("NameService");
  58. NamingContextExt nc = NamingContextExtHelper.narrow(ncobj);
  59. nc.bind(nc.to_name("EchoObject"), obj);
  60.  
  61. //---- Uncomment below to enable fake "by file" Naming Service. ----
  62. //PrintWriter ps = new PrintWriter(new FileOutputStream(new File("server.ior")));
  63. //ps.println(orb.object_to_string(obj));
  64. //ps.close();
  65.  
  66. System.out.println("CORBA Server ready...");
  67.  
  68. // Wait for incoming requests
  69. orb.run();
  70. }
  71. catch(Exception ex) {
  72. ex.printStackTrace();
  73. }
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement