001    /*
002     * Copyright © 2008, 2012 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 Lesser 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 Lesser General Public License for more details.
018     *
019     * You should have received a copy of the GNU Lesser 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.router.dispatcher.Dispatcher;
032    import com.softwarementors.extjs.djn.router.processor.standard.json.DefaultJsonRequestProcessorThread;
033    import com.softwarementors.extjs.djn.router.processor.standard.json.JsonRequestProcessorThread;
034    
035    import edu.umd.cs.findbugs.annotations.CheckForNull;
036    import edu.umd.cs.findbugs.annotations.NonNull;
037    
038    public class GlobalConfiguration {
039      public static final boolean DEFAULT_DEBUG_VALUE = false;
040      @CheckForNull private String contextPath;
041      @NonNull private String providersUrl;
042      private boolean debug;
043      @NonNull private Class<? extends GsonBuilderConfigurator> gsonBuilderConfiguratorClass;
044      @NonNull private Class<? extends JsonRequestProcessorThread> jsonRequestProcessorThreadClass;
045      @NonNull private Class<? extends Dispatcher> dispatcherClass;
046      private boolean batchRequestsMultithreadingEnabled;
047      private int batchRequestsMinThreadsPoolSize;
048      private int batchRequestsMaxThreadsPoolSize; 
049      private int batchRequestsThreadKeepAliveSeconds;
050      private int batchRequestsMaxThreadsPerRequest;
051      private boolean minify;
052      private boolean createSourceFiles;
053      
054      public static final int MIN_BATCH_REQUESTS_MIN_THREAD_POOL_SIZE = 0;
055      public static final int MIN_BATCH_REQUESTS_MAX_THREAD_POOL_SIZE = 1;
056      public static final int MIN_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST = 1;
057      public static final int MIN_BATCH_REQUESTS_THREAD_KEEP_ALIVE_SECONDS = 0;
058    
059      public static final boolean DEFAULT_BATCH_REQUESTS_MULTITHREADING_ENABLED_VALUE = true;
060      public static final int DEFAULT_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST = 8;
061      public static final int DEFAULT_BATCH_REQUESTS_MIN_THREAD_POOL_SIZE = DEFAULT_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST * 2;
062      public static final int DEFAULT_BATCH_REQUESTS_MAX_THREAD_POOL_SIZE = DEFAULT_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST * 10;
063      public static final int DEFAULT_BATCH_REQUESTS_THREAD_KEEP_ALIVE_SECONDS = 60;
064      public static final boolean DEFAULT_MINIFY_VALUE = true;
065      public static final boolean DEFAULT_CREATE_SOURCE_FILES = true;
066      @NonNull public static final Class<? extends GsonBuilderConfigurator> DEFAULT_GSON_BUILDER_CONFIGURATOR_CLASS = DefaultGsonBuilderConfigurator.class;
067      @NonNull public static final Class<? extends JsonRequestProcessorThread> DEFAULT_JSON_REQUEST_PROCESSOR_THREAD_CLASS = DefaultJsonRequestProcessorThread.class;
068    
069      public GlobalConfiguration( String contextPath, String providersUrl, boolean debug, 
070          Class<? extends GsonBuilderConfigurator> gsonBuilderConfiguratorClass,
071          Class<? extends JsonRequestProcessorThread> jsonRequestProcessorThreadClass,
072          Class<? extends Dispatcher> dispatcherClass,
073          boolean minify,
074          boolean batchRequestsMultithreadingEnabled, int batchRequestsMinThreadsPoolSize, int batchRequestsMaxThreadsPoolSize, 
075          int batchRequestsThreadKeepAliveSeconds, int batchRequestsMaxThreadsPerRequest, boolean createSourceFiles) 
076      {
077        assert !StringUtils.isEmpty( providersUrl );
078        assert batchRequestsMinThreadsPoolSize >= MIN_BATCH_REQUESTS_MIN_THREAD_POOL_SIZE;
079        assert batchRequestsMaxThreadsPoolSize >= MIN_BATCH_REQUESTS_MAX_THREAD_POOL_SIZE;
080        assert batchRequestsThreadKeepAliveSeconds >= MIN_BATCH_REQUESTS_THREAD_KEEP_ALIVE_SECONDS;
081        assert batchRequestsMaxThreadsPerRequest >= MIN_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST;
082        assert batchRequestsMinThreadsPoolSize <= batchRequestsMaxThreadsPoolSize;
083        assert gsonBuilderConfiguratorClass != null;
084        assert jsonRequestProcessorThreadClass != null;
085        assert dispatcherClass != null;
086        
087        this.contextPath = contextPath;
088        this.providersUrl = providersUrl;
089        this.debug = debug;
090        this.minify = minify;
091        this.gsonBuilderConfiguratorClass = gsonBuilderConfiguratorClass;
092        this.jsonRequestProcessorThreadClass = jsonRequestProcessorThreadClass;
093        this.dispatcherClass = dispatcherClass;
094            
095        this.batchRequestsMultithreadingEnabled = batchRequestsMultithreadingEnabled;
096        this.batchRequestsMinThreadsPoolSize = batchRequestsMinThreadsPoolSize;
097        this.batchRequestsMaxThreadsPoolSize = batchRequestsMaxThreadsPoolSize; 
098        this.batchRequestsThreadKeepAliveSeconds = batchRequestsThreadKeepAliveSeconds;
099        this.batchRequestsMaxThreadsPerRequest = batchRequestsMaxThreadsPerRequest;
100        
101        this.createSourceFiles = createSourceFiles;
102      }
103      
104      public String getProvidersUrl() {
105        return this.providersUrl;
106      }
107      
108      public boolean getDebug() {
109        return this.debug;
110      }
111    
112      public Class<? extends GsonBuilderConfigurator> getGsonBuilderConfiguratorClass() {
113        return this.gsonBuilderConfiguratorClass;
114      }
115    
116      public Class<? extends JsonRequestProcessorThread> getJsonRequestProcessorThreadClass() {
117        return this.jsonRequestProcessorThreadClass;
118      }
119      
120      public Class<? extends Dispatcher> getDispatcherClass() {
121        return this.dispatcherClass;
122      }
123      
124      public boolean getMinify() {
125        return this.minify;
126      }
127    
128      public boolean getBatchRequestsMultithreadingEnabled() {
129        return this.batchRequestsMultithreadingEnabled;
130      }
131    
132      public int getBatchRequestsMinThreadsPoolSize() {
133        return this.batchRequestsMinThreadsPoolSize;
134      }
135    
136      public int getBatchRequestsMaxThreadsPoolSize() {
137        return this.batchRequestsMaxThreadsPoolSize;
138      }
139    
140      public int getBatchRequestsThreadKeepAliveSeconds() {
141        return this.batchRequestsThreadKeepAliveSeconds;
142      }
143    
144      public int getBatchRequestsMaxThreadsPerRequest() {
145        return this.batchRequestsMaxThreadsPerRequest;
146      }
147     
148      @CheckForNull public String getContextPath() {
149        return this.contextPath;
150      }
151      
152      public boolean getCreateSourceFiles() {
153        return this.createSourceFiles;
154      }
155    }