-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathGateway.java
More file actions
1797 lines (1668 loc) · 61.9 KB
/
Gateway.java
File metadata and controls
1797 lines (1668 loc) · 61.9 KB
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
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
*------------------------------------------------------------------------------
* Copyright (C) 2015-2024 University of Dundee. All rights reserved.
*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*------------------------------------------------------------------------------
*/
package omero.gateway;
import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import ome.formats.OMEROMetadataStoreClient;
import omero.RType;
import omero.ServerError;
import omero.client;
import omero.api.ExporterPrx;
import omero.api.IAdminPrx;
import omero.api.IConfigPrx;
import omero.api.IContainerPrx;
import omero.api.IMetadataPrx;
import omero.api.IPixelsPrx;
import omero.api.IProjectionPrx;
import omero.api.IQueryPrx;
import omero.api.IRenderingSettingsPrx;
import omero.api.IRepositoryInfoPrx;
import omero.api.IRoiPrx;
import omero.api.IScriptPrx;
import omero.api.ITypesPrx;
import omero.api.IUpdatePrx;
import omero.api.RawFileStorePrx;
import omero.api.RawPixelsStorePrx;
import omero.api.RenderingEnginePrx;
import omero.api.SearchPrx;
import omero.api.ServiceFactoryPrx;
import omero.api.StatefulServiceInterfacePrx;
import omero.api.ThumbnailStorePrx;
import omero.cmd.CmdCallbackI;
import omero.cmd.HandlePrx;
import omero.cmd.Request;
import omero.gateway.cache.CacheService;
import omero.gateway.exception.ConnectionStatus;
import omero.gateway.exception.DSOutOfServiceException;
import omero.gateway.facility.Facility;
import omero.gateway.util.NetworkChecker;
import omero.grid.ProcessCallbackI;
import omero.grid.ScriptProcessPrx;
import omero.grid.SharedResourcesPrx;
import omero.log.LogMessage;
import omero.log.Logger;
import omero.model.ExperimenterGroupI;
import omero.gateway.model.ExperimenterData;
import omero.gateway.model.GroupData;
import omero.gateway.util.PojoMapper;
import Glacier2.CannotCreateSessionException;
import Glacier2.PermissionDeniedException;
import Ice.ConnectFailedException;
import Ice.DNSException;
import Ice.SocketException;
import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.LinkedListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Multimaps;
/**
* A Gateway for simplifying access to an OMERO server
*
* @author Dominik Lindner <a
* href="mailto:d.lindner@dundee.ac.uk">d.lindner@dundee.ac.uk</a>
* @since 5.1
*/
public class Gateway implements AutoCloseable {
/** Property to indicate that a {@link Connector} has been created */
public static final String PROP_CONNECTOR_CREATED = "PROP_CONNECTOR_CREATED";
/** Property to indicate that a {@link Connector} has been closed */
public static final String PROP_CONNECTOR_CLOSED = "PROP_CONNECTOR_CLOSED";
/** Property to indicate that a session has been created */
public static final String PROP_SESSION_CREATED = "PROP_SESSION_CREATED";
/** Property to indicate that a session has been closed */
public static final String PROP_SESSION_CLOSED = "PROP_SESSION_CLOSED";
/** Property to indicate that client got detached from a session */
public static final String PROP_SESSION_DETACHED = "PROP_SESSION_DETACHED";
/** Property to indicate that a {@link Facility} has been created */
public static final String PROP_FACILITY_CREATED = "PROP_FACILITY_CREATED";
/** Property to indicate that a {@link Facility} has been closed */
public static final String PROP_FACILITY_CLOSED = "PROP_FACILITY_CLOSED";
/** Property to indicate that an import store has been created */
public static final String PROP_IMPORTSTORE_CREATED = "PROP_IMPORTSTORE_CREATED";
/** Property to indicate that an import store has been closed */
public static final String PROP_IMPORTSTORE_CLOSED = "PROP_IMPORTSTORE_CLOSED";
/** Property to indicate that a rendering engine has been created */
public static final String PROP_RENDERINGENGINE_CREATED = "PROP_RENDERINGENGINE_CREATED";
/** Property to indicate that a rendering engine has been closed */
public static final String PROP_RENDERINGENGINE_CLOSED = "PROP_RENDERINGENGINE_CLOSED";
/** Property to indicate that a stateful service has been created */
public static final String PROP_STATEFUL_SERVICE_CREATED = "PROP_SERVICE_CREATED";
/** Property to indicate that a stateful service has been closed */
public static final String PROP_STATEFUL_SERVICE_CLOSED = "PROP_SERVICE_CLOSED";
/** Property to indicate that a stateless service has been created */
public static final String PROP_STATELESS_SERVICE_CREATED = "PROP_STATELESS_SERVICE_CREATED";
/** Reference to a {@link Logger} */
private Logger log;
/** The version of the server the Gateway is connected to */
private String serverVersion;
/** Checks status of the network interfaces */
private NetworkChecker networkChecker;
/** Flag indicating if the Gateway is connected to a server */
private boolean connected = false;
/** Keeps the session alive */
private ScheduledThreadPoolExecutor keepAliveExecutor;
/** The login credentials used for connecting to the server */
private LoginCredentials login;
/** The logged in user */
private ExperimenterData loggedInUser;
/** Holds all {@link Connector}s for different {@link SecurityContext}s */
private ListMultimap<Long, Connector> groupConnectorMap = Multimaps
.<Long, Connector> synchronizedListMultimap(LinkedListMultimap
.<Long, Connector> create());
/** Optional reference to a {@link CacheService} */
private CacheService cacheService;
/** The PropertyChangeSupport */
private final PropertyChangeSupport pcs = new PropertyChangeSupport(this);
/** Thread pool for asynchronous method calls */
private ExecutorService executorService;
/** Flag to indicate that executor threads should be shutdown on disconnect */
private boolean executorShutdownOnDisconnect = false;
private String serverHost;
/**
* Creates a new Gateway instance
* @param log A {@link Logger}
*/
public Gateway(Logger log) {
this(log, null, null, false);
}
/**
* Creates a new Gateway instance
*
* @param log
* A {@link Logger}
* @param cacheService
* A {@link CacheService}, can be <code>null</code>
*
* @deprecated This constructor will be removed in future. Please
* use {@link #Gateway(Logger) instead}
*/
@Deprecated
public Gateway(Logger log, CacheService cacheService) {
this(log, cacheService, null, true);
}
/**
* Creates a new Gateway instance
*
* @param log
* A {@link Logger}
* @param cacheService
* A {@link CacheService}, can be <code>null</code>
* @param executorService
* A {@link ExecutorService} for handling asynchronous tasks, can
* be <code>null</code> (in which case the Java built-in cached
* thread pool will be used)
* @param executorShutdownOnDisconnect
* Flag to indicate that executor threads should be shutdown on
* disconnect (only taken into account if an
* {@link ExecutorService} was provided; the default cached
* thread pool will be shut down by default)
*
* @deprecated This constructor will be removed in future. Please
* use {@link #Gateway(Logger, ExecutorService, boolean) instead}
*/
@Deprecated
public Gateway(Logger log, CacheService cacheService,
ExecutorService executorService,
boolean executorShutdownOnDisconnect) {
this.log = log;
this.cacheService = cacheService;
this.executorService = executorService == null ? Executors
.newCachedThreadPool() : executorService;
this.executorShutdownOnDisconnect = executorService == null ? true
: executorShutdownOnDisconnect;
}
/**
* Creates a new Gateway instance
*
* @param log
* A {@link Logger}
* @param executorService
* A {@link ExecutorService} for handling asynchronous tasks, can
* be <code>null</code> (in which case the Java built-in cached
* thread pool will be used)
* @param executorShutdownOnDisconnect
* Flag to indicate that executor threads should be shutdown on
* disconnect (only taken into account if an
* {@link ExecutorService} was provided; the default cached
* thread pool will be shut down by default)
*/
public Gateway(Logger log, ExecutorService executorService,
boolean executorShutdownOnDisconnect) {
this.log = log;
this.executorService = executorService == null ? Executors
.newCachedThreadPool() : executorService;
this.executorShutdownOnDisconnect = executorService == null ? true
: executorShutdownOnDisconnect;
}
/**
* Submits an async task
*
* @param task
* The task
* @return The callback reference
*/
public <T> Future<T> submit(Callable<T> task) {
return executorService.submit(task);
}
// Public connection handling methods
/**
* Connect to the server
*
* @param c
* The {@link LoginCredentials}
* @return The {@link ExperimenterData} who is logged in
* @throws DSOutOfServiceException
* If the connection can't be established
*/
public ExperimenterData connect(LoginCredentials c)
throws DSOutOfServiceException {
try {
SessionWrapper session = createSession(c);
loggedInUser = login(session, c);
connected = true;
return loggedInUser;
} catch (CannotCreateSessionException e) {
throw new DSOutOfServiceException("Could not initialize session", e);
} catch (PermissionDeniedException e) {
throw new DSOutOfServiceException("Login credentials not valid", e);
} catch (ServerError e) {
throw new DSOutOfServiceException(e.getMessage(), e);
} catch (ConnectFailedException e) {
throw new DSOutOfServiceException("Can't connect to "
+ c.getServer().getHost(), e);
} catch (SocketException e) {
throw new DSOutOfServiceException(e.getMessage(), e);
} catch (DNSException e) {
throw new DSOutOfServiceException("Can't resolve hostname "
+ c.getServer().getHost(), e);
}
}
/**
* Get the currently logged in user
*
* @return See above.
*/
public ExperimenterData getLoggedInUser() {
return loggedInUser;
}
/**
* Disconnects from the server
*/
public void disconnect() {
if (executorShutdownOnDisconnect) {
// shutdown still running asynchronous tasks
executorService.shutdown();
try {
if (!executorService.awaitTermination(30, TimeUnit.SECONDS)) {
executorService.shutdownNow();
if (!executorService.awaitTermination(30, TimeUnit.SECONDS))
getLogger().warn(this,
"Could not terminate all asynchronous tasks");
}
} catch (InterruptedException ie) {
executorService.shutdownNow();
Thread.currentThread().interrupt();
}
}
boolean online = isNetworkUp(false);
List<Connector> connectors = getAllConnectors();
Iterator<Connector> i = connectors.iterator();
while (i.hasNext())
i.next().shutDownServices(true);
i = connectors.iterator();
while (i.hasNext()) {
try {
i.next().close(online);
} catch (Throwable e) {
if (log != null) {
log.warn(this, new LogMessage("Cannot close connector", e));
}
}
}
Facility.clear();
groupConnectorMap.clear();
if (keepAliveExecutor != null)
keepAliveExecutor.shutdown();
connected = false;
if (cacheService != null)
cacheService.shutDown();
}
/**
* Check if the Gateway is still connected to the server
*
* @return See above.
*/
public boolean isConnected() {
return connected;
}
/**
* Get the ID of the current session
*
* @param user
* The user to get the session ID for
* @return See above
* @throws DSOutOfServiceException
* If the connection is broken, or not logged in
*/
public String getSessionId(ExperimenterData user)
throws DSOutOfServiceException {
Connector c = getConnector(new SecurityContext(user.getGroupId()),
false, false);
if (c != null) {
return c.getClient().getSessionId();
}
return null;
}
/**
* Get the version of the server the Gateway is connected to
*
* @return See above
* @throws DSOutOfServiceException
* If the connection is broken, or not logged in
*/
public String getServerVersion() throws DSOutOfServiceException {
if (serverVersion == null) {
throw new DSOutOfServiceException("Not logged in.");
}
return serverVersion;
}
/**
* Get the hostname of the server the Gateway is connected to
*
* @return See above
* @throws DSOutOfServiceException
* If the connection is broken, or not logged in
*/
public String getServerHost() throws DSOutOfServiceException{
if (serverHost == null) {
throw new DSOutOfServiceException("Not logged in.");
}
return serverHost;
}
/**
* Get a {@link Facility} to perform further operations with the server
*
* @param type
* The kind of {@link Facility} to request
* @return See above
* @throws ExecutionException
* If the {@link Facility} can't be retrieved or instantiated
*/
public <T extends Facility> T getFacility(Class<T> type)
throws ExecutionException {
return Facility.getFacility(type, this);
}
// General public methods
/**
* Adds a {@link PropertyChangeListener}
* @param listener The listener
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
this.pcs.addPropertyChangeListener(listener);
}
/**
* Removes a {@link PropertyChangeListener}
* @param listener The listener
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
this.pcs.removePropertyChangeListener(listener);
}
/**
* Get the {@link PropertyChangeListener}s
* @return See above
*/
public PropertyChangeListener[] getPropertyChangeListeners() {
return this.pcs.getPropertyChangeListeners();
}
/**
* Executes the commands.
*
* @param ctx
* The {@link SecurityContext}
* @param commands
* The commands to execute.
* @param target
* The target context is any.
* @return See above.
* @throws Throwable If an error occurred
*/
public CmdCallbackI submit(SecurityContext ctx, List<Request> commands,
SecurityContext target) throws Throwable {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.submit(commands, target);
return null;
}
/**
* Directly submit a {@link Request} to the server
*
* @param ctx
* The {@link SecurityContext}
* @param cmd
* The {@link Request} to submit
* @return A callback reference, {@link CmdCallbackI}
* @throws Throwable If an error occurred
*/
public CmdCallbackI submit(SecurityContext ctx, Request cmd)
throws Throwable {
Connector c = getConnector(ctx, true, false);
if (c != null) {
client client = getConnector(ctx, true, false).getClient();
HandlePrx handle = client.getSession().submit(cmd);
return new CmdCallbackI(client, handle);
}
return null;
}
/**
* Close Import for a certain user
*
* @param ctx
* The {@link SecurityContext}
* @param userName
* The name of the user which import should be closed
*/
public void closeImport(SecurityContext ctx, String userName) {
try {
Connector c = getConnector(ctx, false, true);
if (c != null) {
if (StringUtils.isNotEmpty(userName))
c = c.getConnector(userName);
c.closeImport();
}
} catch (Throwable e) {
if (log != null)
log.warn(this, "Failed to close import: " + e);
}
}
/**
* Run a script on the server
*
* @param ctx
* The {@link SecurityContext}
* @param scriptID
* The ID of the script
* @param parameters
* Parameters for the script
* @return A callback reference, {@link ProcessCallbackI}
* @throws DSOutOfServiceException
* If the connection is broken, or not logged in
* @throws ServerError If an error in the script execution occurred
*/
public ProcessCallbackI runScript(SecurityContext ctx, long scriptID,
Map<String, RType> parameters) throws DSOutOfServiceException,
ServerError {
Connector c = getConnector(ctx);
if (c == null)
return null;
IScriptPrx svc = c.getScriptService();
ScriptProcessPrx prx = svc.runScript(scriptID, parameters, null);
return new ProcessCallbackI(c.getClient(), prx);
}
/**
* Provides access to the {@link Logger}
*
* @return See above
*/
public Logger getLogger() {
return log;
}
/**
* Provides access to the {@link CacheService}
*
* @return See above
*
* @deprecated This method will be removed in future.
*/
@Deprecated
public CacheService getCacheService() {
return cacheService;
}
// Public service access methods
/**
* Returns the {@link SharedResourcesPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public SharedResourcesPrx getSharedResources(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getSharedResources();
return null;
}
/**
* Returns the {@link IRenderingSettingsPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IRenderingSettingsPrx getRenderingSettingsService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getRenderingSettingsService();
return null;
}
/**
* Returns the {@link IRepositoryInfoPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IRepositoryInfoPrx getRepositoryService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getRepositoryService();
return null;
}
/**
* Returns the {@link IScriptPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IScriptPrx getScriptService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getScriptService();
return null;
}
/**
* Returns the {@link IContainerPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IContainerPrx getPojosService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getPojosService();
return null;
}
/**
* Returns the {@link IQueryPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IQueryPrx getQueryService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getQueryService();
return null;
}
/**
* Returns the {@link IUpdatePrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IUpdatePrx getUpdateService(SecurityContext ctx)
throws DSOutOfServiceException {
return getUpdateService(ctx, null);
}
/**
* Returns the {@link IUpdatePrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @param userName The username
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IUpdatePrx getUpdateService(SecurityContext ctx, String userName)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (StringUtils.isNotEmpty(userName)) {
try {
c = c.getConnector(userName);
} catch (Throwable e) {
throw new DSOutOfServiceException(
"Can't get derived connector.", e);
}
}
if (c != null)
return c.getUpdateService();
return null;
}
/**
* Returns the {@link IMetadataPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IMetadataPrx getMetadataService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getMetadataService();
return null;
}
/**
* Returns the {@link IRoiPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IRoiPrx getROIService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getROIService();
return null;
}
/**
* Returns the {@link IConfigPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IConfigPrx getConfigService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getConfigService();
return null;
}
/**
* Returns the {@link ThumbnailStorePrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public ThumbnailStorePrx getThumbnailService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getThumbnailService();
return null;
}
/**
* Returns the {@link ExporterPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public ExporterPrx getExporterService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getExporterService();
return null;
}
/**
* Returns the {@link RawFileStorePrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException Thrown if the service cannot be initialized.
*/
public RawFileStorePrx getRawFileService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getRawFileService();
return null;
}
/**
* Returns the {@link RawPixelsStorePrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public RawPixelsStorePrx getPixelsStore(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getPixelsStore();
return null;
}
/**
* Returns the {@link IPixelsPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IPixelsPrx getPixelsService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getPixelsService();
return null;
}
/**
* Returns the {@link SearchPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public SearchPrx getSearchService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getSearchService();
return null;
}
/**
* Returns the {@link IProjectionPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IProjectionPrx getProjectionService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getProjectionService();
return null;
}
/**
* Returns the {@link IAdminPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IAdminPrx getAdminService(SecurityContext ctx)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getAdminService();
return null;
}
/**
* Returns the {@link IAdminPrx} service.
*
* @param ctx
* The {@link SecurityContext}
* @param secure
* Pass <code>true</code> to have a secure admin service,
* <code>false</code> otherwise.
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public IAdminPrx getAdminService(SecurityContext ctx, boolean secure)
throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (c != null)
return c.getAdminService();
return null;
}
/**
* Creates or recycles the import store.
* @param ctx The {@link SecurityContext}
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public OMEROMetadataStoreClient getImportStore(SecurityContext ctx)
throws DSOutOfServiceException {
return getImportStore(ctx, null);
}
/**
* Creates or recycles the import store.
* @param ctx The {@link SecurityContext}
* @param userName The username
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
*/
public OMEROMetadataStoreClient getImportStore(SecurityContext ctx,
String userName) throws DSOutOfServiceException {
Connector c = getConnector(ctx, true, false);
if (StringUtils.isNotEmpty(userName)) {
try {
c = c.getConnector(userName);
} catch (Throwable e) {
throw new DSOutOfServiceException(
"Can't get derived connector.", e);
}
}
if (c != null)
return c.getImportStore();
return null;
}
/**
* Returns the {@link RenderingEnginePrx Rendering service}.
* @param ctx The {@link SecurityContext}
* @param pixelsID The pixels ID
* @return See above.
* @throws DSOutOfServiceException
* Thrown if the service cannot be initialized.
* @throws ServerError
* Thrown if the service cannot be initialized.
*/
public RenderingEnginePrx getRenderingService(SecurityContext ctx,
long pixelsID) throws DSOutOfServiceException,
ServerError {
Connector c = getConnector(ctx, true, false);
if (c != null) {
RenderingEnginePrx re = c.getRenderingService(pixelsID, ctx.getCompression());
re.lookupPixels(pixelsID);
return re;
}
return null;
}
// Internal helper methods
/**
* Clears the groupConnector Map
*
* @return The connectors the map held previously
*/
private List<Connector> removeAllConnectors() {
synchronized (groupConnectorMap) {
// This should be the only location which calls values().
List<Connector> rv = new ArrayList<Connector>(
groupConnectorMap.values());
groupConnectorMap.clear();
return rv;
}
}