Skip to content

Commit 07eae6c

Browse files
committed
Add method to import images using multiple threads
1 parent a7b2f0a commit 07eae6c

4 files changed

Lines changed: 53 additions & 7 deletions

File tree

src/main/java/fr/igred/omero/repository/DatasetWrapper.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,28 @@ public void removeImage(Client client, ImageWrapper image)
463463
*/
464464
public boolean importImages(Client client, String... paths)
465465
throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException {
466-
boolean success = importImages(client, data, paths);
466+
return importImages(client, 1, paths);
467+
}
468+
469+
470+
/**
471+
* Imports all images candidates in the paths to the dataset in OMERO.
472+
*
473+
* @param client The client handling the connection.
474+
* @param threads The number of threads (same value used for filesets and uploads).
475+
* @param paths Paths to the image files on the computer.
476+
*
477+
* @return If the import did not exit because of an error.
478+
*
479+
* @throws ServiceException Cannot connect to OMERO.
480+
* @throws AccessException Cannot access data.
481+
* @throws OMEROServerError Server error.
482+
* @throws IOException Cannot read file.
483+
* @throws ExecutionException A Facility can't be retrieved or instantiated.
484+
*/
485+
public boolean importImages(Client client, int threads, String... paths)
486+
throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException {
487+
boolean success = importImages(client, data, threads, paths);
467488
refresh(client);
468489
return success;
469490
}

src/main/java/fr/igred/omero/repository/GenericRepositoryObjectWrapper.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,17 +70,18 @@ protected GenericRepositoryObjectWrapper(T o) {
7070
/**
7171
* Imports all images candidates in the paths to the target in OMERO.
7272
*
73-
* @param client The client handling the connection.
74-
* @param target The import target.
75-
* @param paths Paths to the image files on the computer.
73+
* @param client The client handling the connection.
74+
* @param target The import target.
75+
* @param threads The number of threads (same value used for filesets and uploads).
76+
* @param paths Paths to the image files on the computer.
7677
*
7778
* @return If the import did not exit because of an error.
7879
*
7980
* @throws ServiceException Cannot connect to OMERO.
8081
* @throws OMEROServerError Server error.
8182
* @throws IOException Cannot read file.
8283
*/
83-
protected static boolean importImages(GatewayWrapper client, DataObject target, String... paths)
84+
protected static boolean importImages(GatewayWrapper client, DataObject target, int threads, String... paths)
8485
throws ServiceException, OMEROServerError, IOException {
8586
boolean success;
8687

@@ -89,6 +90,8 @@ protected static boolean importImages(GatewayWrapper client, DataObject target,
8990
config.target.set(type + ":" + target.getId());
9091
config.username.set(client.getUser().getUserName());
9192
config.email.set(client.getUser().getEmail());
93+
config.parallelFileset.set(threads);
94+
config.parallelUpload.set(threads);
9295

9396
OMEROMetadataStoreClient store = client.getImportStore();
9497
try (OMEROWrapper reader = new OMEROWrapper(config)) {

src/main/java/fr/igred/omero/repository/ScreenWrapper.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,28 @@ public void refresh(GatewayWrapper client) throws ServiceException, AccessExcept
351351
*/
352352
public boolean importImages(GatewayWrapper client, String... paths)
353353
throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException {
354-
boolean success = importImages(client, data, paths);
354+
return this.importImages(client, 1, paths);
355+
}
356+
357+
358+
/**
359+
* Imports all images candidates in the paths to the screen in OMERO.
360+
*
361+
* @param client The client handling the connection.
362+
* @param threads The number of threads (same value used for filesets and uploads).
363+
* @param paths Paths to the image files on the computer.
364+
*
365+
* @return If the import did not exit because of an error.
366+
*
367+
* @throws ServiceException Cannot connect to OMERO.
368+
* @throws AccessException Cannot access data.
369+
* @throws OMEROServerError Server error.
370+
* @throws IOException Cannot read file.
371+
* @throws ExecutionException A Facility can't be retrieved or instantiated.
372+
*/
373+
public boolean importImages(GatewayWrapper client, int threads, String... paths)
374+
throws ServiceException, OMEROServerError, AccessException, IOException, ExecutionException {
375+
boolean success = importImages(client, data, threads, paths);
355376
refresh(client);
356377
return success;
357378
}

src/test/java/fr/igred/omero/repository/ImageImportTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ void testImportImage() throws Exception {
4949

5050
DatasetWrapper dataset = client.getDataset(DATASET2.id);
5151

52-
boolean imported = dataset.importImages(client, f1.getAbsolutePath(), f2.getAbsolutePath());
52+
boolean imported = dataset.importImages(client, 2, f1.getAbsolutePath(), f2.getAbsolutePath());
53+
client.closeImport();
5354

5455
removeFile(f1);
5556
removeFile(f2);

0 commit comments

Comments
 (0)