上一篇介绍了CORBA的NotificationService以及如何来使用NotificationService。
上一篇 使用Java进行CORBA编程-JacORB-Notification Service
下面提供使用JacORB的NotificatoinService的一个例程,运行此例子需要启动NameService,
启动方法和例程的启动方法见 使用Java进行CORBA编程-JacORB-入门
另外,还需要启动NotificatoinService,在Windows上可以到JacORB的安装目录下的bin,使用下面的脚本来启动。
需要指定NotificationService使用的端口号,这里是7981。
注意,如果启动中出现错误,可能需要修改JacORB的安装目录下的etc/jacorb.properties文件中的某些设置。
set CLASSPATH=.
set CLASSPATH=%CLASSPATH%;../lib/slf4j-api-1.6.4.jar
set CLASSPATH=%CLASSPATH%;../lib/slf4j-jdk14-1.6.4.jar
set CLASSPATH=%CLASSPATH%;../lib/jacorb.jar
set CLASSPATH=%CLASSPATH%;../lib/jacorb-services.jar
set CLASSPATH=%CLASSPATH%;../lib/antlr-2.7.2.jar
set CLASSPATH=%CLASSPATH%;../lib/picocontainer-1.2.jar
set SYSTEM_PROPS=-Djacorb.home=..
set SYSTEM_PROPS=%SYSTEM_PROPS% -Dorg.omg.CORBA.ORBClass=org.jacorb.orb.ORB
set SYSTEM_PROPS=%SYSTEM_PROPS% -Dorg.omg.CORBA.ORBSingletonClass=org.jacorb.orb.ORBSingleton
java %SYSTEM_PROPS% -cp %CLASSPATH% org.jacorb.notification.ConsoleMain -port 7981 -printCorbaloc
Server代码
1)StructuredPushSupplierImpl.java
package learning.corba.notification.newsbroadcast.server;
import org.omg.CosNotification.EventType;
import org.omg.CosNotifyComm.InvalidEventType;
import org.omg.CosNotifyComm.StructuredPushSupplierPOA;
public class StructuredPushSupplierImpl extends StructuredPushSupplierPOA {
public void disconnect_structured_push_supplier() {
System.out.println("disconnect_structured_push_supplier");
}
public void subscription_change(EventType[] added, EventType[] removed)
throws InvalidEventType {
throw new UnsupportedOperationException();
}
}
2)NewsBCNotifServer.java
package learning.corba.notification.newsbroadcast.server;
import java.util.Properties;
import java.util.Random;
import org.omg.CORBA.IntHolder;
import org.omg.CORBA.ORB;
import org.omg.CosEventComm.Disconnected;
import org.omg.CosNaming.NamingContextExt;
import org.omg.CosNaming.NamingContextExtHelper;
import org.omg.CosNotification.DefaultPriority;
import org.omg.CosNotification.EventHeader;
import org.omg.CosNotification.EventType;
import org.omg.CosNotification.FixedEventHeader;
import org.omg.CosNotification.Priority;
import org.omg.CosNotification.Property;
import org.omg.CosNotification.StructuredEvent;
import org.omg.CosNotifyChannelAdmin.ClientType;
import org.omg.CosNotifyChannelAdmin.EventChannel;
import org.omg.CosNotifyChannelAdmin.EventChannelFactory;
import org.omg.CosNotifyChannelAdmin.