Package krati.retention

Examples of krati.retention.Position


    }
   
    @Override
    public Position syncUp(Position position, Map<byte[], Event<byte[]>> map) {
        Map<K, Event<GenericRecord>> inputMap = new HashMap<K, Event<GenericRecord>>();
        Position nextPosition = _storeBus.get(position, inputMap);
       
        for(Map.Entry<K, Event<GenericRecord>> e : inputMap.entrySet()) {
            byte[] key = _keySerializer.serialize(e.getKey());
           
            GenericRecord record = e.getValue().getValue();
View Full Code Here


        GenericRecord record = (GenericRecord)request;
        String msgName = message.getName();

        if (msgName.equals(ProtocolConstants.MSG_SYNC)) {
            String positionStr = record.get("position").toString();
            Position position = _handler.getPosition(positionStr);
           
            // Check if clock value needs to be transferred
            Utf8 opt = (Utf8)record.get("opt");
            boolean clockNotNeeded = (opt == null) ? false : opt.toString().equals(StoreBusOptions.OPT_NO_CLOCK);
           
            Map<byte[], Event<byte[]>> map = new HashMap<byte[], Event<byte[]>>(1024);
            Position nextPosition = _handler.syncUp(position, map);
           
            Schema schemaKVC = getLocal().getType(ProtocolConstants.TYPE_KeyValueClock);
            Schema schema1 = getLocal().getType(ProtocolConstants.TYPE_SyncResultSet);
            Schema schema2 = schema1.getField("results").schema();
            GenericArray<GenericRecord> array = new GenericData.Array<GenericRecord>(map.size(), schema2);
           
            for(Map.Entry<byte[], Event<byte[]>> e : map.entrySet()) {
                GenericRecord kvc = new GenericData.Record(schemaKVC);
                kvc.put("key", ByteBuffer.wrap(e.getKey()));
               
                byte[] value = e.getValue().getValue();
                kvc.put("value", value == null ? null : ByteBuffer.wrap(value));
               
                Clock clock = clockNotNeeded ? null : e.getValue().getClock();
                kvc.put("clock", clock == null ? null : ByteBuffer.wrap(clock.toByteArray()));
               
                array.add(kvc);
            }
           
            GenericRecord response = new GenericData.Record(schema1);
            response.put("results", array);
            response.put("position", new Utf8(nextPosition.toString()));
           
            return response;
        }
       
        if (msgName.equals(ProtocolConstants.MSG_GET)) {
View Full Code Here

        for(int i = 0; i < 10; i++) {
            System.out.println("position=" + client.getPosition(Clock.ZERO));
            Thread.sleep(100);
        }
       
        Position position, nextPosition;
        Map<String, GenericRecord> map = new HashMap<String, GenericRecord>(1000);
       
        System.out.println();
        c.getElapsedTime();
       
View Full Code Here

        for(int i = 0; i < 10; i++) {
            System.out.println("position=" + client.getPosition(Clock.ZERO));
            Thread.sleep(100);
        }
       
        Position position, nextPosition;
        Map<Integer, GenericRecord> map = new HashMap<Integer, GenericRecord>(1000);
       
        System.out.println();
        c.getElapsedTime();
       
View Full Code Here

        }
        Clock maxClock = clock;
       
        assertEquals(getId(), _retention.getId());
       
        Position pos = _retention.getPosition();
        assertEquals((long)cnt, pos.getOffset());
        assertEquals(cnt, _retention.getOffset());
       
        assertTrue(minClock.compareTo(_retention.getMinClock()) == Occurred.EQUICONCURRENTLY);
        assertTrue(maxClock.compareTo(_retention.getMaxClock()) == Occurred.EQUICONCURRENTLY);
       
        Position sincePosition = _retention.getPosition(idleClock0);
        assertEquals(getId(), sincePosition.getId());
        assertEquals(0, sincePosition.getOffset());
       
        sincePosition = _retention.getPosition(idleClock1);
        assertEquals(getId(), sincePosition.getId());
        assertEquals(1, sincePosition.getOffset());
       
        Retention<T> retention2 = createRetention();
        assertTrue(minClock.compareTo(retention2.getMinClock()) == Occurred.EQUICONCURRENTLY);
        assertTrue(retention2.getMaxClock().beforeEqual(_retention.getMaxClock()));
       
        sincePosition = retention2.getPosition(idleClock0);
        assertEquals(getId(), sincePosition.getId());
        assertEquals(0, sincePosition.getOffset());
       
        sincePosition = _retention.getPosition(idleClock1);
        assertEquals(getId(), sincePosition.getId());
        assertEquals(1, sincePosition.getOffset());
    }
View Full Code Here

        return _readCount;
    }
   
    @Override
    public void run() {
        Position pos = _retention.getPosition(_retention.getClock(0));
        List<Event<T>> list = new ArrayList<Event<T>>();
       
        try {
            while(pos == null || pos.getOffset() < _stopOffset) {
                if(pos != null) {
                    pos = _retention.get(pos, list);
                    _readCount += list.size();
                    list.clear();
                }
View Full Code Here

import krati.retention.Position;

public class TestSimplePosition extends TestCase {
   
    public void testStringSerialization() {
        Position p1 = new SimplePosition(10, 5, 3, new Clock(11,17,23));
        Position p2 = new SimplePosition(10, 5, 3, new Clock(11,17,23));
        Position p3 = new SimplePosition(2, 4, 6, new Clock(8,10,12));
        assertEquals(p1, p2);
        assertFalse(p1.equals(p3));
    }
View Full Code Here

           
            writer.put(key, value, scn++);
            assertTrue(checkValueEquality(value, reader.get(key)));
        }
       
        Position pos = reader.getPosition(Clock.ZERO);
        assertTrue(pos.isIndexed());
        assertEquals(_store.keyIterator().index(), pos.getIndex());
        assertEquals(cnt, pos.getOffset());
        assertTrue(pos.getClock() == Clock.ZERO);
        assertEquals(_retention.getId(), pos.getId());
       
        pos = reader.getPosition(reader.getPosition().getClock());
        assertEquals(false, pos.isIndexed());
        assertEquals(reader.getPosition().getOffset(), pos.getOffset() + 1);
       
        // one more put
        K key = nextKey();
        V value = nextValue();
       
        writer.put(key, value, scn++);
        assertTrue(checkValueEquality(value, reader.get(key)));
        cnt++;
       
        pos = reader.getPosition(Clock.ZERO);
        assertTrue(pos.isIndexed());
        assertEquals(_store.keyIterator().index(), pos.getIndex());
        assertEquals(cnt, pos.getOffset());
        assertTrue(pos.getClock() == Clock.ZERO);
        assertEquals(_retention.getId(), pos.getId());
       
        pos = reader.getPosition(reader.getPosition().getClock());
        assertEquals(false, pos.isIndexed());
        assertEquals(reader.getPosition().getOffset(), pos.getOffset() + 1);
       
        // Read from the retention
        List<Event<K>> list = new ArrayList<Event<K>>();
       
        pos = reader.getPosition();
View Full Code Here

TOP

Related Classes of krati.retention.Position

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.