我有简单的 grails 服务器/groovyfx 应用程序,其中 openDolphin 用于客户端/服务器通信。
以下是发生的情况:当 CMD_LOG 命令从客户端发送到服务器时,服务器会更新presentationModel 的一个值并响应:Whats up?。OpenDolphin 再做一个动作,客户端发送“ValueChanged”确认,服务器接受它,并响应空命令,客户端接收它。
我的问题是,如何实现对“ValueChanged”的自定义响应,例如检查数据库中的相应值,或者是否允许客户端更改它。当我没有实现它时,为什么会发送响应?我对发送不受控制的空消息感觉不舒服。
一点点代码,在客户端,这个闭包在按钮按下时被调用:
def sendToServer = { message ->
clientDolphin.send(message, new OnFinishedHandlerAdapter() {
@Override
public void onFinished(List<ClientPresentationModel> presentationModels) {
// after action on server, this wants to read changed presentation model
}
}
});
}
客户端日志:
INFO: C: sending batch of size 1
IX 17, 2013 7:46:59 ODP. java_util_logging_Logger$info$0 call
INFO: C: -> Command: CMD_LOG
IX 17, 2013 7:46:59 ODP. org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
INFO: C: server responded with 2 command(s): [ValueChanged, Whats up?]
IX 17, 2013 7:46:59 ODP. org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
INFO: C: updating 'x' id '0' from 'null' to '10'
IX 17, 2013 7:46:59 ODP. java_util_logging_Logger$info$0 call
INFO: C: sending batch of size 1
IX 17, 2013 7:46:59 ODP. java_util_logging_Logger$info$0 call
INFO: C: -> Command: ValueChanged attr:0, null -> 10
IX 17, 2013 7:46:59 ODP. org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
SEVERE: C: cannot handle unknown command 'Command: Whats up?'
IX 17, 2013 7:47:00 ODP. org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrap invoke
INFO: C: server responded with 0 command(s): []
服务器端,对应的action handler:
class SimpleStoreServerDirector extends DolphinServerAction {
@Override
void registerIn(ActionRegistry actionRegistry) {
actionRegistry.register "CMD_LOG", { NamedCommand command, response ->
def pm = serverDolphin.findPresentationModelById("input")
changeValue pm["x"], 10
response.add(new NamedCommand("Whats up?"))
}
}
最后,服务器日志:
Creating new Dolphin session
LOG: proccessing Command: CreatePresentationModel pmId input pmType null attributes [[id:0, propertyName:x, tag:VALUE, value:null, qualifier:null]]
LOG results: []
LOG: proccessing Command: CMD_LOG
LOG results: [Command: ValueChanged attr:0, null -> 10, Command: Whats up?]
LOG: proccessing Command: ValueChanged attr:0, null -> 10
LOG results: []
提前寻求答案或任何有用的文档或教程参考。