Package EDU.oswego.cs.dl.util.concurrent

Examples of EDU.oswego.cs.dl.util.concurrent.SynchronousChannel


    public void testConcurrentGC() throws Exception {
        Node root = testRootNode;
        Session session = root.getSession();

        final SynchronousChannel sync = new SynchronousChannel();
        final Node node = root.addNode("slowBlob");
        final int blobLength = 1000;
        final ValueFactory vf = session.getValueFactory();
        new Thread() {
            public void run() {
                try {
                    node.setProperty("slowBlob", vf.createBinary(new InputStream() {
                        int pos;
                        public int read() throws IOException {
                            pos++;
                            if (pos < blobLength) {
                                return pos % 80 == 0 ? '\n' : '.';
                            } else if (pos == blobLength) {
                                try {
                                    sync.put("x");
                                    // deleted
                                    sync.take();
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                                return 'x';
                            }
                            return -1;
                        }
                    }));
                    node.getSession().save();
                    sync.put("saved");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
        assertEquals("x", sync.take());
        DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
        gc.setPersistenceManagerScan(false);
        gc.mark();
        gc.sweep();
        sync.put("deleted");
        assertEquals("saved", sync.take());
        InputStream in = node.getProperty("slowBlob").getBinary().getStream();
        for (int pos = 1; pos < blobLength; pos++) {
            int expected = pos % 80 == 0 ? '\n' : '.';
            assertEquals(expected, in.read());
        }
View Full Code Here


        RepositoryImpl rep = (RepositoryImpl) session.getRepository();
        if (rep.getDataStore() == null) {
            LOG.info("testConcurrentGC skipped. Data store is not used.");
            return;
        }
        final SynchronousChannel sync = new SynchronousChannel();
        final Node node = root.addNode("slowBlob");
        new Thread() {
            public void run() {
                try {
                    node.setProperty("slowBlob", new InputStream() {
                        int pos = 0;
                        public int read() throws IOException {
                            pos++;
                            if (pos < 10000) {
                                return pos % 80 == 0 ? '\n' : '.';
                            } else if (pos == 10000) {
                                try {
                                    sync.put("x");
                                    // deleted
                                    sync.take();
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                                return 'x';
                            }
                            return -1;
                        }
                    });
                    node.getSession().save();
                    sync.put("saved");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
        assertEquals("x", sync.take());
        GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
        gc.scan();
        gc.stopScan();
        gc.deleteUnused();
        sync.put("deleted");
        assertEquals("saved", sync.take());
        InputStream in = node.getProperty("slowBlob").getStream();
        for (int pos = 1; pos < 10000; pos++) {
            int expected = pos % 80 == 0 ? '\n' : '.';
            assertEquals(expected, in.read());
        }
View Full Code Here

        RepositoryImpl rep = (RepositoryImpl) session.getRepository();
        if (rep.getDataStore() == null) {
            LOG.info("testConcurrentGC skipped. Data store is not used.");
            return;
        }
        final SynchronousChannel sync = new SynchronousChannel();
        final Node node = root.addNode("slowBlob");
        new Thread() {
            public void run() {
                try {
                    node.setProperty("slowBlob", new InputStream() {
                        int pos = 0;
                        public int read() throws IOException {
                            pos++;
                            if (pos < 10000) {
                                return pos % 80 == 0 ? '\n' : '.';
                            } else if (pos == 10000) {
                                try {
                                    sync.put("x");
                                    // deleted
                                    sync.take();
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                                return 'x';
                            }
                            return -1;
                        }
                    });
                    node.getSession().save();
                    sync.put("saved");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
        assertEquals("x", sync.take());
        GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
        gc.scan();
        gc.stopScan();
        gc.deleteUnused();
        sync.put("deleted");
        assertEquals("saved", sync.take());
        InputStream in = node.getProperty("slowBlob").getStream();
        for (int pos = 1; pos < 10000; pos++) {
            int expected = pos % 80 == 0 ? '\n' : '.';
            assertEquals(expected, in.read());
        }
View Full Code Here

        RepositoryImpl rep = (RepositoryImpl) session.getRepository();
        if (rep.getDataStore() == null) {
            LOG.info("testConcurrentGC skipped. Data store is not used.");
            return;
        }
        final SynchronousChannel sync = new SynchronousChannel();
        final Node node = root.addNode("slowBlob");
        new Thread() {
            public void run() {
                try {
                    node.setProperty("slowBlob", new InputStream() {
                        int pos;
                        public int read() throws IOException {
                            pos++;
                            if (pos < 10000) {
                                return pos % 80 == 0 ? '\n' : '.';
                            } else if (pos == 10000) {
                                try {
                                    sync.put("x");
                                    // deleted
                                    sync.take();
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                                return 'x';
                            }
                            return -1;
                        }
                    });
                    node.getSession().save();
                    sync.put("saved");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
        assertEquals("x", sync.take());
        GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
        gc.scan();
        gc.stopScan();
        gc.deleteUnused();
        sync.put("deleted");
        assertEquals("saved", sync.take());
        InputStream in = node.getProperty("slowBlob").getStream();
        for (int pos = 1; pos < 10000; pos++) {
            int expected = pos % 80 == 0 ? '\n' : '.';
            assertEquals(expected, in.read());
        }
View Full Code Here

        RepositoryImpl rep = (RepositoryImpl) session.getRepository();
        if (rep.getDataStore() == null) {
            LOG.info("testConcurrentGC skipped. Data store is not used.");
            return;
        }
        final SynchronousChannel sync = new SynchronousChannel();
        final Node node = root.addNode("slowBlob");
        final int blobLength = 1000;
        final ValueFactory vf = session.getValueFactory();
        new Thread() {
            public void run() {
                try {
                    node.setProperty("slowBlob", vf.createBinary(new InputStream() {
                        int pos;
                        public int read() throws IOException {
                            pos++;
                            if (pos < blobLength) {
                                return pos % 80 == 0 ? '\n' : '.';
                            } else if (pos == blobLength) {
                                try {
                                    sync.put("x");
                                    // deleted
                                    sync.take();
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                                return 'x';
                            }
                            return -1;
                        }
                    }));
                    node.getSession().save();
                    sync.put("saved");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
        assertEquals("x", sync.take());
        GarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
        gc.scan();
        gc.stopScan();
        gc.deleteUnused();
        sync.put("deleted");
        assertEquals("saved", sync.take());
        InputStream in = node.getProperty("slowBlob").getBinary().getStream();
        for (int pos = 1; pos < blobLength; pos++) {
            int expected = pos % 80 == 0 ? '\n' : '.';
            assertEquals(expected, in.read());
        }
View Full Code Here

    public void testConcurrentGC() throws Exception {
        Node root = testRootNode;
        Session session = root.getSession();

        final SynchronousChannel sync = new SynchronousChannel();
        final Node node = root.addNode("slowBlob");
        final int blobLength = 1000;
        final ValueFactory vf = session.getValueFactory();
        new Thread() {
            public void run() {
                try {
                    node.setProperty("slowBlob", vf.createBinary(new InputStream() {
                        int pos;
                        public int read() throws IOException {
                            pos++;
                            if (pos < blobLength) {
                                return pos % 80 == 0 ? '\n' : '.';
                            } else if (pos == blobLength) {
                                try {
                                    sync.put("x");
                                    // deleted
                                    sync.take();
                                } catch (InterruptedException e) {
                                    e.printStackTrace();
                                }
                                return 'x';
                            }
                            return -1;
                        }
                    }));
                    node.getSession().save();
                    sync.put("saved");
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }.start();
        assertEquals("x", sync.take());
        DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
        gc.setPersistenceManagerScan(false);
        gc.mark();
        gc.sweep();
        sync.put("deleted");
        assertEquals("saved", sync.take());
        InputStream in = node.getProperty("slowBlob").getBinary().getStream();
        for (int pos = 1; pos < blobLength; pos++) {
            int expected = pos % 80 == 0 ? '\n' : '.';
            assertEquals(expected, in.read());
        }
View Full Code Here

TOP

Related Classes of EDU.oswego.cs.dl.util.concurrent.SynchronousChannel

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.