Search in sources :

Example 86 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project wildfly by wildfly.

the class PersistenceUnitServiceImpl method start.

@Override
public void start(final StartContext context) throws StartException {
    final ExecutorService executor = executorInjector.getValue();
    final AccessControlContext accessControlContext = AccessController.doPrivileged(GetAccessControlContextAction.getInstance());
    final Runnable task = new Runnable() {

        // run async in a background thread
        @Override
        public void run() {
            PrivilegedAction<Void> privilegedAction = new PrivilegedAction<Void>() {

                // run as security privileged action
                @Override
                public Void run() {
                    ClassLoader old = Thread.currentThread().getContextClassLoader();
                    Thread.currentThread().setContextClassLoader(classLoader);
                    if (javaNamespaceSetup != null) {
                        javaNamespaceSetup.setup(Collections.<String, Object>emptyMap());
                    }
                    try {
                        PhaseOnePersistenceUnitServiceImpl phaseOnePersistenceUnitService = phaseOnePersistenceUnitServiceInjectedValue.getOptionalValue();
                        WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName);
                        Object wrapperBeanManagerLifeCycle = null;
                        // creating container EntityManagerFactory
                        if (validatorFactory != null) {
                            properties.getValue().put(VALIDATOR_FACTORY, validatorFactory);
                        }
                        // handle phase 2 of 2 of bootstrapping the persistence unit
                        if (phaseOnePersistenceUnitService != null) {
                            ROOT_LOGGER.startingPersistenceUnitService(2, pu.getScopedPersistenceUnitName());
                            // indicate that the second phase of bootstrapping the persistence unit has started
                            phaseOnePersistenceUnitService.setSecondPhaseStarted(true);
                            if (beanManagerInjector.getOptionalValue() != null) {
                                wrapperBeanManagerLifeCycle = phaseOnePersistenceUnitService.getBeanManagerLifeCycle();
                                // update the bean manager proxy to the actual CDI bean manager
                                proxyBeanManager = phaseOnePersistenceUnitService.getBeanManager();
                                proxyBeanManager.setDelegate(beanManagerInjector.getOptionalValue());
                            }
                            EntityManagerFactoryBuilder emfBuilder = phaseOnePersistenceUnitService.getEntityManagerFactoryBuilder();
                            // persistence unit bootstrap.
                            if (validatorFactory != null) {
                                emfBuilder.withValidatorFactory(validatorFactory);
                            }
                            // get the EntityManagerFactory from the second phase of the persistence unit bootstrap
                            entityManagerFactory = emfBuilder.build();
                        } else {
                            ROOT_LOGGER.startingService("Persistence Unit", pu.getScopedPersistenceUnitName());
                            // start the persistence unit in one pass (1 of 1)
                            pu.setTempClassLoaderFactory(new TempClassLoaderFactoryImpl(classLoader));
                            pu.setJtaDataSource(jtaDataSource.getOptionalValue());
                            pu.setNonJtaDataSource(nonJtaDataSource.getOptionalValue());
                            if (beanManagerInjector.getOptionalValue() != null) {
                                proxyBeanManager = new ProxyBeanManager();
                                proxyBeanManager.setDelegate(beanManagerInjector.getOptionalValue());
                                wrapperBeanManagerLifeCycle = persistenceProviderAdaptor.beanManagerLifeCycle(proxyBeanManager);
                                if (wrapperBeanManagerLifeCycle != null) {
                                    // pass the wrapper object representing the bean manager life cycle object
                                    properties.getValue().put(CDI_BEAN_MANAGER, wrapperBeanManagerLifeCycle);
                                } else {
                                    properties.getValue().put(CDI_BEAN_MANAGER, proxyBeanManager);
                                }
                            }
                            entityManagerFactory = createContainerEntityManagerFactory();
                        }
                        persistenceUnitRegistry.add(getScopedPersistenceUnitName(), getValue());
                        if (wrapperBeanManagerLifeCycle != null) {
                            beanManagerAfterDeploymentValidation.register(persistenceProviderAdaptor, wrapperBeanManagerLifeCycle);
                        }
                        context.complete();
                    } catch (Throwable t) {
                        context.failed(new StartException(t));
                    } finally {
                        Thread.currentThread().setContextClassLoader(old);
                        // release the temp classloader factory (only needed when creating the EMF)
                        pu.setTempClassLoaderFactory(null);
                        WritableServiceBasedNamingStore.popOwner();
                        if (javaNamespaceSetup != null) {
                            javaNamespaceSetup.teardown(Collections.<String, Object>emptyMap());
                        }
                    }
                    return null;
                }
            };
            WildFlySecurityManager.doChecked(privilegedAction, accessControlContext);
        }
    };
    try {
        executor.execute(task);
    } catch (RejectedExecutionException e) {
        task.run();
    } finally {
        context.asynchronous();
    }
}
Also used : EntityManagerFactoryBuilder(org.jipijapa.plugin.spi.EntityManagerFactoryBuilder) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) AccessControlContext(java.security.AccessControlContext) PrivilegedAction(java.security.PrivilegedAction) ExecutorService(java.util.concurrent.ExecutorService) TempClassLoaderFactoryImpl(org.jboss.as.jpa.classloader.TempClassLoaderFactoryImpl) ProxyBeanManager(org.jboss.as.jpa.beanmanager.ProxyBeanManager) StartException(org.jboss.msc.service.StartException)

Example 87 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project wildfly by wildfly.

the class PhaseOnePersistenceUnitServiceImpl method start.

@Override
public void start(final StartContext context) throws StartException {
    final ExecutorService executor = executorInjector.getValue();
    final AccessControlContext accessControlContext = AccessController.doPrivileged(GetAccessControlContextAction.getInstance());
    final Runnable task = new Runnable() {

        // run async in a background thread
        @Override
        public void run() {
            PrivilegedAction<Void> privilegedAction = new PrivilegedAction<Void>() {

                // run as security privileged action
                @Override
                public Void run() {
                    try {
                        ROOT_LOGGER.startingPersistenceUnitService(1, pu.getScopedPersistenceUnitName());
                        pu.setTempClassLoaderFactory(new TempClassLoaderFactoryImpl(classLoader));
                        pu.setJtaDataSource(jtaDataSource.getOptionalValue());
                        pu.setNonJtaDataSource(nonJtaDataSource.getOptionalValue());
                        if (proxyBeanManager != null) {
                            if (wrapperBeanManagerLifeCycle != null) {
                                // pass the wrapper object representing the bean manager life cycle object
                                properties.getValue().put(CDI_BEAN_MANAGER, wrapperBeanManagerLifeCycle);
                            } else {
                                properties.getValue().put(CDI_BEAN_MANAGER, proxyBeanManager);
                            }
                        }
                        WritableServiceBasedNamingStore.pushOwner(deploymentUnitServiceName);
                        entityManagerFactoryBuilder = createContainerEntityManagerFactoryBuilder();
                        context.complete();
                    } catch (Throwable t) {
                        context.failed(new StartException(t));
                    } finally {
                        // release the temp classloader factory (only needed when creating the EMF)
                        pu.setTempClassLoaderFactory(null);
                        WritableServiceBasedNamingStore.popOwner();
                    }
                    return null;
                }
            };
            WildFlySecurityManager.doChecked(privilegedAction, accessControlContext);
        }
    };
    try {
        executor.execute(task);
    } catch (RejectedExecutionException e) {
        task.run();
    } finally {
        context.asynchronous();
    }
}
Also used : AccessControlContext(java.security.AccessControlContext) PrivilegedAction(java.security.PrivilegedAction) ExecutorService(java.util.concurrent.ExecutorService) TempClassLoaderFactoryImpl(org.jboss.as.jpa.classloader.TempClassLoaderFactoryImpl) StartException(org.jboss.msc.service.StartException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 88 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project cloudstack by apache.

the class ClusteredAgentManagerImpl method getTransferScanTask.

private Runnable getTransferScanTask() {
    return new ManagedContextRunnable() {

        @Override
        protected void runInContext() {
            try {
                if (s_logger.isTraceEnabled()) {
                    s_logger.trace("Clustered agent transfer scan check, management server id:" + _nodeId);
                }
                synchronized (_agentToTransferIds) {
                    if (_agentToTransferIds.size() > 0) {
                        s_logger.debug("Found " + _agentToTransferIds.size() + " agents to transfer");
                        // for (Long hostId : _agentToTransferIds) {
                        for (final Iterator<Long> iterator = _agentToTransferIds.iterator(); iterator.hasNext(); ) {
                            final Long hostId = iterator.next();
                            final AgentAttache attache = findAttache(hostId);
                            // if the thread:
                            // 1) timed out waiting for the host to reconnect
                            // 2) recipient management server is not active any more
                            // 3) if the management server doesn't own the host any more
                            // remove the host from re-balance list and delete from op_host_transfer DB
                            // no need to do anything with the real attache as we haven't modified it yet
                            final Date cutTime = DateUtil.currentGMTTime();
                            final HostTransferMapVO transferMap = _hostTransferDao.findActiveHostTransferMapByHostId(hostId, new Date(cutTime.getTime() - rebalanceTimeOut));
                            if (transferMap == null) {
                                s_logger.debug("Timed out waiting for the host id=" + hostId + " to be ready to transfer, skipping rebalance for the host");
                                iterator.remove();
                                _hostTransferDao.completeAgentTransfer(hostId);
                                continue;
                            }
                            if (transferMap.getInitialOwner() != _nodeId || attache == null || attache.forForward()) {
                                s_logger.debug("Management server " + _nodeId + " doesn't own host id=" + hostId + " any more, skipping rebalance for the host");
                                iterator.remove();
                                _hostTransferDao.completeAgentTransfer(hostId);
                                continue;
                            }
                            final ManagementServerHostVO ms = _mshostDao.findByMsid(transferMap.getFutureOwner());
                            if (ms != null && ms.getState() != ManagementServerHost.State.Up) {
                                s_logger.debug("Can't transfer host " + hostId + " as it's future owner is not in UP state: " + ms + ", skipping rebalance for the host");
                                iterator.remove();
                                _hostTransferDao.completeAgentTransfer(hostId);
                                continue;
                            }
                            if (attache.getQueueSize() == 0 && attache.getNonRecurringListenersSize() == 0) {
                                iterator.remove();
                                try {
                                    _executor.execute(new RebalanceTask(hostId, transferMap.getInitialOwner(), transferMap.getFutureOwner()));
                                } catch (final RejectedExecutionException ex) {
                                    s_logger.warn("Failed to submit rebalance task for host id=" + hostId + "; postponing the execution");
                                    continue;
                                }
                            } else {
                                s_logger.debug("Agent " + hostId + " can't be transfered yet as its request queue size is " + attache.getQueueSize() + " and listener queue size is " + attache.getNonRecurringListenersSize());
                            }
                        }
                    } else {
                        if (s_logger.isTraceEnabled()) {
                            s_logger.trace("Found no agents to be transfered by the management server " + _nodeId);
                        }
                    }
                }
            } catch (final Throwable e) {
                s_logger.error("Problem with the clustered agent transfer scan check!", e);
            }
        }
    };
}
Also used : ManagedContextRunnable(org.apache.cloudstack.managed.context.ManagedContextRunnable) ManagementServerHostVO(com.cloud.cluster.ManagementServerHostVO) HostTransferMapVO(com.cloud.cluster.agentlb.HostTransferMapVO) Date(java.util.Date) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Example 89 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project geode by apache.

the class SingleHopClientExecutor method submitAllHA.

static boolean submitAllHA(List callableTasks, LocalRegion region, boolean isHA, ResultCollector rc, Set<String> failedNodes) {
    ClientMetadataService cms = region.getCache().getClientMetadataService();
    boolean reexecute = false;
    if (callableTasks != null && !callableTasks.isEmpty()) {
        List futures = null;
        try {
            futures = execService.invokeAll(callableTasks);
        } catch (RejectedExecutionException rejectedExecutionEx) {
            throw rejectedExecutionEx;
        } catch (InterruptedException e) {
            throw new InternalGemFireException(e.getMessage());
        }
        if (futures != null) {
            GemFireException functionExecutionException = null;
            Iterator futureItr = futures.iterator();
            Iterator taskItr = callableTasks.iterator();
            final boolean isDebugEnabled = logger.isDebugEnabled();
            while (futureItr.hasNext() && !execService.isShutdown() && !execService.isTerminated()) {
                Future fut = (Future) futureItr.next();
                SingleHopOperationCallable task = (SingleHopOperationCallable) taskItr.next();
                ServerLocation server = task.getServer();
                try {
                    fut.get();
                    if (isDebugEnabled) {
                        logger.debug("ExecuteRegionFunctionSingleHopOp#got result from {}", server);
                    }
                } catch (InterruptedException e) {
                    throw new InternalGemFireException(e.getMessage());
                } catch (ExecutionException ee) {
                    if (ee.getCause() instanceof InternalFunctionInvocationTargetException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.InternalFunctionInvocationTargetException : Caused by :{}", ee.getCause());
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        reexecute = true;
                        failedNodes.addAll(((InternalFunctionInvocationTargetException) ee.getCause()).getFailedNodeSet());
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            rc.clearResults();
                        } else {
                            if (ee.getCause().getCause() != null) {
                                functionExecutionException = new FunctionInvocationTargetException(ee.getCause().getCause());
                            } else {
                                functionExecutionException = new FunctionInvocationTargetException(new BucketMovedException(LocalizedStrings.FunctionService_BUCKET_MIGRATED_TO_ANOTHER_NODE.toLocalizedString()));
                            }
                        }
                    } else if (ee.getCause() instanceof FunctionException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.FunctionException : Caused by :{}", ee.getCause());
                        }
                        FunctionException fe = (FunctionException) ee.getCause();
                        if (isHA) {
                            throw fe;
                        } else {
                            functionExecutionException = fe;
                        }
                    } else if (ee.getCause() instanceof ServerOperationException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerOperationException : Caused by :{}", ee.getCause());
                        }
                        ServerOperationException soe = (ServerOperationException) ee.getCause();
                        if (isHA) {
                            throw soe;
                        } else {
                            functionExecutionException = soe;
                        }
                    } else if (ee.getCause() instanceof ServerConnectivityException) {
                        if (isDebugEnabled) {
                            logger.debug("ExecuteRegionFunctionSingleHopOp#ExecutionException.ServerConnectivityException : Caused by :{} The failed server is: {}", ee.getCause(), server);
                        }
                        try {
                            cms = region.getCache().getClientMetadataService();
                        } catch (CacheClosedException e) {
                            return false;
                        }
                        cms.removeBucketServerLocation(server);
                        cms.scheduleGetPRMetaData(region, false);
                        // Clear the results only if isHA so that partial results can be returned.
                        if (isHA) {
                            reexecute = true;
                            rc.clearResults();
                        } else {
                            functionExecutionException = (ServerConnectivityException) ee.getCause();
                        }
                    } else {
                        throw executionThrowable(ee.getCause());
                    }
                }
            }
            if (functionExecutionException != null) {
                throw functionExecutionException;
            }
        }
    }
    return reexecute;
}
Also used : InternalGemFireException(org.apache.geode.InternalGemFireException) ServerLocation(org.apache.geode.distributed.internal.ServerLocation) FunctionException(org.apache.geode.cache.execute.FunctionException) BucketMovedException(org.apache.geode.internal.cache.execute.BucketMovedException) CacheClosedException(org.apache.geode.cache.CacheClosedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ServerConnectivityException(org.apache.geode.cache.client.ServerConnectivityException) InternalGemFireException(org.apache.geode.InternalGemFireException) GemFireException(org.apache.geode.GemFireException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Iterator(java.util.Iterator) FunctionInvocationTargetException(org.apache.geode.cache.execute.FunctionInvocationTargetException) InternalFunctionInvocationTargetException(org.apache.geode.internal.cache.execute.InternalFunctionInvocationTargetException) Future(java.util.concurrent.Future) VersionedObjectList(org.apache.geode.internal.cache.tier.sockets.VersionedObjectList) List(java.util.List) ServerOperationException(org.apache.geode.cache.client.ServerOperationException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) ExecutionException(java.util.concurrent.ExecutionException)

Example 90 with RejectedExecutionException

use of java.util.concurrent.RejectedExecutionException in project geode by apache.

the class QueueManagerImpl method scheduleRedundancySatisfierIfNeeded.

protected void scheduleRedundancySatisfierIfNeeded(long delay) {
    if (shuttingDown) {
        return;
    }
    synchronized (lock) {
        if (shuttingDown) {
            return;
        }
        if (queueConnections.getPrimary() == null || getCurrentRedundancy() < redundancyLevel || redundancyLevel == -1 || queueConnections.primaryDiscoveryFailed()) {
            if (redundancySatisfierTask != null) {
                if (redundancySatisfierTask.getRemainingDelay() > delay) {
                    redundancySatisfierTask.cancel();
                } else {
                    return;
                }
            }
            redundancySatisfierTask = new RedundancySatisfierTask();
            try {
                ScheduledFuture future = recoveryThread.schedule(redundancySatisfierTask, delay, TimeUnit.MILLISECONDS);
                redundancySatisfierTask.setFuture(future);
            } catch (RejectedExecutionException e) {
            // ignore, the timer has been cancelled, which means we're shutting down.
            }
        }
    }
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) RejectedExecutionException(java.util.concurrent.RejectedExecutionException)

Aggregations

RejectedExecutionException (java.util.concurrent.RejectedExecutionException)246 ExecutorService (java.util.concurrent.ExecutorService)42 IOException (java.io.IOException)34 Test (org.junit.Test)34 Future (java.util.concurrent.Future)19 ArrayList (java.util.ArrayList)18 Executor (java.util.concurrent.Executor)18 ExecutionException (java.util.concurrent.ExecutionException)15 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)15 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)15 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)14 List (java.util.List)11 TaskRejectedException (org.springframework.core.task.TaskRejectedException)11 BitmapDrawable (android.graphics.drawable.BitmapDrawable)10 Animation (android.view.animation.Animation)10 Map (java.util.Map)10 CancellationException (java.util.concurrent.CancellationException)10 CacheableBitmapDrawable (uk.co.senab.bitmapcache.CacheableBitmapDrawable)10 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9