简体   繁体   English

读取多个条目模板

[英]Reading multiple Entries template

I'm working with Apache River javaspaces project and I'm trying to figure out a way to write a template that reads multiple entries in the space and returns the ones I don't already have stored somewhere for example: 我正在与Apache River javaspaces项目一起工作,并且试图找到一种写模板的方法,该模板可以读取空间中的多个条目并返回我尚未存储的条目,例如:

User writes three Entries to the space "entry1", "entry2", "entry3". 用户将三个条目写入空间“ entry1”,“ entry2”,“ entry3”。 Later the same user tries to read the Entries from the space, each time the space returns "entry1" because it's not being removed from the space it will always match the given template. 稍后,同一用户尝试从该空间读取条目,每次该空间返回“ entry1”时,因为未从空间中删除它,它将始终与给定模板匹配。

Writing to space: 写空间:

SpaceEntry string = new SpaceEntry("User","entry1"); 
                    space.write(string, null, Lease.FOREVER);

Reading from space: 从太空读取:

SpaceEntry template = new SpaceEntry(); 
                    SpaceEntry read = (SpaceEntry)space.readIfExists(template,null,Long.MAX_VALUE);

$read is stored in a list and the reading process repeats. $ read存储在列表中,重复读取过程。

Template: 模板:

public SpaceEntry (String o, String m){
    this.Owner = o;
    this.Message = m;
}

Finally any suggestions on dynamically modifying the template with the list of values already acquired so the Entries remain in space but different ones are returned? 最后,关于使用已获取的值列表动态修改模板的任何建议,以便条目保留在空间中,但返回不同的条目?

I thought about taking the Entries from the Space storing them in a list and then returning them to the Space when no new entries are left but this would introduce all sorts of confusion, lost data and loose multi-user compatibility. 我考虑过从空间中获取条目并将它们存储在列表中,然后在没有新条目留下时将它们返回到空间,但这会引起各种混乱,丢失数据和松散的多用户兼容性。

Edit1: 编辑1:

Okay so after fiddling about with my code I figured out a way of doing this. 好吧,在摆弄我的代码之后,我想出了一种方法。

The Template has to be changed to use another parameter ID. 模板必须更改为使用另一个参数ID。

public SpaceEntry (int id, String o, String m){
this.ID = id;
this.Owner = o;
this.Message = m;

} }

Now each time the user wants to add a message the code has to read existing Entries in the Space by incrementing the id value in the template by one until none are left and add the new message with the missing id number. 现在,每次用户想要添加一条消息时,代码都必须通过将模板中的id值增加1直到不留任何内容,并使用缺少的ID号添加新消息来读取空间中的现有条目。 The same code could be run to read all the entries in the space and return them by id number. 可以运行相同的代码来读取空间中的所有条目,并按ID号返回它们。

However this poses a threat if one of the Entries is removed how would the Code deal with a missing ID for example 1,2, ,4, ,_,7 any suggestions? 但是,如果删除其中一个条目,这将构成威胁,代码将如何处理缺少的ID,例如1,2, ,4 ,,_,7有什么建议?

Edit2: 编辑2:

Seems like Transaction Manager might be the way to go.. 似乎事务管理器可能是解决方法。

Upon doing some additional research I've come across the answer to this question. 在进行了其他一些研究之后,我遇到了这个问题的答案。 In order to read multiple Entries you have to implement a transaction manager which basically reads all Entries that match the Template into a transaction, a list of sorts, and the manager only adds the entries that are not already in transaction. 为了读取多个条目,您必须实现一个事务管理器,该管理器基本上将与该模板匹配的所有条目读入一个事务,一个排序列表,并且该管理器仅添加尚未在事务中的条目。 Once the transaction is committed the space Entries remain unchanged but you have a complete list of them. 提交事务后,空间“条目”将保持不变,但您将获得它们的完整列表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM