001    /*
002     * Copyright © 2008, 2009 Pedro Agulló Soliveres.
003     * 
004     * This file is part of DirectJNgine.
005     *
006     * DirectJNgine is free software: you can redistribute it and/or modify
007     * it under the terms of the GNU General Public License as published by
008     * the Free Software Foundation, either version 3 of the License.
009     * 
010     * Commercial use is permitted to the extent that the code/component(s)
011     * do NOT become part of another Open Source or Commercially developed
012     * licensed development library or toolkit without explicit permission.
013     *
014     * DirectJNgine is distributed in the hope that it will be useful,
015     * but WITHOUT ANY WARRANTY; without even the implied warranty of
016     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
017     * GNU General Public License for more details.
018     *
019     * You should have received a copy of the GNU General Public License
020     * along with DirectJNgine.  If not, see <http://www.gnu.org/licenses/>.
021     * 
022     * This software uses the ExtJs library (http://extjs.com), which is 
023     * distributed under the GPL v3 license (see http://extjs.com/license).
024     */
025    
026    package com.softwarementors.extjs.djn.config;
027    
028    import com.softwarementors.extjs.djn.StringUtils;
029    import com.softwarementors.extjs.djn.gson.DefaultGsonBuilderConfigurator;
030    import com.softwarementors.extjs.djn.gson.GsonBuilderConfigurator;
031    import com.softwarementors.extjs.djn.servlet.RegistryConfigurator;
032    
033    public class GlobalConfiguration {
034      public static final boolean DEFAULT_DEBUG_VALUE = false;
035      public static final Class<? extends GsonBuilderConfigurator> DEFAULT_GSON_BUILDER_CONFIGURATOR_CLASS = DefaultGsonBuilderConfigurator.class;
036      private String providersUrl;
037      private boolean debug;
038      private Class<? extends GsonBuilderConfigurator> gsonBuilderConfiguratorClass;
039      private Class<? extends RegistryConfigurator> registryConfiguratorClass;
040      private boolean batchRequestsMultithreadingEnabled;
041      private int batchRequestsMinThreadsPoolSize;
042      private int batchRequestsMaxThreadsPoolSize; 
043      private int batchRequestsThreadKeepAliveSeconds;
044      private int batchRequestsMaxThreadsPerRequest;
045      private boolean minify;
046      
047      public static final int MIN_BATCH_REQUESTS_MIN_THREAD_POOL_SIZE = 0;
048      public static final int MIN_BATCH_REQUESTS_MAX_THREAD_POOL_SIZE = 1;
049      public static final int MIN_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST = 1;
050      public static final int MIN_BATCH_REQUESTS_THREAD_KEEP_ALIVE_SECONDS = 0;
051    
052      public static final boolean DEFAULT_BATCH_REQUESTS_MULTITHREADING_ENABLED_VALUE = true;
053      public static final int DEFAULT_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST = 8;
054      public static final int DEFAULT_BATCH_REQUESTS_MIN_THREAD_POOL_SIZE = DEFAULT_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST * 2;
055      public static final int DEFAULT_BATCH_REQUESTS_MAX_THREAD_POOL_SIZE = DEFAULT_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST * 10;
056      public static final int DEFAULT_BATCH_REQUESTS_THREAD_KEEP_ALIVE_SECONDS = 60;
057      public static final boolean DEFAULT_MINIFY_VALUE = true;
058    
059      public GlobalConfiguration( String providersUrl, boolean debug, Class<? extends GsonBuilderConfigurator> gsonBuilderConfiguratorClass, 
060          Class<? extends RegistryConfigurator> registryConfiguratorClass,
061          boolean minify,
062          boolean batchRequestsMultithreadingEnabled, int batchRequestsMinThreadsPoolSize, int batchRequestsMaxThreadsPoolSize, 
063          int batchRequestsThreadKeepAliveSeconds, int batchRequestsMaxThreadsPerRequest) 
064      {
065        assert !StringUtils.isEmpty( providersUrl );
066        assert batchRequestsMinThreadsPoolSize >= MIN_BATCH_REQUESTS_MIN_THREAD_POOL_SIZE;
067        assert batchRequestsMaxThreadsPoolSize >= MIN_BATCH_REQUESTS_MAX_THREAD_POOL_SIZE;
068        assert batchRequestsThreadKeepAliveSeconds >= MIN_BATCH_REQUESTS_THREAD_KEEP_ALIVE_SECONDS;
069        assert batchRequestsMaxThreadsPerRequest >= MIN_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST;
070        assert batchRequestsMinThreadsPoolSize <= batchRequestsMaxThreadsPoolSize;
071        
072        this.providersUrl = providersUrl;
073        this.debug = debug;
074        this.minify = minify;
075        this.gsonBuilderConfiguratorClass = gsonBuilderConfiguratorClass;
076        this.registryConfiguratorClass = registryConfiguratorClass;
077            
078        this.batchRequestsMultithreadingEnabled = batchRequestsMultithreadingEnabled;
079        this.batchRequestsMinThreadsPoolSize = batchRequestsMinThreadsPoolSize;
080        this.batchRequestsMaxThreadsPoolSize = batchRequestsMaxThreadsPoolSize; 
081        this.batchRequestsThreadKeepAliveSeconds = batchRequestsThreadKeepAliveSeconds;
082        this.batchRequestsMaxThreadsPerRequest = batchRequestsMaxThreadsPerRequest; 
083        
084      }
085      
086      public String getProvidersUrl() {
087        return this.providersUrl;
088      }
089      
090      public boolean getDebug() {
091        return this.debug;
092      }
093    
094      public Class<? extends GsonBuilderConfigurator> getGsonBuilderConfiguratorClass() {
095        return this.gsonBuilderConfiguratorClass;
096      }
097      
098      public boolean getMinify() {
099        return this.minify;
100      }
101    
102      public boolean getBatchRequestsMultithreadingEnabled() {
103        return this.batchRequestsMultithreadingEnabled;
104      }
105    
106      public int getBatchRequestsMinThreadsPoolSize() {
107        return this.batchRequestsMinThreadsPoolSize;
108      }
109    
110      public int getBatchRequestsMaxThreadsPoolSize() {
111        return this.batchRequestsMaxThreadsPoolSize;
112      }
113    
114      public int getBatchRequestsThreadKeepAliveSeconds() {
115        return this.batchRequestsThreadKeepAliveSeconds;
116      }
117    
118      public int getBatchRequestsMaxThreadsPerRequest() {
119        return this.batchRequestsMaxThreadsPerRequest;
120      }
121      
122      public Class<? extends RegistryConfigurator> getRegistryConfiguratorClass() {
123        return this.registryConfiguratorClass;
124      }
125    
126      public boolean hasCustomRegistryConfigurationClass() {
127        return this.registryConfiguratorClass != null;
128      }
129    }