forked from LAL/xtremweb-hep
/
CommClient.java
2670 lines (2389 loc) · 69.8 KB
/
CommClient.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
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
/*
* Copyrights : CNRS
* Author : Oleg Lodygensky
* Acknowledgment : XtremWeb-HEP is based on XtremWeb 1.8.0 by inria : http://www.xtremweb.net/
* Web : http://www.xtremweb-hep.org
*
* This file is part of XtremWeb-HEP.
*
* XtremWeb-HEP 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 3 of the License, or
* (at your option) any later version.
*
* XtremWeb-HEP 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 XtremWeb-HEP. If not, see <http://www.gnu.org/licenses/>.
*
*/
package xtremweb.communications;
/**
* CommClient.java
*
*
* Created: Jun 2nd, 2005
*
* @author Oleg Lodygensky
* @since RPCXW
*/
import java.io.BufferedInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.NoRouteToHostException;
import java.net.SocketTimeoutException;
import java.net.URISyntaxException;
import java.net.UnknownHostException;
import java.security.AccessControlException;
import java.security.InvalidKeyException;
import java.util.Vector;
import java.util.Collection;
import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.Iterator;
import javax.net.ssl.SSLHandshakeException;
import org.xml.sax.SAXException;
import xtremweb.common.AppInterface;
import xtremweb.common.Cache;
import xtremweb.common.DataInterface;
import xtremweb.common.GroupInterface;
import xtremweb.common.HostInterface;
import xtremweb.common.Logger;
import xtremweb.common.LoggerLevel;
import xtremweb.common.MileStone;
import xtremweb.common.SessionInterface;
import xtremweb.common.StatusEnum;
import xtremweb.common.Table;
import xtremweb.common.TaskInterface;
import xtremweb.common.TraceInterface;
import xtremweb.common.UID;
import xtremweb.common.UserGroupInterface;
import xtremweb.common.UserInterface;
import xtremweb.common.Version;
import xtremweb.common.WorkInterface;
import xtremweb.common.WorkerParameters;
import xtremweb.common.XMLHashtable;
import xtremweb.common.XMLReader;
import xtremweb.common.XMLValue;
import xtremweb.common.XMLVector;
import xtremweb.common.XMLable;
import xtremweb.common.XWConfigurator;
import xtremweb.common.XWPropertyDefs;
import xtremweb.common.XWTools;
import xtremweb.security.XWAccessRights;
public abstract class CommClient implements ClientAPI {
private final Logger logger;
/**
* @since 7.0.0
*/
public void setLoggerLevel(final LoggerLevel l) {
logger.setLoggerLevel(l);
}
/**
* This is the cache where download object are cached
*/
private static Cache cache = null;
/**
* This hashtable stores known communication handlers. Keys are
* communications schemes; values are CommClient objects.<br />
* This is automatically initialized with the tuple:<br />
* (xtremweb.communications.Connection.XWSCHEME,
* xtremweb.common.XWPropertyDefs.COMMLAYER)<br />
* This is then filled as needs
*
* @see #getClient(URI)
* @see xtremweb.communications.Connection#XWSCHEME
* @see xtremweb.common.XWPropertyDefs#COMMHANDLERS
*/
private static Hashtable commHandlers = null;
/**
* This contains configuration
*/
private static XWConfigurator config = null;
/**
* @return the logger
*/
public Logger getLogger() {
return logger;
}
/**
* This is max amount of times we try on socket time out exception
*
* @since 7.4.0
*/
private static int socketRetries;
/**
* @return the soretries
*/
public static int getSocketRetries() {
return socketRetries;
}
/**
* This aims to display some time stamps
*/
private final MileStone mileStone;
protected void mileStone(final String msg) {
mileStone.println(msg);
}
/**
* This retrieve this client port number
*
* @since 5.9.0
*/
public abstract int getPort();
/**
* This creates a new URI to connect to current dispatcher The URI path
* contains the UID (e.g. xw://monserver; xw://monserver/uid)
*
* @param uid
* is the uid used as path if the returned uri, if not null
* @see xtremweb.communications.URI#URI(String, UID)
*/
public URI newURI(final UID uid) throws URISyntaxException {
logger.finest("CommClient#newURI " + config.getCurrentDispatcher() + ":" + getPort() + "/" + uid);
final URI ret = new URI(config.getCurrentDispatcher(), uid);
return ret;
}
/**
* This call newURI(null)
*
* @see #newURI(UID)
*/
public URI newURI() throws URISyntaxException {
return newURI((UID) null);
}
/**
* This opens communications channel
*/
protected abstract void open(URI u) throws UnknownHostException, NoRouteToHostException, SSLHandshakeException,
SocketTimeoutException, IOException;
/**
* This closes communications channel
*/
public abstract void close();
/**
* This tells whether communication channel should be automatically closed
* or if this is left to the entity using this CommClient. Default is true :
* communications are automatically closed
*
* @since 7.4.0
*/
private boolean autoClose = true;
/**
* @return the autoClose
*/
public boolean isAutoClose() {
return autoClose;
}
/**
* This sets autoClose attribute
*
* @since 7.4.0
*/
public void setAutoClose(final boolean c) {
autoClose = c;
}
/**
* this tells if communication channel is opened
*/
private boolean opened = false;
/**
* @return the opened
*/
public boolean isOpened() {
return opened;
}
/**
* @param opened
* the opened to set
*/
public void setOpened(final boolean opened) {
this.opened = opened;
}
/*
* this contains the amount of messages already sent
*
* @see util#MAXMESSAGES
*/
private int nbMessages = 0;
/**
* @return the nbMessages
*/
public int getNbMessages() {
return nbMessages;
}
/**
* @param nbMessages
* the nbMessages to set
*/
public void setNbMessages(final int nbMessages) {
this.nbMessages = nbMessages;
}
/**
* This writes an object to output channel
*/
protected abstract void write(XMLRPCCommand cmd) throws IOException;
/**
* This is the default constructor; this set connectionless to true, opened
* to false
*/
protected CommClient() {
logger = new Logger(this);
mileStone = new MileStone(getClass());
nbMessages = 0;
autoClose = true;
opened = false;
}
/**
* This does nothing if config is already set. Otherwise this calls
* changeConfig(c)
*
* @see #changeConfig(XWConfigurator)
* @exception IOException
* is thrown if cache directory can not be created
*/
public static void setConfig(final XWConfigurator c) throws IOException {
if (config != null) {
return;
}
changeConfig(c);
}
/**
* This configures this object : this extracts communication layers from
* config file and instantiates communication handlers accordingly. This
* also sets the cache
*
* @param c
* is the configuration
* @exception IOException
* is thrown if cache directory can not be created
*/
public static void changeConfig(final XWConfigurator c) throws IOException {
config = c;
cache = new Cache(config);
commHandlers = new Hashtable();
final Hashtable layers = (Hashtable) XWTools.hash(config.getProperty(XWPropertyDefs.COMMHANDLERS));
final Enumeration enumLayers = layers.keys();
socketRetries = config.getInt(XWPropertyDefs.SORETRIES);
while (enumLayers.hasMoreElements()) {
final String key = (String) enumLayers.nextElement();
final String value = (String) layers.get(key);
try {
addHandler(key, value);
} catch (final Exception e) {
new Logger().exception("Init comm layers: ignoring (" + key + ", " + value + ")", e);
}
}
try {
if (commHandlers.get(Connection.xwScheme()) == null) {
final String defaultLayer = config.getProperty(XWPropertyDefs.COMMLAYER);
addHandler(Connection.xwScheme(), defaultLayer);
}
if (commHandlers.get(Connection.xwsScheme()) == null) {
addHandler(Connection.xwsScheme(), config.getProperty(XWPropertyDefs.COMMLAYER));
}
if (commHandlers.get(Connection.httpScheme()) == null) {
addHandler(Connection.httpScheme(), Connection.HTTPPORT.layer());
}
if (commHandlers.get(Connection.httpsScheme()) == null) {
addHandler(Connection.httpsScheme(), Connection.HTTPPORT.layer());
}
} catch (final Exception e) {
new Logger().exception(e);
XWTools.fatal("init comm layers : " + e);
}
}
/**
* This clears the cache
*/
public void clearCache() {
cache.clear();
}
/**
* This adds or replaces a comm handler
*/
public static void addHandler(final String schema, final String className) {
commHandlers.put(schema, className);
}
/**
* This constructs an object accordingly to the URI scheme; the URI schema
* defines the object type
*
* @see #commHandlers
* @param scheme
* is the URI scheme to retrieve client for
* @throws InstantiationException
* if the class referred by the scheme can not be instantiated
*/
public static CommClient getClient(final String scheme) throws InstantiationException {
if (scheme == null) {
throw new InstantiationException("scheme is null");
}
if (commHandlers == null) {
throw new InstantiationException("Comm Handlers not initialized");
}
try {
return (CommClient) (Class.forName((String) commHandlers.get(scheme))).newInstance();
} catch (final IllegalAccessException e) {
throw new InstantiationException(e.getMessage());
} catch (final ClassNotFoundException e) {
throw new InstantiationException(e.getMessage());
}
}
/**
* This calls getClient(uri.getScheme())
*
* @see #commHandlers
* @see #getClient(String)
* @param uri
* is the URI to connect to
* @throws InstantiationException
* if the class referred by the scheme can not be instantiated
*/
public static CommClient getClient(final URI uri) throws InstantiationException {
return getClient(uri.getScheme());
}
/**
* This retrieves the configuration
*
* @return this client configuration
*/
public XWConfigurator getConfig() {
return config;
}
/**
* This sends an XMLRPC command to be executed on server side This uses
* config._user, if cmd.getUser == null Since 2.2.0, all command needs an
* answer : we don't close comm channel here
*
* @param cmd
* is the command to send
* @throws IOException
* @throws UnknownHostException
* @throws SocketTimeoutException
* @throws SSLHandshakeException
* @throws NoRouteToHostException
*/
@Override
public void sendCommand(final XMLRPCCommand cmd) throws NoRouteToHostException, SSLHandshakeException,
SocketTimeoutException, UnknownHostException, IOException {
try {
mileStone("<sendCommand idrpc='" + cmd.getIdRpc().toString() + "'>");
open(cmd.getURI());
if (cmd.getUser() == null) {
cmd.setUser(config.getUser());
}
logger.finest("sendCommand " + cmd.toXml());
write(cmd);
++nbMessages;
} finally {
mileStone("</sendCommand>");
}
}
/**
* This sends (creates or updates) an object definition
*
* @since 5.0.0
*/
@Override
public void send(final XMLRPCCommandSend command)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
try {
sendCommand(command);
newXMLVector();
} finally {
close();
}
}
/**
* This writes a file to output channel
*/
@Override
public abstract void writeFile(File f) throws IOException;
/**
* This reads a file from input channel
*/
@Override
public abstract void readFile(File f) throws IOException;
/**
* This creates an object from channel
*/
protected abstract AppInterface newAppInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract DataInterface newDataInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract Table newTableInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract GroupInterface newGroupInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract HostInterface newHostInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract SessionInterface newSessionInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract TaskInterface newTaskInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract TraceInterface newTraceInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract UserInterface newUserInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract UserGroupInterface newUserGroupInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract WorkInterface newWorkInterface()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract Version newXMLVersion()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract XMLVector newXMLVector()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected abstract XMLHashtable newXMLHashtable()
throws InvalidKeyException, AccessControlException, IOException, SAXException;
/**
* This creates an object from channel
*/
protected Table newTableInterface(final InputStream in)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final BufferedInputStream input = new BufferedInputStream(in);
try {
input.mark(XWTools.BUFFEREND);
return newWorkInterface(input);
} catch (final SAXException e) {
}
try {
input.reset();
input.mark(XWTools.BUFFEREND);
return newTaskInterface(input);
} catch (final SAXException e) {
}
try {
input.reset();
input.mark(XWTools.BUFFEREND);
return newAppInterface(input);
} catch (final SAXException e) {
}
try {
input.reset();
input.mark(XWTools.BUFFEREND);
return newDataInterface(input);
} catch (final SAXException e) {
}
try {
input.reset();
input.mark(XWTools.BUFFEREND);
return newUserInterface(input);
} catch (final SAXException e) {
}
try {
input.reset();
input.mark(XWTools.BUFFEREND);
return newGroupInterface(input);
} catch (final SAXException e) {
}
try {
input.reset();
input.mark(XWTools.BUFFEREND);
return newSessionInterface(input);
} catch (final SAXException e) {
}
try {
input.reset();
input.mark(XWTools.BUFFEREND);
return newHostInterface(input);
} catch (final SAXException e) {
}
try {
input.reset();
input.mark(XWTools.BUFFEREND);
return newUserGroupInterface(input);
} catch (final SAXException e) {
}
try {
input.reset();
input.mark(XWTools.BUFFEREND);
return newTraceInterface(input);
} catch (final SAXException e) {
}
throw new IOException("Unable to create new Interface from input stream");
}
/**
* This creates an object from channel
*/
protected <T extends Table> T newTableInterface(final T itf, final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
try {
mileStone("<newTableInterface itf='" + itf.getClass() + "'>");
final XMLReader reader = new XMLReader(itf);
reader.read(input);
} finally {
mileStone("</newTableInterface>");
}
return itf;
}
/**
* This creates an object from channel
*/
protected AppInterface newAppInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final AppInterface itf = new AppInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected DataInterface newDataInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final DataInterface itf = new DataInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected GroupInterface newGroupInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final GroupInterface itf = new GroupInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected HostInterface newHostInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final HostInterface itf = new HostInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected SessionInterface newSessionInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final SessionInterface itf = new SessionInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected TaskInterface newTaskInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final TaskInterface itf = new TaskInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected TraceInterface newTraceInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final TraceInterface itf = new TraceInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected UserInterface newUserInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final UserInterface itf = new UserInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected UserGroupInterface newUserGroupInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final UserGroupInterface itf = new UserGroupInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected WorkInterface newWorkInterface(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
final WorkInterface itf = new WorkInterface();
return newTableInterface(itf, input);
}
/**
* This creates an object from channel
*/
protected XMLVector newXMLVector(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
try {
mileStone("<newXMLVector>");
final XMLVector ret = new XMLVector();
final XMLReader reader = new XMLReader(ret);
reader.read(input);
return ret;
} finally {
mileStone("</newXMLVector>");
}
}
/**
* This creates an object from channel
*/
protected Version newXMLVersion(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
try {
mileStone("<newXMLVersion>");
final Version ret = new Version();
final XMLReader reader = new XMLReader(ret);
reader.read(input);
return ret;
} finally {
mileStone("</newXMLVersion>");
}
}
/**
* This creates an object from channel
*/
protected XMLHashtable newXMLHashtable(final InputStream input)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
try {
mileStone("<newXMLHashtable>");
final XMLHashtable ret = new XMLHashtable();
final XMLReader reader = new XMLReader(ret);
reader.read(input);
return ret;
} finally {
mileStone("</newXMLHashtable>");
}
}
/**
* This disconnects this client from current dispatcher. Disconnection
* removes sessions from server
*/
@Override
public void disconnect()
throws InvalidKeyException, AccessControlException, IOException, SAXException, URISyntaxException {
disconnect(new XMLRPCCommandDisconnect(newURI(), config.getUser()));
}
/**
* This disconnects this client. Disconnection removes sessions from server
*/
@Override
public void disconnect(final XMLRPCCommandDisconnect command)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
try {
sendCommand(command);
newXMLVector();
} finally {
close();
}
}
/**
* This adds an URI to cache to be able to manage URL too
*/
public void addToCache(final URI uri) throws IOException {
cache.add(uri);
}
/**
* This sets the content file in cache for the given URI
*
* @since 8.0.1
*/
public void setContentFile(final URI uri, final File f) throws IOException {
cache.setContentFile(uri, f);
}
/**
* This adds an URI to cache to be able to manage URL too
*
* @since 4.2.0
*/
public void addToCache(final Table itf, final URI uri) throws IOException {
cache.add(itf, uri);
}
/**
* This retrieves content file for the given UID The object must be already
* cached
*
* @return a File where to store content for the cached object, null
* otherwise
*/
public File getContentFile(final URI uri) throws IOException {
return cache.getContentFile(uri);
}
/**
* This locks an entry in the cache. The object must be already cached.
*
* @since 7.0.0
* @see Cache#unlock(URI)
*/
public void lock(final URI uri) throws IOException {
cache.lock(uri);
}
/**
* This unlocks an entry in the cache.
*
* @since 7.0.0
* @see Cache#lock(URI)
*/
public void unlock(final URI uri) throws IOException {
cache.unlock(uri);
}
/**
* This retrieves server version
*
* @return a Version object
* @since 5.6.1
*/
public Version version()
throws InvalidKeyException, AccessControlException, IOException, SAXException, URISyntaxException {
return version(new XMLRPCCommandVersion(newURI()));
}
/**
* This retrieves server version
*
* @param command
* is the VERSION command to send to server
* @return a Version object
* @since 5.6.1
*/
public Version version(final XMLRPCCommandVersion command)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
Version version = null;
try {
sendCommand(command);
version = newXMLVersion();
} finally {
close();
}
return version;
}
/**
* This calls get(newURI(uid))
*
* @param uid
* is the UID of the object to retreive
* @see #get(URI)
* @since 1.1.0
*/
@Override
public Table get(final UID uid) throws InvalidKeyException, AccessControlException, IOException,
ClassNotFoundException, SAXException, URISyntaxException {
final URI uri = newURI(uid);
return get(uri);
}
/**
* This calls get(uri, true)
*
* @param uri
* is the URI to get the object from
* @see #get(URI, boolean)
* @since 4.2.0
*/
public Table get(final URI uri) throws InvalidKeyException, AccessControlException, IOException,
ClassNotFoundException, SAXException, URISyntaxException {
return get(uri, false);
}
/**
* This calls get(new XMLRPCCommandGet(uri), bypass)
*
* @param uid
* is the UID of the object to retreive
* @param bypass
* tells to force download
* @see #get(URI, boolean)
* @since 1.0.0
*/
public Table get(final UID uid, final boolean bypass) throws InvalidKeyException, AccessControlException,
IOException, ClassNotFoundException, SAXException, URISyntaxException {
final URI uri = newURI(uid);
return get(uri, bypass);
}
/**
* This calls get(new XMLRPCCommandGet(uri), bypass)
*
* @param uri
* is the URI of the object to get
* @param bypass
* tells to force download
* @see #get(XMLRPCCommandGet, boolean)
* @since 4.2.0
*/
public Table get(final URI uri, final boolean bypass)
throws InvalidKeyException, AccessControlException, IOException, SAXException, URISyntaxException {
final XMLRPCCommandGet cmd = new XMLRPCCommandGet(uri);
return get(cmd, bypass);
}
/**
* This calls get(command, true)
*
* @param command
* is the GET command to send to server
* @see #get(XMLRPCCommandGet, boolean)
* @since 1.0.0
*/
@Override
public Table get(final XMLRPCCommandGet command)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
return get(command, true);
}
/**
* This calls get(command, true)
*
* @param command
* is the GET command to send to server
* @see #get(XMLRPCCommandGet, boolean)
* @since 11.1.0
*/
public Table get(final XMLRPCCommandGetWorkByExternalId command)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
return get(command, true);
}
/**
* This retrieves an object definition given its URI, from server or from
* cache, if already in cache.
*
* @param command
* is the GET command to send to server
* @param bypass
* if true object is downloaded from server even if already in
* cache if false, object is only downloaded if not already in
* cache
* @return an object definition
* @since 1.0.0
*/
public Table get(final XMLRPCCommandGetWorkByExternalId command, final boolean bypass)
throws InvalidKeyException, AccessControlException, IOException, SAXException {
if (!bypass) {
final Table object = cache.get(command.getURI());
if (object != null) {
return object;
}
}