Search in sources :

Example 51 with ArrayBlockingQueue

use of java.util.concurrent.ArrayBlockingQueue in project uavstack by uavorg.

the class NodeOperAgent method start.

@Override
public void start() {
    IActionEngine engine = this.getActionEngineMgr().getActionEngine("NodeOperActionEngine");
    // setup actions
    new MOFInstallMgtAction("installmof", feature, engine);
    new MOFInstallMgtAction("uninstallmof", feature, engine);
    new MSCPGeneralAction("fstart", feature, engine);
    new MSCPGeneralAction("fstop", feature, engine);
    new MSCPGeneralAction("killproc", feature, engine);
    new MSCPGeneralAction("kill", feature, engine);
    new MSCPGeneralAction("shutdown", feature, engine);
    new MSCPGeneralAction("chgsyspro", feature, engine);
    new MSCPGeneralAction("loadnodepro", feature, engine);
    new MSCPGeneralAction("chgnodepro", feature, engine);
    new MSCPGeneralAction("watch", feature, engine);
    new MSCPGeneralAction("unwatch", feature, engine);
    new MSCPGeneralAction("upgrade", feature, engine);
    new MSCPGeneralAction("restart", feature, engine);
    new MSCPGeneralAction("stopuav", feature, engine);
    new MOFCtrlAction("ctrlmof", feature, engine);
    // start HeartBeatServerListenWorker
    nodeOperHttpServer = new NodeOperHttpServer("NodeOperHttpServer", this.feature, "nodeophandlers");
    int port = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.port"), 10101);
    int backlog = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.backlog"), 10);
    int core = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.core"), 5);
    int max = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.max"), 10);
    int bqsize = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.bqsize"), 10);
    @SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor exe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
    /**
     * if the node ctrl server port conflicts, the node process will exit
     */
    nodeOperHttpServer.start(exe, port, backlog, true);
    if (log.isTraceEnable()) {
        log.info(this, "NodeOperHttpServer started");
    }
}
Also used : NodeOperHttpServer(com.creditease.agent.feature.nodeopagent.NodeOperHttpServer) MSCPGeneralAction(com.creditease.agent.feature.nodeopagent.actions.MSCPGeneralAction) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) MOFInstallMgtAction(com.creditease.agent.feature.nodeopagent.actions.MOFInstallMgtAction) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) IActionEngine(com.creditease.agent.spi.IActionEngine) MOFCtrlAction(com.creditease.agent.feature.nodeopagent.actions.MOFCtrlAction)

Example 52 with ArrayBlockingQueue

use of java.util.concurrent.ArrayBlockingQueue in project uavstack by uavorg.

the class AppHubManager method start.

@Override
public void start() {
    // start AppHubMangerServerWorker
    int port = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.port"));
    int backlog = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.backlog"));
    int core = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.core"));
    int max = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.max"));
    int bqsize = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.bqsize"));
    apphubManagerServerListenWorker = new AppHubManagerServerWorker("ApphubMangerServerWorker", this.feature, "appHubManagerHandlers");
    @SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor exe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
    apphubManagerServerListenWorker.start(exe, port, backlog);
    if (log.isTraceEnable()) {
        log.info(this, "AppHubManager DataStore HttpServer started");
    }
    buildDBService("AppHub.app", new AppDataAdpater());
    buildDBService("AppHub.group", new GroupDataAdpater());
    buildDBService("AppHub.feedback", new FeedbackDataAdpater());
    // start datastore
    DataStoreFactory.getInstance().startAll(this.feature);
}
Also used : AppHubManagerServerWorker(com.creditease.uav.feature.apphubmanager.AppHubManagerServerWorker) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) AppDataAdpater(com.creditease.uav.feature.apphubmanager.datastore.adaptors.AppDataAdpater) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) GroupDataAdpater(com.creditease.uav.feature.apphubmanager.datastore.adaptors.GroupDataAdpater) FeedbackDataAdpater(com.creditease.uav.feature.apphubmanager.datastore.adaptors.FeedbackDataAdpater)

Example 53 with ArrayBlockingQueue

use of java.util.concurrent.ArrayBlockingQueue in project uavstack by uavorg.

the class HealthManager method start.

@Override
public void start() {
    // init cache manager
    String cacheServerAddress = this.getConfigManager().getFeatureConfiguration(this.feature, "store.addr");
    int minConcurrent = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.min"));
    int maxConcurrent = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.max"));
    int queueSize = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.bqsize"));
    String password = this.getConfigManager().getFeatureConfiguration(this.feature, "store.concurrent.pwd");
    CacheManager cm = CacheManagerFactory.build(cacheServerAddress, minConcurrent, maxConcurrent, queueSize, password);
    this.getConfigManager().registerComponent(this.feature, "HMCacheManager", cm);
    // start HealthManagerProfileDataLifeKeeper
    isStartLifeKeeper = Boolean.parseBoolean(this.getConfigManager().getFeatureConfiguration(this.feature, "lifekeeper.enable"));
    if (isStartLifeKeeper == true) {
        // init HealthManagerProfileDataLifeKeeper
        HealthManagerProfileDataLifeKeeper profileDataLifeKeepWorker = new HealthManagerProfileDataLifeKeeper("HealthManagerProfileDataLifeKeeper", this.feature);
        long interval = Long.parseLong(this.getConfigManager().getFeatureConfiguration(this.feature, "lifekeeper.interval"));
        long randomDely = new Random().nextInt(3) + 3;
        this.getTimerWorkManager().scheduleWorkInPeriod("HealthManagerProfileDataLifeKeeper", profileDataLifeKeepWorker, randomDely * 1000, interval);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManagerProfileDataLifeKeeper started");
        }
    }
    /**
     * Start the DBStore service NOTE: this must be the first to start
     */
    buildDataStores(this.getConfigManager());
    // start all datastores
    DataStoreFactory.getInstance().startAll(this.feature);
    if (log.isTraceEnable()) {
        log.info(this, "HealthManager DataStore Factory started");
    }
    /**
     * Start the HealthManger Http service
     */
    int port = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.port"));
    int backlog = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.backlog"));
    int core = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.core"));
    int max = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.max"));
    int bqsize = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.bqsize"));
    healthServerListenWorker = new HealthManagerServerWorker("HealthMangerServerWorker", this.feature, "healthMangerHandlers");
    @SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor exe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
    healthServerListenWorker.start(exe, port, backlog);
    if (log.isTraceEnable()) {
        log.info(this, "HealthManager DataStore HttpServer started");
    }
    StandardMessagingBuilder smb = new StandardMessagingBuilder("HMCommonMsgBuilder", this.feature);
    try {
        smb.init("com.creditease.uav.feature.healthmanager.messaging.handlers");
    } catch (IOException e) {
        log.err(this, "Read msgtype2topic.properties FAILs, HealthManager can not START", e);
        return;
    }
    monitorDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Monitor.toString());
    notificationConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Notification.toString());
    profileDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Profile.toString());
    logDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Log.toString());
    nodeinfoDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.NodeInfo.toString());
    // start monitorDataConsumer
    if (monitorDataConsumer != null) {
        monitorDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_MONITOR, monitorDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager MDFConsumer started");
        }
    }
    // start notificationConsumer
    if (this.notificationConsumer != null) {
        notificationConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_NOTIFY, notificationConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager NotifyConsumer started");
        }
    }
    // start profileDataConsumer
    if (this.profileDataConsumer != null) {
        /**
         * INIT StandardProfileModelingEngine & StandardProfileModeler
         */
        IActionEngine engine = this.getActionEngineMgr().newActionEngine("StandardProfileModelingEngine", feature);
        new StandardProfileModeler("StandardProfileModeler", feature, engine);
        // start profile consumer
        profileDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_PROFILE, profileDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager ProfileConsumer started");
        }
    }
    // start logDataConsumer
    if (this.logDataConsumer != null) {
        logDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_LOG, logDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager LogConsumer started");
        }
    }
    // start nodeinfoDataConsumer
    if (nodeinfoDataConsumer != null) {
        nodeinfoDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, HealthManagerConstants.COMSUMER_NODE, nodeinfoDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HealthManager NodeInfoConsumer started");
        }
    }
}
Also used : StandardMessagingBuilder(org.uavstack.resources.common.messaging.StandardMessagingBuilder) HealthManagerServerWorker(com.creditease.uav.feature.healthmanager.HealthManagerServerWorker) IOException(java.io.IOException) IActionEngine(com.creditease.agent.spi.IActionEngine) HealthManagerProfileDataLifeKeeper(com.creditease.uav.feature.healthmanager.HealthManagerProfileDataLifeKeeper) Random(java.util.Random) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) CacheManager(com.creditease.uav.cache.api.CacheManager) StandardProfileModeler(com.creditease.agent.profile.api.StandardProfileModeler) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 54 with ArrayBlockingQueue

use of java.util.concurrent.ArrayBlockingQueue in project uavstack by uavorg.

the class HMNewLogService method start.

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void start() {
    /**
     * INIT ESClient
     */
    String esAddrStr = this.getConfigManager().getFeatureConfiguration(this.feature, "es.addr");
    String clusterName = this.getConfigManager().getFeatureConfiguration(this.feature, "es.clustername");
    ESClient client = new ESClient(esAddrStr, clusterName);
    this.getConfigManager().registerComponent(this.feature, "ESClient", client);
    /**
     * HMNewLogIndexMgr
     */
    new HMNewLogIndexMgr("HMNewLogIndexMgr", feature);
    /**
     * Log Consumer
     */
    StandardMessagingBuilder smb = new StandardMessagingBuilder("HMCommonMsgBuilder", this.feature);
    try {
        smb.init("com.creditease.uav.healthmanager.newlog.handlers");
    } catch (IOException e) {
        log.err(this, "Read msgtype2topic.properties FAILs, HealthManager can not START", e);
        return;
    }
    logDataConsumer = smb.buildConsumer(MonitorDataFrame.MessageType.Log.toString());
    // start logDataConsumer
    if (this.logDataConsumer != null) {
        logDataConsumer.start();
        this.getConfigManager().registerComponent(this.feature, "NewlogDataConsumer", logDataConsumer);
        if (log.isTraceEnable()) {
            log.info(this, "HMNewLogService LogConsumer started");
        }
    }
    // run NewLogQueryServerWorker
    boolean isStartQueryServer = DataConvertHelper.toBoolean(this.getConfigManager().getFeatureConfiguration(this.feature, "http.enable"), true);
    if (isStartQueryServer == true) {
        int port = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.port"), 7899);
        int backlog = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.backlog"), 10);
        int core = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.core"), 10);
        int max = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.max"), 100);
        int bqsize = DataConvertHelper.toInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.bqsize"), 10);
        queryServer = new NewLogQueryServerWorker("NewLogQueryServerWorker", feature, "qhandlers");
        ThreadPoolExecutor executor = new ThreadPoolExecutor(core, max, 30, TimeUnit.SECONDS, new ArrayBlockingQueue(bqsize));
        queryServer.start(executor, port, backlog);
        if (log.isTraceEnable()) {
            log.info(this, "NewLogQueryServerWorker started");
        }
    }
}
Also used : StandardMessagingBuilder(org.uavstack.resources.common.messaging.StandardMessagingBuilder) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) ESClient(com.creditease.uav.elasticsearch.client.ESClient) IOException(java.io.IOException) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) NewLogQueryServerWorker(com.creditease.uav.healthmanager.newlog.http.NewLogQueryServerWorker)

Example 55 with ArrayBlockingQueue

use of java.util.concurrent.ArrayBlockingQueue in project felix by apache.

the class PerformanceTestIT method measureThroughputSend.

@Test
public void measureThroughputSend() {
    loadEventAdmin();
    addListener(new Listener() {

        @Override
        public void handleEvent(Event event) {
            long calledTimes = counter.incrementAndGet();
            if (calledTimes == BATCH_SIZE) {
                synchronized (counter) {
                    counter.notify();
                }
            }
        }
    }, "topic");
    // Warm-up
    Hashtable<String, Object> properties = new Hashtable<String, Object>();
    for (int i = 0; i < BATCH_SIZE; i++) {
        properties.put("key", i);
        send("topic", properties, false);
    }
    int average = 0;
    for (int runs = 0; runs < RUNS; runs++) {
        final CountDownLatch latch = new CountDownLatch(BATCH_SIZE);
        addListener(new Listener() {

            @Override
            public void handleEvent(Event event) {
                latch.countDown();
            }
        }, "topic" + runs);
        ArrayBlockingQueue<Runnable> workQueue = new ArrayBlockingQueue<Runnable>(BATCH_SIZE + 1);
        ThreadPoolExecutor executor = new ThreadPoolExecutor(1, 1, 1000, TimeUnit.MILLISECONDS, workQueue);
        for (int i = 0; i < BATCH_SIZE; i++) {
            final String topicString = "topic" + runs;
            final Hashtable<String, Object> localProperties = new Hashtable<String, Object>();
            localProperties.put(topicString, i);
            workQueue.add(new Runnable() {

                @Override
                public void run() {
                    send(topicString, localProperties, true);
                }
            });
        }
        long startTime = System.nanoTime();
        executor.prestartAllCoreThreads();
        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        long endTime = System.nanoTime();
        long milliseconds = (endTime - startTime) / 1000000;
        logger.info("Post Run " + runs + " Elapsed :" + milliseconds);
        average += milliseconds;
    }
    logger.info("Send Avg: " + average / RUNS);
}
Also used : Hashtable(java.util.Hashtable) CountDownLatch(java.util.concurrent.CountDownLatch) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Event(org.osgi.service.event.Event) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor) Test(org.junit.Test)

Aggregations

ArrayBlockingQueue (java.util.concurrent.ArrayBlockingQueue)440 Test (org.junit.Test)158 ArrayList (java.util.ArrayList)75 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)74 IOException (java.io.IOException)66 CountDownLatch (java.util.concurrent.CountDownLatch)58 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)41 BlockingQueue (java.util.concurrent.BlockingQueue)34 ExecutorService (java.util.concurrent.ExecutorService)34 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)31 List (java.util.List)29 LocalAddress (io.netty.channel.local.LocalAddress)27 HashMap (java.util.HashMap)25 HttpTrade (org.jocean.http.server.HttpServerBuilder.HttpTrade)25 Subscription (rx.Subscription)25 PooledByteBufAllocator (io.netty.buffer.PooledByteBufAllocator)24 HttpInitiator (org.jocean.http.client.HttpClient.HttpInitiator)23 File (java.io.File)22 CompletableFuture (java.util.concurrent.CompletableFuture)22 LinkedList (java.util.LinkedList)21