/
ImportEvent.java
497 lines (417 loc) · 17.7 KB
/
ImportEvent.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
/*
* $Id$
*
* Copyright 2009-2013 Glencoe Software, Inc. All rights reserved.
* Use is subject to license terms supplied in LICENSE.txt
*/
package ome.formats.importer;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import omero.model.Fileset;
import omero.model.IObject;
import omero.model.Pixels;
/**
* Simple event base-class used by {@link IObservable} and {@link IObserver}
* implementations.
*
* @since Beta4.1
*/
public class ImportEvent {
// enums for GROUP_SET types
public static final int GROUP_PUBLIC = 0;
public static final int GROUP_COLLAB_READ = 1;
public static final int GROUP_COLLAB_READ_LINK = 2;
public static final int GROUP_PRIVATE = 3;
public static final int GROUP_SYSTEM = 4;
public String toLog() {
return getClass().getSimpleName();
}
// Base classes
public static class COUNT_EVENT extends ImportEvent {
public final String shortName;
public final Integer index;
public final Integer numDone;
public final Integer total;
COUNT_EVENT(String shortName, Integer index, Integer numDone,
Integer total) {
this.shortName = shortName;
this.index = index;
this.numDone = numDone;
this.total = total;
}
}
public static class PROGRESS_EVENT extends ImportEvent {
public final int index;
public final ImportContainer container;
public final IObject target;
public final Long pixId;
public final int series;
public final ImportSize size;
public final Integer numDone;
public final Integer total;
public PROGRESS_EVENT(int index, ImportContainer container, IObject target, Long pixId,
int series, ImportSize size, Integer numDone, Integer total) {
this.index = index;
this.container = container;
this.target = target;
this.pixId = pixId;
this.series = series;
this.size = size;
this.numDone = numDone;
this.total= total;
}
@Override
public String toLog() {
StringBuilder sb = new StringBuilder();
sb.append(super.toLog());
sb.append(" ");
return sb.toString();
}
}
public static class POST_UPLOAD_EVENT extends PROGRESS_EVENT {
public final Long logFileId;
public POST_UPLOAD_EVENT(int index, ImportContainer container, IObject target, Long pixId,
int series, ImportSize size, Integer numDone, Integer total, Long logFileId) {
super(index, container, target, pixId, series, size, numDone, total);
this.logFileId = logFileId;
}
@Override
public String toLog() {
StringBuilder sb = new StringBuilder();
sb.append(super.toLog());
sb.append(String.format("Step: %d of %d Logfile: %d",
numDone, total, logFileId));
return sb.toString();
}
}
public static class FILE_UPLOAD_EVENT extends ImportEvent {
public final String filename;
public final int fileIndex;
public final int fileTotal;
public final Long uploadedBytes;
public final Long contentLength;
public final Exception exception;
FILE_UPLOAD_EVENT(String filename, int fileIndex, int fileTotal,
Long uploadedBytes, Long contentLength, Exception exception) {
this.filename = filename;
this.fileIndex = fileIndex;
this.fileTotal = fileTotal;
this.uploadedBytes = uploadedBytes;
this.contentLength = contentLength;
this.exception = exception;
}
}
// Data-less events
public static class ADD extends ImportEvent {
}
public static class ERRORS_PENDING extends ImportEvent {
}
public static class ERRORS_COMPLETE extends ImportEvent {
}
public static class ERRORS_FAILED extends ImportEvent {
}
public static class REIMPORT extends ImportEvent {
}
public static class LOGGED_IN extends ImportEvent {
}
public static class LOGGED_OUT extends ImportEvent {
}
// file-upload events
public static class FILE_UPLOAD_STARTED extends FILE_UPLOAD_EVENT {
public FILE_UPLOAD_STARTED(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
}
}
public static class FILE_UPLOAD_BYTES extends FILE_UPLOAD_EVENT {
public Long timeLeft;
public FILE_UPLOAD_BYTES(String filename, int fileIndex, int fileTotal,
Long uploadedBytes, Long contentLength, Long timeLeft,
Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
this.timeLeft = timeLeft;
}
@Override
public String toLog() {
StringBuilder sb = new StringBuilder();
sb.append(super.toLog());
sb.append(String.format(" uploaded: %d of: %d bytes (ETA: %s)",
uploadedBytes, contentLength, msToString(timeLeft)));
return sb.toString();
}
private String msToString(long millis) {
return String.format("%d' %d\"",
TimeUnit.MILLISECONDS.toMinutes(millis),
TimeUnit.MILLISECONDS.toSeconds(millis) -
TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(millis))
);
}
}
public static class FILE_UPLOAD_COMPLETE extends FILE_UPLOAD_EVENT {
public FILE_UPLOAD_COMPLETE(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
}
}
public static class FILE_UPLOAD_FAILED extends FILE_UPLOAD_EVENT {
public FILE_UPLOAD_FAILED(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
}
}
public static class FILE_UPLOAD_ERROR extends FILE_UPLOAD_EVENT {
public FILE_UPLOAD_ERROR(String filename, int fileIndex, int fileTotal,
Long uploadedBytes, Long contentLength, Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
}
}
public static class FILESET_EXCLUSION extends FILE_UPLOAD_EVENT {
public FILESET_EXCLUSION(String filename, int fileIndex, int fileTotal) {
super(filename, fileIndex, fileTotal, 0l, 0l, null);
}
}
public static class FILESET_UPLOAD_PREPARATION extends FILE_UPLOAD_EVENT {
public FILESET_UPLOAD_PREPARATION(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
}
}
public static class FILESET_UPLOAD_START extends FILE_UPLOAD_EVENT {
public FILESET_UPLOAD_START(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
}
}
public static class FILESET_UPLOAD_END extends FILE_UPLOAD_EVENT {
public final String[] srcFiles;
public final List<String> checksums;
public final Map<Integer, String> failingChecksums;
public FILESET_UPLOAD_END(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
String[] srcFiles, List<String> checksums,
Map<Integer, String> failingChecksums, Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
this.srcFiles = srcFiles;
this.checksums = checksums;
this.failingChecksums = failingChecksums;
}
}
public static class FILE_UPLOAD_FINISHED extends FILE_UPLOAD_EVENT {
public FILE_UPLOAD_FINISHED(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
}
}
public static class FILE_UPLOAD_CANCELLED extends FILE_UPLOAD_EVENT {
public FILE_UPLOAD_CANCELLED(String filename, int fileIndex,
int fileTotal, Long uploadedBytes, Long contentLength,
Exception exception) {
super(filename, fileIndex, fileTotal, uploadedBytes, contentLength,
exception);
}
}
// misc-events
public static class DEBUG_SEND extends ImportEvent {
public final boolean sendFiles;
public final boolean sendLogs;
public DEBUG_SEND(boolean sendFiles, boolean sendLogs) {
this.sendFiles = sendFiles;
this.sendLogs = sendLogs;
}
}
public static class IMPORT_STEP extends ImportEvent {
public final int step;
public final int series;
public final int seriesCount;
public IMPORT_STEP(int step, int series, int seriesCount) {
this.step = step;
this.series = series;
this.seriesCount = seriesCount;
}
@Override
public String toLog() {
StringBuilder sb = new StringBuilder();
sb.append(super.toLog());
sb.append(" ");
sb.append(String.format("Image: %d Series: %d Total Series: %d",
step, series, seriesCount));
return sb.toString();
}
}
public static class IMPORT_SUMMARY extends ImportEvent {
public final long importTime;
public final int errorCount;
public IMPORT_SUMMARY(long importTime, int errorCount) {
this.importTime = importTime;
this.errorCount = errorCount;
}
}
// count-events
public static class LOADING_IMAGE extends COUNT_EVENT {
public LOADING_IMAGE(String shortName, Integer index, Integer numDone,
Integer total) {
super(shortName, index, numDone, total);
}
@Override
public String toLog() {
return String.format("%s: %s", super.toLog(), shortName);
}
}
public static class LOADED_IMAGE extends COUNT_EVENT {
public LOADED_IMAGE(String shortName, Integer index, Integer numDone,
Integer total) {
super(shortName, index, numDone, total);
}
@Override
public String toLog() {
return String.format("%s: %s", super.toLog(), shortName);
}
}
//
// Progress-based events: these are used by the FileQueueTable (and others)
// to know which file index is currently in which state. They should
// possibly
// be moved closer to the classes using them.
//
public static class BEGIN_POST_PROCESS extends PROGRESS_EVENT {
public BEGIN_POST_PROCESS(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size) {
super(index, container, target, pixId, series, size, null, null);
}
}
public static class END_POST_PROCESS extends PROGRESS_EVENT {
public END_POST_PROCESS(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size) {
super(index, container, target, pixId, series, size, null, null);
}
}
public static class BEGIN_SAVE_TO_DB extends PROGRESS_EVENT {
public BEGIN_SAVE_TO_DB(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size) {
super(index, container, target, pixId, series, size, null, null);
}
}
public static class END_SAVE_TO_DB extends PROGRESS_EVENT {
public END_SAVE_TO_DB(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size) {
super(index, container, target, pixId, series, size, null, null);
}
}
public static class DATASET_STORED extends PROGRESS_EVENT {
public DATASET_STORED(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size, Integer numDone, Integer total) {
super(index, container, target, pixId, series, size, numDone, total);
}
}
public static class DATA_STORED extends PROGRESS_EVENT {
public DATA_STORED(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size) {
super(index, container, target, pixId, series, size, null, null);
}
}
public static class IMPORT_ARCHIVING extends PROGRESS_EVENT {
public IMPORT_ARCHIVING(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size) {
super(index, container, target, pixId, series, size, null, null);
}
}
public static class IMPORT_OVERLAYS extends PROGRESS_EVENT {
public IMPORT_OVERLAYS(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size) {
super(index, container, target, pixId, series, size, null, null);
}
}
public static class IMPORT_PROCESSING extends PROGRESS_EVENT {
public IMPORT_PROCESSING(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size) {
super(index, container, target, pixId, series, size, null, null);
}
}
// These extra PROGRESS_EVENT classes are added to allow some meaningful
// event reporting under FS rather than abusing the ones above
public static class IMPORT_STARTED extends POST_UPLOAD_EVENT {
public IMPORT_STARTED(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size,
Integer numDone, Integer total, Long fsId) {
super(index, container, target, pixId, series, size, numDone, total, fsId);
}
@Override
public String toLog() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(String.format(" Logfile: %d", logFileId));
return sb.toString();
}
}
public static class METADATA_IMPORTED extends POST_UPLOAD_EVENT {
public METADATA_IMPORTED(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size,
Integer numDone, Integer total, Long fsId) {
super(index, container, target, pixId, series, size, numDone, total, fsId);
}
}
public static class THUMBNAILS_GENERATED extends POST_UPLOAD_EVENT {
public THUMBNAILS_GENERATED(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size,
Integer numDone, Integer total, Long fsId) {
super(index, container, target, pixId, series, size, numDone, total, fsId);
}
}
public static class PIXELDATA_PROCESSED extends POST_UPLOAD_EVENT {
public PIXELDATA_PROCESSED(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size,
Integer numDone, Integer total, Long fsId) {
super(index, container, target, pixId, series, size, numDone, total, fsId);
}
}
public static class METADATA_PROCESSED extends POST_UPLOAD_EVENT {
public METADATA_PROCESSED(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size,
Integer numDone, Integer total, Long fsId) {
super(index, container, target, pixId, series, size, numDone, total, fsId);
}
}
public static class OBJECTS_RETURNED extends POST_UPLOAD_EVENT {
public OBJECTS_RETURNED(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size,
Integer numDone, Integer total, Long fsId) {
super(index, container, target, pixId, series, size, numDone, total, fsId);
}
}
public static class IMPORT_DONE extends PROGRESS_EVENT {
public final List<Pixels> pixels;
public final Fileset fileset;
public final List<IObject> objects;
public IMPORT_DONE(int index, ImportContainer container, IObject target,
Long pixId, int series, ImportSize size, List<Pixels> pixels,
Fileset fileset, List<IObject> objects) {
super(index, container, target, pixId, series, size, null, null);
this.pixels = pixels;
this.fileset = fileset;
this.objects = objects;
}
@Override
public String toLog() {
StringBuilder sb = new StringBuilder();
sb.append(getClass().getSimpleName());
sb.append(String.format(" Imported file: %s", container.getFile().getAbsolutePath()));
return sb.toString();
}
}
}