@Override public String toString() { StringBuilder buf = new StringBuilder(getClass().getSimpleName()); buf.append("(id="); buf.append(id); buf.append(" categories="); buf.append(categories); buf.append(" queuing="); buf.append(isQueuingEnabled()); buf.append(" processing="); buf.append(isProcessingEnabled()); buf.append(" maxThreads="); buf.append(getMaxThreads()); buf.append(" capacity="); buf.append(getCapacity()); buf.append(")"); return buf.toString(); } }
void initializeQueue(WorkQueueDescriptor config) { if (ALL_QUEUES.equals(config.id)) { throw new IllegalArgumentException("cannot initialize all queues"); } if (queuing.getQueue(config.id) != null) { throw new IllegalStateException("work queue " + config.id + " is already initialized"); } if (executors.containsKey(config.id)) { throw new IllegalStateException("work queue " + config.id + " already have an executor"); } NuxeoBlockingQueue queue = queuing.init(config); ThreadFactory threadFactory = new NamedThreadFactory(THREAD_PREFIX + config.id + "-"); int maxPoolSize = config.getMaxThreads(); WorkThreadPoolExecutor executor = new WorkThreadPoolExecutor(maxPoolSize, maxPoolSize, 0, TimeUnit.SECONDS, queue, threadFactory); // prestart all core threads so that direct additions to the queue // (from another Nuxeo instance) can be seen executor.prestartAllCoreThreads(); executors.put(config.id, executor); log.info("Initialized work queue {}, {}", config.id, config); }
protected void initTopology() { // create a single topology with one root per work pool Topology.Builder builder = Topology.builder(); List<WorkQueueDescriptor> descriptors = getDescriptors(QUEUES_EP); descriptors.stream().filter(WorkQueueDescriptor::isProcessingEnabled).forEach(d -> builder.addComputation( () -> new WorkComputation(d.getId()), Collections.singletonList("i1:" + d.getId()))); topology = builder.build(); settings = new Settings(DEFAULT_CONCURRENCY, getPartitions(DEFAULT_CONCURRENCY), getCodec()); descriptors.forEach(item -> settings.setConcurrency(item.getId(), item.getMaxThreads())); descriptors.forEach(item -> settings.setPartitions(item.getId(), getPartitions(item.getMaxThreads()))); }