本文整理汇总了Java中org.apache.hadoop.hbase.util.Writables.getWritable方法的典型用法代码示例。如果您正苦于以下问题:Java Writables.getWritable方法的具体用法?Java Writables.getWritable怎么用?Java Writables.getWritable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.util.Writables
的用法示例。
在下文中一共展示了Writables.getWritable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: nodeDataChanged
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Override
public void nodeDataChanged(String path) {
if (keysParentZNode.equals(ZKUtil.getParent(path))) {
try {
byte[] data = ZKUtil.getDataAndWatch(watcher, path);
if (data == null || data.length == 0) {
LOG.debug("Ignoring empty node "+path);
return;
}
AuthenticationKey key = (AuthenticationKey)Writables.getWritable(data,
new AuthenticationKey());
secretManager.addKey(key);
} catch (KeeperException ke) {
LOG.fatal("Error reading data from zookeeper", ke);
watcher.abort("Error reading updated key znode "+path, ke);
} catch (IOException ioe) {
LOG.fatal("Error reading key writables", ioe);
watcher.abort("Error reading key writables from znode "+path, ioe);
}
}
}
示例2: refreshNodes
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
private void refreshNodes(List<ZKUtil.NodeAndData> nodes) {
for (ZKUtil.NodeAndData n : nodes) {
String path = n.getNode();
String keyId = ZKUtil.getNodeName(path);
try {
byte[] data = n.getData();
if (data == null || data.length == 0) {
LOG.debug("Ignoring empty node "+path);
continue;
}
AuthenticationKey key = (AuthenticationKey)Writables.getWritable(
data, new AuthenticationKey());
secretManager.addKey(key);
} catch (IOException ioe) {
LOG.fatal("Failed reading new secret key for id '" + keyId +
"' from zk", ioe);
watcher.abort("Error deserializing key from znode "+path, ioe);
}
}
}
示例3: parseFrom
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
/**
* @param bytes A pb serialized {@link HTableDescriptor} instance with pb magic prefix
* @return An instance of {@link HTableDescriptor} made from <code>bytes</code>
* @throws DeserializationException
* @throws IOException
* @see #toByteArray()
*/
public static HTableDescriptor parseFrom(final byte [] bytes)
throws DeserializationException, IOException {
if (!ProtobufUtil.isPBMagicPrefix(bytes)) {
return (HTableDescriptor)Writables.getWritable(bytes, new HTableDescriptor());
}
int pblen = ProtobufUtil.lengthOfPBMagic();
TableSchema.Builder builder = TableSchema.newBuilder();
TableSchema ts;
try {
ProtobufUtil.mergeFrom(builder, bytes, pblen, bytes.length - pblen);
ts = builder.build();
} catch (IOException e) {
throw new DeserializationException(e);
}
return convert(ts);
}
示例4: parseFrom
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
/**
* @param bytes A pb serialized {@link HTableDescriptor} instance with pb magic prefix
* @return An instance of {@link HTableDescriptor} made from <code>bytes</code>
* @throws DeserializationException
* @throws IOException
* @see #toByteArray()
*/
public static HTableDescriptor parseFrom(final byte [] bytes)
throws DeserializationException, IOException {
if (!ProtobufUtil.isPBMagicPrefix(bytes)) {
return (HTableDescriptor)Writables.getWritable(bytes, new HTableDescriptor());
}
int pblen = ProtobufUtil.lengthOfPBMagic();
TableSchema.Builder builder = TableSchema.newBuilder();
TableSchema ts;
try {
ts = builder.mergeFrom(bytes, pblen, bytes.length - pblen).build();
} catch (InvalidProtocolBufferException e) {
throw new DeserializationException(e);
}
return convert(ts);
}
示例5: testKeyValue2
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Test public void testKeyValue2() throws Exception {
final String name = "testKeyValue2";
byte[] row = name.getBytes();
byte[] fam = "fam".getBytes();
byte[] qf = "qf".getBytes();
long ts = System.currentTimeMillis();
byte[] val = "val".getBytes();
KeyValue kv = new KeyValue(row, fam, qf, ts, val);
byte [] mb = Writables.getBytes(kv);
KeyValue deserializedKv =
(KeyValue)Writables.getWritable(mb, new KeyValue());
assertTrue(Bytes.equals(kv.getBuffer(), deserializedKv.getBuffer()));
assertEquals(kv.getOffset(), deserializedKv.getOffset());
assertEquals(kv.getLength(), deserializedKv.getLength());
}
示例6: testDelete
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Test public void testDelete() throws Exception{
byte[] row = "row".getBytes();
byte[] fam = "fam".getBytes();
byte[] qf1 = "qf1".getBytes();
long ts = System.currentTimeMillis();
Delete delete = new Delete(row);
delete.deleteColumn(fam, qf1, ts);
byte[] sb = Writables.getBytes(delete);
Delete desDelete = (Delete)Writables.getWritable(sb, new Delete());
assertTrue(Bytes.equals(delete.getRow(), desDelete.getRow()));
List<KeyValue> list = null;
List<KeyValue> desList = null;
for(Map.Entry<byte[], List<KeyValue>> entry :
delete.getFamilyMap().entrySet()){
assertTrue(desDelete.getFamilyMap().containsKey(entry.getKey()));
list = entry.getValue();
desList = desDelete.getFamilyMap().get(entry.getKey());
for(int i=0; i<list.size(); i++){
assertTrue(list.get(i).equals(desList.get(i)));
}
}
}
示例7: testTokenCreation
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Test
public void testTokenCreation() throws Exception {
Token<AuthenticationTokenIdentifier> token =
secretManager.generateToken("testuser");
AuthenticationTokenIdentifier ident = new AuthenticationTokenIdentifier();
Writables.getWritable(token.getIdentifier(), ident);
assertEquals("Token username should match", "testuser",
ident.getUsername());
byte[] passwd = secretManager.retrievePassword(ident);
assertTrue("Token password and password from secret manager should match",
Bytes.equals(token.getPassword(), passwd));
}
示例8: testTableDescriptor
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Test public void testTableDescriptor() throws Exception {
final String name = "testTableDescriptor";
HTableDescriptor htd = createTableDescriptor(name);
byte [] mb = Writables.getBytes(htd);
HTableDescriptor deserializedHtd =
(HTableDescriptor)Writables.getWritable(mb, new HTableDescriptor());
assertEquals(htd.getTableName(), deserializedHtd.getTableName());
}
示例9: fromBytes
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
/**
* Get an instance from bytes. Throws a {@link RuntimeException} if
* there is an error serializing this instance from bytes because it
* represents a code bug.
* @param bytes binary representation of this instance
* @return instance of this class
*/
public static RegionTransitionData fromBytes(byte [] bytes) {
try {
RegionTransitionData data = new RegionTransitionData();
Writables.getWritable(bytes, data);
return data;
} catch(IOException e) {
throw new RuntimeException(e);
}
}
示例10: testReadFields
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Test
public void testReadFields() throws IOException {
HServerAddress hsa1 = new HServerAddress("localhost", 1234);
HServerAddress hsa2 = new HServerAddress("localhost", 1235);
byte [] bytes = Writables.getBytes(hsa1);
HServerAddress deserialized =
(HServerAddress)Writables.getWritable(bytes, new HServerAddress());
assertEquals(hsa1, deserialized);
bytes = Writables.getBytes(hsa2);
deserialized =
(HServerAddress)Writables.getWritable(bytes, new HServerAddress());
assertNotSame(hsa1, deserialized);
}
示例11: testCompareFilter
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Test public void testCompareFilter() throws Exception {
Filter f = new RowFilter(CompareOp.EQUAL,
new BinaryComparator(Bytes.toBytes("testRowOne-2")));
byte [] bytes = Writables.getBytes(f);
Filter ff = (Filter)Writables.getWritable(bytes, new RowFilter());
assertNotNull(ff);
}
示例12: testKeyValue
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Test public void testKeyValue() throws Exception {
final String name = "testKeyValue";
byte [] row = Bytes.toBytes(name);
byte [] family = Bytes.toBytes(name);
byte [] qualifier = Bytes.toBytes(name);
KeyValue original = new KeyValue(row, family, qualifier);
byte [] bytes = Writables.getBytes(original);
KeyValue newone = (KeyValue)Writables.getWritable(bytes, new KeyValue());
assertTrue(KeyValue.COMPARATOR.compare(original, newone) == 0);
}
示例13: testTableDescriptor
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Test public void testTableDescriptor() throws Exception {
final String name = "testTableDescriptor";
HTableDescriptor htd = createTableDescriptor(name);
byte [] mb = Writables.getBytes(htd);
HTableDescriptor deserializedHtd =
(HTableDescriptor)Writables.getWritable(mb, new HTableDescriptor());
assertEquals(htd.getNameAsString(), deserializedHtd.getNameAsString());
}
示例14: testRegionInfo
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
/**
* Test RegionInfo serialization
* @throws Exception
*/
@Test public void testRegionInfo() throws Exception {
HRegionInfo hri = createRandomRegion("testRegionInfo");
byte [] hrib = Writables.getBytes(hri);
HRegionInfo deserializedHri =
(HRegionInfo)Writables.getWritable(hrib, new HRegionInfo());
assertEquals(hri.getEncodedName(), deserializedHri.getEncodedName());
//assertEquals(hri.getTableDesc().getFamilies().size(),
// deserializedHri.getTableDesc().getFamilies().size());
}
示例15: testGet
import org.apache.hadoop.hbase.util.Writables; //导入方法依赖的package包/类
@Test public void testGet() throws Exception{
byte[] row = "row".getBytes();
byte[] fam = "fam".getBytes();
byte[] qf1 = "qf1".getBytes();
long ts = System.currentTimeMillis();
int maxVersions = 2;
long lockid = 5;
RowLock rowLock = new RowLock(lockid);
Get get = new Get(row, rowLock);
get.addColumn(fam, qf1);
get.setTimeRange(ts, ts+1);
get.setMaxVersions(maxVersions);
byte[] sb = Writables.getBytes(get);
Get desGet = (Get)Writables.getWritable(sb, new Get());
assertTrue(Bytes.equals(get.getRow(), desGet.getRow()));
Set<byte[]> set = null;
Set<byte[]> desSet = null;
for(Map.Entry<byte[], NavigableSet<byte[]>> entry :
get.getFamilyMap().entrySet()){
assertTrue(desGet.getFamilyMap().containsKey(entry.getKey()));
set = entry.getValue();
desSet = desGet.getFamilyMap().get(entry.getKey());
for(byte [] qualifier : set){
assertTrue(desSet.contains(qualifier));
}
}
assertEquals(get.getLockId(), desGet.getLockId());
assertEquals(get.getMaxVersions(), desGet.getMaxVersions());
TimeRange tr = get.getTimeRange();
TimeRange desTr = desGet.getTimeRange();
assertEquals(tr.getMax(), desTr.getMax());
assertEquals(tr.getMin(), desTr.getMin());
}