3.4. streaming API


Data Grid 提供了一个流 API,它实现了返回 InputStreamOutputStream 实例的方法,以便您可以在 Hot Rod 客户端和 Data Grid 服务器之间流传输大型对象。

考虑以下大型对象示例:

StreamingRemoteCache<String> streamingCache = remoteCache.streaming();
OutputStream os = streamingCache.put("a_large_object");
os.write(...);
os.close();
Copy to Clipboard Toggle word wrap

您可以通过流读取对象,如下所示:

StreamingRemoteCache<String> streamingCache = remoteCache.streaming();
InputStream is = streamingCache.get("a_large_object");
for(int b = is.read(); b >= 0; b = is.read()) {
   // iterate
}
is.close();
Copy to Clipboard Toggle word wrap
注意

Streaming API 不会 marshall 值,这意味着您无法同时使用 Streaming 和 Non-Streaming API 访问相同的条目。但是,您可以实施一个自定义 marshaller 来处理这个问题单。

RemoteStreamingCache.get (K key) 方法返回的 InputStream 实现了 VersionedMetadata 接口,以便您可以检索版本和过期信息,如下所示:

StreamingRemoteCache<String> streamingCache = remoteCache.streaming();
InputStream is = streamingCache.get("a_large_object");
long version = ((VersionedMetadata) is).getVersion();
for(int b = is.read(); b >= 0; b = is.read()) {
   // iterate
}
is.close();
Copy to Clipboard Toggle word wrap
注意

条件写入方法(putIfAbsent () )在值完全发送到服务器后执行实际条件检查。换句话说,当在 OutputStream 上调用 close () 方法时。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat