Example usage for java.util.concurrent ConcurrentLinkedQueue ConcurrentLinkedQueue

List of usage examples for java.util.concurrent ConcurrentLinkedQueue ConcurrentLinkedQueue

Introduction

In this page you can find the example usage for java.util.concurrent ConcurrentLinkedQueue ConcurrentLinkedQueue.

Prototype

public ConcurrentLinkedQueue() 

Source Link

Document

Creates a ConcurrentLinkedQueue that is initially empty.

Usage

From source file:com.alibaba.jstorm.message.netty.NettyClientSync.java

@SuppressWarnings("rawtypes")
NettyClientSync(Map storm_conf, ChannelFactory factory, ScheduledExecutorService scheduler, String host,
        int port, ReconnectRunnable reconnector) {
    super(storm_conf, factory, scheduler, host, port, reconnector);

    batchQueue = new ConcurrentLinkedQueue<MessageBatch>();

    WaitStrategy waitStrategy = (WaitStrategy) Utils
            .newInstance((String) storm_conf.get(Config.TOPOLOGY_DISRUPTOR_WAIT_STRATEGY));

    disruptorQueue = DisruptorQueue.mkInstance(name, ProducerType.MULTI, MAX_SEND_PENDING * 8, waitStrategy);
    disruptorQueue.consumerStarted();/*from  w w  w  .j  ava  2  s  .com*/

    if (connectMyself == false) {
        registerSyncMetrics();
    }

    Runnable trigger = new Runnable() {
        @Override
        public void run() {
            trigger();
        }
    };

    scheduler.scheduleAtFixedRate(trigger, 10, 1, TimeUnit.SECONDS);

    /**
     * In sync mode, it can't directly use common factory, it will occur problem when client close and restart
     */
    ThreadFactory bossFactory = new NettyRenameThreadFactory(
            MetricDef.NETTY_CLI + JStormServerUtils.getName(host, port) + "-boss");
    bossExecutor = Executors.newCachedThreadPool(bossFactory);
    ThreadFactory workerFactory = new NettyRenameThreadFactory(
            MetricDef.NETTY_CLI + JStormServerUtils.getName(host, port) + "-worker");
    workerExecutor = Executors.newCachedThreadPool(workerFactory);

    clientChannelFactory = new NioClientSocketChannelFactory(bossExecutor, workerExecutor, 1);

    start();

    LOG.info(this.toString());
}

From source file:com.github.gfernandez598.swf.conversation.optforrepl.SessionMapConversationContainer.java

/**
 * Create a new conversation container.//from   w  w  w  . j  a va2 s  .c  om
 * 
 * @param maxConversations
 *            the maximum number of allowed concurrent conversations, -1 for
 *            unlimited
 * @param lockTimeout
 *            lock acquisition timeout of conversation in seconds
 * @param sessionKey
 *            the key of this conversation container in the session
 */
public SessionMapConversationContainer(int maxConversations, int lockTimeout, String sessionKey) {
    Assert.hasText(sessionKey, "A sessionKey must be supplied.");
    this.maxConversations = maxConversations;
    this.lockTimeoutSeconds = lockTimeout;
    this.sessionKey = sessionKey;
    this.conversations = new ConcurrentLinkedQueue<ConversationId>();
}

From source file:org.apache.streams.hbase.HbasePersistWriter.java

/**
 * HbasePersistWriter constructor - resolve HbaseConfiguration from JVM 'hbase'.
 *//*  w  ww  .jav a 2s. c  o m*/
public HbasePersistWriter() {
    this.config = new ComponentConfigurator<>(HbaseConfiguration.class)
            .detectConfiguration(StreamsConfigurator.getConfig().getConfig("hbase"));
    this.persistQueue = new ConcurrentLinkedQueue<>();
}

From source file:org.apache.hadoop.fs.nfs.rpc.RpcClient.java

public RpcClient(String hostname, int port) throws IOException {

    tasks = new ConcurrentHashMap<>();
    pending = new ConcurrentLinkedQueue<>();
    xid = new AtomicInteger(new Random(System.currentTimeMillis()).nextInt(1024) * 1000000);
    errored = new AtomicBoolean(false);
    shutdown = new AtomicBoolean(false);

    ChannelFactory factory = new NioClientSocketChannelFactory(Executors.newCachedThreadPool(),
            Executors.newCachedThreadPool(), 1, 8);

    client = this;
    ChannelPipelineFactory pipelineFactory = new ChannelPipelineFactory() {
        @Override//from ww w  . j a  v  a 2s.c o  m
        public ChannelPipeline getPipeline() {
            return Channels.pipeline(new RpcFrameDecoder(),
                    new IdleStateHandler(timer, 0, 1, 0, TimeUnit.MICROSECONDS),
                    new RpcClientHandler(client, bootstrap, timer));
        }
    };
    bootstrap = new ClientBootstrap(factory);
    bootstrap.setPipelineFactory(pipelineFactory);

    bootstrap.setOption("remoteAddress", new InetSocketAddress(hostname, port));
    bootstrap.setOption("tcpNoDelay", true);
    bootstrap.setOption("keepAlive", false);
    bootstrap.setOption("soLinger", 0);
    bootstrap.setOption("receiveBufferSize", 32 * 1024 * 1024);
    bootstrap.setOption("sendBufferSize", 32 * 1024 * 1024);

    future = bootstrap.connect();
    future.awaitUninterruptibly();
    if (future.isDone() && (future.isCancelled() || !future.isSuccess())) {
        throw new IOException("Could not connect to " + hostname + " on port " + port);
    }
}

From source file:com.joshlong.esb.springintegration.modules.services.amazon.sqs.AmazonSQS2Client.java

public AmazonSQS2Client(String awsUser, String awsPw, String awsHost) {
    this.messageQueuesById = new ConcurrentHashMap<String, MessageQueue>();
    this.messagesNotYetRecieved = new ConcurrentLinkedQueue<Message>();
    this.awsUser = awsUser;
    this.awsPassword = awsPw;

    if (StringUtils.isEmpty(awsHost)) {
        awsHost = null; /// by default itll use "queue.amazonaws.com"  
    }/*  w  w  w  .  ja va 2s .c om*/

    this.awsHost = awsHost;
}

From source file:org.apache.streams.amazon.kinesis.KinesisPersistWriter.java

/**
 * KinesisPersistWriter constructor - resolves KinesisWriterConfiguration from JVM 'kinesis'.
 *//*from  ww  w . j a v  a 2  s.  co  m*/
public KinesisPersistWriter() {
    Config config = StreamsConfigurator.config.getConfig("kinesis");
    this.config = new ComponentConfigurator<>(KinesisWriterConfiguration.class).detectConfiguration(config);
    this.persistQueue = new ConcurrentLinkedQueue<>();
}

From source file:org.o3project.odenos.remoteobject.RemoteObject.java

/**
 * Constructor.//from  w  ww .j av  a  2  s . co m
 * @param objectId object ID.
 * @param dispatcher MessageDispatcher object.
 */
public RemoteObject(String objectId, MessageDispatcher dispatcher) {
    this.objectProperty = new ObjectProperty(this.getClass().getSimpleName(), objectId);
    this.objectProperty.setObjectState(ObjectProperty.State.INITIALIZING);
    setMessageDispatcher(dispatcher);
    this.eventSubscription = new EventSubscription(objectId);

    this.parser = this.createParser();

    this.mailbox = new ConcurrentLinkedQueue<Mail>();
}

From source file:me.schiz.jmeter.ring.udp.sampler.UDPRingSampler.java

@Override
public SampleResult sample(Entry entry) {
    boolean idling = false;
    SampleResult newSampleResult = new SampleResult();
    newSampleResult.setSampleLabel(getName());

    ConcurrentLinkedQueue<SampleResult> queue = tlQueue.get();
    if (queue == null) {
        queue = new ConcurrentLinkedQueue<SampleResult>();
        tlQueue.set(queue);/*from  w w w . j av  a 2s.c  om*/
    }

    Ring ring = UDPRingSourceElement.get(getSource());
    Token t;
    int tid = -1;
    byte[] request_in_bytes = new byte[0];

    ByteBuffer request = tlRequest.get();
    if (request == null) {
        request = tlBuffer.get();
        if (request == null) {
            request = ByteBuffer.allocateDirect(8 * 1024 * 1024);
            tlBuffer.set(request);
        }
        request.clear();

        if (isHex()) {
            try {
                request_in_bytes = Hex.decodeHex(getRequest().toCharArray());
            } catch (DecoderException e) {
                log.error("can't decode request", e);
                idling = true;
            }
        } else {
            request_in_bytes = getRequest().getBytes();
        }
        request.put(request_in_bytes);
    }
    if (!idling) {
        try {
            request.flip();
            while (tid == -1) {
                tid = ring.acquire();
            }
            t = ring.get(tid);
            t.lock.lock();
            if (isHex())
                t.ishex = true;
            newSampleResult.sampleStart();
            try {
                //t.socketChannel.write(request);
                t.sampleResult = newSampleResult;
                t.queue = queue;
                ring.write(tid, request);
                request.clear();
                newSampleResult.setSuccessful(true);
            } catch (IOException e) {
                newSampleResult.setSuccessful(false);
                ring.reset(tid);
                log.warn("IOException", e);
            } finally {
                t.lock.unlock();
            }

        } catch (Exception e) {
            log.error("Exception", e);
            newSampleResult.setSuccessful(false);
            newSampleResult.setResponseCode(e.getClass().getName());
            while (!queue.offer(newSampleResult)) {
            }
            if (tid != -1)
                ring.reset(tid);
        } finally {
            newSampleResult.setRequestHeaders(getRequest());
        }
    }
    SampleResult sampleResult = queue.poll();
    return sampleResult;
}

From source file:playground.johannes.snowball2.Centrality.java

public void run(Graph g, int iteration) {
    if (iteration != lastIteration) {
        isSampled = false;/*from   w  ww.  j av a  2  s  .  com*/
        if (g instanceof SampledGraph)
            isSampled = true;

        graphDecorator = new CentralityGraphDecorator(g);
        graph = (CentralityGraph) graphDecorator.getSparseGraph();
        Queue<CentralityVertex> vertices = new ConcurrentLinkedQueue<CentralityVertex>();
        for (SparseVertex v : graph.getVertices())
            vertices.add((CentralityVertex) v);

        int numThreads = Runtime.getRuntime().availableProcessors();
        List<DijkstraThread> threads = new ArrayList<DijkstraThread>(numThreads);

        DijkstraThread.count = 0;
        for (int i = 0; i < numThreads; i++) {
            threads.add(new DijkstraThread(graph, vertices));
        }

        for (DijkstraThread thread : threads) {
            thread.start();
        }

        for (DijkstraThread thread : threads) {
            try {
                thread.join();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

        calcCloseness();
        calcBetweenness();

        lastIteration = iteration;
    }
}

From source file:org.lambda3.indra.core.RelatednessClient.java

protected List<ScoredTextPair> compute(Map<? extends AnalyzedPair, VectorPair> vectorPairs,
        RelatednessFunction func) {//from   w w w  .  j  av  a  2  s.c  o m
    Queue<ScoredTextPair> scoredTextPairs = new ConcurrentLinkedQueue<>();

    vectorPairs.entrySet().stream().parallel().forEach(entry -> {
        AnalyzedPair pair = entry.getKey();
        VectorPair vectorPair = entry.getValue();

        if (vectorPair.v1 != null && vectorPair.v2 != null) {
            scoredTextPairs.add(new ScoredTextPair(pair,
                    func.sim(vectorPair.v1, vectorPair.v2, vectorSpace.getMetadata().sparse)));
        } else {
            scoredTextPairs.add(new ScoredTextPair(pair, 0));
        }
    });

    //TODO REVIEW HERE
    return new LinkedList<>(scoredTextPairs);
}