Search in sources :

Example 66 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project opennms by OpenNMS.

the class RuleSet method updateEngine.

public void updateEngine(DroolsCorrelationEngine engine) {
    engine.setAssertBehaviour(getAssertBehaviour());
    engine.setEventProcessingMode(getEventProcessingMode());
    engine.setPersistState(getPersistState());
    engine.setScheduler(new ScheduledThreadPoolExecutor(1));
    engine.setInterestingEvents(getInterestingEvents());
    engine.setRulesResources(getRuleResources(engine.getConfigContext()));
    engine.setGlobals(getGlobals(engine.getConfigContext()));
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 67 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project opennms by OpenNMS.

the class JavaMailAckReaderIT method findAndProcessAcks.

@Ignore
@Test
public void findAndProcessAcks() throws InterruptedException {
    AckReader reader = new DefaultAckReader();
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    reader.setAckProcessor(m_processor);
    Future<?> f = executor.schedule(m_processor, 5, TimeUnit.SECONDS);
    m_processor.setJmConfigDao(m_jmDao);
    m_processor.setAckdConfigDao(createAckdConfigDao());
    // Thread.sleep(20000);
    while (!f.isDone()) {
        Thread.sleep(10);
    }
    Assert.assertTrue(f.isDone());
}
Also used : AckReader(org.opennms.netmgt.ackd.AckReader) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 68 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project android_frameworks_base by AOSPA.

the class FileOperationService method onCreate.

@Override
public void onCreate() {
    // Allow tests to pre-set these with test doubles.
    if (executor == null) {
        executor = new ScheduledThreadPoolExecutor(POOL_SIZE);
    }
    if (jobFactory == null) {
        jobFactory = Job.Factory.instance;
    }
    if (DEBUG)
        Log.d(TAG, "Created.");
    mPowerManager = getSystemService(PowerManager.class);
    mNotificationManager = getSystemService(NotificationManager.class);
}
Also used : PowerManager(android.os.PowerManager) NotificationManager(android.app.NotificationManager) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 69 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project ignite by apache.

the class AgentDemoUtils method newScheduledThreadPool.

/**
 * Creates a thread pool that can schedule commands to run after a given delay, or to execute periodically.
 *
 * @param corePoolSize Number of threads to keep in the pool, even if they are idle.
 * @param threadName Part of thread name that would be used by thread factory.
 * @return Newly created scheduled thread pool.
 */
public static ScheduledExecutorService newScheduledThreadPool(int corePoolSize, final String threadName) {
    ScheduledExecutorService srvc = Executors.newScheduledThreadPool(corePoolSize, new ThreadFactory() {

        @Override
        public Thread newThread(Runnable r) {
            Thread thread = new Thread(r, String.format("%s-%d", threadName, THREAD_CNT.getAndIncrement()));
            thread.setDaemon(true);
            return thread;
        }
    });
    ScheduledThreadPoolExecutor executor = (ScheduledThreadPoolExecutor) srvc;
    // Setting up shutdown policy.
    executor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
    executor.setContinueExistingPeriodicTasksAfterShutdownPolicy(false);
    return srvc;
}
Also used : ThreadFactory(java.util.concurrent.ThreadFactory) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor)

Example 70 with ScheduledThreadPoolExecutor

use of java.util.concurrent.ScheduledThreadPoolExecutor in project toolkit by googleapis.

the class Pubsub method gapic.

private static void gapic(final Settings settings) throws Exception {
    ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(1);
    // In real clients, InstantiatingChannelProvider is responsible for adding interceptors.
    // We can't use it here because InstantiatingChannelProvider doesn't have sslContext method.
    // Instead, we imitate HeaderInterceptor.
    ClientInterceptor headerInterceptor = new ClientInterceptor() {

        @Override
        public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
            ClientCall<ReqT, RespT> call = next.newCall(method, callOptions);
            return new SimpleForwardingClientCall<ReqT, RespT>(call) {

                @Override
                public void start(ClientCall.Listener<RespT> responseListener, Metadata headers) {
                    headers.put(X_GOOG_HEADER_KEY, X_GOOG_HEADER_VALUE);
                    super.start(responseListener, headers);
                }
            };
        }
    };
    ManagedChannel channel = NettyChannelBuilder.forTarget(settings.endpoint()).executor(executor).sslContext(GrpcSslContexts.forClient().trustManager(new File(settings.cert())).build()).intercept(headerInterceptor).build();
    final Semaphore semaphore = new Semaphore(settings.numWorkers());
    final TopicAdminClient client = TopicAdminClient.create(TopicAdminSettings.defaultBuilder().setChannelProvider(FixedChannelProvider.create(channel)).setExecutorProvider(FixedExecutorProvider.create(executor)).build());
    final AtomicLong resetTime = new AtomicLong();
    final AtomicLong numCalls = new AtomicLong();
    final AtomicLong numErrs = new AtomicLong();
    long endTime = System.nanoTime() + settings.warmDurNano() + settings.targetDurNano();
    Thread resetter = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(settings.warmDurNano() / MILLION);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            numCalls.set(0);
            numErrs.set(0);
            resetTime.set(System.nanoTime());
        }
    });
    resetter.start();
    while (System.nanoTime() < endTime) {
        semaphore.acquire(1);
        ApiFutures.addCallback(client.getTopicCallable().futureCall(GetTopicRequest.newBuilder().setTopicWithTopicName(TOPIC_NAME_RESOURCE).build()), new ApiFutureCallback<Topic>() {

            @Override
            public void onSuccess(Topic topic) {
                if (!topic.getName().equals(TOPIC_NAME_STRING)) {
                    numErrs.incrementAndGet();
                }
                both();
            }

            @Override
            public void onFailure(Throwable t) {
                numErrs.incrementAndGet();
                both();
            }

            void both() {
                numCalls.incrementAndGet();
                semaphore.release(1);
            }
        });
    }
    long nCalls = numCalls.get();
    long nErrs = numErrs.get();
    long runDurNano = System.nanoTime() - resetTime.get();
    System.out.println("errors: " + nErrs);
    System.out.println("calls: " + nCalls);
    System.out.println("time per call (ns): " + (runDurNano / nCalls));
    System.out.println("QPS: " + (nCalls * BILLION / runDurNano));
    client.close();
    channel.shutdown().awaitTermination(10, TimeUnit.SECONDS);
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
}
Also used : ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Metadata(io.grpc.Metadata) CallOptions(io.grpc.CallOptions) Semaphore(java.util.concurrent.Semaphore) ClientInterceptor(io.grpc.ClientInterceptor) ManagedChannel(io.grpc.ManagedChannel) Topic(com.google.pubsub.v1.Topic) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) MethodDescriptor(io.grpc.MethodDescriptor) AtomicLong(java.util.concurrent.atomic.AtomicLong) TopicAdminClient(com.google.cloud.pubsub.spi.v1.TopicAdminClient) File(java.io.File) SimpleForwardingClientCall(io.grpc.ForwardingClientCall.SimpleForwardingClientCall)

Aggregations

ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)154 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)31 Test (org.junit.Test)26 ExecutorService (java.util.concurrent.ExecutorService)24 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)22 ThreadFactory (java.util.concurrent.ThreadFactory)15 Test (org.testng.annotations.Test)15 ArrayList (java.util.ArrayList)12 List (java.util.List)10 HashMap (java.util.HashMap)9 ServerInstance (com.linkedin.pinot.common.response.ServerInstance)8 NettyClientMetrics (com.linkedin.pinot.transport.metrics.NettyClientMetrics)8 MetricsRegistry (com.yammer.metrics.core.MetricsRegistry)8 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)8 HashedWheelTimer (io.netty.util.HashedWheelTimer)8 File (java.io.File)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ThreadFactoryBuilder (com.google.common.util.concurrent.ThreadFactoryBuilder)7 IOException (java.io.IOException)7 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7