我有一个带有两个客户端的 db4o 服务器的系统。一个客户端托管在进程中,另一个是托管许多需要查询数据库的 servlet 的 Web 服务器。
在 Web 服务器的连接代码中,我已经注册了提交事件,并按照http://community.versant.com/documentation/reference/db4o-8.0/java/reference/上的 db4o 文档的建议使用它来刷新对象内容/advanced_topics/callbacks/possible_usecases/committed_event_example.htm:
client = Db4oClientServer.openClient (context.getBean ("db4oClientConfiguration", ClientConfiguration.class),
arg0.getServletContext ().getInitParameter ("databasehost"),
Integer.parseInt (arg0.getServletContext ().getInitParameter ("databaseport")),
arg0.getServletContext ().getInitParameter ("databaseuser"),
arg0.getServletContext ().getInitParameter ("databasepassword"));
System.out.println ("DB4O connection established");
EventRegistry events = EventRegistryFactory.forObjectContainer (client);
events.committed ().addListener (new EventListener4<CommitEventArgs> () {
public void onEvent (Event4<CommitEventArgs> commitEvent, CommitEventArgs commitEventArgs)
{
for (Iterator4<?> it = commitEventArgs.updated ().iterator (); it.moveNext ();)
{
LazyObjectReference reference = (LazyObjectReference) it.current ();
System.out.println ("Updated object: " + reference.getClass () + ":" + reference.getInternalID ());
//if (trackedClasses.contains (reference.getClass ()))
{
Object obj = reference.getObject ();
commitEventArgs.objectContainer ().ext ().refresh (obj, 1);
System.out.println (" => updated (" + obj + ")");
}
}
}
});
然后在进程内客户端中执行以下代码:
try {
PlayerCharacter pc = new PlayerCharacter (player, name);
pc.setBio(bio);
pc.setArchetype(archetype);
player.getCharacters ().add (pc);
database.store (pc);
database.store (player.getCharacters ());
database.store (player);
database.commit ();
con.sendEvent (id, "CHARACTER_CREATED".getBytes (Constants.CHARSET));
}
catch (Exception e)
{
con.sendEvent (id, EventNames.ERROR, e.toString ());
}
'CHARACTER_CREATED' 事件发送成功,所以我知道提交没有引发异常,但其他客户端上没有显示任何内容。它继续使用旧版本的对象,并且我期望的“更新对象”消息不会出现在服务器控制台上。
任何想法我做错了什么?