Menu

[r678]: / javaontracks / src / net / jot / JOTInitializer.java  Maximize  Restore  History

Download this file

95 lines (85 with data), 3.2 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
------------------------------------
JavaOnTracks Thibaut Colar
tcolar-jot AT colar DOT net
Artistic Licence 2.0
http://www.javaontracks.net
------------------------------------
*/
package net.jot;
import net.jot.logger.JOTLogger;
import net.jot.persistance.JOTFSIndexManager;
import net.jot.persistance.JOTPersistanceManager;
import net.jot.prefs.JOTPreferenceInterface;
import net.jot.prefs.JOTPreferences;
/**
* This handles the initialization(and shutdown) of JOT.
* The init methos initialzes all the required objects for JOT to work, such as thr preferences manager, logger etc...
*
* In the case of a webapp, this will be called for you by JOTFilter (defined in web.xml)
*
* In the case of a Java app(not webapp), you HAVE TO call this manually:
* Call init() when you start your app (very first thing, befor you use any other JOT features)
* Call destroy() when you stop your app (last thing)
* @author tcolar
*/
public class JOTInitializer
{
private static boolean destroyed = false;
public static final String VERSION = "0.1.2";
/**
* Initializes JOT
*
*/
public static void init() throws Exception
{
// give time to debugger to start
Thread.sleep(5000);
destroyed = false;
// Initializing the prefs (we need the prefs to initialized the logger)
JOTPreferenceInterface prefs = JOTPreferences.getInstance();
// Initializing the Logger
JOTLogger.init(prefs, "jot.log");
// Initialize the persistance / databases(s).
JOTPersistanceManager.init(prefs);
}
/**
* To be called on program exit
* Cleans up all resources (close open files, stop threads etc ...)
*
*/
public static void destroy()
{
if (!destroyed)
{
destroyed = true;
JOTLogger.log(JOTLogger.CAT_MAIN, JOTLogger.INFO_LEVEL, JOTInitializer.class, "Destroying");
try
{
JOTLogger.log(JOTLogger.CAT_MAIN, JOTLogger.DEBUG_LEVEL, JOTInitializer.class, "Stopping PersistanceManager");
JOTPersistanceManager.destroy();
JOTLogger.log(JOTLogger.CAT_MAIN, JOTLogger.DEBUG_LEVEL, JOTInitializer.class, "Stopping FSIndexManager");
JOTFSIndexManager.destroy();
JOTLogger.log(JOTLogger.CAT_MAIN, JOTLogger.DEBUG_LEVEL, JOTInitializer.class, "Stopping Logger");
JOTLogger.destroy();
System.out.println("Shutdown complete");
} catch (Exception e)
{
System.err.println(e);
e.printStackTrace();
}
}
}
/**
* On dinalize we call destroy so that even if the user forgot to call it, we cleanup the resources anyhow.
*/
protected void finalize() throws Throwable
{
destroy();
super.finalize();
}
public static void testMethod()
{
JOTLogger.log(JOTLogger.CAT_MAIN, JOTLogger.ERROR_LEVEL, JOTInitializer.class, "########## test method #######");
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.