Project

General

Profile

« Previous | Next » 

Revision 7748

Added by Jing Tao over 11 years ago

Read the waiting time and maximum attempts from the metacat.properties file.

View differences:

metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java
71 71
    private static final String HTTP = "http://";
72 72
    private static final String MNAPPENDIX = "/d1/mn";
73 73
    private static final String RESOURCEMAPPROPERYNAME = "index.resourcemap.namespace";
74
    private static final String WAITIMEPOPERTYNAME = "index.regenerate.start.waitingtime";
75
    private static final String MAXATTEMPTSPROPERTYNAME = "index.regenerate.start.maxattempts";
76
    
77
    private static int waitingTime = WAITTIME;
78
    private static int maxAttempts = MAXWAITNUMBER;
79
    
74 80
    private SolrIndex solrIndex = null;
75 81
    //private SystemMetadataEventListener systemMetadataListener = null;
76 82
    private IMap<Identifier, SystemMetadata> systemMetadataMap;
77
    
78 83
    private IMap<Identifier, String> objectPathMap;
79 84
    private Log log = LogFactory.getLog(IndexGenerator.class);
80 85
    private MNode mNode = null;
......
90 95
        resourceMapNamespaces = Settings.getConfiguration().getList(RESOURCEMAPPROPERYNAME);
91 96
        //this.systemMetadataListener = systemMetadataListener;
92 97
        this.mNode = new MNode(buildMNBaseURL());
98
        try {
99
            waitingTime = Settings.getConfiguration().getInt(WAITIMEPOPERTYNAME);
100
            maxAttempts = Settings.getConfiguration().getInt(MAXATTEMPTSPROPERTYNAME);
101
        } catch (Exception e) {
102
            log.warn("IndexGenerator.constructor - couldn't read the waiting time or maxattempts from the metacat.properties file since : "+e.getMessage()+". Default values will be used");
103
            waitingTime = WAITTIME;
104
            maxAttempts = MAXWAITNUMBER;
105
        }
93 106
    }
94 107
    
95 108
    /**
......
260 273
                mNode.ping();
261 274
                break;
262 275
            } catch (Exception e) {
263
                if(times <= MAXWAITNUMBER) {
276
                if(times <= maxAttempts) {
264 277
                    log.warn("IndexGenerator.getMetadataIds - the mnode "+ mNode.getNodeBaseServiceUrl()+
265
                                    " is not ready :" +e.getMessage()+"\nWe will try to access it 10 seconds later ");
278
                                    " is not ready :" +e.getMessage()+"\nWe will try to access it "+waitingTime/1000+" seconds later ");
266 279
                    try {
267
                        Thread.sleep(WAITTIME);
280
                        Thread.sleep(waitingTime);
268 281
                    } catch (Exception ee) {
269
                        log.warn("IndexGenerator.getMetadataIds - the thread can't sleep for 10 seconds to wait the MNode");
282
                        log.warn("IndexGenerator.getMetadataIds - the thread can't sleep for "+ waitingTime/1000+" seconds to wait the MNode");
270 283
                    }
271 284
                   
272 285
                } else {
273 286
                    throw new ServiceFailure("0000", "IndexGenerator.getMetadataIds - the mnode "+ mNode.getNodeBaseServiceUrl()+
274
                                    " is not ready even though Metacat-index wailted for 30 minutes. We can't get the objects list from it and the building index can't happen this time");
287
                                    " is not ready even though Metacat-index wailted for "+maxAttempts*waitingTime/1000+" seconds. We can't get the objects list from it and the building index can't happen this time");
275 288
                }
276 289
                
277 290
            }
......
380 393
                } catch (FileNotFoundException e) {
381 394
                    throw e;
382 395
                } catch (ServiceFailure e) {
383
                    if(times <= MAXWAITNUMBER) {
396
                    if(times <= maxAttempts) {
384 397
                        log.warn("IndexGenerator.initSystemMetadataMap - the hazelcast service is not ready : "
385
                                         +e.getMessage()+"\nWe will try to access it 10 seconds later ");
398
                                         +e.getMessage()+"\nWe will try to access it "+waitingTime/1000+" seconds later ");
386 399
                        try {
387
                            Thread.sleep(WAITTIME);
400
                            Thread.sleep(waitingTime);
388 401
                        } catch (Exception ee) {
389
                            log.warn("IndexGenerator.initSystemMetadataMap - the thread can't sleep for 10 seconds to wait the hazelcast service");
402
                            log.warn("IndexGenerator.initSystemMetadataMap - the thread can't sleep for "+waitingTime/1000+" seconds to wait the hazelcast service");
390 403
                        }
391 404
                       
392 405
                    } else {
393
                        throw new ServiceFailure("0000", "IndexGenerator.initSystemMetadataMap - the hazelcast service is not ready even though Metacat-index wailted for 30 minutes. We can't get the system metadata from it and the building index can't happen this time");
406
                        throw new ServiceFailure("0000", "IndexGenerator.initSystemMetadataMap - the hazelcast service is not ready even though Metacat-index wailted for "+maxAttempts*waitingTime/1000+" seconds. We can't get the system metadata from it and the building index can't happen this time");
394 407
                    }
395 408
                }
396 409
                times++;

Also available in: Unified diff