异步CMIS客户端:与OpenCMIS并行下载或上传多个文件 [英] Asynchronous CMIS client: Download or upload several files in parallel with OpenCMIS

查看:103
本文介绍了异步CMIS客户端:与OpenCMIS并行下载或上传多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenCMIS 0.14的ChangeLog 说:

已将对异步操作的支持添加到客户端 库.

Support for asynchronous operations has been added to the client library.

作为CMIS客户端,如何使用OpenCMIS 0.14或更高版本并行执行几次下载或并行执行几次上传?

As a CMIS client, how to perform several downloads in parallel, or several uploads in parallel, with OpenCMIS 0.14 or above?

由于多线程,我的目标是更快地完成所有操作.我可以在多个线程之间手动共享一个Session对象,但是如果OpenCMIS具有内置功能,我宁愿使用它.

My goal is to finish all operations faster, thanks to multithreading. I could share a Session object between several thread manually, but if OpenCMIS has a built-in feature I would rather use it.

推荐答案

首先,然后,使用此会话创建

Then, use this session to create an asynchronous session:

int maxParallelRequests = 10;
AsyncSessionFactory asyncFactory = AsyncSessionFactoryImpl.newInstance();
asyncSession = asyncFactory.createAsyncSession(session, maxParallelRequests);

然后像使用普通会话对象一样使用此asyncSession.

Then use this asyncSession as you would use a normal session object.

通常您也会想要执行一些同步操作.例如,同步创建一个文件夹,然后异步上传该文件夹中的文件.因为如果您不等待创建文件夹,文档上传可能会失败.在这种情况下,该怎么做:

Often you will want to perform some synchronous operations too. For instance, create a folder synchronously and then asynchronously upload files inside this folder. Because if you don't wait for the folder to be created, document upload will probably fail. Here is how to do in such cases:

// Create the folder synchronously.
Folder folder = session.getRootFolder().createFolder(properties);

// Upload the file asynchronously.
Future<ObjectId> futureDocumentId = asyncSession.createDocument(
  properties,
  new ObjectIdImpl(remoteFolder.getId()),
  contentStream,
  VersioningState.MAJOR
);

请注意上面的asyncSession.createDocument构造,这是因为您无法编写folder.createDocument,因为它将使用同步会话.

Notice the asyncSession.createDocument construct above, it is because you can not write folder.createDocument as it would use the synchronous session.

futureDocumentId变量将在需要时让您获取文档的标识符:

The futureDocumentId variable will let you get the identifier of the document when you need it, if you need it:

ObjectId documentId = futureDocumentId.get();

仅在确实需要时调用此方法,并尽可能晚地调用它.

Only call this method if you really need it, and call it as late as possible.

这篇关于异步CMIS客户端:与OpenCMIS并行下载或上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆