List of usage examples for java.util.concurrent LinkedBlockingQueue LinkedBlockingQueue
public LinkedBlockingQueue(Collection<? extends E> c)
From source file:com.github.anba.es6draft.util.TestGlobals.java
protected static ThreadPoolExecutor createDefaultSharedExecutor() { int coreSize = 4; int maxSize = 12; long timeout = 60L; int queueCapacity = 10; return new ThreadPoolExecutor(coreSize, maxSize, timeout, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(queueCapacity), new ThreadPoolExecutor.CallerRunsPolicy()); }
From source file:com.petpet.c3po.controller.Controller.java
/** * This constructors sets the persistence layer, initializes the processing * queue and the {@link LocalFileGatherer}; * * @param config/* www . j a v a 2 s . c om*/ * a configurator that holds application specific configs and can * initialize the application. * */ public Controller(Configurator config) { this.configurator = config; this.persistence = config.getPersistence(); this.processingQueue = new LinkedBlockingQueue<Element>(10000); this.gatherer = new LocalFileGatherer(); this.knownAdaptors = new HashMap<String, Class<? extends AbstractAdaptor>>(); this.knownRules = new HashMap<String, Class<? extends ProcessingRule>>(); // TODO detect adaptors automatically from the class path // and add them to this map. this.knownAdaptors.put("FITS", FITSAdaptor.class); this.knownAdaptors.put("TIKA", TIKAAdaptor.class); // TODO detect these automatically from the class path // and add them to this map. // TODO the InferDateFromFileNameRule needs a setter for the cache. // TODO - answer by Peter: The cache can be retrieved statically from the Configurator! this.knownRules.put(Constants.CNF_ELEMENT_IDENTIFIER_RULE, CreateElementIdentifierRule.class); this.knownRules.put(Constants.CNF_EMPTY_VALUE_RULE, EmptyValueProcessingRule.class); this.knownRules.put(Constants.CNF_VERSION_RESOLUTION_RULE, FormatVersionResolutionRule.class); this.knownRules.put(Constants.CNF_HTML_INFO_RULE, HtmlInfoProcessingRule.class); this.knownRules.put(Constants.CNF_INFER_DATE_RULE, InferDateFromFileNameRule.class); this.knownRules.put(Constants.CNF_DROOLS_CONFLICT_RESOLUTION_RULE, DroolsConflictResolutionProcessingRule.class); this.knownRules.put(Constants.CNF_CONTENT_TYPE_IDENTIFICATION_RULE, ContentTypeIdentificationRule.class); this.knownRules.put(Constants.CNF_FILE_EXTENSION_IDENTIFICATION_RULE, FileExtensionIdentificationRule.class); this.knownRules.put(Constants.CNF_CREATED_YEAR_IDENTIFICATION_RULE, CreatedYearIdentificationRule.class); }
From source file:com.olacabs.fabric.compute.source.PipelineStreamSource.java
public void initialize(Properties globalProperties) throws Exception { final Integer count = PropertyReader.readInt(this.properties, globalProperties, "computation.eventset.in_flight_count", 5); jsonConversion = PropertyReader.readBoolean(this.properties, globalProperties, "computation.eventset.is_serialized", true); delivered = new LinkedBlockingQueue<>(count); messages = Maps.newConcurrentMap();// ww w. j a v a 2 s. co m source.initialize(instanceId, globalProperties, properties, processingContext, sourceMetadata); transactionIdGenerator.seed(seedTransactionId()); this.notificationBus.source(this); }
From source file:org.killbill.notificationq.NotificationQueueDispatcher.java
NotificationQueueDispatcher(final Clock clock, final NotificationQueueConfig config, final IDBI dbi, final MetricRegistry metricRegistry) { super("NotificationQ", Executors.newFixedThreadPool(config.getNbThreads() + 1, new ThreadFactory() { @Override/*w w w. j av a 2 s .co m*/ public Thread newThread(final Runnable r) { final Thread th = new Thread(r); th.setName(config.getTableName() + "-th"); th.setUncaughtExceptionHandler(new UncaughtExceptionHandler() { @Override public void uncaughtException(final Thread t, final Throwable e) { log.error("Uncaught exception for thread " + t.getName(), e); } }); return th; } }), 1, config); this.clock = clock; this.config = config; this.nbProcessedEvents = new AtomicLong(); final NotificationSqlDao sqlDao = dbi.onDemand(NotificationSqlDao.class); this.dao = new DBBackedQueue<NotificationEventModelDao>(clock, sqlDao, config, "notif-" + config.getTableName(), metricRegistry, null); this.queues = new TreeMap<String, NotificationQueue>(); this.processedNotificationsSinceStart = metricRegistry.counter( MetricRegistry.name(NotificationQueueDispatcher.class, "processed-notifications-since-start")); this.perQueueProcessingTime = new HashMap<String, Histogram>(); this.pendingNotificationsQ = new LinkedBlockingQueue<NotificationEventModelDao>(config.getQueueCapacity()); this.metricRegistry = metricRegistry; this.pendingNotifications = metricRegistry.register( MetricRegistry.name(NotificationQueueDispatcher.class, "pending-notifications"), new Gauge<Integer>() { @Override public Integer getValue() { return pendingNotificationsQ.size(); } }); this.runners = new NotificationRunner[config.getNbThreads()]; for (int i = 0; i < config.getNbThreads(); i++) { runners[i] = new NotificationRunner(pendingNotificationsQ, clock, config, objectMapper, nbProcessedEvents, queues, dao, perQueueProcessingTime, metricRegistry, processedNotificationsSinceStart); } }
From source file:edu.gmu.isa681.ctn.EncodedChannel.java
private void startHandlers(int inboundCapacity, int outboundCapacity) { inboundQueue = new LinkedBlockingQueue<Encodeable>(inboundCapacity); outboundQueue = new LinkedBlockingQueue<Encodeable>(outboundCapacity); inboundThread = new Thread(new InboundHandler(), "InboundThread[" + name + "]"); outboundThread = new Thread(new OutboundHandler(), "OutboundThread[" + name + "]"); inboundThread.setDaemon(true);/* w ww .j av a 2 s. c o m*/ outboundThread.setDaemon(true); inboundThread.start(); outboundThread.start(); }
From source file:gov.nrel.bacnet.consumer.BACnet.java
private void initialize(Config config) throws IOException { LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(1000); RejectedExecutionHandler rejectedExec = new RejectedExecHandler(); // schedule polling on single threaded service because local device instance is not threadsafe execSvc = Executors.newFixedThreadPool(config.getNumThreads()); //give databus recording 2 threads to match old code recorderSvc = new ThreadPoolExecutor(20, 20, 120, TimeUnit.SECONDS, queue, rejectedExec); schedSvc = (ScheduledThreadPoolExecutor) Executors.newScheduledThreadPool(config.getNumThreads()); exec = new OurExecutor(schedSvc, execSvc, recorderSvc); String devname = config.getNetworkDevice(); int device_id = config.getDeviceId(); NetworkInterface networkinterface = null; try {/*from w w w . ja va 2 s .c o m*/ networkinterface = java.net.NetworkInterface.getByName(devname); } catch (Exception ex) { System.out.println("Unable to open device: " + devname); System.exit(-1); } if (networkinterface == null) { System.out.println("Unable to open device: " + devname); System.exit(-1); } List<InterfaceAddress> addresses = networkinterface.getInterfaceAddresses(); String sbroadcast = null; String saddress = null; //InterfaceAddress ifaceaddr = null; for (InterfaceAddress address : addresses) { logger.fine("Evaluating address: " + address.toString()); if (address.getAddress().getAddress().length == 4) { logger.info("Address is ipv4, selecting: " + address.toString()); sbroadcast = address.getBroadcast().toString().substring(1); saddress = address.getAddress().toString().substring(1); //ifaceaddr = address; break; } else { logger.info("Address is not ipv4, not selecting: " + address.toString()); } } logger.info("Binding to: " + saddress + " " + sbroadcast); localDevice = new LocalDevice(device_id, sbroadcast); localDevice.setPort(LocalDevice.DEFAULT_PORT); localDevice.setTimeout(localDevice.getTimeout() * 3); localDevice.setSegTimeout(localDevice.getSegTimeout() * 3); try { localDevice.initialize(); localDevice.setRetries(0); //don't retry as it seems to really be a waste. } catch (IOException e) { e.printStackTrace(); return; } if (config.getSlaveDeviceEnabled()) { slaveDeviceTimer = new Timer(); slaveDeviceTimer.schedule(new gov.nrel.bacnet.SlaveDevice(localDevice, config), 1000, config.getSlaveDeviceUpdateInterval() * 1000); } int counter = 0; String username = config.getDatabusUserName(); String key = config.getDatabusKey(); logger.info("user=" + username + " key=" + key); DatabusSender sender = null; if (config.getDatabusEnabled()) { sender = new DatabusSender(username, key, execSvc, config.getDatabusUrl(), config.getDatabusPort(), true); } logger.info("databus sender: " + sender); writer = new DatabusDataWriter(new DataPointWriter(sender)); logger.info("databus writer" + writer); }
From source file:org.wso2.carbon.event.output.adapter.http.HTTPEventAdapter.java
@Override public void init() throws OutputEventAdapterException { tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); //ExecutorService will be assigned if it is null if (executorService == null) { int minThread; int maxThread; long defaultKeepAliveTime; int jobQueSize; //If global properties are available those will be assigned else constant values will be assigned if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME) != null) { minThread = Integer.parseInt( globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE_NAME)); } else {//from w ww . j av a2 s.c o m minThread = HTTPEventAdapterConstants.ADAPTER_MIN_THREAD_POOL_SIZE; } if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME) != null) { maxThread = Integer.parseInt( globalProperties.get(HTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE_NAME)); } else { maxThread = HTTPEventAdapterConstants.ADAPTER_MAX_THREAD_POOL_SIZE; } if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME) != null) { defaultKeepAliveTime = Integer .parseInt(globalProperties.get(HTTPEventAdapterConstants.ADAPTER_KEEP_ALIVE_TIME_NAME)); } else { defaultKeepAliveTime = HTTPEventAdapterConstants.DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS; } if (globalProperties.get(HTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME) != null) { jobQueSize = Integer.parseInt( globalProperties.get(HTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME)); } else { jobQueSize = HTTPEventAdapterConstants.ADAPTER_EXECUTOR_JOB_QUEUE_SIZE; } executorService = new ThreadPoolExecutor(minThread, maxThread, defaultKeepAliveTime, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(jobQueSize)); //configurations for the httpConnectionManager which will be shared by every http adapter int defaultMaxConnectionsPerHost; int maxTotalConnections; if (globalProperties.get(HTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST) != null) { defaultMaxConnectionsPerHost = Integer .parseInt(globalProperties.get(HTTPEventAdapterConstants.DEFAULT_MAX_CONNECTIONS_PER_HOST)); } else { defaultMaxConnectionsPerHost = HTTPEventAdapterConstants.DEFAULT_DEFAULT_MAX_CONNECTIONS_PER_HOST; } if (globalProperties.get(HTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS) != null) { maxTotalConnections = Integer .parseInt(globalProperties.get(HTTPEventAdapterConstants.MAX_TOTAL_CONNECTIONS)); } else { maxTotalConnections = HTTPEventAdapterConstants.DEFAULT_MAX_TOTAL_CONNECTIONS; } connectionManager = new MultiThreadedHttpConnectionManager(); connectionManager.getParams().setDefaultMaxConnectionsPerHost(defaultMaxConnectionsPerHost); connectionManager.getParams().setMaxTotalConnections(maxTotalConnections); } }
From source file:com.inmobi.messaging.netty.ScribeTopicPublisher.java
public void init(final String topic, final String host, final int port, final int backoffSeconds, final int timeoutSeconds, final PintailTimingAccumulator stats, final boolean enableRetries, final boolean resendOnAckLost, final long sleepInterval, final int msgQueueSize, final int ackQueueSize, final int numDrainsOnClose) { this.topic = topic; this.stats = stats; this.host = host; this.port = port; this.enabledRetries = enableRetries; this.resendOnAckLost = resendOnAckLost; this.sleepInterval = sleepInterval; this.toBeSent = new LinkedBlockingQueue<Message>(msgQueueSize); // create ack queue only if retry is enabled if (enableRetries) { this.toBeAcked = new LinkedBlockingQueue<Message>(ackQueueSize); }// w ww . j av a 2s .c o m this.numDrainsOnClose = numDrainsOnClose; bootstrap = new ClientBootstrap(NettyEventCore.getInstance().getFactory()); ChannelSetter chs = new ChannelSetter(); handler = new ScribeHandler(stats, chs, backoffSeconds, timer, this); ChannelPipelineFactory cfactory = new ScribePipelineFactory(handler, timeoutSeconds, timer); bootstrap.setPipelineFactory(cfactory); try { chs.connect(); } catch (Exception ioe) { LOG.info("Could not intialize the connection, scheduling reconnect"); handler.setInited(); handler.scheduleReconnect(); } handler.setInited(); senderThread = new Thread(new AsyncSender()); senderThread.start(); }
From source file:com.baifendian.swordfish.masterserver.master.MasterServiceImpl.java
public MasterServiceImpl() { this.flowDao = DaoFactory.getDaoInstance(FlowDao.class); this.adHocDao = DaoFactory.getDaoInstance(AdHocDao.class); this.streamingDao = DaoFactory.getDaoInstance(StreamingDao.class); this.executorServerManager = new ExecutorServerManager(); this.executionFlowQueue = new LinkedBlockingQueue<>(MasterConfig.executionFlowQueueSize); this.checkService = Executors.newScheduledThreadPool(5); }
From source file:com.uber.stream.kafka.mirrormaker.controller.core.OffsetMonitor.java
public OffsetMonitor(final HelixMirrorMakerManager helixMirrorMakerManager, ControllerConf controllerConf) { this.numOffsetThread = controllerConf.getNumOffsetThread(); this.helixMirrorMakerManager = helixMirrorMakerManager; this.srcBrokerList = new ArrayList<>(); this.offsetZkString = controllerConf.getConsumerCommitZkPath().isEmpty() ? controllerConf.getSrcKafkaZkPath() : controllerConf.getConsumerCommitZkPath(); this.srcZkString = controllerConf.getSrcKafkaZkPath(); // disable monitor if SRC_KAFKA_ZK or GROUP_ID is not set if (StringUtils.isEmpty(controllerConf.getSrcKafkaZkPath()) || controllerConf.getGroupId().isEmpty()) { logger.info("Consumer GROUP_ID is not set. Offset manager is disabled"); this.refreshIntervalInSec = 0; } else {// ww w . j av a 2 s. c o m this.refreshIntervalInSec = controllerConf.getOffsetRefreshIntervalInSec(); } this.consumerOffsetPath = "/consumers/" + controllerConf.getGroupId() + "/offsets/"; this.refreshExecutor = Executors.newSingleThreadScheduledExecutor( new ThreadFactoryBuilder().setNameFormat("topic-list-cron-%d").setDaemon(true).build()); this.cronExecutor = new ThreadPoolExecutor(numOffsetThread, numOffsetThread, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(controllerConf.getBlockingQueueSize()), new ThreadFactoryBuilder().setNameFormat("topic-offset-cron-%d").setDaemon(true).build()); this.topicList = new ArrayList<>(); this.brokerConsumer = new ConcurrentHashMap<>(); this.partitionLeader = new ConcurrentHashMap<>(); this.topicPartitionToOffsetMap = new ConcurrentHashMap<>(); this.noProgressMap = new ConcurrentHashMap<>(); }