Package java.util.concurrent

Examples of java.util.concurrent.ScheduledExecutorService


     * that calls the semaphore a large number of times. Even if the semaphore's
     * period does not end, the thread should never block.
     */
    @Test
    public void testAcquireNoLimit() throws InterruptedException {
        ScheduledExecutorService service = EasyMock
                .createMock(ScheduledExecutorService.class);
        ScheduledFuture<?> future = EasyMock.createMock(ScheduledFuture.class);
        prepareStartTimer(service, future);
        EasyMock.replay(service, future);
        TimedSemaphoreTestImpl semaphore = new TimedSemaphoreTestImpl(service,
View Full Code Here


    /**
     * Tests whether the available non-blocking calls can be queried.
     */
    @Test
    public void testGetAvailablePermits() throws InterruptedException {
        ScheduledExecutorService service = EasyMock
                .createMock(ScheduledExecutorService.class);
        ScheduledFuture<?> future = EasyMock.createMock(ScheduledFuture.class);
        prepareStartTimer(service, future);
        EasyMock.replay(service, future);
        TimedSemaphore semaphore = new TimedSemaphore(service, PERIOD, UNIT,
View Full Code Here

    @Override
    public void setUp() throws Exception {
        super.setUp();
        cfg = new ServerConfiguration();
        final ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);
        sm = new ZkSubscriptionManager(zk, new TrivialOwnAllTopicManager(cfg, scheduler), null, cfg, scheduler);
        msgIdCallback = new Callback<MessageSeqId>() {
            @Override
            public void operationFailed(Object ctx, final PubSubException exception) {
                scheduler.execute(new Runnable() {
                    public void run() {
                        ConcurrencyUtils.put(msgIdCallbackQueue, Either.of((MessageSeqId) null, exception));
                    }
                });
            }

            @Override
            public void operationFinished(Object ctx, final MessageSeqId resultOfOperation) {
                scheduler.execute(new Runnable() {
                    public void run() {
                        ConcurrencyUtils.put(msgIdCallbackQueue, Either.of(resultOfOperation, (PubSubException) null));
                    }
                });
            }
        };

        voidCallback = new Callback<Void>() {
            @Override
            public void operationFailed(Object ctx, final PubSubException exception) {
                scheduler.execute(new Runnable() {
                    public void run() {
                        ConcurrencyUtils.put(BooleanCallbackQueue, Either.of((Boolean) null, exception));
                    }
                });
            }

            @Override
            public void operationFinished(Object ctx, Void resultOfOperation) {
                scheduler.execute(new Runnable() {
                    public void run() {
                        ConcurrencyUtils.put(BooleanCallbackQueue, Either.of(true, (PubSubException) null));
                    }
                });
            }
View Full Code Here

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        ServerConfiguration conf = new ServerConfiguration();
        ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();

        TopicManager tm = new TrivialOwnAllTopicManager(conf, executor);
        dm = new StubDeliveryManager();
        PersistenceManager pm = LocalDBPersistenceManager.instance();
        sm = new StubSubscriptionManager(tm, pm, conf, executor);
View Full Code Here

    }

    @Override
    PersistenceManager instantiatePersistenceManager() throws Exception {
        ServerConfiguration conf = new ServerConfiguration();
        ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1);

        return new BookkeeperPersistenceManager(bktb.bk, bktb.getZooKeeperClient(), new TrivialOwnAllTopicManager(conf,
                                                scheduler), conf, scheduler);
    }
View Full Code Here

        super(name);
    }

    public void testDependencyPool() throws Exception {
        // always use more threads than cpus, so that the single-cpu case can be tested
        ScheduledExecutorService executor = ExecutionPool.getExecutor(new ThreadGroup("DependencyPoolTests"), getName(), -2, true);
        DependencyPool<Integer, TestItem, String> pool = new DependencyPool<Integer, TestItem, String>(executor);
        int itemSize = 100, depMax = 5, subMax = 3;
        List<TestItem> items = new ArrayList<TestItem>(itemSize);
        List<TestItem> previousItems = new ArrayList<TestItem>(itemSize);
        for (int i = 0; i < itemSize; i++) {
            int depSize = (int) (Math.random() * Math.min(depMax, itemSize - i - 1));
            List<Integer> deps = new ArrayList<Integer>(depSize);
            for (int j = i + 1, k = 0; j < itemSize && k < depSize; j++) {
                if (Math.random() * (itemSize - j) / (depSize - k + 1) < 1) {
                    deps.add(j);
                    k++;
                }
            }
            int subSize = (int) (Math.random() * Math.min(subMax, i));
            List<TestItem> subItems = new ArrayList<TestItem>(subSize);
OUTER:
            for (int j = 0; j < previousItems.size() && subItems.size() < subSize;) {
                if (Math.random() * j < 1) {
                    TestItem previousItem = previousItems.get(j);
                    for (int k = 0; k < deps.size(); k++) {
                        if (previousItem.getDependencies().contains(deps.get(k))) {
                            j++;
                            continue OUTER;
                        }
                    }
                    subItems.add(previousItem);
                    previousItems.remove(j);
                } else {
                    j++;
                }
            }
            TestItem item = new TestItem(pool, Integer.valueOf(i), Integer.toString(i), deps, subItems);
            items.add(item);
            previousItems.add(item);
        }
        pool.addAll(items);
        pool.start();
        pool.await();
        assertEquals("result count", itemSize, pool.getResultCount());
        for (int i = 0; i < itemSize; i++) {
            TestItem item = items.get(i);
            assertEquals("item(" + i + ") result", Integer.toString(i), pool.getResult(item));
        }
        executor.shutdown();
    }
View Full Code Here

        List<String> loadedMounts = FastList.newInstance();
        if (webResourceInfos == null) {
            return;
        }

        ScheduledExecutorService executor = ExecutionPool.getExecutor(CATALINA_THREAD_GROUP, "catalina-startup", -1, true);
        try {
            List<Future<Context>> futures = FastList.newInstance();

            for (int i = webResourceInfos.size(); i > 0; i--) {
                ComponentConfig.WebappInfo appInfo = webResourceInfos.get(i - 1);
                String engineName = appInfo.server;
                List<String> virtualHosts = appInfo.getVirtualHosts();
                String mount = appInfo.getContextRoot();
                List<String> keys = FastList.newInstance();
                if (UtilValidate.isEmpty(virtualHosts)) {
                    keys.add(engineName + ":DEFAULT:" + mount);
                } else {
                    for (String virtualHost: virtualHosts) {
                        keys.add(engineName + ":" + virtualHost + ":" + mount);
                    }
                }
                if (!keys.removeAll(loadedMounts)) {
                    // nothing was removed from the new list of keys; this
                    // means there are no existing loaded entries that overlap
                    // with the new set
                    if (appInfo.location != null) {
                        futures.add(executor.submit(createContext(appInfo)));
                    }
                    loadedMounts.addAll(keys);
                } else {
                    appInfo.appBarDisplay = false; // disable app bar display on overrided apps
                    Debug.logInfo("Duplicate webapp mount; not loading : " + appInfo.getName() + " / " + appInfo.getLocation(), module);
                }
            }
            ExecutionPool.getAllFutures(futures);
        } finally {
            executor.shutdown();
        }
    }
View Full Code Here

            if (executorService instanceof ScheduledExecutorService) {
                return (ScheduledExecutorService) executorService;
            }
            throw new IllegalArgumentException("ExecutorServiceRef " + definition.getExecutorServiceRef() + " is not an ScheduledExecutorService instance");
        } else if (definition.getExecutorServiceRef() != null) {
            ScheduledExecutorService answer = routeContext.getCamelContext().getRegistry().lookup(definition.getExecutorServiceRef(), ScheduledExecutorService.class);
            if (answer == null) {
                // then create a thread pool assuming the ref is a thread pool profile id
                ThreadPoolProfile profile = manager.getThreadPoolProfile(definition.getExecutorServiceRef());
                if (profile != null) {
                    answer = manager.newScheduledThreadPool(definition, name, profile);
View Full Code Here

    @Override
    public Processor createProcessor(RouteContext routeContext) throws Exception {
        Processor childProcessor = this.createChildProcessor(routeContext, true);

        ScheduledExecutorService scheduled = ProcessorDefinitionHelper.getConfiguredScheduledExecutorService(routeContext, "Throttle", this, isAsyncDelayed());

        // should be default 1000 millis
        long period = getTimePeriodMillis() != null ? getTimePeriodMillis() : 1000L;

        // max requests per period is mandatory
View Full Code Here

    private ScheduledExecutorService getConfiguredScheduledExecutorService(RouteContext routeContext) {
        // TODO: maybe rather than this one-off method to support an executorService & scheduledExecutorService for the aggregator,
        // create ScheduledExecutorServiceAwareDefinition and the change other definitions that currently use ScheduledExecutorServices to
        // use that one instead of the more generic ExecutorServiceAwareDefinition
        ScheduledExecutorService answer = routeContext.getCamelContext().getRegistry().lookup(timeoutCheckerExecutorServiceRef, ScheduledExecutorService.class);
        if (answer == null) {
            ExecutorServiceManager manager = routeContext.getCamelContext().getExecutorServiceManager();
            // then create a thread pool assuming the ref is a thread pool profile id               
            ThreadPoolProfile profile = manager.getThreadPoolProfile(timeoutCheckerExecutorServiceRef);
            if (profile != null) {
View Full Code Here

TOP

Related Classes of java.util.concurrent.ScheduledExecutorService

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.