gpt4 book ai didi

java - 在java中成功初始化Corba通知服务,但在linux中无法获取任何事件,但在windows中完成

转载 作者:行者123 更新时间:2023-12-01 05:27:09 25 4
gpt4 key购买 nike

当我测试用 Java 编写的应用程序时,我对一个奇怪的错误感到头疼。问题就在这里:我已经使用 CORBA 连接技术编写了我的应用程序。它是一个 CORBA 客户端应用程序模块。在windows环境中,事件推送成功,但在linux(redhat和ubuntu)中却没有成功。然而,它太奇怪了,我可以调用任何 CORBA 函数并准确地获取返回的数据。我调试了代码,发现 CORBA 连接和通知服务的初始化成功。在Linux操作系统中,防火墙被禁用,并且端口12002未被任何应用程序使用。这里没有任何异常(exception)。那么,您能为我解释一下这是什么原因吗?我对CORBA的经验较少。对于我这样的新手来说太复杂了。请帮助我!

P/s:+ 初始化代码如下:

        Properties props = new Properties();
/*props.setProperty("borland.enterprise.licenseDefaultDir", "C:/Borland/VisiBroker/license");*/
props.setProperty("org.omg.CORBA.ORBClass", "com.inprise.vbroker.orb.ORB");
props.setProperty("org.omg.CORBA.ORBSingletonClass", "com.inprise.vbroker.orb.ORBSingleton");
props.setProperty("javax.rmi.CORBA.StubClass", "com.inprise.vbroker.rmi.CORBA.StubImpl");
props.setProperty("javax.rmi.CORBA.UtilClass", "com.inprise.vbroker.rmi.CORBA.UtilImpl");
props.setProperty("javax.rmi.CORBA.PortableRemoteObjectClass", "com.inprise.vbroker.rmi.CORBA.PortableRemoteObjectImpl");
props.setProperty("vbroker.agent.enableLocator", "false");
props.setProperty("vbroker.orb.initRef", "NotificationService=corbaloc::x.x.x.x:12002/NotificationService");


try {
System.out.println("orb = org.omg.CORBA.ORB.init(new String[0], props);");
orb = org.omg.CORBA.ORB.init(new String[0], props);
} catch (Exception e) {
System.out.println("Fail initial orb for Noti-Service.."+e);
System.exit(1);
}

try {
org.omg.CORBA.Object poa = orb.resolve_initial_references("RootPOA");
rootPoa = POAHelper.narrow(poa);
} catch (org.omg.CORBA.ORBPackage.InvalidName e) {
System.out.println("Can't get RootPOA"+ e);
System.exit(1);
}

try {
rootPoa.the_POAManager().activate();
System.out.println("rootPoa.the_POAManager().activate();");
} catch (org.omg.PortableServer.POAManagerPackage.AdapterInactive ex) {
System.out.println("Can't activate POAManager"+ex);
System.exit(1);
}

Runtime.getRuntime().addShutdownHook(new Thread(new ShutdownHook(orb)));

Thread thread = new Thread() {
public void run() {
orb.run();
}
};

thread.setName("OpenFusion ORB thread");
thread.start();
  • getObject()方法:

    私有(private) StructuredPushConsumer getObject() { StructuredPushConsumer serverObj = null;

        org.omg.PortableServer.Servant servant = new StructuredPushConsumerPOATie(this, rootPoa);

    try {
    org.omg.CORBA.Object ref = rootPoa.servant_to_reference(servant);
    serverObj = StructuredPushConsumerHelper.narrow(ref);
    } catch (ServantNotActive e) {
    System.out.println("Unexpected Exception: "+e);
    System.exit(1);
    } catch (WrongPolicy e) {
    System.out.println("Unexpected Exception: "+e);
    System.exit(1);
    }
    return serverObj;

    }
  • connect() 方法:

     public void connect() {
    /* Defines the type of proxy required */
    ClientType ctype = ClientType.STRUCTURED_EVENT;
    /* Holder to hold the proxy id */
    org.omg.CORBA.IntHolder pid = new org.omg.CORBA.IntHolder();
    /* Proxy supplier variable */
    ProxySupplier proxySupplier = null;
    /* Obtain the consumer admin object reference */
    ConsumerAdmin admin = channel.default_consumer_admin();

    try {
    /* obtain a structured push supplier object reference. */

    proxySupplier = ((ConsumerAdminOperations) admin).obtain_notification_push_supplier(ctype, pid);
    System.out.println("proxySupplier = ((ConsumerAdminOperations) admin).obtain_notification_push_supplier(ctype, pid);");
    } catch (AdminLimitExceeded ex) {
    /*
    * Thrown if the admin object is unable to have any more proxy suppliers associated with it.
    */
    System.err.println("Maximum number of proxies exceeded!");
    System.exit(1);
    }

    /* Narrow the proxy supplier to a Structured Proxy Push Supplier */
    proxy = StructuredProxyPushSupplierHelper.narrow(proxySupplier);

    try {
    /* connect the consumer to the proxy */
    proxy.connect_structured_push_consumer(getObject());
    System.out.println("proxy.connect_structured_push_consumer(getObject());");
    } catch (AlreadyConnected e) {
    /*
    * This exception is thrown if a consumer is already connected to this proxy. This should not be thrown because the proxy has just been created.
    */
    System.err.println("Already connected!");
    System.exit(1);
    } catch (TypeError e) {
    /*
    * This exception is thrown if you attempt to connect a sequenced consumer to a structured proxy or vice versa.
    */
    System.err.println("Type error!");
    System.exit(1);
    }

    }

  • disconnect() 方法:

    public void disconnect() {    
    if (proxy != null) {
    System.out.println("Disconnected!");
    }
    }

最佳答案

我认为您的对象激活丢失了。此时 ORB 行为可能尚未完全定义,因此您应在此处使用更显式的激活。

// create TIE 
StructuredPushConsumerPOATie pushConsumer =
new StructuredPushConsumerPOATie(this, rootPoa);

// activate object (may work without that)
rootPoa.activate_object(pushConsumer);
try {
// implicit activation
org.omg.CORBA.Object ref = pushConsumer._this_object();
serverObj = StructuredPushConsumerHelper.narrow(ref);
}

关于java - 在java中成功初始化Corba通知服务,但在linux中无法获取任何事件,但在windows中完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9547234/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com