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