@Override public PageReference readFirstReference() throws SirixIOException { final PageReference uberPageReference = new PageReference(); // Read primary beacon. final long lastIndex = mChronicle.size() - 1; uberPageReference.setKey(lastIndex); final UberPage page = (UberPage) read(lastIndex, null); uberPageReference.setPage(page); return uberPageReference; }
public static void main(String[] args) throws Exception { String name = TMP + "/chronicle"; Chronicle chronicle = new IndexedChronicle(name); DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER); List<String> underlying = new ArrayList<String>(); int maxMessageSize = 128; ListWrapper<String> list = new ListWrapper<String>(dataStore, "testlist", String.class, underlying, maxMessageSize); dataStore.start(); for (int i = 0; i < 1000000; i++) { list.add(0, "hello" + i); list.add(1, "world" + i); list.remove(0); list.remove(1); // does nothing until second loop and leaves one elements } System.out.println("list.size(): " + list.size()); System.out.println("list: " + list); chronicle.close(); }
public InProcessChronicleSource(Chronicle chronicle, int port) throws IOException { this.chronicle = chronicle; server = ServerSocketChannel.open(); server.socket().setReuseAddress(true); server.socket().bind(new InetSocketAddress(port)); name = chronicle.name() + "@" + port; logger = Logger.getLogger(getClass().getName() + "." + name); service = Executors.newCachedThreadPool(new NamedThreadFactory(name)); service.execute(new Acceptor()); }
@Override public void close() { closed = true; chronicle.close(); try { server.close(); } catch (IOException e) { logger.warning("Error closing server port " + e); } }
public ChronicleReader(final Chronicle chronicle, final ByteHandler handler) throws SirixIOException { mChronicle = checkNotNull(chronicle); mByteHandler = checkNotNull(handler); mExcerpt = mChronicle.createExcerpt(); }
@Override public <E> EnumeratedMarshaller<E> getMarshaller(Class<E> eClass) { return chronicle.getMarshaller(eClass); }
@Override public <E> void setEnumeratedMarshaller(EnumeratedMarshaller<E> marshaller) { chronicle.setEnumeratedMarshaller(marshaller); }
@Override public ByteOrder byteOrder() { return chronicle.byteOrder(); }
@Override public long sizeInBytes() { return chronicle.sizeInBytes(); }
@Override public long size() { return chronicle.size(); }
@Override public String name() { return chronicle.name(); }
@Test public void testMethods() throws IOException { String name = TMP + "/set-methods"; ChronicleTools.deleteOnExit(name); { MapListener stringsListener = createMock("strings", MapListener.class); stringsListener.eventStart(1, "strings"); stringsListener.add("Hello", "hi"); stringsListener.eventEnd(true); stringsListener.eventStart(3, "strings"); stringsListener.add("World", "all"); stringsListener.eventEnd(true); MapListener intListener = createMock("ints", MapListener.class); for (int i = 0; i < 3; i++) { intListener.eventStart(i * 2, "ints"); intListener.add(i, i + 1000); intListener.eventEnd(true); } replay(stringsListener); replay(intListener); Chronicle chronicle = new IndexedChronicle(name); DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER); MapWrapper<String, String> strings = new MapWrapper<String, String>( dataStore, "strings", String.class, String.class, new LinkedHashMap<String, String>(), 16); strings.addListener(stringsListener); MapWrapper<Integer, Integer> ints = new MapWrapper<Integer, Integer>( dataStore, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16); ints.addListener(intListener); dataStore.start(); ints.put(0, 1000); strings.put("Hello", "hi"); ints.put(1, 1001); strings.put("World", "all"); ints.put(2, 1002); verify(stringsListener); verify(intListener); assertEquals("{Hello=hi, World=all}", strings.toString()); assertEquals("{0=1000, 1=1001, 2=1002}", ints.toString()); chronicle.close(); } { MapListener stringsListener = createMock("strings", MapListener.class); stringsListener.eventStart(5, "strings"); stringsListener.add("!", "end"); stringsListener.eventEnd(true); MapListener intListener = createMock("ints", MapListener.class); intListener.eventStart(6, "ints"); intListener.add(3, 1003); intListener.eventEnd(true); replay(stringsListener); replay(intListener); Chronicle chronicle = new IndexedChronicle(name); DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER); MapWrapper<String, String> strings = new MapWrapper<String, String>( dataStore, "strings", String.class, String.class, new LinkedHashMap<String, String>(), 16); strings.addListener(stringsListener); MapWrapper<Integer, Integer> ints = new MapWrapper<Integer, Integer>( dataStore, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16); ints.addListener(intListener); // assume we have all the events written so far dataStore.start(chronicle.size()); strings.put("!", "end"); ints.put(3, 1003); verify(stringsListener); verify(intListener); assertEquals("{Hello=hi, World=all, !=end}", strings.toString()); assertEquals("{0=1000, 1=1001, 2=1002, 3=1003}", ints.toString()); chronicle.close(); } }
@Test public void testMapPerformance() throws IOException { String name = TMP + "/map-perf"; ChronicleTools.deleteOnExit(name); long start = System.nanoTime(); int size = 0; { Chronicle chronicle = new IndexedChronicle(name); DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER); MapWrapper<String, String> strings = new MapWrapper<String, String>( dataStore, "strings", String.class, String.class, new LinkedHashMap<String, String>(), 16); MapWrapper<Integer, Integer> ints = new MapWrapper<Integer, Integer>( dataStore, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16); dataStore.start(); ints.clear(); strings.clear(); for (int j = 0; j < 10000; j++) { for (int i = 0; i < 100; i++) { ints.put(i, i + j); strings.put(Integer.toString(i), Integer.toString(i + j)); } size += Math.min(strings.size(), ints.size()); for (int i = 0; i < 100; i++) { ints.remove(i); strings.remove(Integer.toString(i)); } } chronicle.close(); } long mid = System.nanoTime(); { Chronicle chronicle = new IndexedChronicle(name); DataStore dataStore = new DataStore(chronicle, ModelMode.MASTER); MapWrapper<String, String> strings = new MapWrapper<String, String>( dataStore, "strings", String.class, String.class, new LinkedHashMap<String, String>(), 16); MapWrapper<Integer, Integer> ints = new MapWrapper<Integer, Integer>( dataStore, "ints", Integer.class, Integer.class, new LinkedHashMap<Integer, Integer>(), 16); dataStore.start(); chronicle.close(); } long end = System.nanoTime(); System.out.printf( "Took %.1f seconds avg to add&remove %,d elements and %.1f seconds avg to reload them%n", (mid - start) / 2e9, size, (end - mid) / 2e9); }