我正在开发一个ADF Fusion Web应用程序,其中包含一个带有JDeveloper 11.1.1.4.0的消息传递模块。我搜索了技术以进行服务器端推送(也问了question关于它)我搜索了“彗星”,服务器端推送等。 我找到了Active Data Service和一些聊天或服务器端推送示例:
我按照biemond's blog中的说明执行ADS的配置
在ADF META-INF / services文件夹
下的adf-config.xml中添加了广告配置<ads:adf-activedata-config xmlns="http://xmlns.oracle.com/adf/activedata/config">
<transport>long-polling</transport>
<latency-threshold>10000</latency-threshold>
<keep-alive-interval>10000</keep-alive-interval>
<polling-interval>3000</polling-interval>
<max-reconnect-attempt-time>1800000</max-reconnect-attempt-time>
<reconnect-wait-time>10000</reconnect-wait-time></ads:adf-activedata-config>
并创建了adf-config.properties文件
http\://xmlns.oracle.com/adf/activedata/config=oracle.adfinternal.view.faces.activedata.ActiveDataConfiguration$ActiveDataConfigCallback
并在jsf页面中创建了一个表。
<af:table value="#{MessageModel}" var="row"
rows="#{bindings.MessageVO.rangeSize}"
emptyText="#{bindings.MessageVO.viewable ? 'No data to display.' : 'Access Denied.'}"
fetchSize="#{bindings.MessageVO.rangeSize}"
rowBandingInterval="0" id="t1">
<af:column sortProperty="id" sortable="false"
headerText="#{bindings.MessageVO.hints.id.label}"
id="c1">
<af:outputText value="#{row.id}" id="ot2">
<af:convertNumber groupingUsed="false"
pattern="#{bindings.MessageVO.hints.id.format}"/>
</af:outputText>
</af:column>
<af:column sortProperty="Title" sortable="false"
headerText="#{bindings.MessageVO.hints.Title.label}"
id="c2">
<af:outputText value="#{row.title}" id="ot3"/>
</af:column>
</af:table>
创建了MessageModel类,用作jsff中的表值。
public class MessageModel extends ActiveCollectionModelDecorator {
private MessageActiveDataModel activeDataModel = new MessageActiveDataModel();
private CollectionModel model = null;
public CollectionModel getCollectionModel() {
if (model == null) {
DCBindingContainer dcBindings = (DCBindingContainer)BindingContext.getCurrent().getCurrentBindingsEntry();
FacesCtrlHierBinding treeData = (FacesCtrlHierBinding)dcBindings.getControlBinding("MessageVO");
model = treeData.getCollectionModel();
}
return model;
}
public MessageActiveDataModel getActiveDataModel() {
return activeDataModel;
}
public MessageActiveDataModel getMessageActiveDataModel() {
return activeDataModel;
}
}
和一个ActiveDataModel类
public class MessageActiveDataModel extends BaseActiveDataModel {
private final AtomicInteger listenerCount = new AtomicInteger(0);
private final AtomicInteger currEventId = new AtomicInteger();
protected void startActiveData(Collection<Object> rowKeys,
int startChangeCount) {
listenerCount.incrementAndGet();
if (listenerCount.get() == 1) {
System.out.println("start up");
Runnable dataChanger = new Runnable() {
public void run() {
System.out.println("MyThread starting.");
try {
Thread.sleep(2000);
System.out.println("thread running");
Change chg = new Change();
chg.triggerDataChange(MessageActiveDataModel.this);
} catch (Exception exc) {
System.out.println("MyThread exceptioned out.");
}
System.out.println("MyThread terminating.");
}
};
Thread newThrd = new Thread(dataChanger);
newThrd.start();
}
}
protected void stopActiveData(Collection<Object> rowKeys) {
listenerCount.decrementAndGet();
if (listenerCount.get() == 0) {
System.out.println("tear down");
}
}
public int getCurrentChangeCount() {
return currEventId.get();
}
public void bumpChangeCount() {
currEventId.incrementAndGet();
}
public void dataChanged(ActiveDataUpdateEvent event) {
fireActiveDataUpdate(event);
}
}
ActiveDataModel类中的线程触发名为Change
的类public class Change {
public Change() {
}
public void triggerDataChange(MessageActiveDataModel model) throws Exception {
for (int i = 0; i < 10; i++) {
try {
Thread.sleep(4000);
} catch (InterruptedException ie) {
ie.printStackTrace();
}
model.bumpChangeCount();
ActiveDataUpdateEvent event =
ActiveDataEventUtil.buildActiveDataUpdateEvent(ActiveDataEntry.ChangeType.UPDATE,
model.getCurrentChangeCount(),
JboActiveDataEventUtil.convertKeyPath(new Object[] { new Long(1),
new Integer(0) }),
null,
new String[] { "title" },
new Object[] { "Administration" });
model.dataChanged(event);
}
}
}
当我运行应用程序时,我可以在表中看到来自MessageVO的行。它进入模型类,活动数据模型类和更改类,更改ActiveDataMode类中的listenerCount和currentEventId值。当我更新数据库中的行时,它不会触发更改事件,也不会检测数据库中的更新。
有没有人知道如何监听数据库中的更改并根据ADF中的db更改执行服务器端推送?
先谢谢。