Clover Coverage Report
Coverage timestamp: Fri May 24 2013 13:47:27 UTC
../../../../img/srcFileCovDistChart10.png 0% of files have more coverage
186   699   133   1.72
34   488   0.72   108
108     1.23  
1    
 
  KernelContext       Line # 46 186 133 91.5% 0.91463417
 
  (243)
 
1    /* This file is part of the project "Hilbert II" - http://www.qedeq.org
2    *
3    * Copyright 2000-2013, 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;
17   
18    import java.io.File;
19    import java.io.FileOutputStream;
20    import java.io.IOException;
21    import java.net.URL;
22    import java.nio.channels.FileLock;
23   
24    import org.qedeq.base.io.IoUtility;
25    import org.qedeq.base.trace.Trace;
26    import org.qedeq.base.utility.StringUtility;
27    import org.qedeq.kernel.bo.common.BasicKernel;
28    import org.qedeq.kernel.bo.common.KernelProperties;
29    import org.qedeq.kernel.bo.common.KernelServices;
30    import org.qedeq.kernel.bo.common.KernelState;
31    import org.qedeq.kernel.bo.common.QedeqBo;
32    import org.qedeq.kernel.bo.common.ServiceModule;
33    import org.qedeq.kernel.bo.common.ServiceProcess;
34    import org.qedeq.kernel.bo.log.QedeqLog;
35    import org.qedeq.kernel.se.common.ModuleAddress;
36    import org.qedeq.kernel.se.common.Plugin;
37    import org.qedeq.kernel.se.config.QedeqConfig;
38    import org.qedeq.kernel.se.visitor.InterruptException;
39   
40   
41    /**
42    * This class provides static access methods for the kernel.
43    *
44    * @author Michael Meyling
45    */
 
46    public final class KernelContext implements KernelProperties, KernelServices {
47   
48    /** Message for non started kernel. */
49    private static final String KERNEL_NOT_STARTED = "Kernel not started";
50   
51    /** Message for non initialized kernel. */
52    private static final String KERNEL_NOT_INITIALIZED = "Kernel not initialized";
53   
54    /** This class. */
55    private static final Class CLASS = KernelContext.class;
56   
57    /** One and only instance of this class. */
58    private static final KernelContext INSTANCE = new KernelContext();
59   
60    /** Lock file. */
61    private File lockFile;
62   
63    /** Lock file stream. */
64    private FileOutputStream lockStream;
65   
66    /** Initial kernel state. */
67    private final KernelState initialState = new KernelState() {
68   
 
69  499 toggle public void init(final QedeqConfig config, final ServiceModule moduleServices, final KernelProperties basic)
70    throws IOException {
71  499 if (config == null) {
72  1 throw new NullPointerException("QedeqConfig is null");
73    }
74  498 if (moduleServices == null) {
75  1 throw new NullPointerException("ServiceModule is null");
76    }
77  497 if (basic == null) {
78  0 throw new NullPointerException("KernelProperties is null");
79    }
80  497 KernelContext.this.config = config;
81  497 KernelContext.this.basic = basic;
82  497 Trace.setTraceOn(config.isTraceOn());
83  497 checkJavaVersion();
84  497 createAllNecessaryDirectories();
85  497 checkIfApplicationIsAlreadyRunningAndLockFile();
86  497 KernelContext.this.services = moduleServices;
87  497 QedeqLog.getInstance().logMessage("--------------------------------------------------"
88    + "---------------------------------------");
89  497 QedeqLog.getInstance().logMessage("This is "
90    + KernelContext.getInstance().getDescriptiveKernelVersion());
91  497 QedeqLog.getInstance().logMessage(" see \"http://www.qedeq.org\" for more "
92    + "information");
93  497 QedeqLog.getInstance().logMessage(" supports rules till version "
94    + KernelContext.getInstance().getMaximalRuleVersion());
95  497 QedeqLog.getInstance().logMessage(" Java version: "
96    + StringUtility.alignRight(System.getProperty("java.version", "unknown"), 10));
97  497 QedeqLog.getInstance().logMessage(" used memory: "
98    + StringUtility.alignRight(Runtime.getRuntime().totalMemory()
99    - Runtime.getRuntime().freeMemory(), 10));
100  497 QedeqLog.getInstance().logMessage(" free memory: "
101    + StringUtility.alignRight(Runtime.getRuntime().freeMemory(), 10));
102  497 QedeqLog.getInstance().logMessage(" total memory: "
103    + StringUtility.alignRight(Runtime.getRuntime().totalMemory(), 10));
104  497 QedeqLog.getInstance().logMessage(" max. memory: "
105    + StringUtility.alignRight(Runtime.getRuntime().maxMemory(), 10));
106  497 QedeqLog.getInstance().logMessage(" processors/cores: "
107    + StringUtility.alignRight(Runtime.getRuntime().availableProcessors(), 6));
108  497 currentState = initializedState;
109    }
110   
 
111  2 toggle public void startup() {
112  2 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
113    }
114   
 
115  558 toggle public void shutdown() {
116  558 currentState = initialState;
117    // close stream and associated channel
118  558 IoUtility.close(lockStream);
119  558 lockStream = null;
120  558 config = null;
121  558 services = null;
122    }
123   
 
124  1 toggle public void removeAllModules() {
125  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
126    }
127   
 
128  1 toggle public void removeModule(final ModuleAddress address) {
129  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
130    }
131   
 
132  1 toggle public boolean clearLocalBuffer() {
133  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
134    }
135   
 
136  1 toggle public QedeqBo loadModule(final ModuleAddress address) {
137  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
138    }
139   
 
140  1 toggle public boolean loadAllModulesFromQedeq() {
141  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
142    }
143   
 
144  1 toggle public boolean loadRequiredModules(final ModuleAddress address) {
145  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
146    }
147   
 
148  1 toggle public ModuleAddress[] getAllLoadedModules() {
149  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
150    }
151   
 
152  1 toggle public QedeqBo getQedeqBo(final ModuleAddress address) {
153  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
154    }
155   
 
156  1 toggle public ModuleAddress getModuleAddress(final URL url) {
157  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
158    }
159   
 
160  1 toggle public ModuleAddress getModuleAddress(final String url) {
161  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
162    }
163   
 
164  1 toggle public ModuleAddress getModuleAddress(final File file) {
165  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
166    }
167   
 
168  1 toggle public String getSource(final ModuleAddress address) {
169  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
170    }
171   
 
172  1 toggle public boolean checkWellFormedness(final ModuleAddress address) {
173  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
174    }
175   
 
176  1 toggle public boolean checkFormallyProved(final ModuleAddress address) {
177  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
178    }
179   
 
180  1 toggle public Plugin[] getPlugins() {
181  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
182    }
183   
 
184  1 toggle public Object executePlugin(final String pluginName, final ModuleAddress address,
185    final Object data) {
186  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
187    }
188   
 
189  1 toggle public void clearAllPluginResults(final ModuleAddress address) {
190  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
191    }
192   
 
193  1 toggle public ServiceProcess[] getServiceProcesses() {
194  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
195    }
196   
 
197  1 toggle public ServiceProcess[] getRunningServiceProcesses() {
198  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
199    }
200   
 
201  1 toggle public void stopAllPluginExecutions() {
202  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
203    }
204   
205    };
206   
207    /** Initial kernel state. */
208    private final KernelState initializedState = new KernelState() {
209   
 
210  1 toggle public void init(final QedeqConfig config, final ServiceModule moduleServices,
211    final KernelProperties basic) throws IOException {
212  1 throw new IllegalStateException("Kernel is already initialized");
213    }
214   
 
215  493 toggle public void startup() {
216  493 services.startupServices();
217  493 currentState = readyState;
218  493 QedeqLog.getInstance().logMessage("QEDEQ kernel opened.");
219    }
220   
 
221  497 toggle public void shutdown() {
222  497 services.shutdownServices();
223  497 KernelContext.this.services = null;
224  497 initialState.shutdown();
225  497 QedeqLog.getInstance().logMessage("QEDEQ Kernel closed.");
226    }
227   
 
228  1 toggle public void removeAllModules() {
229  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
230    }
231   
 
232  1 toggle public void removeModule(final ModuleAddress address) {
233  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
234    }
235   
 
236  1 toggle public boolean clearLocalBuffer() {
237  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
238    }
239   
 
240  1 toggle public QedeqBo loadModule(final ModuleAddress address) {
241  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
242    }
243   
 
244  1 toggle public boolean loadAllModulesFromQedeq() {
245  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
246    }
247   
 
248  1 toggle public boolean loadRequiredModules(final ModuleAddress address) {
249  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
250    }
251   
 
252  1 toggle public ModuleAddress[] getAllLoadedModules() {
253  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
254    }
255   
 
256  1 toggle public QedeqBo getQedeqBo(final ModuleAddress address) {
257  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
258    }
259   
 
260  1 toggle public ModuleAddress getModuleAddress(final URL url) {
261  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
262    }
263   
 
264  1 toggle public ModuleAddress getModuleAddress(final String url) {
265  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
266    }
267   
 
268  1 toggle public ModuleAddress getModuleAddress(final File file) {
269  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
270    }
271   
 
272  1 toggle public String getSource(final ModuleAddress address) {
273  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
274    }
275   
 
276  1 toggle public boolean checkWellFormedness(final ModuleAddress address) {
277  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
278    }
279   
 
280  1 toggle public boolean checkFormallyProved(final ModuleAddress address) {
281  1 throw new IllegalStateException(KERNEL_NOT_INITIALIZED);
282    }
283   
 
284  1 toggle public Plugin[] getPlugins() {
285  1 return services.getPlugins();
286    }
287   
 
288  1 toggle public Object executePlugin(final String pluginName, final ModuleAddress address,
289    final Object data) {
290  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
291    }
292   
 
293  1 toggle public void clearAllPluginResults(final ModuleAddress address) {
294  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
295    }
296   
 
297  1 toggle public ServiceProcess[] getServiceProcesses() {
298  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
299    }
300   
 
301  1 toggle public ServiceProcess[] getRunningServiceProcesses() {
302  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
303    }
304   
 
305  1 toggle public void stopAllPluginExecutions() {
306  1 throw new IllegalStateException(KERNEL_NOT_STARTED);
307    }
308   
309    };
310   
311    /** State for ready kernel. */
312    private final KernelState readyState = new KernelState() {
313   
 
314  0 toggle public void init(final QedeqConfig config, final ServiceModule moduleServices,
315    final KernelProperties basic) throws IOException {
316    // we are already ready
317    }
318   
 
319  0 toggle public void startup() {
320    // we are already ready
321    }
322   
 
323  493 toggle public void shutdown() {
324  493 try {
325  493 final ModuleAddress[] addresses = services.getAllLoadedModules();
326  493 if (addresses != null) {
327  471 final String[] buffer = new String[addresses.length];
328  1038 for (int i = 0; i < addresses.length; i++) {
329  567 buffer[i] = addresses[i].toString();
330    }
331  471 getConfig().setPreviouslyLoadedModules(buffer);
332  471 getConfig().store();
333  471 QedeqLog.getInstance().logMessage("Current config file successfully saved.");
334    }
335    } catch (IOException e) {
336  0 Trace.trace(CLASS, this, "shutdown()", e);
337  0 QedeqLog.getInstance().logMessage("Saving current config file failed.");
338    }
339  493 initializedState.shutdown();
340    }
341   
 
342  1 toggle public void removeAllModules() {
343  1 services.removeAllModules();
344    }
345   
 
346  1 toggle public void removeModule(final ModuleAddress address) {
347  1 services.removeModule(address);
348    }
349   
 
350  1 toggle public boolean clearLocalBuffer() {
351  1 return services.clearLocalBuffer();
352    }
353   
 
354  5 toggle public QedeqBo loadModule(final ModuleAddress address) {
355  5 return services.loadModule(address);
356    }
357   
 
358  1 toggle public boolean loadAllModulesFromQedeq() {
359  1 return services.loadAllModulesFromQedeq();
360    }
361   
 
362  21 toggle public boolean loadRequiredModules(final ModuleAddress address) {
363  21 return services.loadRequiredModules(address);
364    }
365   
 
366  1 toggle public ModuleAddress[] getAllLoadedModules() {
367  1 return services.getAllLoadedModules();
368    }
369   
 
370  43892 toggle public QedeqBo getQedeqBo(final ModuleAddress address) {
371  43892 return services.getQedeqBo(address);
372    }
373   
 
374  21 toggle public ModuleAddress getModuleAddress(final URL url) throws IOException {
375  21 return services.getModuleAddress(url);
376    }
377   
 
378  1 toggle public ModuleAddress getModuleAddress(final String url) throws IOException {
379  1 return services.getModuleAddress(url);
380    }
381   
 
382  1 toggle public ModuleAddress getModuleAddress(final File file) throws IOException {
383  1 return services.getModuleAddress(file);
384    }
385   
 
386  1 toggle public String getSource(final ModuleAddress address) throws IOException {
387  1 return services.getSource(address);
388    }
389   
 
390  27 toggle public boolean checkWellFormedness(final ModuleAddress address) {
391  27 return services.checkWellFormedness(address);
392    }
393   
 
394  1 toggle public boolean checkFormallyProved(final ModuleAddress address) {
395  1 return services.checkFormallyProved(address);
396    }
397   
 
398  1 toggle public Plugin[] getPlugins() {
399  1 return services.getPlugins();
400    }
401   
 
402  1 toggle public Object executePlugin(final String pluginName, final ModuleAddress address,
403    final Object data) throws InterruptException {
404  1 return services.executePlugin(pluginName, address, data);
405    }
406   
 
407  1 toggle public void clearAllPluginResults(final ModuleAddress address) {
408  1 services.clearAllPluginResults(address);
409    }
410   
 
411  1 toggle public ServiceProcess[] getServiceProcesses() {
412  1 return services.getServiceProcesses();
413    }
414   
 
415  1 toggle public ServiceProcess[] getRunningServiceProcesses() {
416  1 return services.getRunningServiceProcesses();
417    }
418   
 
419  1 toggle public void stopAllPluginExecutions() {
420  1 services.stopAllPluginExecutions();
421    }
422   
423    };
424   
425    /** Kernel configuration. */
426    private QedeqConfig config;
427   
428    /** Initial kernel state. */
429    private KernelState currentState = initialState;
430   
431    /** For basic kernel informations. */
432    private KernelProperties basic;
433   
434    /** This object can service QEDEQ modules. */
435    private ServiceModule services;
436   
437    /**
438    * Constructor.
439    */
 
440  48 toggle private KernelContext() {
441  48 basic = new BasicKernel();
442    }
443   
444    /**
445    * Get instance of kernel context.
446    *
447    * @return Singleton, which is responsible for the kernel access.
448    */
 
449  9483 toggle public static final KernelContext getInstance() {
450  9483 return INSTANCE;
451    }
452   
 
453  1 toggle public String getBuildId() {
454  1 return basic.getBuildId();
455    }
456   
 
457  1 toggle public final String getKernelVersion() {
458  1 return basic.getKernelVersion();
459    }
460   
 
461  1 toggle public final String getKernelCodeName() {
462  1 return basic.getKernelCodeName();
463    }
464   
 
465  1803 toggle public final String getKernelVersionDirectory() {
466  1803 return basic.getKernelVersionDirectory();
467    }
468   
 
469  509 toggle public final String getDescriptiveKernelVersion() {
470  509 return basic.getDescriptiveKernelVersion();
471    }
472   
 
473  1 toggle public final String getDedication() {
474  1 return basic.getDedication();
475    }
476   
 
477  499 toggle public final String getMaximalRuleVersion() {
478  499 return basic.getMaximalRuleVersion();
479    }
480   
 
481  3 toggle public final boolean isRuleVersionSupported(final String ruleVersion) {
482  3 return basic.isRuleVersionSupported(ruleVersion);
483    }
484   
 
485  1 toggle public boolean isSetConnectionTimeOutSupported() {
486  1 return basic.isSetConnectionTimeOutSupported();
487    }
488   
 
489  1 toggle public boolean isSetReadTimeoutSupported() {
490  1 return basic.isSetReadTimeoutSupported();
491    }
492   
 
493  4900 toggle public QedeqConfig getConfig() {
494  4900 return config;
495    }
496   
497    /**
498    * Init the kernel.
499    *
500    * @param config Configuration access. Must not be <code>null</code>.
501    * @param moduleServices Services for the kernel. Must not be <code>null</code>.
502    * @throws IllegalStateException Kernel is already initialized.
503    * @throws IOException Initialization failure.
504    */
 
505  500 toggle public void init(final QedeqConfig config, final ServiceModule moduleServices) throws IOException {
506  500 currentState.init(config, moduleServices, basic);
507    }
508   
509    /**
510    * Startup the kernel.
511    */
 
512  495 toggle public void startup() {
513  495 currentState.startup();
514    }
515   
516    /**
517    * Shutdown the kernel.
518    */
 
519  558 toggle public void shutdown() {
520  558 currentState.shutdown();
521    }
522   
 
523  3 toggle public void removeAllModules() {
524  3 currentState.removeAllModules();
525    }
526   
 
527  3 toggle public void removeModule(final ModuleAddress address) {
528  3 currentState.removeModule(address);
529    }
530   
 
531  3 toggle public boolean clearLocalBuffer() {
532  3 return currentState.clearLocalBuffer();
533    }
534   
 
535  7 toggle public QedeqBo loadModule(final ModuleAddress address) {
536  7 return currentState.loadModule(address);
537    }
538   
 
539  3 toggle public boolean loadAllModulesFromQedeq() {
540  3 return currentState.loadAllModulesFromQedeq();
541    }
542   
 
543  23 toggle public boolean loadRequiredModules(final ModuleAddress address) {
544  23 return currentState.loadRequiredModules(address);
545    }
546   
 
547  3 toggle public ModuleAddress[] getAllLoadedModules() {
548  3 return currentState.getAllLoadedModules();
549    }
550   
 
551  43894 toggle public QedeqBo getQedeqBo(final ModuleAddress address) {
552  43894 return currentState.getQedeqBo(address);
553    }
554   
 
555  23 toggle public ModuleAddress getModuleAddress(final URL url) throws IOException {
556  23 return currentState.getModuleAddress(url);
557    }
558   
 
559  3 toggle public ModuleAddress getModuleAddress(final String url) throws IOException {
560  3 return currentState.getModuleAddress(url);
561    }
562   
 
563  3 toggle public ModuleAddress getModuleAddress(final File file) throws IOException {
564  3 return currentState.getModuleAddress(file);
565    }
566   
 
567  3 toggle public String getSource(final ModuleAddress address) throws IOException {
568  3 return currentState.getSource(address);
569    }
570   
 
571  29 toggle public boolean checkWellFormedness(final ModuleAddress address) {
572  29 return currentState.checkWellFormedness(address);
573    }
574   
 
575  3 toggle public boolean checkFormallyProved(final ModuleAddress address) {
576  3 return currentState.checkFormallyProved(address);
577    }
578   
 
579  3 toggle public Plugin[] getPlugins() {
580  3 return currentState.getPlugins();
581    }
582   
 
583  3 toggle public Object executePlugin(final String pluginName, final ModuleAddress address,
584    final Object data) throws InterruptException {
585  3 return currentState.executePlugin(pluginName, address, data);
586    }
587   
 
588  3 toggle public void clearAllPluginResults(final ModuleAddress address) {
589  3 currentState.clearAllPluginResults(address);
590    }
591   
 
592  3 toggle public ServiceProcess[] getServiceProcesses() {
593  3 return currentState.getServiceProcesses();
594    }
595   
 
596  3 toggle public ServiceProcess[] getRunningServiceProcesses() {
597  3 return currentState.getRunningServiceProcesses();
598    }
599   
 
600  3 toggle public void stopAllPluginExecutions() {
601  3 currentState.stopAllPluginExecutions();
602    }
603   
604    /**
605    * Check java version. We want to be sure that the kernel is run at least with java 1.4.2
606    *
607    * @throws IOException Application is running below java 1.4.2.
608    */
 
609  497 toggle private void checkJavaVersion() throws IOException {
610  497 final String method = "checkJavaVersion";
611  497 Trace.info(CLASS, this, method, "running on java version "
612    + System.getProperty("java.version"));
613  497 final int[] versions = IoUtility.getJavaVersion();
614  497 if (versions == null) {
615  0 Trace.fatal(CLASS, this, method, "running java version unknown", null);
616    // we try to continue
617  0 return;
618    }
619  497 final StringBuffer version = new StringBuffer();
620  1988 for (int i = 0; i < versions.length; i++) {
621  1491 if (i > 0) {
622  994 version.append(".");
623    }
624  1491 version.append(versions[i]);
625    }
626  497 Trace.paramInfo(CLASS, this, method, "version", version);
627    // >= 1
628  497 if (versions.length < 1 || versions[0] < 1) {
629  0 throw new IOException("This application requires at least Java 1.4.2 but we got "
630    + version);
631    }
632  497 if (versions[0] == 1) { // further checking
633    // >= 1.4
634  497 if (versions.length < 2 || versions[1] < 4) {
635  0 throw new IOException("This application requires at least Java 1.4.2 but we got "
636    + version);
637    }
638  497 if (versions[1] == 4) { // further checking
639    // >=1.4.2
640  0 if (versions.length < 3 || versions[2] < 2) {
641  0 throw new IOException(
642    "This application requires at least Java 1.4.2 but we got "
643    + version);
644    }
645    }
646    }
647    }
648   
649    /**
650    * Create all necessary directories for the kernel.
651    *
652    * @throws IOException Creation was not possible.
653    */
 
654  497 toggle void createAllNecessaryDirectories() throws IOException {
655    // log directory
656  497 final File logFile = getConfig().getLogFile();
657  497 final File logDir = logFile.getParentFile();
658  497 if (!logDir.exists() && !logDir.mkdirs()) {
659  0 throw new IOException("can't create directory: " + logDir.getAbsolutePath());
660    }
661    // buffer directory
662  497 final File bufferDir = getConfig().getBufferDirectory();
663  497 if (!bufferDir.exists() && !bufferDir.mkdirs()) {
664  0 throw new IOException("can't create directory: " + bufferDir.getAbsolutePath());
665    }
666    // generation directory
667  497 final File generationDir = getConfig().getGenerationDirectory();
668  497 if (!generationDir.exists() && !generationDir.mkdirs()) {
669  0 throw new IOException("can't create directory: " + generationDir.getAbsolutePath());
670    }
671    }
672   
673    /**
674    * Checks if the application is already running. To check that we create a file in the
675    * buffer directory, open a stream and write something into it. The stream is not closed
676    * until kernel shutdown.
677    *
678    * @throws IOException Application is already running.
679    */
 
680  497 toggle private void checkIfApplicationIsAlreadyRunningAndLockFile()
681    throws IOException {
682  497 lockFile = new File(getConfig().getBufferDirectory(), "qedeq_lock.lck");
683  497 FileLock fl = null;
684  497 try {
685  497 lockStream = new FileOutputStream(lockFile);
686  497 lockStream.write("LOCKED".getBytes("UTF8"));
687  497 lockStream.flush();
688  497 fl = lockStream.getChannel().tryLock();
689    } catch (IOException e) {
690  0 throw new IOException("It seems the application is already running.\n"
691    + "At least accessing the file \"" + lockFile.getAbsolutePath() + "\" failed.");
692    }
693  497 if (fl == null) {
694  0 throw new IOException("It seems the application is already running.\n"
695    + "At least locking the file \"" + lockFile.getAbsolutePath() + "\" failed.");
696    }
697    }
698   
699    }