private static <E> BlockingQueue<E> getBlockingQueueFrom(Class<? extends Queue> queueClass,
            Class<? extends TakeStrategy> takeStrat, Class<? extends PutStrategy> putStrat, int capacity) {
        // Build model for template filling
        BlockingModel model = new BlockingModel();
        model.queueClassName = queueClass.getSimpleName();
        model.blockingQueueClassName = model.queueClassName + "Blocking";
        model.TakeStrategy = takeStrat.getSimpleName();
        model.PutStrategy = putStrat.getSimpleName();

        // Check for the Queue in cache
        Class blockingClass = null; // blockingQueueCache.get(queueClass); // Can't use cache right now because of
                                    // capacity hardcoded in class
        if (blockingClass == null) {
            // Load and fill template
            Template blockingTemplate = Template
                    .fromFile(BlockingQueueFactory.class, "TemplateBlocking.java");
            String blockingQueueClassFile = blockingTemplate.render(model);

            // System.out.println(blockingQueueClassFile);

            // Compile result
            SimpleCompiler compiler = new SimpleCompiler();
            CompilationResult result = compiler.compile(model.blockingQueueClassName, blockingQueueClassFile);

            if (result.isSuccessful()) {
                try {
                    // Load class
                    blockingClass = result.getClassLoader().loadClass("org.jctools.queues.blocking."+model.blockingQueueClassName);

                } catch (Exception e) {
                    throw new IllegalStateException(e);
                }
                // Store class in cache for later re-use
                blockingQueueCache.put(queueClass, blockingClass);
            } else {
                System.out.println(result.getDiagnostics());
                return null;
            }
        }

        // Instantiate new Blocking queue
        BlockingQueue<E> q = null;
        try {

            q = (BlockingQueue<E>) blockingClass.getConstructor(Integer.TYPE).newInstance(capacity);
        } catch (Exception e) {
            throw new IllegalStateException(e);
        }

        return q;
    }
The queue factory produces {@link java.util.Queue} instances based on a best fit to the {@link ConcurrentQueueSpec}.
This allows minimal dependencies between user code and the queue implementations and gives users a way to express
their requirements on a higher level.

@author nitsanw
jctools-experimental/src/main/java/org/jctools/queues/blocking/BlockingQueueFactory.java