/
ConditionalWriterConfig.java
116 lines (102 loc) · 4.28 KB
/
ConditionalWriterConfig.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
/*
* 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.accumulo.core.client;
import java.util.concurrent.TimeUnit;
import org.apache.accumulo.core.security.Authorizations;
import org.apache.accumulo.core.util.ArgumentChecker;
/**
*
* @since 1.6.0
*/
public class ConditionalWriterConfig {
private static final Long DEFAULT_TIMEOUT = Long.MAX_VALUE;
private Long timeout = null;
private static final Integer DEFAULT_MAX_WRITE_THREADS = 3;
private Integer maxWriteThreads = null;
private Authorizations auths = Authorizations.EMPTY;
/**
* A set of authorization labels that will be checked against the column visibility of each key in order to filter data. The authorizations passed in must be
* a subset of the accumulo user's set of authorizations. If the accumulo user has authorizations (A1, A2) and authorizations (A2, A3) are passed, then an
* exception will be thrown.
*
* <p>
* Any condition that is not visible with this set of authorizations will fail.
*/
public ConditionalWriterConfig setAuthorizations(Authorizations auths) {
ArgumentChecker.notNull(auths);
this.auths = auths;
return this;
}
/**
* Sets the maximum amount of time an unresponsive server will be re-tried. When this timeout is exceeded, the {@link ConditionalWriter} should return the
* mutation with an exception.<br />
* For no timeout, set to zero, or {@link Long#MAX_VALUE} with {@link TimeUnit#MILLISECONDS}.
*
* <p>
* {@link TimeUnit#MICROSECONDS} or {@link TimeUnit#NANOSECONDS} will be truncated to the nearest {@link TimeUnit#MILLISECONDS}.<br />
* If this truncation would result in making the value zero when it was specified as non-zero, then a minimum value of one {@link TimeUnit#MILLISECONDS} will
* be used.
*
* <p>
* <b>Default:</b> {@link Long#MAX_VALUE} (no timeout)
*
* @param timeout
* the timeout, in the unit specified by the value of {@code timeUnit}
* @param timeUnit
* determines how {@code timeout} will be interpreted
* @throws IllegalArgumentException
* if {@code timeout} is less than 0
* @return {@code this} to allow chaining of set methods
*/
public ConditionalWriterConfig setTimeout(long timeout, TimeUnit timeUnit) {
if (timeout < 0)
throw new IllegalArgumentException("Negative timeout not allowed " + timeout);
if (timeout == 0)
this.timeout = Long.MAX_VALUE;
else
// make small, positive values that truncate to 0 when converted use the minimum millis instead
this.timeout = Math.max(1, timeUnit.toMillis(timeout));
return this;
}
/**
* Sets the maximum number of threads to use for writing data to the tablet servers.
*
* <p>
* <b>Default:</b> 3
*
* @param maxWriteThreads
* the maximum threads to use
* @throws IllegalArgumentException
* if {@code maxWriteThreads} is non-positive
* @return {@code this} to allow chaining of set methods
*/
public ConditionalWriterConfig setMaxWriteThreads(int maxWriteThreads) {
if (maxWriteThreads <= 0)
throw new IllegalArgumentException("Max threads must be positive " + maxWriteThreads);
this.maxWriteThreads = maxWriteThreads;
return this;
}
public Authorizations getAuthorizations() {
return auths;
}
public long getTimeout(TimeUnit timeUnit) {
return timeUnit.convert(timeout != null ? timeout : DEFAULT_TIMEOUT, TimeUnit.MILLISECONDS);
}
public int getMaxWriteThreads() {
return maxWriteThreads != null ? maxWriteThreads : DEFAULT_MAX_WRITE_THREADS;
}
}