本文整理汇总了Java中org.apache.cassandra.utils.ByteBufferUtil.writeWithLength方法的典型用法代码示例。如果您正苦于以下问题:Java ByteBufferUtil.writeWithLength方法的具体用法?Java ByteBufferUtil.writeWithLength怎么用?Java ByteBufferUtil.writeWithLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.cassandra.utils.ByteBufferUtil
的用法示例。
在下文中一共展示了ByteBufferUtil.writeWithLength方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
public void serialize(Version version, CompactionMetadata component, DataOutputPlus out) throws IOException
{
if (version.hasCompactionAncestors())
{ // write empty ancestor marker
out.writeInt(0);
}
ByteBufferUtil.writeWithLength(component.cardinalityEstimator.getBytes(), out);
}
示例2: saveSummary
import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
/**
* Save index summary to Summary.db file.
*/
public static void saveSummary(Descriptor descriptor, DecoratedKey first, DecoratedKey last, IndexSummary summary)
{
String filePath = descriptor.filenameFor(Component.SUMMARY);
//TODO: add a retry here on deletion
HadoopFileUtils.deleteIfExists(filePath, descriptor.getConfiguration());
//TODO: will make the retry nicer
int attempt = 0;
int maxAttempt = 5;
boolean isSuccess = false;
while (!isSuccess) {
if (attempt > 0)
FBUtilities.sleepQuietly((int) Math.round(Math.pow(2, attempt)) * 1000);
try (HadoopFileUtils.HadoopFileChannel hos = HadoopFileUtils.newFilesystemChannel(filePath,
descriptor.getConfiguration());
DataOutputStreamPlus oStream = new BufferedDataOutputStreamPlus(hos)) {
IndexSummary.serializer.serialize(summary, oStream, descriptor.version.hasSamplingLevel());
if (first != null && last != null) {
ByteBufferUtil.writeWithLength(first.getKey(), oStream);
ByteBufferUtil.writeWithLength(last.getKey(), oStream);
}
isSuccess = true;
} catch (Throwable e) {
logger.trace("Cannot save SSTable Summary: ", e);
// corrupted hence delete it and let it load it now.
HadoopFileUtils.deleteIfExists(filePath, descriptor.getConfiguration());
attempt++;
if (attempt == maxAttempt) //TODO: do we need to record all retried excpetions here or assume they'r same
throw new RuntimeException("Have retried for " + maxAttempt + " times but still failed!", e);
}
}
}
示例3: serialize
import org.apache.cassandra.utils.ByteBufferUtil; //导入方法依赖的package包/类
public void serialize(Token token, DataOutputPlus out, int version) throws IOException
{
IPartitioner p = token.getPartitioner();
ByteBuffer b = p.getTokenFactory().toByteArray(token);
ByteBufferUtil.writeWithLength(b, out);
}