Package krati.retention.clock

Examples of krati.retention.clock.Clock


        return -1;
    }
   
    @Override
    public boolean put(Event<T> event) {
        Clock clock = event.getClock();
        int size = _events.size();
       
        if(size == 0 && _minClock.before(clock)) {
            _minClock = clock;
            _maxClock = clock;
View Full Code Here


    protected RandomClockFactory _randClockFactory = new RandomClockFactory(2);
   
    public void testApiBasics() {
        EventBatch<String> batch;
        long origin = _rand.nextInt(Integer.MAX_VALUE);
        Clock clock = _randClockFactory.next();
        int capacity = Math.max(EventBatch.MINIMUM_BATCH_SIZE, _rand.nextInt(2000));
       
        batch = new SimpleEventBatch<String>(origin, clock, capacity);
       
        assertEquals(EventBatch.VERSION, batch.getVersion());
        assertEquals(0, batch.getSize());
        assertEquals(origin, batch.getOrigin());
        assertEquals(Occurred.EQUICONCURRENTLY, clock.compareTo(batch.getMinClock()));
        assertEquals(Occurred.EQUICONCURRENTLY, clock.compareTo(batch.getMaxClock()));
       
        // Add the first event
        clock = _randClockFactory.next();
        batch.put(new SimpleEvent<String>("Event." + clock, clock));
       
        assertTrue(clock.compareTo(batch.getMinClock()) == Occurred.EQUICONCURRENTLY);
        assertTrue(clock.compareTo(batch.getMaxClock()) == Occurred.EQUICONCURRENTLY);
        assertEquals(1, batch.getSize());
       
        // Add the second event
        clock = _randClockFactory.next();
        batch.put(new SimpleEvent<String>("Event." + clock, clock));
       
        assertTrue(clock.after(batch.getMinClock()));
        assertTrue(clock.compareTo(batch.getMaxClock()) == Occurred.EQUICONCURRENTLY);
        assertEquals(2, batch.getSize());
       
        do {
            clock = _randClockFactory.next();
        } while(batch.put(new SimpleEvent<String>("Event." + clock, clock)));
       
        assertTrue(clock.after(batch.getMinClock()));
        assertTrue(clock.after(batch.getMaxClock()));
        assertEquals(capacity, batch.getSize());
       
        batch.setCompletionTime(System.currentTimeMillis() + 1);
        assertTrue(batch.getCreationTime() < batch.getCompletionTime());
       
View Full Code Here

        assertEquals(batch.getOrigin() + batch.getSize(), nextOffset);
    }
   
    public void testEventBatchSerializer() {
        long origin = _rand.nextInt(Integer.MAX_VALUE);
        Clock clock = _randClockFactory.next();
       
        EventBatch<String> batch = new SimpleEventBatch<String>(origin, clock);
        do {
            clock = _randClockFactory.next();
        } while(batch.put(new SimpleEvent<String>("Event." + clock, clock)));
View Full Code Here

                  _logger.error("Failed to open a cursor", e);
              }
            }
        }
       
        Clock batchClock = Clock.ZERO;
        long batchOrigin = 0L;
        int cnt = list.size();
       
        if (cnt > 0) {
            Collections.sort(list, new Comparator<EventBatchCursor>() {
View Full Code Here

        return _batch.getOrigin() + _batch.getSize();
    }
   
    @Override
    public Clock getMinClock() {
        Clock batchMinClock = _batch.getMinClock();
        EventBatchCursor cursor = _retentionQueue.peek();
        return cursor == null ? batchMinClock : cursor.getHeader().getMinClock();
    }
View Full Code Here

    }
   
    @Override
    public Clock getClock(long offset) {
        EventBatch<T> b;
        Clock clock;
       
        if(offset < getOrigin()) {
            return null;
        }
       
View Full Code Here

       
        // Get events from _batch       
        b = _batch;
        if(b.getOrigin() <= pos.getOffset()) {
            long newOffset = b.get(pos.getOffset(), list);
            Clock clock = pos.getOffset() < newOffset ?
                    b.getClock(newOffset - 1) : pos.getClock();
            return new SimplePosition(getId(), newOffset, clock);
        }
       
        // Get events from _lastBatch
        b = _lastBatch;
        if(b != null && b.getOrigin() <= pos.getOffset()) {
            long newOffset = b.get(pos.getOffset(), list);
            Clock clock = pos.getOffset() < newOffset ?
                    b.getClock(newOffset - 1) : pos.getClock();
            return new SimplePosition(getId(), newOffset, clock);
        }
       
        // Get events from batches in retention
        int cnt = 0;
        Iterator<EventBatchCursor> iter = _retentionQueue.iterator();
        while(iter.hasNext()) {
            EventBatchCursor c = iter.next();
            if(c.getHeader().getOrigin() <= pos.getOffset()) {
                byte[] dat = _store.get(c.getLookup());
                try {
                    b = _eventBatchSerializer.deserialize(dat);
                    long newOffset = b.get(pos.getOffset(), list);
                    if(pos.getOffset() < newOffset) {
                        Clock clock = b.getClock(newOffset - 1);
                        return new SimplePosition(getId(), newOffset, clock);
                    }
                } catch(Exception e) {
                    _logger.warn("Ignored EventBatch: " + c.getHeader().getOrigin());
                }
View Full Code Here

            iter.reset(index);
        } catch(ArrayIndexOutOfBoundsException e) {
            return new SimplePosition(_id, pos.getOffset(), pos.getClock());
        }
       
        Clock evtClock;
        Clock posClock = pos.getClock();
       
        int cnt = 0;
        int lastIndex = index;
        while(iter.hasNext()) {
            lastIndex = iter.index();
            Entry<T, Clock> e = iter.next();
           
            evtClock = e.getValue();
            if(posClock.beforeEqual(evtClock)) {
                list.add(new SimpleEvent<T>(e.getKey(), evtClock));
                cnt++;
            }
           
            if(cnt >= _eventBatchSize) {
                index = iter.index();
                if(lastIndex == index) {
                    while(iter.hasNext() && iter.index() == index) {
                        e = iter.next();
                       
                        evtClock = e.getValue();
                        if(posClock.beforeEqual(evtClock)) {
                            list.add(new SimpleEvent<T>(e.getKey(), evtClock));
                            cnt++;
                        }
                    }
                    index++;
View Full Code Here

        return new RetentionPolicyOnTime(getRetentionTimeInSeconds(), TimeUnit.SECONDS);
    }
   
    @Override
    public void testRetentionPolicy() throws Exception {
        Clock clock;
        Clock startClock;
       
        clock = _clockFactory.next();
        startClock = clock;
        _retention.put(nextEvent(clock));
       
View Full Code Here

        long[] values = new long[parts.length - 3];
        for(int i = 0; i < values.length; i++) {
            values[i] = Long.parseLong(parts[3+i]);
        }
       
        return new SimplePosition(id, offset, index, new Clock(values));
    }
View Full Code Here

TOP

Related Classes of krati.retention.clock.Clock

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.