InitWebApp.java
4 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package it.softecspa.portal;
import it.softecspa.fileproxy.DatabaseBalancer;
import it.softecspa.fileproxy.services.ClusterSynchronizer;
import it.softecspa.fileproxy.services.ServerCacheFactory;
import it.softecspa.mvc.WebApp;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import org.apache.log4j.Logger;
/**
* Classe di visibilità ed utilità generale per tutta la initWebApp
*/
@SuppressWarnings("serial")
public class InitWebApp extends WebApp {
public void init(ServletConfig config) throws ServletException {
super.init(config);
try {
log.info("WebApp. Initialization with InitWebApp.");
//...inserire qui il codice di configurazione custom dell'applicazione!
/*
* 1) Chiamata utilizzata soltanto per caricare il singleton
* Bilanciatore database
* Sono bufferizzate le connessioni ai database MASTER e STAGE
* sia in lettura/scrittura che in sola lettura
*
* - Questo servizio dipende da DatabaseManager
*/
if (log.isDebugEnabled()) log.debug("Create instance of " + DatabaseBalancer.class + " service");
DatabaseBalancer databaseBalancer = DatabaseBalancer.getInstance();
/*
* 2) Chiamata utilizzata soltanto per caricare il singleton
* Caricamento delle strutture dati in cache
*
* - Questo servizio dipende da DatabaseBalancer
*/
if (databaseBalancer.isActive()) {
if (log.isDebugEnabled()) log.debug("Create instance of " + ServerCacheFactory.class + " service");
ServerCacheFactory.getInstance();
}
/*
* 3) Chiamata utilizzata per caricare il singleton ed effettuare la prima registrazione
* Gestore cluster
* Il sistema registra se stesso nel "registro" dei cluster
* e attiva il thread "HeartBeat"
*
* - Questo servizio dipende da DatabaseBalancer
*/
if (databaseBalancer.isActive()) {
if (log.isDebugEnabled()) log.debug("Create instance of " + ClusterSynchronizer.class + " service");
ClusterSynchronizer.getInstance().init();
}
// ------------------------------------------------------------------------
// Tracciamento dei riavvi dei nodi su log specifico, DESTROY
traceReload("PUBLISH");
// ------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------
log.info("WebApp. Initialization completed with success.");
} catch (Exception e) {
log.error("ERROR: Impossibile to complete WebApp initailization!",e);
} finally {
//log.info("--------------------------------------------------------------------------------");
}
}
public void destroy() {
/*
...inserire qui il codice custom
*/
try {
ClusterSynchronizer.getInstance().endLife();
} catch (Exception e) {
log.error("Error write end life",e);
}
// ------------------------------------------------------------------------
// Tracciamento dei riavvi dei nodi su log specifico, DESTROY
traceReload("DESTROY");
// ------------------------------------------------------------------------
super.destroy();
}
private void traceReload(String status) {
// ------------------------------------------------------------------------
// Tracciamento dei riavvi dei nodi su log specifico, DESTROY
Parameters parameters = Parameters.getInstance();
Version versione = Version.getInstance();
String installation = parameters.get(Parameters.APPLICATION_ENVIRONMENT);
String hostname = ApplicationClusterInfo.getInstance().getHostNameAddress();
Logger.getLogger("reload").info(parameters.getChannelInfo().getApplicationTitle() +" "+ status + " - Versione " + versione.toString() + " (" + installation + ")" + (hostname != null ? " on host " + hostname : ""));
// ------------------------------------------------------------------------
}
}