PageRenderTime 45ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/Frameworks/Misc/JavaMonitorFramework/Sources/com/webobjects/monitor/_private/MApplication.java

https://bitbucket.org/molequedeideias/wonder
Java | 474 lines | 322 code | 80 blank | 72 comment | 48 complexity | 27eb334bd1f231f65405c64e16fdaef8 MD5 | raw file
  1. /*
  2. © Copyright 2006- 2007 Apple Computer, Inc. All rights reserved.
  3. IMPORTANT: This Apple software is supplied to you by Apple Computer, Inc. ("Apple") in consideration of your agreement to the following terms, and your use, installation, modification or redistribution of this Apple software constitutes acceptance of these terms. If you do not agree with these terms, please do not use, install, modify or redistribute this Apple software.
  4. In consideration of your agreement to abide by the following terms, and subject to these terms, Apple grants you a personal, non-exclusive license, under Apple's copyrights in this original Apple software (the "Apple Software"), to use, reproduce, modify and redistribute the Apple Software, with or without modifications, in source and/or binary forms; provided that if you redistribute the Apple Software in its entirety and without modifications, you must retain this notice and the following text and disclaimers in all such redistributions of the Apple Software. Neither the name, trademarks, service marks or logos of Apple Computer, Inc. may be used to endorse or promote products derived from the Apple Software without specific prior written permission from Apple. Except as expressly stated in this notice, no other rights or licenses, express or implied, are granted by Apple herein, including but not limited to any patent rights that may be infringed by your derivative works or by other works in which the Apple Software may be incorporated.
  5. The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS.
  6. IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF
  7. SUCH DAMAGE.
  8. */
  9. package com.webobjects.monitor._private;
  10. import java.util.Enumeration;
  11. import com.webobjects.foundation.NSArray;
  12. import com.webobjects.foundation.NSDictionary;
  13. import com.webobjects.foundation.NSMutableArray;
  14. import com.webobjects.foundation.NSMutableDictionary;
  15. public class MApplication extends MObject {
  16. /*
  17. String name;
  18. Integer startingPort;
  19. Integer timeForStartup;
  20. Boolean phasedStartup;
  21. Boolean autoRecover;
  22. Integer minimumActiveSessionsCount;
  23. String unixPath;
  24. String winPath;
  25. String macPath;
  26. Boolean cachingEnabled;
  27. String adaptor;
  28. Integer adaptorThreads;
  29. Integer listenQueueSize;
  30. Integer adaptorThreadsMin;
  31. Integer adaptorThreadsMax;
  32. String projectSearchPath;
  33. Integer sessionTimeOut;
  34. String statisticsPassword;
  35. Boolean debuggingEnabled;
  36. String unixOutputPath;
  37. String winOutputPath;
  38. String macOutputPath;
  39. Boolean autoOpenInBrowser;
  40. Integer lifebeatInterval;
  41. String additionalArgs;
  42. Boolean notificationEmailEnabled;
  43. String notificationEmailAddr;
  44. Integer retries;
  45. String scheduler; // "RANDOM" | "ROUNDROBIN" | "LOADAVERAGE"
  46. Integer dormant;
  47. String redir;
  48. Integer sendTimeout;
  49. Integer recvTimeout;
  50. Integer cnctTimeout;
  51. Integer sendBufSize;
  52. Integer recvBufSize;
  53. Integer poolsize;
  54. Integer urlVersion; // 3 | 4
  55. */
  56. String _name;
  57. @Override
  58. public int hashCode() {
  59. final int prime = 31;
  60. int result = 1;
  61. result = prime * result + ((name() == null) ? 0 : name().hashCode());
  62. return result;
  63. }
  64. @Override
  65. public boolean equals(Object obj) {
  66. if (this == obj)
  67. return true;
  68. if (obj == null)
  69. return false;
  70. if (getClass() != obj.getClass())
  71. return false;
  72. final MApplication other = (MApplication) obj;
  73. if ( name() == null) {
  74. if (other. name() != null)
  75. return false;
  76. } else if (! name().equals(other.name()))
  77. return false;
  78. return true;
  79. }
  80. /********** 'values' accessors **********/
  81. public String name() { return (String) values.valueForKey("name"); }
  82. public void setName(String value) {
  83. if (!value.equals(name())) {
  84. setOldname(name());
  85. values.takeValueForKey(value, "name");
  86. _siteConfig.dataHasChanged();
  87. }
  88. }
  89. public Integer startingPort() { return (Integer) values.valueForKey("startingPort"); }
  90. public void setStartingPort(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "startingPort"); _siteConfig.dataHasChanged(); }
  91. public Integer timeForStartup() { return (Integer) values.valueForKey("timeForStartup"); }
  92. public void setTimeForStartup(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "timeForStartup"); _siteConfig.dataHasChanged(); }
  93. public Boolean phasedStartup() { return (Boolean) values.valueForKey("phasedStartup"); }
  94. public void setPhasedStartup(Boolean value) { values.takeValueForKey(value, "phasedStartup"); _siteConfig.dataHasChanged(); }
  95. public Boolean autoRecover() { return (Boolean) values.valueForKey("autoRecover"); }
  96. public void setAutoRecover(Boolean value) { values.takeValueForKey(value, "autoRecover"); _siteConfig.dataHasChanged(); }
  97. public Integer minimumActiveSessionsCount() { return (Integer) values.valueForKey("minimumActiveSessionsCount"); }
  98. public void setMinimumActiveSessionsCount(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "minimumActiveSessionsCount"); _siteConfig.dataHasChanged(); }
  99. public String unixPath() { return (String) values.valueForKey("unixPath"); }
  100. public void setUnixPath(String value) { values.takeValueForKey(value, "unixPath"); _siteConfig.dataHasChanged(); }
  101. public String winPath() { return (String) values.valueForKey("winPath"); }
  102. public void setWinPath(String value) { values.takeValueForKey(value, "winPath"); _siteConfig.dataHasChanged(); }
  103. public String macPath() { return (String) values.valueForKey("macPath"); }
  104. public void setMacPath(String value) { values.takeValueForKey(value, "macPath"); _siteConfig.dataHasChanged(); }
  105. public Boolean cachingEnabled() { return (Boolean) values.valueForKey("cachingEnabled"); }
  106. public void setCachingEnabled(Boolean value) { values.takeValueForKey(value, "cachingEnabled"); _siteConfig.dataHasChanged(); }
  107. public String adaptor() { return (String) values.valueForKey("adaptor"); }
  108. public void setAdaptor(String value) { values.takeValueForKey(value, "adaptor"); _siteConfig.dataHasChanged(); }
  109. public Integer adaptorThreads() { return (Integer) values.valueForKey("adaptorThreads"); }
  110. public void setAdaptorThreads(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "adaptorThreads"); _siteConfig.dataHasChanged(); }
  111. public Integer listenQueueSize() { return (Integer) values.valueForKey("listenQueueSize"); }
  112. public void setListenQueueSize(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "listenQueueSize"); _siteConfig.dataHasChanged(); }
  113. public Integer adaptorThreadsMin() { return (Integer) values.valueForKey("adaptorThreadsMin"); }
  114. public void setAdaptorThreadsMin(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "adaptorThreadsMin"); _siteConfig.dataHasChanged(); }
  115. public Integer adaptorThreadsMax() { return (Integer) values.valueForKey("adaptorThreadsMax"); }
  116. public void setAdaptorThreadsMax(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "adaptorThreadsMax"); _siteConfig.dataHasChanged(); }
  117. public String projectSearchPath() { return (String) values.valueForKey("projectSearchPath"); }
  118. public void setProjectSearchPath(String value) { values.takeValueForKey(value, "projectSearchPath"); _siteConfig.dataHasChanged(); }
  119. public Integer sessionTimeOut() { return (Integer) values.valueForKey("sessionTimeOut"); }
  120. public void setSessionTimeOut(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "sessionTimeOut"); _siteConfig.dataHasChanged(); }
  121. public String statisticsPassword() { return (String) values.valueForKey("statisticsPassword"); }
  122. public void setStatisticsPassword(String value) { values.takeValueForKey(value, "statisticsPassword"); _siteConfig.dataHasChanged(); }
  123. public Boolean debuggingEnabled() { return (Boolean) values.valueForKey("debuggingEnabled"); }
  124. public void setDebuggingEnabled(Boolean value) { values.takeValueForKey(value, "debuggingEnabled"); _siteConfig.dataHasChanged(); }
  125. public String unixOutputPath() { return (String) values.valueForKey("unixOutputPath"); }
  126. public void setUnixOutputPath(String value) { values.takeValueForKey(value, "unixOutputPath"); _siteConfig.dataHasChanged(); }
  127. public String winOutputPath() { return (String) values.valueForKey("winOutputPath"); }
  128. public void setWinOutputPath(String value) { values.takeValueForKey(value, "winOutputPath"); _siteConfig.dataHasChanged(); }
  129. public String macOutputPath() { return (String) values.valueForKey("macOutputPath"); }
  130. public void setMacOutputPath(String value) { values.takeValueForKey(value, "macOutputPath"); _siteConfig.dataHasChanged(); }
  131. public Boolean autoOpenInBrowser() { return (Boolean) values.valueForKey("autoOpenInBrowser"); }
  132. public void setAutoOpenInBrowser(Boolean value) { values.takeValueForKey(value, "autoOpenInBrowser"); _siteConfig.dataHasChanged(); }
  133. public Integer lifebeatInterval() { return (Integer) values.valueForKey("lifebeatInterval"); }
  134. public void setLifebeatInterval(Integer value) { values.takeValueForKey(MObject.validatedLifebeatInterval(value), "lifebeatInterval"); _siteConfig.dataHasChanged(); }
  135. public String additionalArgs() { return (String) values.valueForKey("additionalArgs"); }
  136. public void setAdditionalArgs(String value) { values.takeValueForKey(value, "additionalArgs"); _siteConfig.dataHasChanged(); }
  137. public Boolean notificationEmailEnabled() { return (Boolean) values.valueForKey("notificationEmailEnabled"); }
  138. public void setNotificationEmailEnabled(Boolean value) { values.takeValueForKey(value, "notificationEmailEnabled"); _siteConfig.dataHasChanged(); }
  139. public String notificationEmailAddr() { return (String) values.valueForKey("notificationEmailAddr"); }
  140. public void setNotificationEmailAddr(String value) { values.takeValueForKey(value, "notificationEmailAddr"); _siteConfig.dataHasChanged(); }
  141. public Integer retries() { return (Integer) values.valueForKey("retries"); }
  142. public void setRetries(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "retries"); _siteConfig.dataHasChanged(); }
  143. public String scheduler() { return (String) values.valueForKey("scheduler"); }
  144. public void setScheduler(String value) { values.takeValueForKey(value, "scheduler"); _siteConfig.dataHasChanged(); }
  145. public Integer dormant() { return (Integer) values.valueForKey("dormant"); }
  146. public void setDormant(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "dormant"); _siteConfig.dataHasChanged(); }
  147. public String redir() { return (String) values.valueForKey("redir"); }
  148. public void setRedir(String value) { values.takeValueForKey(value, "redir"); _siteConfig.dataHasChanged(); }
  149. public Integer sendTimeout() { return (Integer) values.valueForKey("sendTimeout"); }
  150. public void setSendTimeout(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "sendTimeout"); _siteConfig.dataHasChanged(); }
  151. public Integer recvTimeout() { return (Integer) values.valueForKey("recvTimeout"); }
  152. public void setRecvTimeout(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "recvTimeout"); _siteConfig.dataHasChanged(); }
  153. public Integer cnctTimeout() { return (Integer) values.valueForKey("cnctTimeout"); }
  154. public void setCnctTimeout(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "cnctTimeout"); _siteConfig.dataHasChanged(); }
  155. public Integer sendBufSize() { return (Integer) values.valueForKey("sendBufSize"); }
  156. public void setSendBufSize(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "sendBufSize"); _siteConfig.dataHasChanged(); }
  157. public Integer recvBufSize() { return (Integer) values.valueForKey("recvBufSize"); }
  158. public void setRecvBufSize(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "recvBufSize"); _siteConfig.dataHasChanged(); }
  159. public Integer poolsize() { return (Integer) values.valueForKey("poolsize"); }
  160. public void setPoolsize(Integer value) { values.takeValueForKey(MObject.validatedInteger(value), "poolsize"); _siteConfig.dataHasChanged(); }
  161. public Integer urlVersion() { return (Integer) values.valueForKey("urlVersion"); }
  162. public void setUrlVersion(Integer value) { values.takeValueForKey(MObject.validatedUrlVersion(value), "urlVersion"); _siteConfig.dataHasChanged(); }
  163. /**********/
  164. /********** 'values' accessors **********/
  165. public String oldname() { return (String) values.valueForKey("oldname"); }
  166. public void setOldname(String value) { values.takeValueForKey(value, "oldname"); _siteConfig.dataHasChanged(); }
  167. /**********/
  168. /********** Adding and Removing Instance primitives **********/
  169. public void _addInstancePrimitive(MInstance anInstance) {
  170. _instanceArray.addObject(anInstance);
  171. if (!_hostArray.containsObject(anInstance._host)) {
  172. _hostArray.addObject(anInstance._host);
  173. }
  174. }
  175. public void _removeInstancePrimitive(MInstance anInstance) {
  176. _instanceArray.removeObject(anInstance);
  177. boolean uniqueHost = true;
  178. for (Enumeration e = _instanceArray.objectEnumerator(); e.hasMoreElements(); ) {
  179. MInstance anInst = (MInstance) e.nextElement();
  180. if (anInstance._host == anInst._host) {
  181. uniqueHost = false;
  182. break;
  183. }
  184. }
  185. if (uniqueHost) {
  186. _hostArray.removeObject(anInstance._host);
  187. }
  188. }
  189. /**********/
  190. /********** Object Graph **********/
  191. NSMutableArray _instanceArray = new NSMutableArray();
  192. NSMutableArray _hostArray = new NSMutableArray();
  193. public NSArray<MInstance> instanceArray() { return _instanceArray; }
  194. public NSArray<MHost> hostArray() { return _hostArray; }
  195. /**********/
  196. /********** Constructors **********/
  197. // For UI
  198. public MApplication (String aName, MSiteConfig aConfig) {
  199. this(new NSDictionary<Object, Object>(new Object[]{aName}, new Object[]{"name"} ), aConfig);
  200. takeValuesFromDefaults();
  201. }
  202. // For Unarchiving
  203. public MApplication (NSDictionary aDict, MSiteConfig aConfig) {
  204. _siteConfig = aConfig;
  205. updateValues(aDict);
  206. }
  207. // For Cheating on the AppConfigurePage
  208. public MApplication (NSMutableDictionary aDict, MSiteConfig aConfig, Object o) {
  209. _siteConfig = aConfig;
  210. values = aDict.mutableClone();
  211. }
  212. private static NSDictionary _defaults = new NSDictionary <Object, Object>(new Object[]{
  213. Integer.valueOf(2001),
  214. Integer.valueOf(30),
  215. Boolean.TRUE,
  216. Boolean.TRUE,
  217. Integer.valueOf(0),
  218. Boolean.TRUE,
  219. "WODefaultAdaptor",
  220. Integer.valueOf(8),
  221. Integer.valueOf(128),
  222. Integer.valueOf(16),
  223. Integer.valueOf(256),
  224. "()",
  225. Integer.valueOf(3600),
  226. "",
  227. Boolean.FALSE,
  228. Boolean.FALSE,
  229. Integer.valueOf(30),
  230. "",
  231. Boolean.FALSE,
  232. "/Library/WebObjects/Logs",
  233. "/Library/WebObjects/Applications"},
  234. new Object[]{
  235. "startingPort",
  236. "timeForStartup",
  237. "phasedStartup",
  238. "autoRecover",
  239. "minimumActiveSessionsCount",
  240. "cachingEnabled",
  241. "adaptor",
  242. "adaptorThreads",
  243. "listenQueueSize",
  244. "adaptorThreadsMin",
  245. "adaptorThreadsMax",
  246. "projectSearchPath",
  247. "sessionTimeOut",
  248. "statisticsPassword",
  249. "debuggingEnabled",
  250. "autoOpenInBrowser",
  251. "lifebeatInterval",
  252. "additionalArgs",
  253. "notificationEmailEnabled",
  254. "macOutputPath",
  255. "macPath"});
  256. public void takeValuesFromDefaults() {
  257. values.addEntriesFromDictionary(_defaults);
  258. }
  259. public void pushValuesToInstances() {
  260. int instanceArrayCount = _instanceArray.count();
  261. for (int i=0; i<instanceArrayCount; i++) {
  262. MInstance anInstance = (MInstance) _instanceArray.objectAtIndex(i);
  263. anInstance.takeValuesFromApplication();
  264. }
  265. }
  266. /**********/
  267. /********** Archiving Support **********/
  268. public NSDictionary dictionaryForArchive() { return values; }
  269. @Override
  270. public String toString() {
  271. if(false) {
  272. return values.toString();
  273. }
  274. return "MApplication@" + name();
  275. }
  276. public void extractAdaptorValuesFromSiteConfig() {
  277. // get my application settings
  278. adaptorValues.takeValueForKey(values.valueForKey("retries"), "retries");
  279. adaptorValues.takeValueForKey(values.valueForKey("scheduler"), "scheduler");
  280. adaptorValues.takeValueForKey(values.valueForKey("dormant"), "dormant");
  281. adaptorValues.takeValueForKey(values.valueForKey("redir"), "redir");
  282. adaptorValues.takeValueForKey(values.valueForKey("poolsize"), "poolsize");
  283. adaptorValues.takeValueForKey(values.valueForKey("urlVersion"), "urlVersion");
  284. // get MSiteConfig application settings for settings that are still not set
  285. if (adaptorValues.valueForKey("retries") == null)
  286. adaptorValues.takeValueForKey(_siteConfig.values.valueForKey("retries"), "retries");
  287. if (adaptorValues.valueForKey("scheduler") == null)
  288. adaptorValues.takeValueForKey(_siteConfig.values.valueForKey("scheduler"), "scheduler");
  289. if (adaptorValues.valueForKey("dormant") == null)
  290. adaptorValues.takeValueForKey(_siteConfig.values.valueForKey("dormant"), "dormant");
  291. if (adaptorValues.valueForKey("redir") == null)
  292. adaptorValues.takeValueForKey(_siteConfig.values.valueForKey("redir"), "redir");
  293. if (adaptorValues.valueForKey("poolsize") == null)
  294. adaptorValues.takeValueForKey(_siteConfig.values.valueForKey("poolsize"), "poolsize");
  295. if (adaptorValues.valueForKey("urlVersion") == null)
  296. adaptorValues.takeValueForKey(_siteConfig.values.valueForKey("urlVersion"), "urlVersion");
  297. }
  298. /**********/
  299. public Integer nextID() {
  300. int instanceArrayCount = _instanceArray.count();
  301. int lastSequence = 0;
  302. for (int i=0; i<instanceArrayCount; i++) {
  303. MInstance anInst = (MInstance) _instanceArray.objectAtIndex(i);
  304. int thisSequence = anInst.id().intValue();
  305. if (thisSequence > lastSequence) {
  306. lastSequence = thisSequence;
  307. }
  308. }
  309. return Integer.valueOf(lastSequence+1);
  310. }
  311. public boolean isIDInUse(Integer ID) {
  312. if (instanceWithID(ID) == null) {
  313. return false;
  314. }
  315. return true;
  316. }
  317. public MInstance instanceWithID(Integer ID) {
  318. int instanceArrayCount = _instanceArray.count();
  319. for (int i=0; i<instanceArrayCount; i++) {
  320. MInstance anInst = (MInstance) _instanceArray.objectAtIndex(i);
  321. if (anInst.id().equals(ID)) {
  322. return anInst;
  323. }
  324. }
  325. return null;
  326. }
  327. public Integer runningInstancesCount_W() {
  328. int runningInstances = 0;
  329. int numInstances = _instanceArray.count();
  330. for (int i=0; i<numInstances; i++) {
  331. MInstance anInstance = (MInstance) _instanceArray.objectAtIndex(i);
  332. if (anInstance.isRunning_W()) {
  333. runningInstances++;
  334. }
  335. }
  336. return Integer.valueOf(runningInstances);
  337. }
  338. public boolean isRunning_W() {
  339. if (runningInstancesCount_W().intValue() > 0) {
  340. return true;
  341. }
  342. return false;
  343. }
  344. // Used for the ApplicationsPage
  345. private Integer runningInstancesCount = MObject._zeroInteger;
  346. public boolean isRunning() {
  347. // AK: this one is called from the overview page (may or may not be correct)
  348. return runningInstancesCount.intValue() > 0;
  349. }
  350. public int runningInstancesCount() {
  351. return runningInstancesCount.intValue();
  352. }
  353. public void setRunningInstancesCount(int cnt) {
  354. runningInstancesCount = Integer.valueOf(cnt);
  355. }
  356. // Used for the AppDetailPage
  357. public Integer runningInstancesCount_M() {
  358. int runningInstances = runningInstances_M().count();
  359. Integer riInt = Integer.valueOf(runningInstances);
  360. runningInstancesCount = riInt;
  361. return riInt;
  362. }
  363. public NSArray<MInstance> runningInstances_M() {
  364. NSMutableArray<MInstance> instances = new NSMutableArray<MInstance>();
  365. int numInstances = _instanceArray.count();
  366. for (int i=0; i<numInstances; i++) {
  367. MInstance anInstance = (MInstance) _instanceArray.objectAtIndex(i);
  368. if (anInstance.isRunning_M()) {
  369. instances.addObject(anInstance);
  370. }
  371. }
  372. return instances;
  373. }
  374. public boolean isRunning_M() {
  375. if (runningInstancesCount_M().intValue() > 0) {
  376. return true;
  377. }
  378. return false;
  379. }
  380. public boolean isStopped_M() {
  381. int numInstances = _instanceArray.count();
  382. for (int i=0; i<numInstances; i++) {
  383. MInstance anInstance = (MInstance) _instanceArray.objectAtIndex(i);
  384. if (anInstance.state != MObject.DEAD) {
  385. return false;
  386. }
  387. }
  388. return true;
  389. }
  390. }