List of usage examples for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue
public LinkedBlockingQueue(Collection<? extends E> c)
From source file:org.openiot.gsn.http.rest.RestStreamHanlder.java
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException { Object is2ndPass = request.getAttribute("2ndPass"); Continuation continuation = ContinuationSupport.getContinuation(request); if (continuation.isExpired()) { logger.debug("Continuation has expired."); return;//from www . j a v a 2 s .c o m } String[] cred = null; if (Main.getContainerConfig().isAcEnabled()) { cred = parseAuthorizationHeader(request); if (cred == null) { try { response.setHeader("WWW-Authenticate", "Basic realm=\"GSN Access Control\"");// set the supported challenge response.sendError(HttpStatus.SC_UNAUTHORIZED, "Unauthorized access."); } catch (IOException e) { logger.debug(e.getMessage(), e); } return; } } if (is2ndPass == null) { continuation.setAttribute("2ndPass", Boolean.TRUE); continuation.setAttribute("status", new LinkedBlockingQueue<Boolean>(1)); continuation.setTimeout(-1); // Disable the timeout on the continuation. continuation.suspend(); final DefaultDistributionRequest streamingReq; try { URLParser parser = new URLParser(request); // if (Main.getContainerConfig().isAcEnabled()) { String vsName = parser.getVSensorConfig().getName(); if (DataSource.isVSManaged(vsName)) { User user = GeneralServicesAPI.getInstance().doLogin(cred[0], cred[1]); if ((user == null || (!user.isAdmin() && !user.hasReadAccessRight(vsName)))) { response.setHeader("WWW-Authenticate", "Basic realm=\"GSN Access Control\"");// set the supported challenge response.sendError(HttpStatus.SC_UNAUTHORIZED, "Unauthorized access."); return; } } } // RestDelivery deliverySystem = new RestDelivery(continuation); streamingReq = DefaultDistributionRequest.create(deliverySystem, parser.getVSensorConfig(), parser.getQuery(), parser.getStartTime()); DataDistributer.getInstance(deliverySystem.getClass()).addListener(streamingReq); } catch (Exception e) { logger.warn(e.getMessage()); continuation.complete(); } } else { boolean status = false; try { status = !continuation.getServletResponse().getWriter().checkError(); } catch (Exception e) { logger.debug(e.getMessage(), e); } continuation.suspend(); try { ((LinkedBlockingQueue<Boolean>) continuation.getAttribute("status")).put(status); } catch (InterruptedException e) { logger.debug(e.getMessage(), e); } } }
From source file:org.addsimplicity.anicetus.io.jms.JMSDeliveryAdapter.java
/** * Called by Spring once all properties have been set. This method will * establish the connection to the JMS broker. *//*from w w w . j ava2s. c o m*/ public void afterPropertiesSet() throws Exception { BlockingQueue<Runnable> q = new LinkedBlockingQueue<Runnable>(m_maxDeliveryQueue); m_executor = new ThreadPoolExecutor(1, m_maxDeliveryThreads, 60l, TimeUnit.SECONDS, q, new DeliveryThreadFactory(), m_rejectionHandler); m_template = new JmsTemplate(m_connectionFactory); m_template.setDefaultDestination(m_destination); m_template.setMessageConverter(m_messageConverter); }
From source file:com.isthari.spring.cloud.config.cassandra.CassandraEnvironmentRepository.java
public CassandraEnvironmentRepository(ConfigurableEnvironment environment, String hostnames, String username, String password, Boolean createSchema) { // Create cluster object Cluster.Builder builder = Cluster.builder(); // Add contact points for (String hostname : hostnames.split(",")) { builder.addContactPoints(hostname); }// www.ja v a 2 s. c o m if (username != null && password != null) { builder.withCredentials(username, password); } Cluster cluster = builder.build(); if (createSchema) { this.createSchema(cluster); } // Connect session = cluster.connect("cloud_config"); this.stmtGetVersion = session.prepare( "select version from application_label_version where application=? and label=? and profile=? limit 1"); this.stmtGetSnapshot = session .prepare("select parameters from configuration_snapshot where application=? and version=?"); // Executor for async tasks BlockingQueue<Runnable> workQueue = new LinkedBlockingQueue<Runnable>(10); executor = new ThreadPoolExecutor(4, 10, 1, TimeUnit.DAYS, workQueue); }
From source file:c3.ops.priam.aws.S3FileSystem.java
@Inject public S3FileSystem(Provider<AbstractBackupPath> pathProvider, ICompression compress, final IConfiguration config, ICredential cred) { this.pathProvider = pathProvider; this.compress = compress; this.config = config; int threads = config.getMaxBackupUploadThreads(); LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(threads); this.executor = new BlockingSubmitThreadPoolExecutor(threads, queue, UPLOAD_TIMEOUT); double throttleLimit = config.getUploadThrottle(); rateLimiter = RateLimiter.create(throttleLimit < 1 ? Double.MAX_VALUE : throttleLimit); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String mbeanName = MBEAN_NAME; try {//from w ww . j av a 2 s . c o m mbs.registerMBean(this, new ObjectName(mbeanName)); } catch (Exception e) { logger.warn("Fail to register " + mbeanName); //throw new RuntimeException(e); } s3Client = new AmazonS3Client(cred.getAwsCredentialProvider()); s3Client.setEndpoint(getS3Endpoint()); }
From source file:algo.ad.feeder.TwitterStreamSpout.java
@Override public void open(Map conf, TopologyContext context, SpoutOutputCollector collector) { queue = new LinkedBlockingQueue<Status>(1000); _collector = collector;// w w w . ja va 2 s. c om startTime = System.currentTimeMillis(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { long elapsedTime = System.currentTimeMillis() - startTime; //System.out.println("*************elapsedTime:" + elapsedTime); if (elapsedTime > keywordRefreshInterval) { /// System.out.println("*************Changing Query:"); // Update the keyword list//////////////////// String[] temp_keywords = DatabaseHelper.getKeywordsFromDB(tweetsJDBCTemplate, DB_BASE_URL, DB_NAME, MAX_NUMBER_OF_QUERIES); if (!keyWords.equals(temp_keywords)) { keyWords = temp_keywords; FilterQuery query = new FilterQuery().track(keyWords); _twitterStream.filter(query); } // ///////////////////////////////////// startTime = System.currentTimeMillis(); } queue.offer(status); } @Override public void onDeletionNotice(StatusDeletionNotice sdn) { } @Override public void onTrackLimitationNotice(int i) { } @Override public void onScrubGeo(long l, long l1) { } @Override public void onException(Exception ex) { } @Override public void onStallWarning(StallWarning arg0) { // TODO Auto-generated method stub } }; _twitterStream = new TwitterStreamFactory(new ConfigurationBuilder().setJSONStoreEnabled(true).build()) .getInstance(); _twitterStream.addListener(listener); _twitterStream.setOAuthConsumer(consumerKey, consumerSecret); AccessToken token = new AccessToken(accessToken, accessTokenSecret); _twitterStream.setOAuthAccessToken(token); keyWords = DatabaseHelper.getKeywordsFromDB(tweetsJDBCTemplate, DB_BASE_URL, DB_NAME, MAX_NUMBER_OF_QUERIES); if (keyWords.length == 0) { _twitterStream.sample(); } else { FilterQuery query = new FilterQuery().track(keyWords); _twitterStream.filter(query); } }
From source file:com.brienwheeler.svc.monitor.telemetry.impl.AsynchronousTelemetryInfoProcessor.java
@Override protected void onStart() throws InterruptedException { super.onStart(); LinkedBlockingQueue<TelemetryInfo> queue = new LinkedBlockingQueue<TelemetryInfo>(maxCapacity); this.queue.set(queue); TelemetryInfoProcessThread backgroundThread = new TelemetryInfoProcessThread(queue); this.backgroundThread.set(backgroundThread); backgroundThread.start();//from w w w. j ava2 s.co m }
From source file:com.amazonaws.metrics.internal.cloudwatch.MetricCollectorSupport.java
protected MetricCollectorSupport(CloudWatchMetricConfig config) { if (config == null) { throw new IllegalArgumentException(); }// w ww . ja v a2 s.co m this.config = config; this.queue = new LinkedBlockingQueue<MetricDatum>(config.getMetricQueueSize()); this.requestMetricCollector = new RequestMetricCollectorSupport(queue); this.serviceMetricCollector = new ServiceMetricCollectorSupport(queue); }
From source file:com.netflix.priam.aws.S3FileSystem.java
@Inject public S3FileSystem(Provider<AbstractBackupPath> pathProvider, ICompression compress, final IConfiguration config, ICredential cred) { this.pathProvider = pathProvider; this.compress = compress; this.config = config; int threads = config.getMaxBackupUploadThreads(); LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(threads); this.executor = new BlockingSubmitThreadPoolExecutor(threads, queue, UPLOAD_TIMEOUT); double throttleLimit = config.getUploadThrottle(); rateLimiter = RateLimiter.create(throttleLimit < 1 ? Double.MAX_VALUE : throttleLimit); MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); String mbeanName = MBEAN_NAME; try {/*from ww w . j a v a 2s. com*/ mbs.registerMBean(this, new ObjectName(mbeanName)); } catch (Exception e) { throw new RuntimeException(e); } s3Client = new AmazonS3Client(cred.getAwsCredentialProvider()); s3Client.setEndpoint(getS3Endpoint()); }
From source file:com.alibaba.dubbo.monitor.simple.SimpleMonitorService.java
public SimpleMonitorService() { queue = new LinkedBlockingQueue<URL>( Integer.parseInt(ConfigUtils.getProperty("dubbo.monitor.queue", "100000"))); writeThread = new Thread(new Runnable() { public void run() { while (running) { try { write(); // } catch (Throwable t) { // logger.error("Unexpected error occur at write stat log, cause: " + t.getMessage(), t); try { Thread.sleep(5000); // } catch (Throwable t2) { }// w w w.ja v a2 s. co m } } } }); writeThread.setDaemon(true); writeThread.setName("DubboMonitorAsyncWriteLogThread"); writeThread.start(); chartFuture = scheduledExecutorService.scheduleWithFixedDelay(new Runnable() { public void run() { try { draw(); // } catch (Throwable t) { // logger.error("Unexpected error occur at draw stat chart, cause: " + t.getMessage(), t); } } }, 1, 300, TimeUnit.SECONDS); INSTANCE = this; }
From source file:com.amazonaws.mobileconnectors.pinpoint.targeting.TargetingClient.java
/** * Initializes a client to manage updating the endpoint profile * * @param context The {@link PinpointContext} *//*www. ja v a 2 s.com*/ public TargetingClient(final PinpointContext context) { this(context, new ThreadPoolExecutor(1, 1, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(MAX_EVENT_OPERATIONS), new ThreadPoolExecutor.DiscardPolicy())); }