public void buildPool()

in src/main/java/com/revo/deployr/rbroker/example/service/FraudService.java [74:168]


    public void buildPool(int poolSize) {

        try {

            String msg = "RBroker pool initializing on " +
                         System.getProperty("endpoint") +
                         ". Requested " + poolSize +
                         " R session(s) in the pool. " +
                         "This may take some time. Please wait.";
            alertClient(msg, null, false);

            if(rBroker == null) {

                /*
                 * Create initial RBroker instance.
                 */

                RAuthentication rAuth =
                    new RBasicAuthentication(System.getProperty("username"),
                                             System.getProperty("password"));

                PoolCreationOptions poolOptions = new PoolCreationOptions();

                PoolPreloadOptions preloadOptions = 
                                        new PoolPreloadOptions();
                preloadOptions.filename = System.getProperty("repository-model");
                preloadOptions.directory = System.getProperty("repository-directory");
                preloadOptions.author = System.getProperty("username");
                poolOptions.preloadWorkspace = preloadOptions;
                String endpoint = System.getProperty("endpoint");
                boolean allowSelfSigned = 
                    Boolean.valueOf(System.getProperty("allow.SelfSignedSSLCert"));

                /*
                 * Ensure releaseGridResources property is enabled
                 * so server-side grid resource management will auto
                 * clear prior pool resources before creating a new
                 * pool on a refresh.
                 */
                poolOptions.releaseGridResources = true;

                brokerConfig = new PooledBrokerConfig(endpoint,
                                                      rAuth,
                                                      poolSize,
                                                      poolOptions);
                brokerConfig.allowSelfSignedSSLCert = allowSelfSigned;

                rBroker = RBrokerFactory.pooledTaskBroker(brokerConfig);
                lastAllocatedPoolSize = rBroker.maxConcurrency();

                rBroker.addTaskListener(this);
                rBroker.addBrokerListener(this);

                log.info("RBroker pool initialized with " +
                    lastAllocatedPoolSize + " R sessions.");

            } else {

                /*
                 * Release old instance of RBroker.
                 */
                rBroker.shutdown();

                /*
                 * Create new instance of RBroker.
                 */
                brokerConfig.maxConcurrentTaskLimit = poolSize;
                rBroker = RBrokerFactory.pooledTaskBroker(brokerConfig);
                lastAllocatedPoolSize = rBroker.maxConcurrency();

                log.info("RBroker pool resized to " +
                    lastAllocatedPoolSize + " R sessions.");

                rBroker.addTaskListener(this);
                rBroker.addBrokerListener(this);

            }

            RuntimeStats runtimeStats = new RuntimeStats();
            runtimeStats = populateRuntimeStats(runtimeStats, null);
            /*
             * Push RuntimeStats message over STOMP Web Socket to clients
             * listening on FRAUDMSGTOPIC.
             */
            simpMessagingTemplate.convertAndSend(FRAUDMSGTOPIC, runtimeStats);

        } catch(Exception ex) {
            log.warn("FraudService: init ex=" + ex);
            String msg = "RBroker pool initialization failed. Is " +
                System.getProperty("endpoint") +
                " a valid DeployR server endpoint?" +
                " Using valid user credentials?";
            alertClient(msg, ex.getMessage(), true);
        }
    }