Clover Coverage Report
Coverage timestamp: Sat Sep 18 2010 04:09:52 UTC
../../../../../img/srcFileCovDistChart5.png 77% of files have more coverage
152   705   112   1.69
28   419   0.74   45
90     1.24  
2    
 
  KernelContext       Line # 41 152 111 50.2% 0.5018587
  KernelContext.LazyHolderTimeoutMethods       Line # 471 0 1 0% 0.0
 
  (150)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2010, Michael Meyling <mime@qedeq.org>.
4    *
5    * "Hilbert II" is free software; you can redistribute
6    * it and/or modify it under the terms of the GNU General Public
7    * License as published by the Free Software Foundation; either
8    * version 2 of the License, or (at your option) any later version.
9    *
10    * This program is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13    * GNU General Public License for more details.
14    */
15   
16    package org.qedeq.kernel.bo.context;
17   
18    import java.io.File;
19    import java.io.FileOutputStream;
20    import java.io.IOException;
21    import java.net.URL;
22    import java.net.URLConnection;
23    import java.nio.channels.FileLock;
24    import java.util.Map;
25   
26    import org.qedeq.base.io.IoUtility;
27    import org.qedeq.base.trace.Trace;
28    import org.qedeq.base.utility.YodaUtility;
29    import org.qedeq.kernel.bo.QedeqBo;
30    import org.qedeq.kernel.bo.log.QedeqLog;
31    import org.qedeq.kernel.common.ModuleAddress;
32    import org.qedeq.kernel.common.SourceFileExceptionList;
33    import org.qedeq.kernel.config.QedeqConfig;
34   
35   
36    /**
37    * This class provides static access methods for basic informations.
38    *
39    * @author Michael Meyling
40    */
 
41    public final class KernelContext implements KernelProperties, KernelState, KernelServices {
42   
43    /** Message for non started kernel. */
44    private static final String KERNEL_NOT_STARTED = "Kernel not started";
45   
46    /** Message for non initialized kernel. */
47    private static final String KERNEL_NOT_INITIALIZED = "Kernel not initialized";
48   
49    /** This class. */
50    private static final Class CLASS = KernelContext.class;
51   
52    /** Version of this kernel. */
53    private static final String KERNEL_VERSION = "0.03.12";
54   
55    /** Version dependent directory of this kernel. */
56    private static final String KERNEL_VERSION_DIRECTORY = KERNEL_VERSION.replace('.', '_');
57   
58    /** Version code . */
59    private static final String KERNEL_CODE_NAME = "mongaga";
60   
61    /** Kernel version dedication. */
62    private static final String KERNEL_DEDICATED
63    = "dedicated to Therese Schirrmacher, who died on 2010-08-20";
64   
65    /** Descriptive version information of this kernel. */
66    private static final String DESCRIPTIVE_KERNEL_VERSION
67    = "Hilbert II - Version " + KERNEL_VERSION + " (" + KERNEL_CODE_NAME + ") ["
68    + getBuildIdFromManifest() + "] " + KERNEL_DEDICATED;
69   
70    /** Maximal supported rule version of this kernel. */
71    private static final String MAXIMAL_RULE_VERSION = "1.00.00";
72   
73    /** One and only instance of this class. */
74    private static final KernelContext INSTANCE = new KernelContext();
75   
76    /** Lock file. */
77    private File lockFile;
78   
79    /** Lock file stream. */
80    private FileOutputStream lockStream;
81   
82    /** Initial kernel state. */
83    private final KernelState initialState = new KernelState() {
84   
 
85  54 toggle public void init(final KernelServices moduleServices, final QedeqConfig qedeqConfig)
86    throws IOException {
87  54 config = qedeqConfig;
88  54 checkJavaVersion();
89  54 createAllNecessaryDirectories();
90  54 checkIfApplicationIsAlreadyRunningAndLockFile();
91  54 KernelContext.this.services = moduleServices;
92  54 Trace.log("-----------------------------------------------------------------------------------------");
93  54 QedeqLog.getInstance().logMessage("This is "
94    + KernelContext.getInstance().getDescriptiveKernelVersion());
95  54 QedeqLog.getInstance().logMessage(" see \"http://www.qedeq.org\" for more "
96    + "information");
97  54 QedeqLog.getInstance().logMessage(" supports rules till version "
98    + KernelContext.getInstance().getMaximalRuleVersion());
99  54 currentState = initializedState;
100    }
101   
 
102  0 toggle public boolean isReady() {
103  0 return false;
104    }
105   
 
106  54 toggle public void shutdown() {
107  54 currentState = initialState;
108  54 config = null;
109    // close stream and associated channel
110  54 IoUtility.close(lockStream);
111  54 lockStream = null;
112    }
113   
 
114  0 toggle public void startupServices() {
115  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
116    }
117   
 
118  0 toggle public void removeAllModules() {
119  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
120    }
121   
 
122  0 toggle public void removeModule(final ModuleAddress address) {
123  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
124    }
125   
 
126  0 toggle public void clearLocalBuffer() throws IOException {
127  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
128    }
129   
 
130  0 toggle public QedeqBo loadModule(final ModuleAddress address) {
131  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
132    }
133   
 
134  0 toggle public boolean loadAllModulesFromQedeq() {
135  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
136    }
137   
 
138  0 toggle public void loadRequiredModules(final ModuleAddress address) {
139  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
140    }
141   
 
142  0 toggle public ModuleAddress[] getAllLoadedModules() {
143  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
144    }
145   
 
146  0 toggle public QedeqBo getQedeqBo(final ModuleAddress address) {
147  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
148    }
149   
 
150  0 toggle public ModuleAddress getModuleAddress(final URL url) {
151  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
152    }
153   
 
154  0 toggle public ModuleAddress getModuleAddress(final String url) {
155  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
156    }
157   
 
158  0 toggle public ModuleAddress getModuleAddress(final File file) {
159  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
160    }
161   
 
162  0 toggle public String getSource(final ModuleAddress address) {
163  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
164    }
165   
 
166  0 toggle public boolean checkModule(final ModuleAddress address) {
167  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
168    }
169   
 
170  0 toggle public Object executePlugin(final String pluginName, final ModuleAddress address,
171    final Map parameters) {
172  0 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
173    }
174   
175    };
176   
177    /** Initial kernel state. */
178    private final KernelState initializedState = new KernelState() {
179   
 
180  0 toggle public void init(final KernelServices moduleServices, final QedeqConfig qedeqConfig)
181    throws IOException {
182  0 throw new IllegalStateException("Kernel is already initialized");
183    }
184   
 
185  0 toggle public boolean isReady() {
186  0 return false;
187    }
188   
 
189  54 toggle public void shutdown() {
190  54 QedeqLog.getInstance().logMessage("QEDEQ Kernel closed.");
191  54 KernelContext.this.services = null;
192  54 initialState.shutdown();
193    }
194   
 
195  54 toggle public void startupServices() {
196  54 services.startupServices();
197  54 currentState = readyState;
198  54 QedeqLog.getInstance().logMessage("QEDEQ kernel opened.");
199    }
200   
 
201  0 toggle public void removeAllModules() {
202  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
203    }
204   
 
205  0 toggle public void removeModule(final ModuleAddress address) {
206  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
207    }
208   
 
209  0 toggle public void clearLocalBuffer() throws IOException {
210  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
211    }
212   
 
213  0 toggle public QedeqBo loadModule(final