/
SiteToSiteClient.java
834 lines (754 loc) · 31.8 KB
/
SiteToSiteClient.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
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.nifi.remote.client;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Serializable;
import java.security.KeyStore;
import java.security.SecureRandom;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory;
import org.apache.nifi.events.EventReporter;
import org.apache.nifi.remote.Transaction;
import org.apache.nifi.remote.TransferDirection;
import org.apache.nifi.remote.client.socket.SocketClient;
import org.apache.nifi.remote.exception.HandshakeException;
import org.apache.nifi.remote.exception.PortNotRunningException;
import org.apache.nifi.remote.exception.ProtocolException;
import org.apache.nifi.remote.exception.UnknownPortException;
import org.apache.nifi.remote.protocol.DataPacket;
/**
* <p>
* The SiteToSiteClient provides a mechanism for sending data to a remote
* instance of NiFi (or NiFi cluster) and retrieving data from a remote instance
* of NiFi (or NiFi cluster).
* </p>
*
* <p>
* When configuring the client via the {@link SiteToSiteClient.Builder}, the
* Builder must be provided the URL of the remote NiFi instance. If the URL
* points to a standalone instance of NiFi, all interaction will take place with
* that instance of NiFi. However, if the URL points to the NiFi Cluster Manager
* of a cluster, the client will automatically handle load balancing the
* transactions across the different nodes in the cluster.
* </p>
*
* <p>
* The SiteToSiteClient provides a {@link Transaction} through which all
* interaction with the remote instance takes place. After data has been
* exchanged or it is determined that no data is available, the Transaction can
* then be canceled (via the {@link Transaction#cancel(String)} method) or can
* be completed (via the {@link Transaction#complete(boolean)} method).
* </p>
*
* <p>
* An instance of SiteToSiteClient can be obtained by constructing a new
* instance of the {@link SiteToSiteClient.Builder} class, calling the
* appropriate methods to configured the client as desired, and then calling the
* {@link SiteToSiteClient.Builder#build() build()} method.
* </p>
*
* <p>
* The SiteToSiteClient itself is immutable once constructed and is thread-safe.
* Many threads can share access to the same client. However, the
* {@link Transaction} that is created by the client is not thread safe and
* should not be shared among threads.
* </p>
*/
public interface SiteToSiteClient extends Closeable {
/**
* <p>
* Creates a new Transaction that can be used to either send data to a
* remote NiFi instance or receive data from a remote NiFi instance,
* depending on the value passed for the {@code direction} argument.
* </p>
*
* <p>
* <b>Note:</b> If all of the nodes are penalized (See
* {@link Builder#nodePenalizationPeriod(long, TimeUnit)}), then this method
* will return <code>null</code>.
* </p>
*
* @param direction specifies which direction the data should be
* transferred. A value of {@link TransferDirection#SEND} indicates that
* this Transaction will send data to the remote instance; a value of
* {@link TransferDirection#RECEIVE} indicates that this Transaction will be
* used to receive data from the remote instance.
*
* @return a Transaction to use for sending or receiving data, or
* <code>null</code> if all nodes are penalized.
* @throws org.apache.nifi.remote.exception.HandshakeException he
* @throws org.apache.nifi.remote.exception.PortNotRunningException pnre
* @throws IOException ioe
* @throws org.apache.nifi.remote.exception.UnknownPortException upe
*/
Transaction createTransaction(TransferDirection direction) throws HandshakeException, PortNotRunningException, ProtocolException, UnknownPortException, IOException;
/**
* <p>
* In order to determine whether the server is configured for secure
* communications, the client may have to query the server's RESTful
* interface. Doing so could result in an IOException.
* </p>
*
* @return {@code true} if site-to-site communications with the remote
* instance are secure, {@code false} if site-to-site communications with
* the remote instance are not secure. Whether or not communications are
* secure depends on the server, not the client
* @throws IOException if unable to query the remote instance's RESTful
* interface or if the remote instance is not configured to allow
* site-to-site communications
*/
boolean isSecure() throws IOException;
/**
*
* @return the configuration object that was built by the Builder
*/
SiteToSiteClientConfig getConfig();
/**
* <p>
* The Builder is the mechanism by which all configuration is passed to the
* SiteToSiteClient. Once constructed, the SiteToSiteClient cannot be
* reconfigured (i.e., it is immutable). If a change in configuration should
* be desired, the client should be {@link Closeable#close() closed} and a
* new client created.
* </p>
*/
public static class Builder implements Serializable {
private static final long serialVersionUID = -4954962284343090219L;
private String url;
private long timeoutNanos = TimeUnit.SECONDS.toNanos(30);
private long penalizationNanos = TimeUnit.SECONDS.toNanos(3);
private long idleExpirationNanos = TimeUnit.SECONDS.toNanos(30L);
private SSLContext sslContext;
private String keystoreFilename;
private String keystorePass;
private KeystoreType keystoreType;
private String truststoreFilename;
private String truststorePass;
private KeystoreType truststoreType;
private EventReporter eventReporter;
private File peerPersistenceFile;
private boolean useCompression;
private String portName;
private String portIdentifier;
private int batchCount;
private long batchSize;
private long batchNanos;
/**
* Populates the builder with values from the provided config
*
* @param config to start with
* @return the builder
*/
public Builder fromConfig(final SiteToSiteClientConfig config) {
this.url = config.getUrl();
this.timeoutNanos = config.getTimeout(TimeUnit.NANOSECONDS);
this.penalizationNanos = config.getPenalizationPeriod(TimeUnit.NANOSECONDS);
this.idleExpirationNanos = config.getIdleConnectionExpiration(TimeUnit.NANOSECONDS);
this.sslContext = config.getSslContext();
this.keystoreFilename = config.getKeystoreFilename();
this.keystorePass = config.getKeystorePassword();
this.keystoreType = config.getKeystoreType();
this.truststoreFilename = config.getTruststoreFilename();
this.truststorePass = config.getTruststorePassword();
this.truststoreType = config.getTruststoreType();
this.eventReporter = config.getEventReporter();
this.peerPersistenceFile = config.getPeerPersistenceFile();
this.useCompression = config.isUseCompression();
this.portName = config.getPortName();
this.portIdentifier = config.getPortIdentifier();
this.batchCount = config.getPreferredBatchCount();
this.batchSize = config.getPreferredBatchSize();
this.batchNanos = config.getPreferredBatchDuration(TimeUnit.NANOSECONDS);
return this;
}
/**
* Specifies the URL of the remote NiFi instance. If this URL points to
* the Cluster Manager of a NiFi cluster, data transfer to and from
* nodes will be automatically load balanced across the different nodes.
*
* @param url url of remote instance
* @return the builder
*/
public Builder url(final String url) {
this.url = url;
return this;
}
/**
* Specifies the communications timeouts to use when interacting with
* the remote instances. The default value is 30 seconds.
*
* @param timeout to use when interacting with remote instances
* @param unit unit of time over which to interpret the given timeout
* @return the builder
*/
public Builder timeout(final long timeout, final TimeUnit unit) {
this.timeoutNanos = unit.toNanos(timeout);
return this;
}
/**
* Specifies the amount of time that a connection can remain idle in the
* connection pool before it is "expired" and shutdown. The default
* value is 30 seconds.
*
* @param timeout to use when interacting with remote instances
* @param unit unit of time over which to interpret the given timeout
* @return the builder
*/
public Builder idleExpiration(final long timeout, final TimeUnit unit) {
this.idleExpirationNanos = unit.toNanos(timeout);
return this;
}
/**
* If there is a problem communicating with a node (i.e., any node in
* the remote NiFi cluster or the remote instance of NiFi if it is
* standalone), specifies how long the client should wait before
* attempting to communicate with that node again. While a particular
* node is penalized, all other nodes in the remote cluster (if any)
* will still be available for communication. The default value is 3
* seconds.
*
* @param period time to wait between communication attempts
* @param unit over which to evaluate the given period
* @return the builder
*/
public Builder nodePenalizationPeriod(final long period, final TimeUnit unit) {
this.penalizationNanos = unit.toNanos(period);
return this;
}
/**
* Specifies the SSL Context to use when communicating with the remote
* NiFi instance(s). If not specified, communications will not be
* secure. The remote instance of NiFi always determines whether or not
* Site-to-Site communications are secure (i.e., the client will always
* use secure or non-secure communications, depending on what the server
* dictates). <b>Note:</b> The SSLContext provided by this method will be
* ignored if using a Serializable Configuration (see {@link #buildSerializableConfig()}).
* If a Serializable Configuration is required and communications are to be
* secure, the {@link #keystoreFilename(String)}, {@link #keystorePass(String)},
* {@link #keystoreType}, {@link #truststoreFilename}, {@link #truststorePass(String)},
* and {@link #truststoreType(KeystoreType)} methods must be used instead.
*
* @param sslContext the context
* @return the builder
*/
public Builder sslContext(final SSLContext sslContext) {
this.sslContext = sslContext;
return this;
}
/**
* @return the filename to use for the Keystore in order to communicate securely
* with the remote instance of NiFi
*/
public String getKeystoreFilename() {
return keystoreFilename;
}
/**
* Sets the filename to use for the Keystore in order to communicate securely
* with the remote instance of NiFi
*
* @param keystoreFilename the filename to use for the Keystore in order to communicate securely
* with the remote instance of NiFi
* @return the builder
*/
public Builder keystoreFilename(final String keystoreFilename) {
this.keystoreFilename = keystoreFilename;
return this;
}
/**
* @return the password to use for the Keystore in order to communicate securely
* with the remote instance of NiFi
*/
public String getKeystorePass() {
return keystorePass;
}
/**
* Sets the password to use for the Keystore in order to communicate securely
* with the remote instance of NiFi
*
* @param keystorePass the password to use for the Keystore in order to communicate securely
* with the remote instance of NiFi
* @return the builder
*/
public Builder keystorePass(final String keystorePass) {
this.keystorePass = keystorePass;
return this;
}
/**
* @return the type of Keystore to use in order to communicate securely
* with the remote instance of NiFi
*/
public KeystoreType getKeystoreType() {
return keystoreType;
}
/**
* Sets the type of the Keystore to use in order to communicate securely
* with the remote instance of NiFi
*
* @param keystoreType the type of the Keystore to use in order to communicate securely
* with the remote instance of NiFi
* @return the builder
*/
public Builder keystoreType(final KeystoreType keystoreType) {
this.keystoreType = keystoreType;
return this;
}
/**
* @return the filename to use for the Truststore in order to communicate securely
* with the remote instance of NiFi
*/
public String getTruststoreFilename() {
return truststoreFilename;
}
/**
* Sets the filename to use for the Truststore in order to communicate securely
* with the remote instance of NiFi
*
* @param truststoreFilename the filename to use for the Truststore in order to communicate securely
* with the remote instance of NiFi
* @return the builder
*/
public Builder truststoreFilename(final String truststoreFilename) {
this.truststoreFilename = truststoreFilename;
return this;
}
/**
* @return the password to use for the Truststore in order to communicate securely
* with the remote instance of NiFi
*/
public String getTruststorePass() {
return truststorePass;
}
/**
* Sets the password to use for the Truststore in order to communicate securely
* with the remote instance of NiFi
*
* @param truststorePass the filename to use for the Truststore in order to communicate securely
* with the remote instance of NiFi
*/
public Builder truststorePass(final String truststorePass) {
this.truststorePass = truststorePass;
return this;
}
/**
* @return the type of the Truststore to use in order to communicate securely
* with the remote instance of NiFi
*/
public KeystoreType getTruststoreType() {
return truststoreType;
}
/**
* Sets the password type of the Truststore to use in order to communicate securely
* with the remote instance of NiFi
*
* @param truststoreType the type of the Truststore to use in order to communicate securely
* with the remote instance of NiFi
* @return the builder
*/
public Builder truststoreType(final KeystoreType truststoreType) {
this.truststoreType = truststoreType;
return this;
}
/**
* Provides an EventReporter that can be used by the client in order to
* report any events that could be of interest when communicating with
* the remote instance. The EventReporter provided must be threadsafe.
*
* @param eventReporter reporter
* @return the builder
*/
public Builder eventReporter(final EventReporter eventReporter) {
this.eventReporter = eventReporter;
return this;
}
/**
* Specifies a file that the client can write to in order to persist the
* list of nodes in the remote cluster and recover the list of nodes
* upon restart. This allows the client to function if the remote
* Cluster Manager is unavailable, even after a restart of the client
* software. If not specified, the list of nodes will not be persisted
* and a failure of the Cluster Manager will result in not being able to
* communicate with the remote instance if a new client is created.
*
* @param peerPersistenceFile file
* @return the builder
*/
public Builder peerPersistenceFile(final File peerPersistenceFile) {
this.peerPersistenceFile = peerPersistenceFile;
return this;
}
/**
* Specifies whether or not data should be compressed before being
* transferred to or from the remote instance.
*
* @param compress true if should compress
* @return the builder
*/
public Builder useCompression(final boolean compress) {
this.useCompression = compress;
return this;
}
/**
* Specifies the name of the port to communicate with. Either the port
* name or the port identifier must be specified.
*
* @param portName name of port
* @return the builder
*/
public Builder portName(final String portName) {
this.portName = portName;
return this;
}
/**
* Specifies the unique identifier of the port to communicate with. If
* it is known, this is preferred over providing the port name, as the
* port name may change.
*
* @param portIdentifier identifier of port
* @return the builder
*/
public Builder portIdentifier(final String portIdentifier) {
this.portIdentifier = portIdentifier;
return this;
}
/**
* When pulling data from a NiFi instance, the sender chooses how large
* a Transaction is. However, the client has the ability to request a
* particular batch size/duration. This method specifies the preferred
* number of {@link DataPacket}s to include in a Transaction.
*
* @param count client preferred batch size
* @return the builder
*/
public Builder requestBatchCount(final int count) {
this.batchCount = count;
return this;
}
/**
* When pulling data from a NiFi instance, the sender chooses how large
* a Transaction is. However, the client has the ability to request a
* particular batch size/duration. This method specifies the preferred
* number of bytes to include in a Transaction.
*
* @param bytes client preferred batch size
* @return the builder
*/
public Builder requestBatchSize(final long bytes) {
this.batchSize = bytes;
return this;
}
/**
* When pulling data from a NiFi instance, the sender chooses how large
* a Transaction is. However, the client has the ability to request a
* particular batch size/duration. This method specifies the preferred
* amount of time that a Transaction should span.
*
* @param value client preferred batch duration
* @param unit client preferred batch duration unit
* @return the builder
*/
public Builder requestBatchDuration(final long value, final TimeUnit unit) {
this.batchNanos = unit.toNanos(value);
return this;
}
/**
* @return a {@link SiteToSiteClientConfig} for the configured values
* but does not create a SiteToSiteClient
*/
public SiteToSiteClientConfig buildConfig() {
return new StandardSiteToSiteClientConfig(this);
}
/**
* @return a new SiteToSiteClient that can be used to send and receive
* data with remote instances of NiFi
*
* @throws IllegalStateException if either the url is not set or neither
* the port name nor port identifier is set.
*/
public SiteToSiteClient build() {
if (url == null) {
throw new IllegalStateException("Must specify URL to build Site-to-Site client");
}
if (portName == null && portIdentifier == null) {
throw new IllegalStateException("Must specify either Port Name or Port Identifier to build Site-to-Site client");
}
return new SocketClient(buildConfig());
}
/**
* @return the configured URL for the remote NiFi instance
*/
public String getUrl() {
return url;
}
/**
* @param timeUnit unit over which to interpret the timeout
* @return the communications timeout
*/
public long getTimeout(final TimeUnit timeUnit) {
return timeUnit.convert(timeoutNanos, TimeUnit.NANOSECONDS);
}
/**
* @param timeUnit unit over which to interpret the time
* @return the amount of of time that a connection can remain idle in
* the connection pool before being shutdown
*/
public long getIdleConnectionExpiration(final TimeUnit timeUnit) {
return timeUnit.convert(idleExpirationNanos, TimeUnit.NANOSECONDS);
}
/**
* @param timeUnit unit of reported time
* @return the amount of time that a particular node will be ignored
* after a communications error with that node occurs
*/
public long getPenalizationPeriod(TimeUnit timeUnit) {
return timeUnit.convert(penalizationNanos, TimeUnit.NANOSECONDS);
}
/**
* @return the SSL Context that is configured for this builder
*/
public SSLContext getSslContext() {
if (sslContext != null) {
return sslContext;
}
final KeyManagerFactory keyManagerFactory;
if (keystoreFilename != null && keystorePass != null && keystoreType != null) {
try {
// prepare the keystore
final KeyStore keyStore = KeyStore.getInstance(getKeystoreType().name());
try (final InputStream keyStoreStream = new FileInputStream(new File(getKeystoreFilename()))) {
keyStore.load(keyStoreStream, getKeystorePass().toCharArray());
}
keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(keyStore, getKeystorePass().toCharArray());
} catch (final Exception e) {
throw new RuntimeException("Failed to load Keystore", e);
}
} else {
keyManagerFactory = null;
}
final TrustManagerFactory trustManagerFactory;
if (truststoreFilename != null && truststorePass != null && truststoreType != null) {
try {
// prepare the truststore
final KeyStore trustStore = KeyStore.getInstance(getTruststoreType().name());
try (final InputStream trustStoreStream = new FileInputStream(new File(getTruststoreFilename()))) {
trustStore.load(trustStoreStream, getTruststorePass().toCharArray());
}
trustManagerFactory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
} catch (final Exception e) {
throw new RuntimeException("Failed to load Truststore", e);
}
} else {
trustManagerFactory = null;
}
if (keyManagerFactory != null && trustManagerFactory != null) {
try {
// initialize the ssl context
final SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
sslContext.getDefaultSSLParameters().setNeedClientAuth(true);
return sslContext;
} catch (final Exception e) {
throw new RuntimeException("Created keystore and truststore but failed to initialize SSLContext");
}
} else {
return null;
}
}
/**
* @return the EventReporter that is to be used by clients to report
* events
*/
public EventReporter getEventReporter() {
return eventReporter;
}
/**
* @return the file that is to be used for persisting the nodes of a
* remote cluster, if any
*/
public File getPeerPersistenceFile() {
return peerPersistenceFile;
}
/**
* @return a boolean indicating whether or not compression will be used
* to transfer data to and from the remote instance
*/
public boolean isUseCompression() {
return useCompression;
}
/**
* @return the name of the port that the client is to communicate with
*/
public String getPortName() {
return portName;
}
/**
* @return the identifier of the port that the client is to communicate
* with
*/
public String getPortIdentifier() {
return portIdentifier;
}
}
class StandardSiteToSiteClientConfig implements SiteToSiteClientConfig, Serializable {
private static final long serialVersionUID = 1L;
private final String url;
private final long timeoutNanos;
private final long penalizationNanos;
private final long idleExpirationNanos;
private final SSLContext sslContext;
private final String keystoreFilename;
private final String keystorePass;
private final KeystoreType keystoreType;
private final String truststoreFilename;
private final String truststorePass;
private final KeystoreType truststoreType;
private final EventReporter eventReporter;
private final File peerPersistenceFile;
private final boolean useCompression;
private final String portName;
private final String portIdentifier;
private final int batchCount;
private final long batchSize;
private final long batchNanos;
// some serialization frameworks require a default constructor
private StandardSiteToSiteClientConfig() {
this.url = null;
this.timeoutNanos = 0;
this.penalizationNanos = 0;
this.idleExpirationNanos = 0;
this.sslContext = null;
this.keystoreFilename = null;
this.keystorePass = null;
this.keystoreType = null;
this.truststoreFilename = null;
this.truststorePass = null;
this.truststoreType = null;
this.eventReporter = null;
this.peerPersistenceFile = null;
this.useCompression = false;
this.portName = null;
this.portIdentifier = null;
this.batchCount = 0;
this.batchSize = 0;
this.batchNanos = 0;
}
private StandardSiteToSiteClientConfig(final SiteToSiteClient.Builder builder) {
this.url = builder.url;
this.timeoutNanos = builder.timeoutNanos;
this.penalizationNanos = builder.penalizationNanos;
this.idleExpirationNanos = builder.idleExpirationNanos;
this.sslContext = builder.sslContext;
this.keystoreFilename = builder.keystoreFilename;
this.keystorePass = builder.keystorePass;
this.keystoreType = builder.keystoreType;
this.truststoreFilename = builder.truststoreFilename;
this.truststorePass = builder.truststorePass;
this.truststoreType = builder.truststoreType;
this.eventReporter = builder.eventReporter;
this.peerPersistenceFile = builder.peerPersistenceFile;
this.useCompression = builder.useCompression;
this.portName = builder.portName;
this.portIdentifier = builder.portIdentifier;
this.batchCount = builder.batchCount;
this.batchSize = builder.batchSize;
this.batchNanos = builder.batchNanos;
}
@Override
public boolean isUseCompression() {
return useCompression;
}
@Override
public String getUrl() {
return url;
}
@Override
public long getTimeout(final TimeUnit timeUnit) {
return timeUnit.convert(timeoutNanos, TimeUnit.NANOSECONDS);
}
@Override
public long getIdleConnectionExpiration(final TimeUnit timeUnit) {
return timeUnit.convert(idleExpirationNanos, TimeUnit.NANOSECONDS);
}
@Override
public SSLContext getSslContext() {
return sslContext;
}
@Override
public String getPortName() {
return portName;
}
@Override
public String getPortIdentifier() {
return portIdentifier;
}
@Override
public long getPenalizationPeriod(final TimeUnit timeUnit) {
return timeUnit.convert(penalizationNanos, TimeUnit.NANOSECONDS);
}
@Override
public File getPeerPersistenceFile() {
return peerPersistenceFile;
}
@Override
public EventReporter getEventReporter() {
return eventReporter;
}
@Override
public long getPreferredBatchDuration(final TimeUnit timeUnit) {
return timeUnit.convert(batchNanos, TimeUnit.NANOSECONDS);
}
@Override
public long getPreferredBatchSize() {
return batchSize;
}
@Override
public int getPreferredBatchCount() {
return batchCount;
}
@Override
public String getKeystoreFilename() {
return keystoreFilename;
}
@Override
public String getKeystorePassword() {
return keystorePass;
}
@Override
public KeystoreType getKeystoreType() {
return keystoreType;
}
@Override
public String getTruststoreFilename() {
return truststoreFilename;
}
@Override
public String getTruststorePassword() {
return truststorePass;
}
@Override
public KeystoreType getTruststoreType() {
return truststoreType;
}
}
}