1919import java .util .Properties ;
2020
2121public class AliDip2BK implements Runnable {
22-
2322 public static String Version = "2.0 14-Nov-2023" ;
2423 public static String DNSnode = "dipnsdev.cern.ch" ;
2524 public static String [] endFillCases = {"CUCU" };
2625 public static boolean LIST_PARAM = false ;
2726 static public String LIST_PARAM_PAT = "*" ;
2827 static public int DEBUG_LEVEL = 1 ;
2928 static public String OUTPUT_FILE = null ;
30- public static String BKURL = "http://localhost:4000" ;
31- public static String BKP_TOKEN = null ;
29+ public static String bookkeepingUrl = "http://localhost:4000" ;
30+ public static String bookkeepingToken = null ;
3231 public static boolean SAVE_PARAMETERS_HISTORY_PER_RUN = false ;
3332 public static String KEEP_RUNS_HISTORY_DIRECTORY = null ;
3433 public static String KEEP_FILLS_HISTORY_DIRECTORY = null ;
@@ -49,14 +48,13 @@ public class AliDip2BK implements Runnable {
4948 String confFile = "AliDip2BK.properties" ;
5049 DipClient client ;
5150 DipMessagesProcessor process ;
52- BookkeepingClient dbw ;
51+ BookkeepingClient bookkeepingClient ;
5352 StartOfRunKafkaConsumer kcs ;
5453 EndOfRunKafkaConsumer kce ;
5554 private long startDate ;
5655 private long stopDate ;
5756
5857 public AliDip2BK () {
59-
6058 startDate = (new Date ()).getTime ();
6159
6260 ProgPath = getClass ().getClassLoader ().getResource ("." ).getPath ();
@@ -67,8 +65,8 @@ public AliDip2BK() {
6765
6866 verifyDirs ();
6967
70- dbw = new BookkeepingClient ();
71- process = new DipMessagesProcessor (dbw );
68+ bookkeepingClient = new BookkeepingClient (bookkeepingUrl , bookkeepingToken );
69+ process = new DipMessagesProcessor (bookkeepingClient );
7270
7371 client = new DipClient (DipParametersFile , process );
7472
@@ -86,7 +84,6 @@ public AliDip2BK() {
8684
8785 Thread t = new Thread (this );
8886 t .start ();
89-
9087 }
9188
9289 static public void log (int level , String module , String mess ) {
@@ -98,18 +95,14 @@ static public void log(int level, String module, String mess) {
9895 }
9996
10097 public static void main (String [] args ) {
101-
10298 @ SuppressWarnings ("unused" )
10399 AliDip2BK service = new AliDip2BK ();
104-
105100 }
106101
107102 public void run () {
108-
109103 int stat_count = 0 ;
110104
111105 for (; ; ) {
112-
113106 try {
114107 Thread .sleep (10000 );
115108 stat_count = stat_count + 10 ;
@@ -139,8 +132,7 @@ public void run() {
139132 Thread .currentThread ().interrupt ();
140133 }
141134
142- if (process .QueueSize () == 0 )
143- break ;
135+ if (process .QueueSize () == 0 ) break ;
144136 }
145137 }
146138
@@ -151,7 +143,6 @@ public void run() {
151143 }
152144 process .saveState ();
153145 writeStat ("AliDip2BK.stat" , true );
154- dbw .close ();
155146 }
156147 });
157148 }
@@ -164,16 +155,14 @@ public void showConfig() {
164155 con = con + "* DIP/DIM =" + DNSnode + "\n " ;
165156 con = con + "* KAFKA Server = " + bootstrapServers + "\n " ;
166157 con = con + "* KAFKA Group ID=" + KAFKA_group_id + "\n " ;
167- con = con + "* Bookkeeping URL =" + BKURL + "\n " ;
158+ con = con + "* Bookkeeping URL =" + bookkeepingUrl + "\n " ;
168159 con = con + "* \n " ;
169160 con = con + "*************************************************\n " ;
170161
171162 System .out .println (con );
172-
173163 }
174164
175- public void loadConf (String filename ) {
176-
165+ private void loadConf (String filename ) {
177166 String input = ProgPath + "/" + filename ;
178167
179168 Properties prop = new Properties ();
@@ -195,7 +184,6 @@ public void loadConf(String filename) {
195184 DipParametersFile = ProgPath + para_file_name ;
196185 } else {
197186 log (4 , "AliDip2BK.loadConf" , " Dip Data Providers Subscription file name is undefined in the conf file " );
198-
199187 }
200188
201189 String list_param = prop .getProperty ("ListDataProvidersPattern" );
@@ -204,11 +192,8 @@ public void loadConf(String filename) {
204192
205193 LIST_PARAM = true ;
206194 LIST_PARAM_PAT = list_param ;
207-
208195 } else {
209- log (4 , "AliDip2BK.loadConf " ,
210- " List DIP Data Providers Pattern is undefined ! The DIP broswer will not start " );
211-
196+ log (4 , "AliDip2BK.loadConf " , " List DIP Data Providers Pattern is undefined ! The DIP broswer will not start " );
212197 }
213198
214199 String debug_n = prop .getProperty ("DEBUG_LEVEL" );
@@ -227,13 +212,9 @@ public void loadConf(String filename) {
227212 if (keh != null ) {
228213 keh = keh .trim ();
229214 SAVE_PARAMETERS_HISTORY_PER_RUN = false ;
230- if (keh .equalsIgnoreCase ("Y" ))
231- SAVE_PARAMETERS_HISTORY_PER_RUN = true ;
232- if (keh .equalsIgnoreCase ("YES" ))
233- SAVE_PARAMETERS_HISTORY_PER_RUN = true ;
234- if (keh .equalsIgnoreCase ("true" ))
235- SAVE_PARAMETERS_HISTORY_PER_RUN = true ;
236-
215+ if (keh .equalsIgnoreCase ("Y" )) SAVE_PARAMETERS_HISTORY_PER_RUN = true ;
216+ if (keh .equalsIgnoreCase ("YES" )) SAVE_PARAMETERS_HISTORY_PER_RUN = true ;
217+ if (keh .equalsIgnoreCase ("true" )) SAVE_PARAMETERS_HISTORY_PER_RUN = true ;
237218 }
238219
239220 String kfhd = prop .getProperty ("KEEP_FILLS_HISTORY_DIRECTORY" );
@@ -249,12 +230,9 @@ public void loadConf(String filename) {
249230 String sde = prop .getProperty ("SIMULATE_DIP_EVENTS" );
250231 if (sde != null ) {
251232
252- if (sde .equalsIgnoreCase ("Y" ))
253- SIMULATE_DIP_EVENTS = true ;
254- if (sde .equalsIgnoreCase ("YES" ))
255- SIMULATE_DIP_EVENTS = true ;
256- if (sde .equalsIgnoreCase ("true" ))
257- SIMULATE_DIP_EVENTS = true ;
233+ if (sde .equalsIgnoreCase ("Y" )) SIMULATE_DIP_EVENTS = true ;
234+ if (sde .equalsIgnoreCase ("YES" )) SIMULATE_DIP_EVENTS = true ;
235+ if (sde .equalsIgnoreCase ("true" )) SIMULATE_DIP_EVENTS = true ;
258236 }
259237
260238 String kgid = prop .getProperty ("KAFKA_group_id" );
@@ -283,22 +261,18 @@ public void loadConf(String filename) {
283261 String bkurl = prop .getProperty ("BookkeepingURL" );
284262
285263 if (bkurl != null ) {
286- BKURL = bkurl ;
264+ bookkeepingUrl = bkurl ;
287265 }
288266 String bkpToken = prop .getProperty (("BKP_TOKEN" ));
289267 if (bkpToken != null ) {
290- BKP_TOKEN = bkpToken ;
268+ bookkeepingToken = bkpToken ;
291269 }
292-
293270 } catch (IOException ex ) {
294271 log (4 , "AliDip2BK.loadCong" , "Failed to access properties file " + ex );
295-
296272 }
297-
298273 }
299274
300275 public void writeStat (String file , boolean final_report ) {
301-
302276 String full_file = ProgPath + AliDip2BK .KEEP_STATE_DIR + file ;
303277
304278 stopDate = (new Date ()).getTime ();
@@ -336,20 +310,16 @@ public void writeStat(String file, boolean final_report) {
336310
337311 AliDip2BK .log (4 , "ProcData.writeStat" , " ERROR writing file=" + full_file + " ex=" + e );
338312 }
339-
340313 }
341314
342315 public void verifyDirs () {
343-
344316 verifyDir (KEEP_RUNS_HISTORY_DIRECTORY );
345317 verifyDir (KEEP_FILLS_HISTORY_DIRECTORY );
346318 verifyDir (STORE_HIST_FILE_DIR );
347319 verifyDir (KEEP_STATE_DIR );
348-
349320 }
350321
351322 public void verifyDir (String name ) {
352-
353323 if (name != null ) {
354324
355325 File directory = new File (String .valueOf (ProgPath + "/" + name ));
@@ -358,8 +328,6 @@ public void verifyDir(String name) {
358328 directory .mkdir ();
359329 AliDip2BK .log (2 , "AliDip2BK->verifyDir" , "created new Directory=" + name );
360330 }
361-
362331 }
363332 }
364-
365333}
0 commit comments