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

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


    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.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


     * @param maxPoolSize the maximum no. of threads to use
     * @param daemon      if <code>true</code> all threads will be daemon
     *                    threads
     */
    public ThreadPool(String name, int maxPoolSize, boolean daemon) {
        this(new ThreadGroup(name), name, new SynchronousChannel(), maxPoolSize,
                daemon);
    }
View Full Code Here

     * @param group       the thread group. May be <code>null</code>
     * @param name        the name to assign worker threads
     * @param maxPoolSize the maximum no. of threads to use
     */
    public ThreadPool(ThreadGroup group, String name, int maxPoolSize) {
        this(group, name, new SynchronousChannel(), maxPoolSize, false);
    }
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

                               long timeout) {
        this.extractor = extractor;
        this.timout = timeout;
        Channel c;
        if (backLog <= 0) {
            c = new SynchronousChannel();
        } else {
            c = new BoundedLinkedQueue(backLog);
        }
        this.executor = new PooledExecutor(c, poolSize);
        this.executor.setMinimumPoolSize(poolSize);
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

                               long timeout) {
        this.extractor = extractor;
        this.timout = timeout;
        Channel c;
        if (backLog <= 0) {
            c = new SynchronousChannel();
        } else {
            c = new BoundedLinkedQueue(backLog);
        }
        this.executor = new PooledExecutor(c, poolSize);
        this.executor.setMinimumPoolSize(poolSize);
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());
        DataStoreGarbageCollector gc = ((SessionImpl) session).createDataStoreGarbageCollector();
        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

                               long timeout) {
        this.extractor = extractor;
        this.timout = timeout;
        Channel c;
        if (backLog <= 0) {
            c = new SynchronousChannel();
        } else {
            c = new BoundedLinkedQueue(backLog);
        }
        this.executor = new PooledExecutor(c, poolSize);
        this.executor.setMinimumPoolSize(poolSize);
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.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$Queue

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.