简体   繁体   English

Java通过Swing接收CORBA回调

[英]Java Receiving CORBA Callback with Swing

I have a class that extends Swing JFrame. 我有一个扩展Swing JFrame的类。 In order for this class to receive a callback and call a method in this class, the class should extend the POA class. 为了使此类接收回调并在此类中调用方法,该类应扩展POA类。 I don't know how to do that. 我不知道该怎么做。 What about multiple inheritance? 多重继承呢? Should I make another class that extends the POA class? 我应该再做一个扩展POA类的类吗?

Code

public final class JFSECorbaClient extends javax.swing.JFrame {

//
// init and other method
//

public static void main(final String args[]) throws ClassNotFoundException, IllegalAccessException, InstantiationException{

        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                frame = new JFSECorbaClient().setVisible(true);
                try {

                    //initialize orb
                    Properties props = System.getProperties();
                    props.put("org.omg.CORBA.ORBInitialPort", "1050");
                    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"));
                    rootPOA.activate_object(this.frame); //this.frame should extends jfseCallbackPOA
                    ref = jfseCallbackHelper.narrow(
                            rootPOA.servant_to_reference(callbackListener));

                    //Resolve MessageServer
                    jfseServer = jfseORBHelper.narrow(
                            orb.string_to_object("corbaname:iiop:1.2@localhost:1050#MessageServer"));

                    //Activate rootpoa
                    rootPOA.the_POAManager().activate();
                    //thread for receive callback in other class thread
                    JFSECorrbaListener th = new JFSECorrbaListener();
                    th.setOrb(orb);
                    th.start();

                } catch (Exception e) {
                    System.out.println(e);
                }
            }
        });

    }

It doesn't have to extend the POA class if you are in control of the IDL: you can define your callback via RMI/IIOP, generate the IDL from the remote interface when generating the stub (rmic -iiop), and use PortableRemoteObject.exportObject() to export it. 如果您控制着IDL,则不必扩展POA类:您可以通过RMI / IIOP定义回调,可以在生成存根(rmic -iiop)时从远程接口生成IDL,并使用PortableRemoteObject。 exportObject()导出它。 No need to extend any specific class. 无需扩展任何特定的类。

Having said all that, it's the wrong answer. 说了这么多,那是错误的答案。 Your JFrame-extending class has no need to also be a CORBA callback. 您的JFrame扩展类不必也为CORBA回调。 Define your CORBA callback as a completely separate class, and provide it with hooks into your JFrame-extending class to do whatever is required when the callback occurs. 将CORBA回调定义为完全独立的类,并为您的JFrame扩展类提供钩子,以执行发生回调时所需的任何操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM