Search in sources :

Example 46 with ArrayBlockingQueue

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

the class CollectionProducerTest method testCollectionProducer.

public void testCollectionProducer() throws Exception {
    Queue<Exchange> queue = new ArrayBlockingQueue<Exchange>(10);
    Endpoint endpoint = context.getEndpoint("seda://foo");
    MyProducer my = new MyProducer(endpoint, queue);
    my.start();
    Exchange exchange = new DefaultExchange(context);
    exchange.getIn().setBody("Hello World");
    my.process(exchange);
    Exchange top = queue.poll();
    assertNotNull(top);
    assertEquals("Hello World", top.getIn().getBody());
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) DefaultExchange(org.apache.camel.impl.DefaultExchange) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Endpoint(org.apache.camel.Endpoint)

Example 47 with ArrayBlockingQueue

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

the class SedaQueueTest method testQueueRef.

public void testQueueRef() throws Exception {
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedBodiesReceived("Hello World");
    template.sendBody("seda:array?queue=#arrayQueue", "Hello World");
    SedaEndpoint sedaEndpoint = resolveMandatoryEndpoint("seda:array?queue=#arrayQueue", SedaEndpoint.class);
    assertTrue(sedaEndpoint.getQueue() instanceof ArrayBlockingQueue);
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) MockEndpoint(org.apache.camel.component.mock.MockEndpoint)

Example 48 with ArrayBlockingQueue

use of java.util.concurrent.ArrayBlockingQueue in project redisson by redisson.

the class RedissonLiveObjectServiceTest method testNoTransformation.

@Test
public void testNoTransformation() {
    RLiveObjectService service = redisson.getLiveObjectService();
    TestClassNoTransformation ts = new TestClassNoTransformation();
    ts = service.persist(ts);
    HashMap<String, String> m = new HashMap<>();
    ts.setContent(m);
    assertTrue(HashMap.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RMap.class.isAssignableFrom(ts.getContent().getClass()));
    HashSet<String> s = new HashSet<>();
    ts.setContent(s);
    assertTrue(HashSet.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RSet.class.isAssignableFrom(ts.getContent().getClass()));
    TreeSet<String> ss = new TreeSet<>();
    ts.setContent(ss);
    assertTrue(TreeSet.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RSortedSet.class.isAssignableFrom(ts.getContent().getClass()));
    ArrayList<String> al = new ArrayList<>();
    ts.setContent(al);
    assertTrue(ArrayList.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RList.class.isAssignableFrom(ts.getContent().getClass()));
    ConcurrentHashMap<String, String> chm = new ConcurrentHashMap<>();
    ts.setContent(chm);
    assertTrue(ConcurrentHashMap.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RMap.class.isAssignableFrom(ts.getContent().getClass()));
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue<>(10);
    abq.add("111");
    ts.setContent(abq);
    assertTrue(ArrayBlockingQueue.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RBlockingQueue.class.isAssignableFrom(ts.getContent().getClass()));
    ConcurrentLinkedQueue<String> clq = new ConcurrentLinkedQueue<>();
    ts.setContent(clq);
    assertTrue(ConcurrentLinkedQueue.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RQueue.class.isAssignableFrom(ts.getContent().getClass()));
    LinkedBlockingDeque<String> lbdq = new LinkedBlockingDeque<>();
    ts.setContent(lbdq);
    assertTrue(LinkedBlockingDeque.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RBlockingDeque.class.isAssignableFrom(ts.getContent().getClass()));
    LinkedList<String> ll = new LinkedList<>();
    ts.setContent(ll);
    assertTrue(LinkedList.class.isAssignableFrom(ts.getContent().getClass()));
    assertFalse(RDeque.class.isAssignableFrom(ts.getContent().getClass()));
}
Also used : LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RQueue(org.redisson.api.RQueue) ArrayList(java.util.ArrayList) RMap(org.redisson.api.RMap) RBlockingQueue(org.redisson.api.RBlockingQueue) RLiveObjectService(org.redisson.api.RLiveObjectService) RBlockingDeque(org.redisson.api.RBlockingDeque) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) RSet(org.redisson.api.RSet) TreeSet(java.util.TreeSet) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashSet(java.util.HashSet) LinkedList(java.util.LinkedList) RDeque(org.redisson.api.RDeque) RList(org.redisson.api.RList) RSortedSet(org.redisson.api.RSortedSet) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Test(org.junit.Test)

Example 49 with ArrayBlockingQueue

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

the class MonitorAgent method startMDSListenServer.

private void startMDSListenServer() {
    boolean isStartMDFListener = DataConvertHelper.toBoolean(this.getConfigManager().getFeatureConfiguration(this.feature, "http.enable"), false);
    if (isStartMDFListener == true) {
        // start MDFListenServer
        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"));
        mdfListenServer = new MDFListenServer("MDFListenServer", this.feature, "mdfhandlers");
        @SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor exe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
        mdfListenServer.start(exe, port, backlog);
        if (log.isTraceEnable()) {
            log.info(this, "MDFListenServer started");
        }
    }
}
Also used : ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) MDFListenServer(com.creditease.agent.feature.monitoragent.MDFListenServer) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

Example 50 with ArrayBlockingQueue

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

the class HeartBeatServerAgent 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, "HBCacheManager", cm);
    // start HeartBeatServerListenWorker
    hbServerListenWorker = new HeartBeatServerListenWorker("HeartBeatServerListenWorker", this.feature, "hbhandlers");
    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"));
    @SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor exe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
    hbServerListenWorker.start(exe, port, backlog);
    if (log.isTraceEnable()) {
        log.info(this, "HeartBeatServerListenWorker started");
    }
    // start HeartBeatQueryListenWorker
    hbqueryListenWorker = new HeartBeatQueryListenWorker("HeartBeatQueryListenWorker", this.feature, "hbqueryhandlers");
    int qport = Integer.parseInt(this.getConfigManager().getFeatureConfiguration(this.feature, "http.qport"));
    @SuppressWarnings({ "rawtypes", "unchecked" }) ThreadPoolExecutor qexe = new ThreadPoolExecutor(core, max, 30000, TimeUnit.MILLISECONDS, new ArrayBlockingQueue(bqsize));
    hbqueryListenWorker.start(qexe, qport, backlog);
    if (log.isTraceEnable()) {
        log.info(this, "HeartBeatQueryListenWorker started");
    }
    // start HeartBeatServerLifeKeeper
    boolean isStartLifeKeeper = Boolean.parseBoolean(this.getConfigManager().getFeatureConfiguration(this.feature, "lifekeeper.enable"));
    if (!isStartLifeKeeper) {
        return;
    }
    HeartBeatServerLifeKeeper hbserverLifeKeepWorker = new HeartBeatServerLifeKeeper("HeartBeatServerLifeKeeper", this.feature);
    long interval = Long.parseLong(this.getConfigManager().getFeatureConfiguration(this.feature, "lifekeeper.interval"));
    long randomDely = new Random().nextInt(3) + 3;
    this.getTimerWorkManager().scheduleWorkInPeriod("HeartBeatServerLifeKeeper", hbserverLifeKeepWorker, randomDely * 1000, interval);
    if (log.isTraceEnable()) {
        log.info(this, "HeartBeatServerLifeKeeper started");
    }
}
Also used : HeartBeatServerListenWorker(com.creditease.agent.feature.hbagent.HeartBeatServerListenWorker) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Random(java.util.Random) CacheManager(com.creditease.uav.cache.api.CacheManager) HeartBeatQueryListenWorker(com.creditease.agent.feature.hbagent.HeartBeatQueryListenWorker) HeartBeatServerLifeKeeper(com.creditease.agent.feature.hbagent.HeartBeatServerLifeKeeper) ThreadPoolExecutor(java.util.concurrent.ThreadPoolExecutor)

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