List of usage examples for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue
public LinkedBlockingQueue(Collection<? extends E> c)
From source file:com.googlecode.jmxtrans.guice.JmxTransModule.java
private ThreadPoolExecutor createExecutorService(int poolSize, int workQueueCapacity, String componentName) { BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(workQueueCapacity); ThreadFactory threadFactory = threadFactory(componentName); return new ThreadPoolExecutor(poolSize, poolSize, 0L, MILLISECONDS, workQueue, threadFactory); }
From source file:org.apache.streams.elasticsearch.ElasticsearchPersistReader.java
private Queue<StreamsDatum> constructQueue() { return Queues.synchronizedQueue(new LinkedBlockingQueue<StreamsDatum>(10000)); }
From source file:Proxy.java
public void start() throws Exception { Map.Entry entry;/*from w w w.j a va 2 s . c om*/ Selector selector; ServerSocketChannel sock_channel; MyInetSocketAddress key, value; if (remote != null && local != null) mappings.put(new InetSocketAddress(local, local_port), new InetSocketAddress(remote, remote_port)); if (mapping_file != null) { try { populateMappings(mapping_file); } catch (Exception ex) { log("Failed reading " + mapping_file); throw ex; } } log("\nProxy started at " + new java.util.Date()); if (verbose) { log("\nMappings:\n---------"); for (Iterator it = mappings.entrySet().iterator(); it.hasNext();) { entry = (Map.Entry) it.next(); log(toString((InetSocketAddress) entry.getKey()) + " <--> " + toString((InetSocketAddress) entry.getValue())); } log("\n"); } // 1. Create a Selector selector = Selector.open(); // Create a thread pool (Executor) executor = new ThreadPoolExecutor(MIN_THREAD_POOL_SIZE, MAX_THREAD_POOL_SIZE, 30000, TimeUnit.MILLISECONDS, new LinkedBlockingQueue(1000)); for (Iterator it = mappings.keySet().iterator(); it.hasNext();) { key = (MyInetSocketAddress) it.next(); value = (MyInetSocketAddress) mappings.get(key); // if either source or destination are SSL, we cannot use JDK 1.4 // NIO selectors, but have to fall back on separate threads per connection if (key.ssl() || value.ssl()) { // if(2 == 2) { SocketAcceptor acceptor = new SocketAcceptor(key, value); executor.execute(acceptor); continue; } // 2. Create a ServerSocketChannel sock_channel = ServerSocketChannel.open(); sock_channel.configureBlocking(false); sock_channel.socket().bind(key); // 3. Register the selector with all server sockets. 'Key' is attachment, so we get it again on // select(). That way we can associate it with the mappings hashmap to find the corresponding // value sock_channel.register(selector, SelectionKey.OP_ACCEPT, key); } // 4. Start main loop. won't return until CTRL-C'ed loop(selector); }
From source file:com.clustercontrol.systemlog.service.SystemLogMonitor.java
@Override public synchronized void start() { _executor = new MonitoredThreadPoolExecutor(_threadSize, _threadSize, 0L, TimeUnit.MICROSECONDS, new LinkedBlockingQueue<Runnable>(_queueSize), new ThreadFactory() { private volatile int _count = 0; @Override//from ww w. j a v a 2 s . com public Thread newThread(Runnable r) { return new Thread(r, "SystemLogFilter-" + _count++); } }, new SystemLogRejectionHandler()); }
From source file:org.apache.solr.client.solrj.impl.ConcurrentUpdateSolrClient.java
/** * Uses the supplied HttpClient to send documents to the Solr server. * //from ww w . j a va 2 s . c o m * @deprecated use {@link Builder} instead. This will soon be a * protected method, and will only be available for use in implementing subclasses. */ @Deprecated public ConcurrentUpdateSolrClient(String solrServerUrl, HttpClient client, int queueSize, int threadCount, ExecutorService es, boolean streamDeletes) { this.internalHttpClient = (client == null); this.client = new HttpSolrClient.Builder(solrServerUrl).withHttpClient(client).build(); this.client.setFollowRedirects(false); queue = new LinkedBlockingQueue<>(queueSize); this.threadCount = threadCount; runners = new LinkedList<>(); this.streamDeletes = streamDeletes; if (es != null) { scheduler = es; shutdownExecutor = false; } else { scheduler = ExecutorUtil .newMDCAwareCachedThreadPool(new SolrjNamedThreadFactory("concurrentUpdateScheduler")); shutdownExecutor = true; } }
From source file:com.uber.stream.kafka.mirrormaker.controller.core.OffsetMonitor.java
public void start() { if (refreshIntervalInSec > 0) { // delay for 1-5 minutes int delaySec = 60 + new Random().nextInt(240); logger.info("OffsetMonitor starts updating offsets every {} seconds with delay {} seconds", refreshIntervalInSec, delaySec); MetricRegistry metricRegistry = HelixKafkaMirrorMakerMetricsReporter.get().getRegistry(); Counter counter = metricRegistry.counter("offsetMonitor.executed"); refreshExecutor.scheduleAtFixedRate(new Runnable() { @Override/*from w ww .jav a 2s . co m*/ public void run() { logger.info("TopicList starts updating"); if (zkClientQueue == null) { zkClientQueue = new LinkedBlockingQueue<>(numOffsetThread); for (int i = 0; i < numOffsetThread; i++) { ZkClient zkClient = new ZkClient(offsetZkString, 30000, 30000, ZKStringSerializer$.MODULE$); zkClientQueue.add(zkClient); } ZkClient zkClient = new ZkClient(srcZkString, 30000, 30000, ZKStringSerializer$.MODULE$); List<String> brokerIdList = zkClient.getChildren("/brokers/ids"); for (String id : brokerIdList) { try { JSONObject json = JSONObject .parseObject(zkClient.readData("/brokers/ids/" + id).toString()); srcBrokerList.add( String.valueOf(json.get("host")) + ":" + String.valueOf(json.get("port"))); } catch (Exception e) { logger.warn("Failed to get broker", e); } } logger.info("OffsetMonitor starts with brokerList=" + srcBrokerList); } updateTopicList(); updateOffset(); updateOffsetMetrics(); counter.inc(); lastSucceedOffsetCheck = new Date().getTime(); } }, delaySec, refreshIntervalInSec, TimeUnit.SECONDS); registerNoProgressMetric(); registerUpdateOffsetStatusMetric(); } else { logger.info("OffsetMonitor is disabled"); } }
From source file:org.wso2.carbon.event.output.adaptor.http.HTTPEventAdaptor.java
@Override protected void init() { this.populateAdapterMessageProps(); this.supportOutputMessageTypes = new ArrayList<String>(); this.supportOutputMessageTypes.add(MessageType.XML); this.supportOutputMessageTypes.add(MessageType.JSON); this.supportOutputMessageTypes.add(MessageType.TEXT); this.executorService = new ThreadPoolExecutor(HTTPEventAdaptorConstants.ADAPTER_MIN_THREAD_POOL_SIZE, HTTPEventAdaptorConstants.ADAPTER_MAX_THREAD_POOL_SIZE, HTTPEventAdaptorConstants.DEFAULT_KEEP_ALIVE_TIME, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(HTTPEventAdaptorConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE)); }
From source file:com.inmobi.messaging.consumer.databus.AbstractMessagingDatabusConsumer.java
protected void initializeConfig(ClientConfig config) throws IOException { String hadoopConfFileName = config.getString(hadoopConfigFileKey); if (hadoopConfFileName != null) { Configuration.addDefaultResource(hadoopConfFileName); }/*from w w w. java 2 s .c o m*/ conf = new Configuration(); super.init(config); // verify authentication if (UserGroupInformation.isSecurityEnabled()) { String principal = config.getString(consumerPrincipal); String keytab = config.getString(consumerKeytab); if (principal != null && keytab != null) { Configuration conf = new Configuration(); conf.set(consumerPrincipal, principal); conf.set(consumerKeytab, keytab); SecurityUtil.login(conf, consumerKeytab, consumerPrincipal); UserGroupInformation ugi = UserGroupInformation.getLoginUser(); LOG.info("User logged in :" + ugi); } else { LOG.info( "There is no principal or key tab file passed. Using the" + " commandline authentication."); } } // Read consumer id String consumerIdStr = config.getString(consumerIdInGroupConfig, DEFAULT_CONSUMER_ID); String[] id = consumerIdStr.split("/"); try { consumerNumber = Integer.parseInt(id[0]); totalConsumers = Integer.parseInt(id[1]); partitionMinList = new HashSet<Integer>(); if (isValidConfiguration()) { for (int i = 0; i < 60; i++) { if ((i % totalConsumers) == (consumerNumber - 1)) { partitionMinList.add(i); } } } else { throw new IllegalArgumentException("Invalid consumer group membership"); } } catch (NumberFormatException nfe) { throw new IllegalArgumentException("Invalid consumer group membership", nfe); } // Create checkpoint provider and initialize checkpoint String chkpointProviderClassName = config.getString(chkProviderConfig, DEFAULT_CHK_PROVIDER); String databusCheckpointDir = config.getString(checkpointDirConfig, DEFAULT_CHECKPOINT_DIR); this.checkpointProvider = createCheckpointProvider(chkpointProviderClassName, databusCheckpointDir); createCheckpoint(); currentCheckpoint.read(checkpointProvider, getChkpointKey()); //create buffer bufferSize = config.getInteger(queueSizeConfig, DEFAULT_QUEUE_SIZE); buffer = new LinkedBlockingQueue<QueueEntry>(bufferSize); // initialize other common configuration waitTimeForFileCreate = config.getLong(waitTimeForFileCreateConfig, DEFAULT_WAIT_TIME_FOR_FILE_CREATE); // get the retention period of the topic retentionInHours = config.getString(retentionConfig); relativeStartTimeStr = config.getString(relativeStartTimeConfig); if (relativeStartTimeStr == null && retentionInHours != null) { LOG.warn(retentionConfig + " is deprecated." + " Use " + relativeStartTimeConfig + " instead"); int minutes = (Integer.parseInt(retentionInHours)) * 60; relativeStartTimeStr = String.valueOf(minutes); } String stopTimeStr = config.getString(stopDateConfig); stopTime = getDateFromString(stopTimeStr); startOfStream = config.getBoolean(startOfStreamConfig, DEFAULT_START_OF_STREAM); closedReadercount = 0; }