本文整理匯總了Java中com.google.common.primitives.Longs類的典型用法代碼示例。如果您正苦於以下問題:Java Longs類的具體用法?Java Longs怎麽用?Java Longs使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Longs類屬於com.google.common.primitives包,在下文中一共展示了Longs類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: rename
import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
fileLength) {
long blockSize = 0;
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Pipeline pipelined = jedis.pipelined();
//add new file length
pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
//add new file content
blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
}
values.clear();
pipelined.sync();
} finally {
jedis.close();
deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
}
示例2: updateCommitted
import com.google.common.primitives.Longs; //導入依賴的package包/類
/**
* Find the median value of the list of matchIndex, this value is the committedIndex since, by definition, half of the
* matchIndex values are greater and half are less than this value. So, at least half of the replicas have stored the
* median value, this is the definition of committed.
*/
private void updateCommitted() {
List<ReplicaManager> sorted = newArrayList(managers.values());
Collections.sort(sorted, new Comparator<ReplicaManager>() {
@Override
public int compare(ReplicaManager o, ReplicaManager o2) {
return Longs.compare(o.getMatchIndex(), o2.getMatchIndex());
}
});
final int middle = (int) Math.ceil(sorted.size() / 2.0);
final long committed = sorted.get(middle).getMatchIndex();
log.updateCommitIndex(committed);
SortedMap<Long, SettableFuture<Boolean>> entries = requests.headMap(committed + 1);
for (SettableFuture<Boolean> f : entries.values()) {
f.set(true);
}
entries.clear();
}
示例3: renameFile
import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void renameFile(String source, String dest) throws IOException {
List<byte[]> values = new ArrayList<>();
//在get的時候不需要加事務
//在刪除和添加的時候使用事務
//Get the file length with old file name
byte[] hget = inputOutputStream.hget(Constants.DIR_METADATA_BYTES, source.getBytes(), FILE_LENGTH);
long length = Longs.fromByteArray(hget);
long blockSize = getBlockSize(length);
for (int i = 0; i < blockSize; i++) {
//Get the contents with old file name
byte[] res = inputOutputStream.hget(Constants.FILE_METADATA_BYTES, getBlockName(source, i), FILE_DATA);
values.add(res);
}
inputOutputStream.rename(Constants.DIRECTORY_METADATA, Constants.FILE_METADATA, source, dest, values, length);
log.debug("Rename file success from {} to {}", source, dest);
}
示例4: saveFile
import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
Pipeline pipelined = jedis.pipelined();
pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
if (i % Constants.SYNC_COUNT == 0) {
pipelined.sync();
pipelined = jedis.pipelined();
}
}
values.clear();
pipelined.sync();
} finally {
jedis.close();
}
}
示例5: rename
import com.google.common.primitives.Longs; //導入依賴的package包/類
/**
* Use transactions to add index file and then delete the old one
*
* @param fileLengthKey the key using for hash file length
* @param fileDataKey the key using for hash file data
* @param oldField the old hash field
* @param newField the new hash field
* @param values the data values of the old hash field
* @param fileLength the data length of the old hash field
*/
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
fileLength) {
ShardedJedis shardedJedis = getShardedJedis();
ShardedJedisPipeline pipelined = shardedJedis.pipelined();
//add new file length
pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
//add new file content
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
}
pipelined.sync();
shardedJedis.close();
values.clear();
deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
示例6: saveFile
import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
ShardedJedis shardedJedis = getShardedJedis();
ShardedJedisPipeline pipelined = shardedJedis.pipelined();
pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
if (i % Constants.SYNC_COUNT == 0) {
pipelined.sync();
pipelined = shardedJedis.pipelined();
}
}
pipelined.sync();
shardedJedis.close();
values.clear();
}
示例7: rename
import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void rename(String fileLengthKey, String fileDataKey, String oldField, String newField, List<byte[]> values, long
fileLength) {
Jedis jedis = openJedis();
Pipeline pipelined = jedis.pipelined();
//add new file length
pipelined.hset(fileLengthKey.getBytes(), newField.getBytes(), Longs.toByteArray(fileLength));
//add new file content
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(newField, i), compressFilter(values.get(i)));
}
pipelined.sync();
jedis.close();
values.clear();
deleteFile(fileLengthKey, fileDataKey, oldField, blockSize);
}
示例8: saveFile
import com.google.common.primitives.Longs; //導入依賴的package包/類
@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values, long fileLength) {
Jedis jedis = openJedis();
Pipeline pipelined = jedis.pipelined();
pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
Long blockSize = getBlockSize(fileLength);
for (int i = 0; i < blockSize; i++) {
pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
if (i % Constants.SYNC_COUNT == 0) {
pipelined.sync();
pipelined = jedis.pipelined();
}
}
pipelined.sync();
jedis.close();
values.clear();
}
示例9: ThreadsIterator
import com.google.common.primitives.Longs; //導入依賴的package包/類
public ThreadsIterator(final SabotContext dbContext, final OperatorContext context) {
this.dbContext = dbContext;
threadMXBean = ManagementFactory.getThreadMXBean();
final long[] ids = threadMXBean.getAllThreadIds();
final Iterator<Long> threadIdIterator = Longs.asList(ids).iterator();
this.threadInfoIterator = Iterators.filter(
Iterators.transform(threadIdIterator, new Function<Long, ThreadInfo>() {
@Override
public ThreadInfo apply(Long input) {
return threadMXBean.getThreadInfo(input, 100);
}
}),
Predicates.notNull());
logger.debug("number of threads = {}, number of cores = {}", ids.length, NUMBER_OF_CORES);
this.stats = dbContext.getWorkStatsProvider().get();
}
示例10: compare
import com.google.common.primitives.Longs; //導入依賴的package包/類
/**
* Compare cells.
* TODO: Replace with dynamic rather than static comparator so can change comparator
* implementation.
* @param a
* @param b
* @param ignoreSequenceid True if we are to compare the key portion only and ignore
* the sequenceid. Set to false to compare key and consider sequenceid.
* @return 0 if equal, -1 if a < b, and +1 if a > b.
*/
public static int compare(final Cell a, final Cell b, boolean ignoreSequenceid) {
// row
int c = compareRows(a, b);
if (c != 0) return c;
c = compareWithoutRow(a, b);
if(c != 0) return c;
if (!ignoreSequenceid) {
// Negate following comparisons so later edits show up first
// mvccVersion: later sorts first
return Longs.compare(b.getMvccVersion(), a.getMvccVersion());
} else {
return c;
}
}
示例11: testOneEvent
import com.google.common.primitives.Longs; //導入依賴的package包/類
@Test
public void testOneEvent() throws Exception {
initContextForSimpleHbaseEventSerializer();
HBaseSink sink = new HBaseSink(conf);
Configurables.configure(sink, ctx);
Channel channel = new MemoryChannel();
Configurables.configure(channel, new Context());
sink.setChannel(channel);
sink.start();
Transaction tx = channel.getTransaction();
tx.begin();
Event e = EventBuilder.withBody(
Bytes.toBytes(valBase));
channel.put(e);
tx.commit();
tx.close();
sink.process();
sink.stop();
HTable table = new HTable(conf, tableName);
byte[][] results = getResults(table, 1);
byte[] out = results[0];
Assert.assertArrayEquals(e.getBody(), out);
out = results[1];
Assert.assertArrayEquals(Longs.toByteArray(1), out);
}
示例12: GabrielGatewayClient
import com.google.common.primitives.Longs; //導入依賴的package包/類
public GabrielGatewayClient(int shardId, Channel channel) throws IOException {
super(shardId, channel, true);
channel.queueDeclare("shard-" + shardId + "-getping", false, false, false, null);
channel.queueDeclare("shard-" + shardId + "-getping-response", false, false, false, null);
channel.basicConsume("shard-" + shardId + "-getping-response", true, new DefaultConsumer(channel) {
@Override
public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
long now = System.currentTimeMillis();
ping = now - Longs.fromByteArray(body);
}
});
calculatePing();
PING_CALCULATOR.scheduleAtFixedRate(this::calculatePing, 30, 30, TimeUnit.SECONDS);
}
示例13: assertErrorsOnLines
import com.google.common.primitives.Longs; //導入依賴的package包/類
/**
* Asserts that the given diagnostics contain errors with a message containing "[CheckerName]"
* on the given lines of the given file. If there should be multiple errors on a line, the line
* number must appear multiple times. There may not be any errors in any other file.
*/
public void assertErrorsOnLines(String file,
List<Diagnostic<? extends JavaFileObject>> diagnostics, long... lines) {
ListMultimap<String, Long> actualErrors = ArrayListMultimap.create();
for (Diagnostic<? extends JavaFileObject> diagnostic : diagnostics) {
String message = diagnostic.getMessage(Locale.US);
// The source may be null, e.g. for diagnostics about command-line flags
assertNotNull(message, diagnostic.getSource());
String sourceName = diagnostic.getSource().getName();
assertEquals(
"unexpected error in source file " + sourceName + ": " + message,
file, sourceName);
actualErrors.put(diagnostic.getSource().getName(), diagnostic.getLineNumber());
// any errors from the compiler that are not related to this checker should fail
assertThat(message).contains("[" + checker.getAnnotation(BugPattern.class).name() + "]");
}
assertEquals(
ImmutableMultiset.copyOf(Longs.asList(lines)),
ImmutableMultiset.copyOf(actualErrors.get(file)));
}
示例14: toArray
import com.google.common.primitives.Longs; //導入依賴的package包/類
@SuppressWarnings({"unchecked", "rawtypes"}) // NOTE: We assume the component type matches the list
private Object toArray(Class<?> componentType, List<Object> values) {
if (componentType == boolean.class) {
return Booleans.toArray((Collection) values);
} else if (componentType == byte.class) {
return Bytes.toArray((Collection) values);
} else if (componentType == short.class) {
return Shorts.toArray((Collection) values);
} else if (componentType == int.class) {
return Ints.toArray((Collection) values);
} else if (componentType == long.class) {
return Longs.toArray((Collection) values);
} else if (componentType == float.class) {
return Floats.toArray((Collection) values);
} else if (componentType == double.class) {
return Doubles.toArray((Collection) values);
} else if (componentType == char.class) {
return Chars.toArray((Collection) values);
}
return values.toArray((Object[]) Array.newInstance(componentType, values.size()));
}
示例15: getValues
import com.google.common.primitives.Longs; //導入依賴的package包/類
static
public List<?> getValues(Tensor tensor){
DataType dataType = tensor.dataType();
switch(dataType){
case FLOAT:
return Floats.asList(TensorUtil.toFloatArray(tensor));
case DOUBLE:
return Doubles.asList(TensorUtil.toDoubleArray(tensor));
case INT32:
return Ints.asList(TensorUtil.toIntArray(tensor));
case INT64:
return Longs.asList(TensorUtil.toLongArray(tensor));
case STRING:
return Arrays.asList(TensorUtil.toStringArray(tensor));
case BOOL:
return Booleans.asList(TensorUtil.toBooleanArray(tensor));
default:
throw new IllegalArgumentException();
}
}