- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
在 i386 上使用 dds 库进行操作,尝试重复提取样本。我明确地“读取
”而不是“获取
”样本,因此它们永远不会过期或被删除。
看来我“打破”了它!我相信样本的生命周期应该是无穷大(或者说我已经理解了......但无法确认!) - 但我无法明确设置它。 topicQos.lifespan.duration
的类型为 Duration_t
,但我无法将其设置为“new Duration_t(Duration_t.DURATION_INFINITY_SEC,Duration_t.DURATION_INFINITY_NSEC)
”,因为它已经最终确定?
public class Main {
private static final String EVENT_TOPIC_NAME = "EVENTS";
private static BufferedReader in = null;
private static PrintStream out = null;
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintStream(new BufferedOutputStream(System.out));
DomainParticipantFactory factory = DomainParticipantFactory.TheParticipantFactory;
DomainParticipant participant = factory.create_participant(100,
DomainParticipantFactory.PARTICIPANT_QOS_DEFAULT,
null,
StatusKind.STATUS_MASK_NONE);
EventTypeSupport.register_type(participant, EventTypeSupport.get_type_name());
TopicQos topicQos = new TopicQos();
topicQos.durability.direct_communication = true;
topicQos.durability.kind = DurabilityQosPolicyKind.TRANSIENT_DURABILITY_QOS;
topicQos.reliability.kind = ReliabilityQosPolicyKind.RELIABLE_RELIABILITY_QOS;
topicQos.resource_limits.max_instances = 100;
topicQos.resource_limits.max_samples = 100;
topicQos.resource_limits.max_samples_per_instance = 1;
topicQos.ownership.kind = OwnershipQosPolicyKind.SHARED_OWNERSHIP_QOS;
topicQos.history.kind = HistoryQosPolicyKind.KEEP_LAST_HISTORY_QOS;
topicQos.history.depth = 1;
topicQos.history.refilter = RefilterQosPolicyKind.ALL_REFILTER_QOS;
// Since this is on the same computer, and being typed by a human, we can exepct source timestamps to be useful in ordering
topicQos.destination_order.kind = DestinationOrderQosPolicyKind.BY_SOURCE_TIMESTAMP_DESTINATIONORDER_QOS;
Topic topic =
participant.create_topic(EVENT_TOPIC_NAME,
EventTypeSupport.get_type_name(),
topicQos,
new EventTopicListener(),
StatusKind.STATUS_MASK_ALL);
exitIfNullBecause(topic, "Could not create topic");
Subscriber subscriber = participant.create_subscriber(DomainParticipant.SUBSCRIBER_QOS_DEFAULT,
null,
StatusKind.STATUS_MASK_NONE);
exitIfNullBecause(subscriber, "Could not create subscriber");
DataReader reader = subscriber.create_datareader(participant.lookup_topicdescription(EVENT_TOPIC_NAME),
subscriber.DATAREADER_QOS_USE_TOPIC_QOS,
null,
StatusKind.STATUS_MASK_NONE);
exitIfNullBecause(reader, "Could not create reader");
EventDataReader eventReader = (EventDataReader) reader;
Publisher publisher = participant.create_publisher(DomainParticipant.PUBLISHER_QOS_DEFAULT,
null,
StatusKind.STATUS_MASK_NONE);
exitIfNullBecause(publisher, "Could not create publisher");
DataWriter writer = publisher.create_datawriter(topic,
publisher.DATAWRITER_QOS_USE_TOPIC_QOS,
null,
StatusKind.STATUS_MASK_NONE);
exitIfNullBecause(writer, "Could not create writer");
EventDataWriter eventWriter = (EventDataWriter)writer;
boolean loop = true;
byte inputBuffer[] = new byte[1024];
String command;
while(loop){
print("Enter action [read|write|exit]: ");
command = in.readLine();
if(command.startsWith("r")){
dumpCache(eventReader);
} else if(command.startsWith("w")) {
writeCache(eventWriter);
} else if(command.startsWith("e")){
println("exiting...");
System.exit(0);
} else {
println("Unknown: '" + command + "'");
}
}
System.exit(0);
}
private static void print(String output){
out.print(output);
out.flush();
}
private static void println(String output){
out.println(output);
out.flush();
}
private static void exitIfNullBecause(Object thing, String string) {
if (thing == null) {
println("ERROR: " + string);
System.exit(1);
}
}
private static void dumpCache(EventDataReader eventReader) {
// Something interesting here: I can creat it with a collection as a paramter. TODO: Investigate!
EventSeq eventSeq = new EventSeq();
SampleInfoSeq infoSeq = new SampleInfoSeq();
Event event = null;
SampleInfo info = null;
try{
eventReader.read(eventSeq, infoSeq, 100, SampleStateKind.ANY_SAMPLE_STATE, ViewStateKind.ANY_VIEW_STATE, InstanceStateKind.ANY_INSTANCE_STATE);
} catch (Exception e){
println("Cache is empty");
return;
}
Iterator<SampleInfo> infoIter = infoSeq.iterator();
out.printf("| Sensor ID | Event ID | Value |\n");
for(int i=0; i<infoSeq.size(); i++){
event = (Event)eventSeq.get(i);
out.printf("| %9d | %8d | %5d |\n", event.sensor_id, event.event_id, event.value);
}
out.flush();
}
private static void writeCache(EventDataWriter eventWriter) throws IOException {
Event event = new Event();
print("Sensor ID: ");
String sensor_id_str = in.readLine();
print("Event ID: ");
String event_id_str = in.readLine();
print("Value: ");
String value_str = in.readLine();
Event sample = new Event();
sample.sensor_id = Integer.parseInt(sensor_id_str);
sample.event_id = Integer.parseInt(event_id_str);
sample.value = Integer.parseInt(value_str);
InstanceHandle_t handle = eventWriter.register_instance(sample);
// eventWriter.write(sample, handle);
eventWriter.write_w_timestamp(sample, handle, Time_t.now());
out.printf("SensorID: %s, EventID: %s, Value: %s\n",sensor_id_str,event_id_str,value_str); out.flush();
}
}
最佳答案
该问题似乎与生命周期
无关。
我不确定您使用的是哪种 DDS 实现,但根据 DDS 规范,您正在 dumpCache
方法中执行零复制操作。如果您忘记归还贷款,您使用的实现可能会表现出这样的行为。
您通常应该在使用零拷贝读取/获取后return_loan
。
因此,请在 dumpCache
方法末尾添加以下代码:
try{
eventReader.return_loan(eventSeq, infoSeq);
} catch (Exception e){
println("Error returning loan");
return;
}
关于java - DDS DataReader 缓存损坏且无法再访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4108830/
是 dataReader[i] 逻辑上等价于 dataReader.GetValue(i) 他们是一样的吗?它们不同吗?是否存在一种情况比另一种更合适的情况? 有documented differen
我有一个 DataReader...我将 DataReader 的结果用作另一个 DataReader 的参数,该 DataReader 连接到具有存储过程类型的命令。它现在工作得很快,但我担心我的数
我正在尝试验证我的数据库中经过哈希处理和加盐处理的密码。我在用户表用户名、哈希值和盐中创建了一列。现在我想知道我可以使用数据读取器访问其他列值。 我尝试了这个方法,但出现了一条红线。这也是我失败的尝试
正如您可能已经从标题中猜到的,我正在尝试这样做: #region check new nations private void checknewnations() {
我正在实现 IDataReader,我想知道 Dispose 的实现是否应该调用 Close。 此外,Close 是否应该调用 Dispose? 我的猜测是 Close 不应调用 Dispose 而
类似于this question ,但答案从来没有真正解决我想知道的问题。从 DataReader 获取值是否有任何标准?即,是这个 dataReader.GetString(dataReader.G
Microsoft(和许多开发人员)claim SqlDataReader.GetOrdinal 方法提高了从 DataReader 检索值的性能,而不是使用命名查找,即。读者[“列名”]。问题是什么
我们正在使用 Dapper 来映射我们的 sql 数据,到目前为止它运行良好。我有一个案例,我们正在做类似的事情: someObject = con.Query("GetInfoSproc", p,
let reader = selectCommand.ExecuteReader() let getBytesData (x : IDataReader) = let len = reader
所以我对市场之间的冗余标签名称有点问题。例如在使用以下代码获取数据时: from pandas_datareader import data as pdr from datetime import d
我有一个相当复杂的 SQL 查询,它根据客户 ID 从数据库中提取不同类型的产品。它提取三种不同类型的产品,由其唯一标识符编号范围标识(即,ID 1000-1999 是一种产品,2000-2999 是
我的目标是从数据源检索数据,向其中添加一些元数据并将其插入到另一个目标。 目标的架构比源(计算列)多四列。 我正在使用 SqlBulkCopy,它需要一个具有所有列(包括 4 个计算的列)的读取器。
所以基本上我的应用程序中有两个连接: conn = new MySqlConnection("server=" + ip + ";uid=" + user +";pwd=" + pass + ";da
我使用下面的代码在 C# 中从 mySql 获取数据。当我这样做时,我收到代码下方提到的错误。我发现了一些关于这个主题的问题,但他们使用了 DataReader,而我没有。 MySqlConnecti
我使用 EF+MySql,数据库包含两个 foriegnkey,当我运行我的项目时,它说:已经有一个打开的 DataReader 与此连接关联,必须先关闭,然后我将 MultipleActiveRes
我正在尝试创建一个基于变量的DataReader。我需要根据选择了 TreeView 中的哪个节点来填充一系列 TextBoxes,并且父节点数据与子节点数据不同。所以,我写了这段代码: using
我遇到了一个错误,提示我的数据读取器已经打开。 我的代码是这样的 public static Users GetByID(int ID, SqlConnection connection) {
我想做的与 OP 在此处提出的要求类似: Multiples Table in DataReader 我试图将一个或多个 SQL 查询的结果存储到单独的数据表中。上述问题的方法的问题在于它仅适用于每个
我正在遍历我的数据库以显示球员关联的联赛列表。如果玩家不是任何联盟的成员,则会显示一条消息告诉他们。 这是代码 if (dReader.Read()) { while (dR
我只是使用 pandas datareader 来获取过去两周左右的股票数据,它运行良好。突然间,从昨天开始,所提供的日期就不再有效了。它只是给我过去一年的数据,我无法更改日期。曾经与注释掉的那个一起
我是一名优秀的程序员,十分优秀!