@@ -48,6 +48,59 @@ public abstract class ReadPreference {
48
48
ReadPreference () {
49
49
}
50
50
51
+ /**
52
+ * Create a new ReadPreference instance with a new tag set.
53
+ * <p>
54
+ * Note: this method is not supported for a primary read preference.
55
+ * </p>
56
+ *
57
+ * @param tagSet the new tag set
58
+ * @return a new ReadPreference instance with a new tag set
59
+ * @since 4.1
60
+ */
61
+ public abstract ReadPreference withTagSet (TagSet tagSet );
62
+
63
+ /**
64
+ * Create a new ReadPreference instance with a new tag set list.
65
+ * <p>
66
+ * Note: this method is not supported for a primary read preference.
67
+ * </p>
68
+ *
69
+ * @param tagSet the new tag set list
70
+ * @return a new ReadPreference instance with a new tag set list
71
+ * @since 4.1
72
+ */
73
+ public abstract ReadPreference withTagSetList (List <TagSet > tagSet );
74
+
75
+ /**
76
+ * Create a new ReadPreference instance with the maximum acceptable staleness of a secondary in order to be considered for
77
+ * read operations.
78
+ * <p>
79
+ * Note: this method is not supported for a primary read preference.
80
+ * </p>
81
+ *
82
+ * @param maxStalenessMS the max allowable staleness of secondaries. The minimum value is either 90 seconds, or the heartbeat frequency
83
+ * plus 10 seconds, whichever is greatest.
84
+ * @param timeUnit the time unit of maxStaleness
85
+ * @return a new ReadPreference instance with a new maximum allowable staleness
86
+ * @since 4.1
87
+ * @mongodb.server.release 3.4
88
+ */
89
+ public abstract ReadPreference withMaxStalenessMS (Long maxStalenessMS , TimeUnit timeUnit );
90
+
91
+ /**
92
+ * Create a new ReadPreference instance with hedge options.
93
+ * <p>
94
+ * Note: this method is not supported for a primary read preference.
95
+ * </p>
96
+ *
97
+ * @param hedgeOptions the hedge options
98
+ * @return a new ReadPreference instance with hedge options
99
+ * @since 4.1
100
+ * @mongodb.server.release 4.4
101
+ */
102
+ public abstract ReadPreference withHedgeOptions (ReadPreferenceHedgeOptions hedgeOptions );
103
+
51
104
/**
52
105
* True if this read preference allows reading from a secondary member of a replica set.
53
106
*
@@ -573,7 +626,7 @@ private static TaggableReadPreference valueOf(final String name, final List<TagS
573
626
String nameToCheck = name .toLowerCase ();
574
627
575
628
if (nameToCheck .equals (PRIMARY .getName ().toLowerCase ())) {
576
- throw new IllegalArgumentException ("Primary read preference can not also specify tag sets or max staleness" );
629
+ throw new IllegalArgumentException ("Primary read preference can not also specify tag sets, max staleness or hedge " );
577
630
}
578
631
579
632
if (nameToCheck .equals (SECONDARY .getName ().toLowerCase ())) {
@@ -599,6 +652,26 @@ private static final class PrimaryReadPreference extends ReadPreference {
599
652
private PrimaryReadPreference () {
600
653
}
601
654
655
+ @ Override
656
+ public ReadPreference withTagSet (final TagSet tagSet ) {
657
+ throw new UnsupportedOperationException ("Primary read preference can not also specify tag sets" );
658
+ }
659
+
660
+ @ Override
661
+ public TaggableReadPreference withTagSetList (final List <TagSet > tagSet ) {
662
+ throw new UnsupportedOperationException ("Primary read preference can not also specify tag sets" );
663
+ }
664
+
665
+ @ Override
666
+ public TaggableReadPreference withMaxStalenessMS (final Long maxStalenessMS , final TimeUnit timeUnit ) {
667
+ throw new UnsupportedOperationException ("Primary read preference can not also specify max staleness" );
668
+ }
669
+
670
+ @ Override
671
+ public TaggableReadPreference withHedgeOptions (final ReadPreferenceHedgeOptions hedgeOptions ) {
672
+ throw new UnsupportedOperationException ("Primary read preference can not also specify hedge" );
673
+ }
674
+
602
675
@ Override
603
676
public boolean isSlaveOk () {
604
677
return false ;
0 commit comments