001    package com.softwarementors.extjs.djn.config;
002    
003    import com.softwarementors.extjs.djn.StringUtils;
004    import com.softwarementors.extjs.djn.gson.DefaultGsonBuilderConfigurator;
005    import com.softwarementors.extjs.djn.gson.GsonBuilderConfigurator;
006    
007    public class GlobalConfiguration {
008      public static final boolean DEFAULT_DEBUG_VALUE = false;
009      public static final Class<? extends GsonBuilderConfigurator> DEFAULT_GSON_BUILDER_CONFIGURATOR_CLASS = DefaultGsonBuilderConfigurator.class;
010      private String providersUrl;
011      private boolean debug;
012      private Class<? extends GsonBuilderConfigurator> gsonBuilderConfiguratorClass;
013      private boolean batchRequestsMultithreadingEnabled;
014      private int batchRequestsMinThreadsPoolSize;
015      private int batchRequestsMaxThreadsPoolSize; 
016      private int batchRequestsThreadKeepAliveSeconds;
017      private int batchRequestsMaxThreadsPerRequest;
018      private boolean minify;
019      
020      public static final int MIN_BATCH_REQUESTS_MIN_THREAD_POOL_SIZE = 0;
021      public static final int MIN_BATCH_REQUESTS_MAX_THREAD_POOL_SIZE = 1;
022      public static final int MIN_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST = 1;
023      public static final int MIN_BATCH_REQUESTS_THREAD_KEEP_ALIVE_SECONDS = 0;
024    
025      public static final boolean DEFAULT_BATCH_REQUESTS_MULTITHREADING_ENABLED_VALUE = true;
026      public static final int DEFAULT_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST = 8;
027      public static final int DEFAULT_BATCH_REQUESTS_MIN_THREAD_POOL_SIZE = DEFAULT_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST * 2;
028      public static final int DEFAULT_BATCH_REQUESTS_MAX_THREAD_POOL_SIZE = DEFAULT_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST * 10;
029      public static final int DEFAULT_BATCH_REQUESTS_THREAD_KEEP_ALIVE_SECONDS = 60;
030      public static final boolean DEFAULT_MINIFY_VALUE = true;
031    
032      public GlobalConfiguration( String providersUrl, boolean debug, Class<? extends GsonBuilderConfigurator> gsonBuilderConfiguratorClass, 
033          boolean minify,
034          boolean batchRequestsMultithreadingEnabled, int batchRequestsMinThreadsPoolSize, int batchRequestsMaxThreadsPoolSize, 
035          int batchRequestsThreadKeepAliveSeconds, int batchRequestsMaxThreadsPerRequest) 
036      {
037        assert !StringUtils.isEmpty( providersUrl );
038        assert batchRequestsMinThreadsPoolSize >= MIN_BATCH_REQUESTS_MIN_THREAD_POOL_SIZE;
039        assert batchRequestsMaxThreadsPoolSize >= MIN_BATCH_REQUESTS_MAX_THREAD_POOL_SIZE;
040        assert batchRequestsThreadKeepAliveSeconds >= MIN_BATCH_REQUESTS_THREAD_KEEP_ALIVE_SECONDS;
041        assert batchRequestsMaxThreadsPerRequest >= MIN_BATCH_REQUESTS_MAX_THREADS_PER_REQUEST;
042        assert batchRequestsMinThreadsPoolSize <= batchRequestsMaxThreadsPoolSize;
043        
044        this.providersUrl = providersUrl;
045        this.debug = debug;
046        this.minify = minify;
047        this.gsonBuilderConfiguratorClass = gsonBuilderConfiguratorClass;
048            
049        this.batchRequestsMultithreadingEnabled = batchRequestsMultithreadingEnabled;
050        this.batchRequestsMinThreadsPoolSize = batchRequestsMinThreadsPoolSize;
051        this.batchRequestsMaxThreadsPoolSize = batchRequestsMaxThreadsPoolSize; 
052        this.batchRequestsThreadKeepAliveSeconds = batchRequestsThreadKeepAliveSeconds;
053        this.batchRequestsMaxThreadsPerRequest = batchRequestsMaxThreadsPerRequest; 
054        
055      }
056      
057      public String getProvidersUrl() {
058        return this.providersUrl;
059      }
060      
061      public boolean getDebug() {
062        return this.debug;
063      }
064    
065      public Class<? extends GsonBuilderConfigurator> getGsonBuilderConfiguratorClass() {
066        return this.gsonBuilderConfiguratorClass;
067      }
068      
069      public boolean getMinify() {
070        return this.minify;
071      }
072    
073      public boolean getBatchRequestsMultithreadingEnabled() {
074        return this.batchRequestsMultithreadingEnabled;
075      }
076    
077      public int getBatchRequestsMinThreadsPoolSize() {
078        return this.batchRequestsMinThreadsPoolSize;
079      }
080    
081      public int getBatchRequestsMaxThreadsPoolSize() {
082        return this.batchRequestsMaxThreadsPoolSize;
083      }
084    
085      public int getBatchRequestsThreadKeepAliveSeconds() {
086        return this.batchRequestsThreadKeepAliveSeconds;
087      }
088    
089      public int getBatchRequestsMaxThreadsPerRequest() {
090        return this.batchRequestsMaxThreadsPerRequest;
091      }
092    }