Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2016 The Async HBase Authors. All rights reserved.
* This file is part of Async HBase.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* - Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* - Neither the name of the StumbleUpon nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package org.hbase.async;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.cache.CacheStats;
import com.google.common.cache.LoadingCache;
import com.google.common.cache.RemovalListener;
import com.google.common.cache.RemovalNotification;
import com.stumbleupon.async.Deferred;
import java.util.Arrays;
import java.util.Map;
import java.util.concurrent.atomic.AtomicLong;
/**
* Package-private class to uniquely identify a buffered multi-column atomic increment.
* @since 1.8
*/
final class BufferedMultiColumnIncrement {
private static boolean byteArrayEquals(byte[][] self, byte[][] other) {
if (self.length != other.length) {
return false;
}
for (int i = 0; i < self.length; i++) {
if (Bytes.memcmp(self[i], other[i]) != 0) {
return false;
}
}
return true;
}
private static int byteArrayHashCode(byte[][] self) {
int hashCode = 1;
for (byte[] aSelf : self) {
hashCode = Arrays.hashCode(aSelf) + 41 * hashCode;
}
return hashCode;
}
private static int byteArrayLength(byte[][] self) {
int len = 0;
for (byte[] aSelf : self) {
len += aSelf.length;
}
return len;
}
private static void byteArrayToString(StringBuilder sb, byte[][] self) {
for (byte[] aSelf : self) {
sb.append(Bytes.pretty(aSelf));
}
}
private final byte[] table;
private final byte[] key;
private final byte[] family;
private final byte[][] qualifiers;
BufferedMultiColumnIncrement(final byte[] table, final byte[] key,
final byte[] family, final byte[][] qualifiers) {
this.table = table;
this.key = key;
this.family = family;
this.qualifiers = qualifiers;
}
public boolean equals(final Object other) {
if (other == null || !(other instanceof BufferedMultiColumnIncrement)) {
return false;
}
final BufferedMultiColumnIncrement incr = (BufferedMultiColumnIncrement) other;
// Compare fields most likely to be different first.
return Bytes.equals(key, incr.key)
&& byteArrayEquals(qualifiers, incr.qualifiers)
&& Bytes.equals(family, incr.family)
&& Bytes.equals(table, incr.table);
}
public int hashCode() {
return
Arrays.hashCode(table) + 41 * (
Arrays.hashCode(key) + 41 * (
Arrays.hashCode(family) + 41 * (
byteArrayHashCode(qualifiers) + 41
)
)
);
}
public String toString() {
final StringBuilder buf =
new StringBuilder(52 + table.length + key.length * 2 + family.length
+ byteArrayLength(qualifiers));
buf.append("BufferedIncrement(table=");
Bytes.pretty(buf, table);
buf.append(", key=");
Bytes.pretty(buf, key);
buf.append(", family=");
Bytes.pretty(buf, family);
buf.append(", qualifier=");
byteArrayToString(buf, qualifiers);
buf.append(')');
return buf.toString();
}
/**
* Atomic increment amounts.
*
* This behaves like a signed 49 bit atomic integer that
* can only be incremented/decremented a specific number
* of times. The {@link #update} method must be used
* for all increment/decrement operations, as the underlying
* raw value of the {@code long} from {@link AtomicLong} is
* not the value of the counter, as some of its bits are
* reserved to keep track of how many times the value
* got changed.
*
* Implementation details:
* The first 49 most significant bits are the value of
* the amount (including 1 bit for the sign), the last
* 15 least significant bits are the number of times
* left that {@link #update} can be called.
*
* Again, this class opportunistically inherits from
* {@link AtomicLong}, but don't call methods
* from the parent class directly.
*/
static final class Amounts {
/** Number of least-significant bits (LSB) we reserve to track updates. */
private final static int UPDATE_BITS = 15;
/** Mask used to retrieve number of updates left (0x0000000000007FFFL). */
private final static long UPDATE_MASK = (1L << UPDATE_BITS) - 1;
/** Mask used to get value bits we can't store (0xFFFF000000000000L). */
private final static long OVERFLOW_MASK = (UPDATE_MASK << (64 - UPDATE_BITS)
>> 1); // Reserve the sign bit.
final AtomicLong[] values;
/** Everyone waiting for this increment is queued up here. */
final Deferred