当前位置: 首页>>代码示例>>Java>>正文


Java StaticBuffer.asReadBuffer方法代码示例

本文整理汇总了Java中com.thinkaurelius.titan.diskstorage.StaticBuffer.asReadBuffer方法的典型用法代码示例。如果您正苦于以下问题:Java StaticBuffer.asReadBuffer方法的具体用法?Java StaticBuffer.asReadBuffer怎么用?Java StaticBuffer.asReadBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.thinkaurelius.titan.diskstorage.StaticBuffer的用法示例。


在下文中一共展示了StaticBuffer.asReadBuffer方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parse

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
public static Entry parse(StaticBuffer buffer, Serializer serializer, TimestampProvider times) {
    ReadBuffer read = buffer.asReadBuffer();
    Instant txTimestamp = times.getTime(read.getLong());
    TransactionLogHeader header = new TransactionLogHeader(VariableLong.readPositive(read),
            txTimestamp, times);
    LogTxStatus status = serializer.readObjectNotNull(read,LogTxStatus.class);
    EnumMap<LogTxMeta,Object> metadata = new EnumMap<LogTxMeta, Object>(LogTxMeta.class);
    int metaSize = VariableLong.unsignedByte(read.getByte());
    for (int i=0;i<metaSize;i++) {
        LogTxMeta meta = LogTxMeta.values()[VariableLong.unsignedByte(read.getByte())];
        metadata.put(meta,serializer.readObjectNotNull(read,meta.dataType()));
    }
    if (read.hasRemaining()) {
        StaticBuffer content = read.subrange(read.getPosition(),read.length()-read.getPosition());
        return new Entry(header,content, status,metadata);
    } else {
        return new Entry(header,null, status,metadata);
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:20,代码来源:TransactionLogHeader.java

示例2: parse

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
public static Entry parse(StaticBuffer buffer, Serializer serializer, TimestampProvider times) {
    ReadBuffer read = buffer.asReadBuffer();
    Timepoint txTimestamp = new StandardTimepoint(read.getLong(), times);
    TransactionLogHeader header = new TransactionLogHeader(VariableLong.readPositive(read),
            txTimestamp);
    LogTxStatus status = serializer.readObjectNotNull(read,LogTxStatus.class);
    EnumMap<LogTxMeta,Object> metadata = new EnumMap<LogTxMeta, Object>(LogTxMeta.class);
    int metaSize = VariableLong.unsignedByte(read.getByte());
    for (int i=0;i<metaSize;i++) {
        LogTxMeta meta = LogTxMeta.values()[VariableLong.unsignedByte(read.getByte())];
        metadata.put(meta,serializer.readObjectNotNull(read,meta.dataType()));
    }
    if (read.hasRemaining()) {
        StaticBuffer content = read.subrange(read.getPosition(),read.length()-read.getPosition());
        return new Entry(header,content, status,metadata);
    } else {
        return new Entry(header,null, status,metadata);
    }
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:20,代码来源:TransactionLogHeader.java

示例3: parallelDeserialization

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
@Test
public void parallelDeserialization() throws InterruptedException {
    serialize.registerClass(1,TClass2.class, new TClass2Serializer());

    final long value = 8;
    final String str = "123456";
    final TClass2 c = new TClass2("abcdefg",333);

    DataOutput out = serialize.getDataOutput(128);
    out.putLong(value);
    out.writeClassAndObject(Long.valueOf(value));
    out.writeObject(c, TClass2.class);
    out.writeObjectNotNull(str);
    final StaticBuffer b = out.getStaticBuffer();

    int numThreads = 4;
    Thread[] threads = new Thread[numThreads];
    for (int i = 0; i < numThreads; i++) {
        threads[i] = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 100000; j++) {
                    ReadBuffer buffer = b.asReadBuffer();
                    assertEquals(8, buffer.getLong());
                    assertEquals (value , (long)serialize.readClassAndObject(buffer));
                    assertEquals(c,serialize.readObject(buffer,TClass2.class));
                    assertEquals(str,serialize.readObjectNotNull(buffer,String.class));
                }
            }
        });
        threads[i].start();
    }
    for (int i = 0; i < numThreads; i++) {
        threads[i].join();
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:37,代码来源:SerializerTest.java

示例4: testSerializationMixture

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
@Test
public void testSerializationMixture() {
    serialize.registerClass(1,TClass1.class, new TClass1Serializer());

    for (int t = 0; t < 1000; t++) {
        DataOutput out = serialize.getDataOutput(128);
        int num = random.nextInt(100)+1;
        List<SerialEntry> entries = new ArrayList<SerialEntry>(num);
        for (int i = 0; i < num; i++) {
            Map.Entry<Class,Factory> type = Iterables.get(TYPES.entrySet(),random.nextInt(TYPES.size()));
            Object element = type.getValue().newInstance();
            boolean notNull = true;
            if (random.nextDouble()<0.5) {
                notNull = false;
                if (random.nextDouble()<0.2) element=null;
            }
            entries.add(new SerialEntry(element,type.getKey(),notNull));
            if (notNull) out.writeObjectNotNull(element);
            else out.writeObject(element,type.getKey());
        }
        StaticBuffer sb = out.getStaticBuffer();
        ReadBuffer in = sb.asReadBuffer();
        for (SerialEntry entry : entries) {
            Object read;
            if (entry.notNull) read = serialize.readObjectNotNull(in,entry.clazz);
            else read = serialize.readObject(in,entry.clazz);
            if (entry.object==null) assertNull(read);
            else if (entry.clazz.isArray()) {
                assertEquals(Array.getLength(entry.object),Array.getLength(read));
                for (int i = 0; i < Array.getLength(read); i++) {
                    assertEquals(Array.get(entry.object,i),Array.get(read,i));
                }
            } else assertEquals(entry.object,read);
        }
    }
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:37,代码来源:SerializerTest.java

示例5: fromLockColumn

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
public TimestampRid fromLockColumn(StaticBuffer lockKey, TimestampProvider provider) {
    ReadBuffer r = lockKey.asReadBuffer();
    int len = r.length();
    long tsNS = r.getLong();
    len -= 8;
    byte[] curRid = new byte[len];
    for (int i = 0; r.hasRemaining(); i++) {
        curRid[i] = r.getByte();
    }
    StaticBuffer rid = new StaticArrayBuffer(curRid);
    Instant time = provider.getTime(tsNS);
    return new TimestampRid(time, rid);
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:14,代码来源:ConsistentKeyLockerSerializer.java

示例6: SecondaryFailures

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
private SecondaryFailures(StaticBuffer content, Serializer serializer) {
    ReadBuffer in = content.asReadBuffer();
    this.userLogFailure = !in.getBoolean();
    int size = in.getInt();
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (int i = 0; i < size; i++) {
        builder.add(serializer.readObjectNotNull(in,String.class));
    }
    this.failedIndexes = builder.build();
}
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:11,代码来源:TransactionLogHeader.java

示例7: parallelDeserialization

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
@Test
public void parallelDeserialization() throws InterruptedException {
    DataOutput out = serialize.getDataOutput(128);
    out.putLong(8);
    out.writeClassAndObject(Long.valueOf(8));
    TestClass c = new TestClass(5, 8, new short[]{1, 2, 3, 4, 5}, TestEnum.Two);
    out.writeObject(c, TestClass.class);
    final StaticBuffer b = out.getStaticBuffer();

    int numThreads = 1;
    Thread[] threads = new Thread[numThreads];
    for (int i = 0; i < numThreads; i++) {
        threads[i] = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int j = 0; j < 100000; j++) {
                    ReadBuffer c = b.asReadBuffer();
                    assertEquals(8, c.getLong());
                    Long l = (Long) serialize.readClassAndObject(c);
                    assertEquals(8, l.longValue());
                    TestClass c2 = serialize.readObject(c, TestClass.class);
                }
            }
        });
        threads[i].start();
    }
    for (int i = 0; i < numThreads; i++) {
        threads[i].join();
    }
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:31,代码来源:SerializerTest.java

示例8: testSerializationMixture

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
@Test
public void testSerializationMixture() {
    for (int t = 0; t < 1000; t++) {
        DataOutput out = serialize.getDataOutput(128);
        int num = random.nextInt(100)+1;
        List<SerialEntry> entries = new ArrayList<SerialEntry>(num);
        for (int i = 0; i < num; i++) {
            Map.Entry<Class,Factory> type = Iterables.get(TYPES.entrySet(),random.nextInt(TYPES.size()));
            Object element = type.getValue().newInstance();
            boolean notNull = true;
            if (random.nextDouble()<0.5) {
                notNull = false;
                if (random.nextDouble()<0.2) element=null;
            }
            entries.add(new SerialEntry(element,type.getKey(),notNull));
            if (notNull) out.writeObjectNotNull(element);
            else out.writeObject(element,type.getKey());
        }
        StaticBuffer sb = out.getStaticBuffer();
        ReadBuffer in = sb.asReadBuffer();
        for (SerialEntry entry : entries) {
            Object read;
            if (entry.notNull) read = serialize.readObjectNotNull(in,entry.clazz);
            else read = serialize.readObject(in,entry.clazz);
            if (entry.object==null) assertNull(read);
            else if (entry.clazz.isArray()) {
                assertEquals(Array.getLength(entry.object),Array.getLength(read));
                for (int i = 0; i < Array.getLength(read); i++) {
                    assertEquals(Array.get(entry.object,i),Array.get(read,i));
                }
            } else assertEquals(entry.object,read);
        }
    }
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:35,代码来源:SerializerTest.java

示例9: fromLockColumn

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
public TimestampRid fromLockColumn(StaticBuffer lockKey) {
    ReadBuffer r = lockKey.asReadBuffer();
    int len = r.length();
    long tsNS = r.getLong();
    len -= 8;
    byte[] curRid = new byte[len];
    for (int i = 0; r.hasRemaining(); i++) {
        curRid[i] = r.getByte();
    }
    StaticBuffer rid = new StaticArrayBuffer(curRid);
    return new TimestampRid(tsNS, rid);
}
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:13,代码来源:ConsistentKeyLockerSerializer.java

示例10: edgeTypeIDTest

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
@Test
    public void edgeTypeIDTest() {
        int partitionBits = 16;
        IDManager eid = new IDManager(partitionBits);
        int trails = 1000000;
        assertEquals(eid.getPartitionBound(), (1l << partitionBits));

        Serializer serializer = new StandardSerializer();
        for (int t = 0; t < trails; t++) {
            long count = RandomGenerator.randomLong(1, eid.getSchemaCountBound());
            long id;
            IDHandler.DirectionID dirID;
            RelationCategory type;
            if (Math.random() < 0.5) {
                id = eid.getSchemaId(IDManager.VertexIDType.UserEdgeLabel,count);
                assertTrue(eid.isEdgeLabelId(id));
                assertFalse(eid.isSystemRelationTypeId(id));
                type = RelationCategory.EDGE;
                if (Math.random() < 0.5)
                    dirID = IDHandler.DirectionID.EDGE_IN_DIR;
                else
                    dirID = IDHandler.DirectionID.EDGE_OUT_DIR;
            } else {
                type = RelationCategory.PROPERTY;
                id = eid.getSchemaId(IDManager.VertexIDType.UserPropertyKey,count);
                assertTrue(eid.isPropertyKeyId(id));
                assertFalse(eid.isSystemRelationTypeId(id));
                dirID = IDHandler.DirectionID.PROPERTY_DIR;
            }
            assertTrue(eid.isRelationTypeId(id));

            StaticBuffer b = IDHandler.getRelationType(id, dirID, false);
//            System.out.println(dirID);
//            System.out.println(getBinary(id));
//            System.out.println(getBuffer(b.asReadBuffer()));
            ReadBuffer rb = b.asReadBuffer();
            IDHandler.RelationTypeParse parse = IDHandler.readRelationType(rb);
            assertEquals(id,parse.typeId);
            assertEquals(dirID, parse.dirID);
            assertFalse(rb.hasRemaining());

            //Inline edge type
            WriteBuffer wb = new WriteByteBuffer(9);
            IDHandler.writeInlineRelationType(wb, id);
            long newId = IDHandler.readInlineRelationType(wb.getStaticBuffer().asReadBuffer());
            assertEquals(id,newId);

            //Compare to Kryo
            DataOutput out = serializer.getDataOutput(10);
            IDHandler.writeRelationType(out, id, dirID, false);
            assertEquals(b, out.getStaticBuffer());

            //Make sure the bounds are right
            StaticBuffer[] bounds = IDHandler.getBounds(type,false);
            assertTrue(bounds[0].compareTo(b)<0);
            assertTrue(bounds[1].compareTo(b)>0);
            bounds = IDHandler.getBounds(RelationCategory.RELATION,false);
            assertTrue(bounds[0].compareTo(b)<0);
            assertTrue(bounds[1].compareTo(b)>0);
        }
    }
 
开发者ID:graben1437,项目名称:titan1withtp3.1,代码行数:62,代码来源:IDManagementTest.java

示例11: edgeTypeIDTest

import com.thinkaurelius.titan.diskstorage.StaticBuffer; //导入方法依赖的package包/类
@Test
    public void edgeTypeIDTest() {
        int partitionBits = 16;
        IDManager eid = new IDManager(partitionBits);
        IDInspector isp = eid.getIdInspector();
        int trails = 1000000;
        assertEquals(eid.getPartitionBound(), (1l << partitionBits));

        Serializer serializer = new StandardSerializer();
        for (int t = 0; t < trails; t++) {
            long count = RandomGenerator.randomLong(1, eid.getSchemaCountBound());
            long id;
            IDHandler.DirectionID dirID;
            RelationCategory type;
            if (Math.random() < 0.5) {
                id = eid.getSchemaId(IDManager.VertexIDType.UserEdgeLabel,count);
                assertTrue(isp.isEdgeLabelId(id));
                assertFalse(isp.isSystemRelationTypeId(id));
                type = RelationCategory.EDGE;
                if (Math.random() < 0.5)
                    dirID = IDHandler.DirectionID.EDGE_IN_DIR;
                else
                    dirID = IDHandler.DirectionID.EDGE_OUT_DIR;
            } else {
                type = RelationCategory.PROPERTY;
                id = eid.getSchemaId(IDManager.VertexIDType.UserPropertyKey,count);
                assertTrue(isp.isPropertyKeyId(id));
                assertFalse(isp.isSystemRelationTypeId(id));
                dirID = IDHandler.DirectionID.PROPERTY_DIR;
            }
            assertTrue(isp.isRelationTypeId(id));

            StaticBuffer b = IDHandler.getEdgeType(id, dirID, false);
//            System.out.println(dirID);
//            System.out.println(getBinary(id));
//            System.out.println(getBuffer(b.asReadBuffer()));
            ReadBuffer rb = b.asReadBuffer();
            IDHandler.EdgeTypeParse parse = IDHandler.readEdgeType(rb);
            assertEquals(id,parse.typeId);
            assertEquals(dirID, parse.dirID);
            assertFalse(rb.hasRemaining());

            //Inline edge type
            WriteBuffer wb = new WriteByteBuffer(9);
            IDHandler.writeInlineEdgeType(wb, id);
            long newId = IDHandler.readInlineEdgeType(wb.getStaticBuffer().asReadBuffer());
            assertEquals(id,newId);

            //Compare to Kryo
            DataOutput out = serializer.getDataOutput(10);
            IDHandler.writeEdgeType(out, id, dirID, false);
            assertEquals(b, out.getStaticBuffer());

            //Make sure the bounds are right
            StaticBuffer[] bounds = IDHandler.getBounds(type,false);
            assertTrue(bounds[0].compareTo(b)<0);
            assertTrue(bounds[1].compareTo(b)>0);
            bounds = IDHandler.getBounds(RelationCategory.RELATION,false);
            assertTrue(bounds[0].compareTo(b)<0);
            assertTrue(bounds[1].compareTo(b)>0);
        }
    }
 
开发者ID:graben1437,项目名称:titan0.5.4-hbase1.1.1-custom,代码行数:63,代码来源:IDManagementTest.java


注:本文中的com.thinkaurelius.titan.diskstorage.StaticBuffer.asReadBuffer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。