List of usage examples for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue
public LinkedBlockingQueue(Collection<? extends E> c)
From source file:com.zonekey.ssm.common.log.queue.QueuesHolder.java
/** * ?queueName???.//from w ww.j a v a 2s . com * ??, . */ public static <T> BlockingQueue<T> getQueue(String queueName) { BlockingQueue queue = queueMap.get(queueName); if (queue == null) { BlockingQueue newQueue = new LinkedBlockingQueue(queueSize); //???,Null.??. queue = queueMap.putIfAbsent(queueName, newQueue); if (queue == null) { queue = newQueue; } } return queue; }
From source file:com.twitter.hbc.example.FilterStreamExample.java
public static void run(String consumerKey, String consumerSecret, String token, String secret) throws Exception { BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000); StatusesFilterEndpoint endpoint = new StatusesFilterEndpoint(); // add some track terms endpoint.trackTerms(Lists.newArrayList("#AAPBreakUp")); Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret); // Authentication auth = new BasicAuth(username, password); // Create a new BasicClient. By default gzip is enabled. Client client = new ClientBuilder().hosts(Constants.STREAM_HOST).endpoint(endpoint).authentication(auth) .processor(new StringDelimitedProcessor(queue)).build(); // Establish a connection client.connect();//from ww w . j a v a 2 s . com buildDS(); // Do whatever needs to be done with messages int Limit = 20; for (int msgRead = 0; msgRead < Limit; msgRead++) { String msg = queue.take(); JSONObject json = new JSONObject(msg); String tweet = (String) json.get("text"); System.out.println(tweet + "Sentiment =" + classifyText(tweet)); } client.stop(); }
From source file:Main.java
public static ExecutorService fixedThreadsExecutor(String name, int count) { ThreadFactory threadFactory = daemonThreadFactory(name); return new ThreadPoolExecutor(count, count, 10, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(Integer.MAX_VALUE), threadFactory) { @Override//from w ww . j av a 2 s . c om protected void afterExecute(Runnable runnable, Throwable throwable) { if (throwable != null) { //Console.getInstance().info("Unexpected failure from " + runnable, throwable); } } }; }
From source file:com.ewcms.publication.task.MemoryTaskQueue.java
public MemoryTaskQueue(int max, PublishDaoable publishDao) { tasks = new LinkedBlockingQueue<Taskable>(max); this.publishDao = publishDao; }
From source file:com.example.SampleStreamExample.java
public static void run(String consumerKey, String consumerSecret, String token, String secret) throws InterruptedException { // Create an appropriately sized blocking queue BlockingQueue<String> queue = new LinkedBlockingQueue<String>(10000); // Define our endpoint: By default, delimited=length is set (we need this for our processor) // and stall warnings are on. StatusesSampleEndpoint endpoint = new StatusesSampleEndpoint(); endpoint.stallWarnings(false);//from ww w. j a v a 2s . c o m File file = new File("/usr/local/Output11.txt"); if (!file.exists()) { try { file.createNewFile(); FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); bw.write("["); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } Authentication auth = new OAuth1(consumerKey, consumerSecret, token, secret); //Authentication auth = new com.twitter.hbc.httpclient.auth.BasicAuth(username, password); // Create a new BasicClient. By default gzip is enabled. BasicClient client = new ClientBuilder().name("sampleExampleClient").hosts(Constants.STREAM_HOST) .endpoint(endpoint).authentication(auth).processor(new StringDelimitedProcessor(queue)).build(); // Establish a connection client.connect(); // Do whatever needs to be done with messages for (int msgRead = 0; msgRead < 1000; msgRead++) { if (client.isDone()) { System.out.println("Client connection closed unexpectedly: " + client.getExitEvent().getMessage()); break; } String msg = queue.poll(5, TimeUnit.SECONDS); // String Time="time",Text="Text"; //Lang id; if (msg == null) { System.out.println("Did not receive a message in 5 seconds"); } else { System.out.println(msg); //System.out.println("**************hahahahahahahah********************"); try { FileWriter fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); if (msgRead == 999) bw.write(msg); else bw.write(msg + ","); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } /* JSONParser jsonParser = new JSONParser(); //JsonElement jsonElement = null; String key=""; try { //jsonElement= (JsonElement) jsonParser.parse(msg); JSONObject jsonObject = (JSONObject) jsonParser.parse(msg); //JsonObject jsonObjec = jsonElement.getAsJsonObject(); //for(Entry<String, JsonElement> entry : jsonObjec.entrySet()) // { key = entry.getKey(); // if(key=="delete") // System.out.println("this comment is deleted"); // } //JsonElement value = entry.getValue(); //***** printing date // Time = (String) jsonObject.get("created_at"); System.out.println("Date of creation====: " + jsonObject.get("created_at")); //******printing id // id = (Lang) jsonObject.get("id"); // System.out.println("id=========: " + jsonObject.get("id")); //*******text //Text = (String) jsonObject.get("text"); //System.out.println("Text==========: " + jsonObject.get("text")); //************inside user************ JSONObject structure = (JSONObject) jsonObject.get("user"); System.out.println("Into user structure , id====: " + structure.get("id")); System.out.println("Into user structure , name====: " + structure.get("name")); System.out.println("Into user structure , screen_name====: " + structure.get("screen_name")); System.out.println("Into user structure , location====: " + structure.get("location")); System.out.println("Into user structure , description====: " + structure.get("description")); System.out.println("Into user structure , followers====: " + structure.get("followers_count")); System.out.println("Into user structure , friends====: " + structure.get("friends_count")); System.out.println("Into user structure , listed====: " + structure.get("listed_count")); System.out.println("Into user structure , favorite====: " + structure.get("favorites_count")); System.out.println("Into user structure , status_count====: " + structure.get("status_count")); System.out.println("Into user structure , created at====: " + structure.get("created at")); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } */ } } FileWriter fw; try { fw = new FileWriter(file.getAbsoluteFile(), true); BufferedWriter bw = new BufferedWriter(fw); bw.write("]"); bw.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } client.stop(); // Print some stats System.out.printf("The client read %d messages!\n", client.getStatsTracker().getNumMessages()); }
From source file:com.sm.store.AppSyncHandler.java
private void init() { BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue); threadPools = new ThreadPoolExecutor(maxThreads, maxThreads, 30, TimeUnit.SECONDS, queue); }
From source file:com.github.lpezet.antiope.metrics.aws.MetricsCollectorSupport.java
public MetricsCollectorSupport(Config pConfig) { if (pConfig == null) { throw new IllegalArgumentException(); }//from w w w .ja va 2 s.c o m mConfig = pConfig; mQueue = new LinkedBlockingQueue<MetricDatum>(pConfig.getCloudWatchConfig().getMetricQueueSize()); mMetricsCollectorImpl = new MetricsQueueCollection(pConfig, mQueue); //mRequestMetricsCollector = new RequestMetricsCollectorSupport(pConfig, mQueue); //mServiceMetricsCollector = new ServiceMetricsCollectorSupport(pConfig, mQueue); }
From source file:org.apache.bigtop.bigpetstore.qstream.HttpLoadGen.java
/** * Appends via REST calls./* w ww .java 2 s . c o m*/ */ public LinkedBlockingQueue<Transaction> startWriteQueue(final int milliseconds) { /** * Write queue. Every 5 seconds, write */ final LinkedBlockingQueue<Transaction> transactionQueue = new LinkedBlockingQueue<Transaction>( getQueueSize()); new Thread() { @Override public void run() { int fileNumber = 0; while (true) { waitFor(milliseconds, transactionQueue); System.out.println("CLEARING " + transactionQueue.size() + " elements from queue."); Stack<Transaction> transactionsToWrite = new Stack<Transaction>(); transactionQueue.drainTo(transactionsToWrite); /** * pop transactions from the queue, and sent them over http as json. */ while (!transactionsToWrite.isEmpty()) { try { String trAsJson = URLEncoder.encode(Utils.toJson(transactionsToWrite.pop())); /** * i.e. wget http://localhost:3000/rpush/guestbook/{"name":"cos boudnick", "state":"...",...} */ HttpResponse resp = Utils.get(path + "/" + trAsJson); if (total % 20 == 0) System.out.println("wrote customer " + trAsJson); total++; } catch (Throwable t) { System.err.println("transaction failed.... !"); t.printStackTrace(); } System.out.println("TRANSACTIONS SO FAR " + total++ + " RATE " + total / ((System.currentTimeMillis() - startTime) / 1000)); } } } }.start(); return transactionQueue; }
From source file:nblair.pipeline.PipelineThreadPoolExecutor.java
/** * Calls the superclass' constructor passing in the queueCapacity, * 1 Minute keep alive time, a bounded {@link LinkedBlockingQueue}, * a {@link CustomizableThreadFactory}, and an {@link OfferRejectedExecutionHandler}. * /* w ww. j a v a2s . c o m*/ * @see LinkedBlockingQueue * @see ThreadPoolExecutor * @see CustomizableThreadFactory * @param queueCapacity the capacity of the work queue * @param namePrefix the thread name prefix */ public PipelineThreadPoolExecutor(int queueCapacity, String namePrefix) { super(queueCapacity, queueCapacity, 1, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(queueCapacity), new CustomizableThreadFactory(namePrefix), new OfferRejectedExecutionHandler()); }
From source file:com.sm.transport.netty.ServerSyncHandler.java
private void init() { BlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(maxQueue); threadPools = new ThreadPoolExecutor(maxThreads, maxThreads, 30, TimeUnit.SECONDS, queue); }