リスナーオブジェクトを正常に使用しているにもかかわらず、以下のクラスオブジェクト「bd」をパラメーターとして持つメソッドを使用すると、クライアントが動作しなくなりました。「太字としてマーク」注:たとえば、「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;
}
}