CORBA创建一个最终成为客户端的服务器?

时间:2012-11-23 02:59:32

标签: java corba

好的,我的问题是我正在开展一个非常像收费的项目。 客户端在第一个服务器成为客户端并连接到第二个服务器之后向第一个服务器发送一个ID,如果汽车可以通过则返回一个进程。 现在我在CORBA中遇到了麻烦(项目最初是在RMI中创建的,其中工作正常)但是我遇到了从第一台服务器到第二台服务器的连接问题。 有人告诉我,ORB必须以其他方式进行初始化,而不是像运行客户端时那样是XXXClient -ORBInitialPort 1999。 我可以很好地与第一台服务器连接,但没有任何东西到达第二台服务器。 以下是最终将成为客户端的服务器代码

import PROApp.*;
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;

class PROImpl extends PROPOA {
private ORB orb;

public void setORB(ORB orb_val) {
 orb = orb_val; 
  }

  // implement sayHello() method
  public String check1(int number) 
  {
    try{
        if(number > 0 && number <8000) 
        {
            String serverReply2 = "parta";
            serverReply2 = proCarImpl.check2(number);
            System.out.println(serverReply2);
            if(serverReply2.equals("ACK"))
            {
                return "You shall pass";
            }
        else if(serverReply2.equals("NACK"))
            {
                return "You shall not pass, not enought credits";
            }
        else
            {
                return "You're probably not on the list or something went wrong";
            }
    }
    else
     {
        return "Wrong ID number";
     }
     }
     catch (Exception e)
        {
            System.out.println("PROServer is not bound in rmiregistry... Exception:" + e);
        }return "ooups";
  }

  // implement shutdown() method
  public void shutdown() {
    orb.shutdown(false);
  }
}


public class PROServer {

  public static void main(String args[]) {
    try{
  // create and initialize the ORB
  ORB orb = ORB.init(args, null);

  // get reference to rootpoa & activate the POAManager
  POA rootpoa = POAHelper.narrow(orb.resolve_initial_references("RootPOA"));
  rootpoa.the_POAManager().activate();

  // create servant and register it with the ORB
  PROImpl proImpl = new PROImpl();
  proImpl.setORB(orb); 

  // get object reference from the servant
  org.omg.CORBA.Object ref = rootpoa.servant_to_reference(proImpl);
  PRO href = PROHelper.narrow(ref);

  // get the root naming context
  // NameService invokes the name service
  org.omg.CORBA.Object objRef =
      orb.resolve_initial_references("NameService");
  // Use NamingContextExt which is part of the Interoperable
  // Naming Service (INS) specification.
  NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);

  // bind the Object Reference in Naming
  String name = "project corba";
  NameComponent path[] = ncRef.to_name(name);
  ncRef.rebind(path, href);

  System.out.println("PROServer with name "+ name+ " is up and it's waiting ...");

  // wait for invocations from clients
  orb.run();

        ORB orb = ORB.init(args, null);

        org.omg.CORBA.Object objRef = 
        orb.resolve_initial_references("NameService");
        NamingContextExt ncRef = NamingContextExtHelper.narrow(objRef);
        String name = "project corba car";
        proCarImpl = PROCarHelper.narrow(ncRef.resolve_str(name));

        System.out.println("Obtained a handle on server object: " + proCarImpl);

} 

  catch (Exception e) {
    System.err.println("ERROR: " + e);
    e.printStackTrace(System.out);
  }

  System.out.println("HelloServer Exiting ...");

  }
}

0 个答案:

没有答案