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 ModuleAddress address) {
214  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
215    }
216   
 
217  0 toggle public boolean loadAllModulesFromQedeq() {
218  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
219    }
220   
 
221  0 toggle public void loadRequiredModules(final ModuleAddress address) {
222  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
223    }
224   
 
225  0 toggle public ModuleAddress[] getAllLoadedModules() {
226  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
227    }
228   
 
229  0 toggle public QedeqBo getQedeqBo(final ModuleAddress address) {
230  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
231    }
232   
 
233  0 toggle public ModuleAddress getModuleAddress(final URL url) {
234  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
235    }
236   
 
237  0 toggle public ModuleAddress getModuleAddress(final String url) {
238  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
239    }
240   
 
241  0 toggle public ModuleAddress getModuleAddress(final File file) {
242  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
243    }
244   
 
245  0 toggle public String getSource(final ModuleAddress address) {
246  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
247    }
248   
 
249  0 toggle public boolean checkModule(final ModuleAddress address) {
250  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
251    }
252   
 
253  0 toggle public Object executePlugin(final String pluginName, final ModuleAddress address,
254    final Map parameters) {
255  0 throw new IllegalStateException(KERNEL_NOT_STARTED);
256    }
257   
258    };
259   
260    /** State for ready kernel. */
261    private final KernelState readyState = new KernelState() {
262   
 
263  0 toggle public void init(final KernelServices moduleServices, final QedeqConfig qedeqConfig)
264    throws IOException {
265    // we are already ready
266    }
267   
 
268  0 toggle public boolean isReady() {
269  0 return false;
270    }
271   
 
272  54 toggle public void shutdown() {
273  54 try {
274  54 final ModuleAddress[] addresses = services.getAllLoadedModules();
275  54 final String[] buffer = new String[addresses.length];
276  208 for (int i = 0; i < addresses.length; i++) {
277  154 buffer[i] = addresses[i].toString();
278    }
279  54 config.setLoadedModules(buffer);
280  54 config.store();
281  54 QedeqLog.getInstance().logMessage("Current config file successfully saved.");
282    } catch (IOException e) {
283  0 Trace.trace(CLASS, this, "shutdown()", e);
284  0 QedeqLog.getInstance().logMessage("Saving current config file failed.");
285    }
286  54 initializedState.shutdown();
287    }
288   
 
289  0 toggle public void startupServices() {
290  0 throw new IllegalStateException("Kernel is already initialized");
291    }
292   
 
293  0 toggle public void removeAllModules() {
294  0 services.removeAllModules();
295    }
296   
 
297  0 toggle public void removeModule(final ModuleAddress address) {
298  0 services.removeModule(address);
299    }
300   
 
301  0 toggle public void clearLocalBuffer() throws IOException {
302  0 services.clearLocalBuffer();
303    }
304   
 
305  37 toggle public QedeqBo loadModule(final ModuleAddress address) throws SourceFileExceptionList {
306  37 return services.loadModule(address);
307    }
308   
 
309  0 toggle public boolean loadAllModulesFromQedeq() {
310  0 return services.loadAllModulesFromQedeq();
311    }
312   
 
313  70 toggle public void loadRequiredModules(final ModuleAddress address)
314    throws SourceFileExceptionList {
315  70 services.loadRequiredModules(address);
316    }
317   
 
318  0 toggle public ModuleAddress[] getAllLoadedModules() {
319  0 return services.getAllLoadedModules();
320    }
321   
 
322  58 toggle public QedeqBo getQedeqBo(final ModuleAddress address) {
323  58 return services.getQedeqBo(address);
324    }
325   
 
326  51 toggle public ModuleAddress getModuleAddress(final URL url) throws IOException {
327  51 return services.getModuleAddress(url);
328    }
329   
 
330  0 toggle public ModuleAddress getModuleAddress(final String url) throws IOException {
331  0 return services.getModuleAddress(url);
332    }
333   
 
334  2 toggle public ModuleAddress getModuleAddress(final File file) throws IOException {
335  2 return services.getModuleAddress(file);
336    }
337   
 
338  2 toggle public String getSource(final ModuleAddress address) throws IOException {
339  2 return services.getSource(address);
340    }
341   
 
342  91 toggle public boolean checkModule(final ModuleAddress address) {
343  91 return services.checkModule(address);
344    }
345   
 
346  4 toggle public Object executePlugin(final String pluginName, final ModuleAddress address,
347    final Map parameters) {
348  4 return services.executePlugin(pluginName, address, parameters);
349    }
350   
351    };
352   
353    /** Initial kernel state. */
354    private KernelState currentState = initialState;
355   
356    /** For config access. */
357    private QedeqConfig config;
358   
359    /** This object can service QEDEQ modules. */
360    private KernelServices services;
361   
362    /**
363    * Constructor.
364    */
 
365  15 toggle private KernelContext() {
366    // nothing to do
367    }
368   
369    /**
370    * Get instance of kernel context.
371    *
372    * @return Singleton, which is responsible for the kernel access.
373    */
 
374  1234 toggle public static final KernelContext getInstance() {
375  1234 return INSTANCE;
376    }
377   
378    /**
379    * Get build information from JAR manifest file. Is also non empty string if no manifest
380    * information is available.
381    *
382    * @return Implementation-version.
383    */
 
384  15 toggle private static String getBuildIdFromManifest() {
385  15 String build = KernelContext.class.getPackage().getImplementationVersion();
386  15 if (build == null) {
387  15 build = "no regular build";
388    }
389  15 return build;
390    }
391   
392    /**
393    * Get build information.
394    *
395    * @return Implementation-version.
396    */
 
397  0 toggle public String getBuildId() {
398  0 return getBuildIdFromManifest();
399    }
400   
401    /**
402    * Get version of this kernel.
403    *
404    * @return Kernel version.
405    */
 
406  0 toggle public final String getKernelVersion() {
407  0 return KERNEL_VERSION;
408    }
409   
410    /**
411    * Get code name of this kernel.
412    *
413    * @return Kernel code name.
414    */
 
415  0 toggle public final String getKernelCodeName() {
416  0 return KERNEL_CODE_NAME;
417    }
418   
419    /**
420    * Get relative version directory of this kernel.
421    *
422    * @return Version sub directory.
423    */
 
424  737 toggle public final String getKernelVersionDirectory() {
425  737 return KERNEL_VERSION_DIRECTORY;
426    }
427   
428    /**
429    * Get descriptive version information of this kernel.
430    *
431    * @return Version Information.
432    */
 
433  54 toggle public final String getDescriptiveKernelVersion() {
434  54 return DESCRIPTIVE_KERNEL_VERSION;
435    }
436   
437    /**
438    * Get dedication for this kernel.
439    *
440    * @return Kernel code dedication.
441    */
 
442  0 toggle public final String getDedication() {
443  0 return KERNEL_DEDICATED;
444    }
445   
446    /**
447    * Get maximal supported rule version of this kernel.
448    *
449    * @return Maximal supported rule version.
450    */
 
451  54 toggle public final String getMaximalRuleVersion() {
452  54 return MAXIMAL_RULE_VERSION;
453    }
454   
455    /**
456    * Is a given rule version supported?
457    *
458    * @param ruleVersion Check this one.
459    * @return Is the given rule version supported?
460    */
 
461  0 toggle public final boolean isRuleVersionSupported(final String ruleVersion) {
462  0 return MAXIMAL_RULE_VERSION.equals(ruleVersion);
463    }
464   
465   
466    /**
467    * This class ist just for solving the lazy loading problem thread save.
468    * see <a href="http://en.wikipedia.org/wiki/Initialization_on_demand_holder_idiom">
469    * Initialization_on_demand_holder_idiom</a>.
470    */
 
471    private static final class LazyHolderTimeoutMethods {
472   
473    /** Lazy initialized constant that knows about the existence of the method
474    * <code>URLConnection.setConnectTimeout</code>. This depends on the currently running
475    * JVM. */
476    private static final boolean IS_SET_CONNECTION_TIMEOUT_SUPPORTED = YodaUtility.existsMethod(
477    URLConnection.class, "setConnectTimeout",
478    new Class[] {Integer.TYPE});
479   
480    /** Lazy initialized constant that knows about the existence of the method
481    * <code>URLConnection.setReadTimeout</code>. This depends on the currently running
482    * JVM. */
483    private static final boolean IS_SET_READ_TIMEOUT_SUSPPORTED = YodaUtility.existsMethod(
484    URLConnection.class, "setReadTimeout",
485    new Class[] {Integer.TYPE});
486   
487    /**
488    * Hidden constructor.
489    */
 
490  0 toggle private LazyHolderTimeoutMethods() {
491    // nothing to do
492    }
493   
494    }
495   
496   
497    /**
498    * Does {@link java.net.URLConnection} support the method <code>setConnectionTimeOut</code>
499    * in the currently running JVM. This should be true since version 1.5 but false for 1.4.2.
500    *
501    * @return Method is supported?
502    */
 
503  0 toggle public boolean isSetConnectionTimeOutSupported() {
504  0 return LazyHolderTimeoutMethods.IS_SET_CONNECTION_TIMEOUT_SUPPORTED;
505    }
506   
507    /**
508    * Does {@link java.net.URLConnection} support the method <code>setReadTimeOut</code>
509    * in the currently running JVM. This should be true since version 1.5 but false for 1.4.2.
510    *
511    * @return Method is supported?
512    */
 
513  0 toggle public boolean isSetReadTimeoutSupported() {
514  0 return LazyHolderTimeoutMethods.IS_SET_READ_TIMEOUT_SUSPPORTED;
515    }
516   
 
517  134 toggle public QedeqConfig getConfig() {
518  134 return config;
519    }
520   
 
521  54 toggle public void init(final KernelServices moduleServices, final QedeqConfig qedeqConfig)
522    throws IOException {
523  54 currentState.init(moduleServices, qedeqConfig);
524    }
525   
 
526  0 toggle public boolean isReady() {
527  0 return currentState.isReady();
528    }
529   
 
530  54 toggle public void shutdown() {
531  54 currentState.shutdown();
532    }
533   
 
534  54 toggle public void startupServices() {
535  54 currentState.startupServices();
536    }
537   
 
538  0 toggle public void removeAllModules() {
539  0 currentState.removeAllModules();
540    }
541   
 
542  0 toggle public void removeModule(final ModuleAddress address) {
543  0 currentState.removeModule(address);
544    }
545   
 
546  0 toggle public void clearLocalBuffer() throws IOException {
547  0 currentState.clearLocalBuffer();
548    }
549   
 
550  37 toggle public QedeqBo loadModule(final ModuleAddress address) throws SourceFileExceptionList {
551  37 return currentState.loadModule(address);
552    }
553   
 
554  0 toggle public boolean loadAllModulesFromQedeq() {
555  0 return currentState.loadAllModulesFromQedeq();
556    }
557   
 
558  70 toggle public void loadRequiredModules(final ModuleAddress address) throws SourceFileExceptionList {
559  70 currentState.loadRequiredModules(address);
560    }
561   
 
562  0 toggle public ModuleAddress[] getAllLoadedModules() {
563  0 return currentState.getAllLoadedModules();
564    }
565   
 
566  58 toggle public QedeqBo getQedeqBo(final ModuleAddress address) {
567  58 return currentState.getQedeqBo(address);
568    }
569   
 
570  51 toggle public ModuleAddress getModuleAddress(final URL url) throws IOException {
571  51 return currentState.getModuleAddress(url);
572    }
573   
 
574  0 toggle public ModuleAddress getModuleAddress(final String url) throws IOException {
575  0 return currentState.getModuleAddress(url);
576    }
577   
 
578  2 toggle public ModuleAddress getModuleAddress(final File file) throws IOException {
579  2 return currentState.getModuleAddress(file);
580    }
581   
 
582  2 toggle public String getSource(final ModuleAddress address) throws IOException {
583  2 return currentState.getSource(address);
584    }
585   
 
586  91 toggle public boolean checkModule(final ModuleAddress address) {
587  91 return currentState.checkModule(address);
588    }
589   
 
590  4 toggle public Object executePlugin(final String pluginName, final ModuleAddress address,
591    final Map parameters) {
592  4 return currentState.executePlugin(pluginName, address, parameters);
593    }
594   
595    /**
596    * Check java version. We want to be shure that the kernel is run at least with java 1.4.2
597    *
598    * @throws IOException Application is running below java 1.4.2.
599    */
 
600  54 toggle private void checkJavaVersion() throws IOException {
601  54 Trace.log("running on java version " + System.getProperty("java.version"));
602  54 final int[] versions = IoUtility.getJavaVersion();
603  54 if (versions == null) {
604  0 Trace.fatal(CLASS, this, "checkJavaVersion", "running java version unknown", null);
605    // we try to continue
606  0 return;
607    }
608  54 final StringBuffer version = new StringBuffer();
609  216 for (int i = 0; i < versions.length; i++) {
610  162 if (i > 0) {
611  108 version.append(".");
612    }
613  162 version.append(versions[i]);
614    }
615  54 Trace.paramInfo(CLASS, this, "checkJavaVersion", "version", version);
616    // >= 1
617  54 if (versions.length < 1 || versions[0] < 1) {
618  0 throw new IOException("This application requires at least Java 1.4.2 but we got "
619    + version);
620    }
621  54 if (versions[0] == 1) { // further checking
622    // >= 1.4
623  54 if (versions.length < 2 || versions[1] < 4) {
624  0 throw new IOException("This application requires at least Java 1.4.2 but we got "
625    + version);
626    }
627  54 if (versions[1] == 4) { // further checking
628    // >=1.4.2
629  0 if (versions.length < 3 || versions[2] < 2) {
630  0 throw new IOException(
631    "This application requires at least Java 1.4.2 but we got "
632    + version);
633    }
634    }
635    }
636    }
637   
638    /**
639    * Create all necessary directories for the kernel.
640    *
641    * @throws IOException Creation was not possible.
642    */
 
643  54 toggle void createAllNecessaryDirectories() throws IOException {
644    // log directory
645  54 final File logFile = new File(config.getBasisDirectory(), config.getLogFile());
646  54 final File logDir = logFile.getParentFile();
647  54 if (!logDir.exists() && !logDir.mkdirs()) {
648  0 throw new IOException("can't create directory: " + logDir.getAbsolutePath());
649    }
650    // buffer directory
651  54 final File bufferDir = config.getBufferDirectory();
652  54 if (!bufferDir.exists() && !bufferDir.mkdirs()) {
653  0 throw new IOException("can't create directory: " + bufferDir.getAbsolutePath());
654    }
655    // generation directory
656  54 final File generationDir = config.getGenerationDirectory();
657  54 if (!generationDir.exists() && !generationDir.mkdirs()) {
658  0 throw new IOException("can't create directory: " + generationDir.getAbsolutePath());
659    }
660    }
661   
662   
663    /**
664    * Checks if the application is already running. To check that we create a file in the
665    * buffer directory, open a stream and write something into it. The stream is not closed
666    * until kernel shutdown.
667    *
668    * @throws IOException Application is already running.
669    */
 
670  54 toggle private void checkIfApplicationIsAlreadyRunningAndLockFile()
671    throws IOException {
672  54 lockFile = new File(config.getBufferDirectory(), "qedeq_lock.lck");
673    /* LATER 20100217 mime: remove old code, now we use FileLock mechanism
674    final String osName = System.getProperty("os.name");
675    if (osName.startsWith("Windows")) {
676    if ((lockFile.exists() && !lockFile.delete())) {
677    throw new IOException("It seems the application is already running.\n"
678    + "At least the file \"" + lockFile.getAbsolutePath()
679    + "\" couldn't be deleted.");
680    }
681    } else {
682    if ((lockFile.exists())) {
683    throw new IOException("It seems the application is already running or crashed."
684    + "\nAt least the file \"" + lockFile.getAbsolutePath()
685    + "\" must be manually deleted!");
686    }
687    }
688    */
689  54 FileLock fl = null;
690  54 try {
691  54 lockStream = new FileOutputStream(lockFile);
692  54 lockStream.write("LOCKED".getBytes("UTF8"));
693  54 lockStream.flush();
694  54 fl = lockStream.getChannel().tryLock();
695    } catch (IOException e) {
696  0 throw new IOException("It seems the application is already running.\n"
697    + "At least accessing the file \"" + lockFile.getAbsolutePath() + "\" failed.");
698    }
699  54 if (fl == null) {
700  0 throw new IOException("It seems the application is already running.\n"
701    + "At least locking the file \"" + lockFile.getAbsolutePath() + "\" failed.");
702    }
703    }
704   
705    }