-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29850 Add support for dynamic per-request attributes in AsyncTable #7665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
ba61a0c
d708dba
28b6367
204f04d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| /* | ||
| * 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.hadoop.hbase.client; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
|
|
||
| /** | ||
| * A {@link RequestAttributesFactory} that returns a fixed set of attributes for every call. Use | ||
| * this when attributes are fixed and do not change. | ||
| * @see AsyncTableBuilder#setRequestAttributesFactory(RequestAttributesFactory) | ||
| */ | ||
| @InterfaceAudience.Public | ||
| public final class FixedRequestAttributesFactory implements RequestAttributesFactory { | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The other ideas I had were |
||
|
|
||
| /** | ||
| * A factory that always returns an empty map. | ||
| */ | ||
| public static final RequestAttributesFactory EMPTY = Collections::emptyMap; | ||
|
|
||
| /** | ||
| * Builder for creating {@link FixedRequestAttributesFactory} instances. | ||
| */ | ||
| public static final class Builder { | ||
| private final Map<String, byte[]> requestAttributes = new LinkedHashMap<>(); | ||
|
|
||
| /** | ||
| * Sets a request attribute. If value is null, the attribute is removed. | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The underlying Protobuf |
||
| * @param key the attribute key | ||
| * @param value the attribute value, or null to remove | ||
| * @return this builder | ||
| */ | ||
| public Builder setAttribute(String key, byte[] value) { | ||
| if (value == null) { | ||
| requestAttributes.remove(key); | ||
| } else { | ||
| requestAttributes.put(key, value); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Gets the accumulated request attributes. | ||
| */ | ||
| public Map<String, byte[]> getAttributes() { | ||
| return Collections.unmodifiableMap(requestAttributes); | ||
| } | ||
|
|
||
| /** | ||
| * Builds a {@link FixedRequestAttributesFactory} with the configured attributes. | ||
| * @return the factory | ||
| */ | ||
| public FixedRequestAttributesFactory build() { | ||
| return new FixedRequestAttributesFactory(new LinkedHashMap<>(requestAttributes)); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns a new builder. | ||
| * @return a new builder instance | ||
| */ | ||
| public static Builder newBuilder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| private final Map<String, byte[]> requestAttributes; | ||
|
|
||
| private FixedRequestAttributesFactory(Map<String, byte[]> requestAttributes) { | ||
| this.requestAttributes = Collections.unmodifiableMap(requestAttributes); | ||
| } | ||
|
|
||
| @Override | ||
| public Map<String, byte[]> create() { | ||
| return requestAttributes; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think master is 4.0.0; should it get deprecated for a later version or should I remove it from master?