CORBA客户端停止或挂起没有错误

时间:2012-11-28 19:51:44

标签: java corba

当我使用下面有类对象“bd”的方法作为参数时,我的客户端停止工作,尽管我成功使用了侦听器对象。 “标记为大胆” 没有,当我试图使用另一种方法,例如任何一个pramater“STring”成功地工作。

import java.util.Properties;
        import org.omg.CORBA.ORB;
        import org.omg.PortableServer.POA;
        import org.omg.PortableServer.POAHelper;
        import org.omg.CosNaming.NameComponent;
        import org.omg.CosNaming.NamingContext;
        import org.omg.CosNaming.NamingContextHelper;

        public class BackupDaemonMain {

            public static void main(String[] args) {
            try {

                    //initialize orb
                    Properties props = System.getProperties();
                    props.put("org.omg.CORBA.ORBInitialPort", "1050");
                    //Replace MyHost with the name of the host on which you are running the server
                    props.put("org.omg.CORBA.ORBInitialHost", "localhost");
                    ORB orb = ORB.init(args, props);
                System.out.println("Initialized ORB");

                    //Instantiate Servant and create reference
                POA rootPOA = POAHelper.narrow(
                orb.resolve_initial_references("RootPOA"));

                    MessageListenerImpl listener  = new MessageListenerImpl();
                    BackupDaemonImpl  bdImpl=new BackupDaemonImpl();
                    // bdImpl.backupDaemonUser("Yarab");
                  rootPOA.activate_object(listener);
                  rootPOA.activate_object(bdImpl);
                   MessageListener ref = MessageListenerHelper.narrow(
                        rootPOA.servant_to_reference(listener));
                        **BackupDaemon bd = BackupDaemonHelper.narrow(
                       rootPOA.servant_to_reference(bdImpl));**
                      System.out.println("After rootPOA.servant_to_reference(bdImpl)); ");

                    //Resolve MessageServer
                 MessageServer msgServer = MessageServerHelper.narrow(
                orb.string_to_object("corbaname:iiop:1.2@localhost:1050#MessageServer"));
            BackupServer bdServer=BackupServerHelper.narrow(
                 orb.string_to_object("corbaname:iiop:1.2@localhost:1050#BackupServer"));
                    //Register listener reference (callback object) with MessageServer
                /* if(bd==null)
                      {
                       System.out.println("Null");
                      }
                      else
                      {
                      System.out.println("Not Null With " + bd.backupDaemonUser());
                      }*/
                    // bd.backupDaemonMacAddress("YYYYYYYYYY");
         System.out.println("Initialized ORB +++++++++++++++++++++++ ");
             msgServer.register(ref); 
         **bdServer.registerBackupDaemon(bd);**
               System.out.println("Initialized ORB +++++++++++++++++++++++ )))))))))");
                    //System.out.println("I am  Here" + 
                    //bd.deleteBackup("00000000000","asdas");//);
                    System.out.println("Initialized ORB +++++++++++++++++++++++ _____________________________");
                    System.out.println("Listener registered with MessageServer With User :- ");
                    System.out.println("Backup Daemon registered with BackupServer With User :- " );

                //Activate rootpoa
                    rootPOA.the_POAManager().activate();

                    //Wait for messages
                    System.out.println("Wait for incoming messages");
                    orb.run();

            } catch (Exception e) {
                e.printStackTrace();
            }
            }
        }

服务器实施

// BackupServerImpl.java

import java.util.Enumeration;
import java.util.Vector;
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 util.CORBAAlgorithms;

  public class BackupServerImpl extends BackupServerPOA {
   private ORB orb;

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

  public String sayHello(){
    return "\nHello world !!\n";
  }

  public void shutdown(){
    orb.shutdown(false);
  }
      // This BankServer's list of Banks.
      private Vector myBackups;
   public BackupServerImpl() 
   {
  //super("In Impl");
        System.out.println("\n \t @ Constructor of Server");  

      }


      public BackupServerImpl(String name) {

         // super(name);

          myBackups = new Vector();

      }

      public boolean registerBackupDaemon(BackupDaemon bd) throws InvalidBackupDaemonException
              {

              System.out.println("\n \t Backup Agent Registration With User" + bd.backupDaemonUser());
      return true;
      }

      public boolean unRegisterBackupDaemon(String backupDaemonMacAddress) throws
              InvalidBackupDaemonException {
          System.out.println("Backup Daemon Un-Registration With Mac " + backupDaemonMacAddress);
            return true;   
      }

      public BackupDaemon[] getBackupDeamons() {

          BackupDaemon[] list = new BackupDaemon[myBackups.size()];
          myBackups.copyInto(list);

          Enumeration e = myBackups.elements();
          while (e.hasMoreElements()) {
              ((BackupDaemon)e.nextElement())._duplicate();
          }

          return list;
      }


 }

2 个答案:

答案 0 :(得分:0)

您可能错过了我们网址中的NameService

corbaname:iiop:1.2@localhost:1050/NameService#BackupServer

bdServer的调用也可能在远程站点上挂起......

答案 1 :(得分:0)

当前线程上的run org.omg.CORBA.ORB方法阻塞。你应该在一个单独的线程中启动它。请参阅javadoc。运行你的ORB

Thread orbThread = new Thread("Orb Thread") {

   public void run() {
    orb.run();     
  }
};

orbThread.start();