Revision 7774
Added by Jing Tao over 11 years ago
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/DistributedMapsFactory.java | ||
---|---|---|
54 | 54 |
private static HazelcastClient hzClient = null; |
55 | 55 |
private static String hzSystemMetadata = null; |
56 | 56 |
private static String hzObjectPath = null; |
57 |
private static int waitingTime = IndexGenerator.WAITTIME; |
|
58 |
private static int maxAttempts = IndexGenerator.MAXWAITNUMBER; |
|
57 | 59 |
|
58 | 60 |
/* |
59 | 61 |
* Start the hazel cast client |
60 | 62 |
*/ |
61 | 63 |
private static void startHazelCastClient() throws FileNotFoundException, ServiceFailure{ |
64 |
|
|
65 |
try { |
|
66 |
waitingTime = Settings.getConfiguration().getInt(IndexGenerator.WAITIMEPOPERTYNAME); |
|
67 |
maxAttempts = Settings.getConfiguration().getInt(IndexGenerator.MAXATTEMPTSPROPERTYNAME); |
|
68 |
} catch (Exception e) { |
|
69 |
log.warn("DistributedMapFactory.startHazelCastClient - couldn't read the waiting time or maxattempts from the metacat.properties file since : "+e.getMessage()+". Default values will be used"); |
|
70 |
waitingTime = IndexGenerator.WAITTIME; |
|
71 |
maxAttempts = IndexGenerator.MAXWAITNUMBER; |
|
72 |
} |
|
62 | 73 |
// get config values |
63 | 74 |
hzSystemMetadata = Settings.getConfiguration().getString( |
64 | 75 |
"dataone.hazelcast.storageCluster.systemMetadataMap"); |
... | ... | |
90 | 101 |
cc.getGroupConfig().setName(hzGroupName); |
91 | 102 |
cc.getGroupConfig().setPassword(hzGroupPassword); |
92 | 103 |
cc.addAddress(hzAddress); |
93 |
try { |
|
94 |
hzClient = HazelcastClient.newHazelcastClient(cc); |
|
95 |
} catch (Exception e) { |
|
96 |
log.error("Unable to create hazelcast client: ", e); |
|
97 |
throw new ServiceFailure("0000","DistributedMapsFactory.startHazelCastClient - can't start the hazel cast client since "+e.getMessage()); |
|
104 |
|
|
105 |
int times = 0; |
|
106 |
while(true) { |
|
107 |
//System.out.println("here =================="); |
|
108 |
try { |
|
109 |
hzClient = HazelcastClient.newHazelcastClient(cc); |
|
110 |
break; |
|
111 |
} catch (Exception e) { |
|
112 |
if(times <= maxAttempts) { |
|
113 |
log.warn("DistributedMapFactory.startHazelCastClient - the hazelcast service is not ready : " |
|
114 |
+e.getMessage()+"\nWe will try to access it "+waitingTime/1000+" seconds later "); |
|
115 |
try { |
|
116 |
Thread.sleep(waitingTime); |
|
117 |
} catch (Exception ee) { |
|
118 |
log.warn("DistributedMapFactory.startHazelCastClient - the thread can't sleep for "+waitingTime/1000+" seconds to wait the hazelcast service"); |
|
119 |
} |
|
120 |
|
|
121 |
} else { |
|
122 |
throw new ServiceFailure("0000", "DistributedMapFactory.startHazelCastClient - the hazelcast service is not ready even though Metacat-index wailted for "+ |
|
123 |
maxAttempts*waitingTime/1000+" seconds. We can't get the system metadata from it and the building index can't happen this time"); |
|
124 |
} |
|
125 |
} |
|
126 |
times++; |
|
127 |
//System.out.println("here ==================2"); |
|
98 | 128 |
} |
129 |
|
|
130 |
|
|
99 | 131 |
} |
100 | 132 |
|
101 | 133 |
/** |
metacat-index/src/main/java/edu/ucsb/nceas/metacat/index/IndexGenerator.java | ||
---|---|---|
66 | 66 |
|
67 | 67 |
private static final int FIRST =0; |
68 | 68 |
private static final int SECOND =1; |
69 |
private static final int WAITTIME = 10000;
|
|
70 |
private static final int MAXWAITNUMBER = 180;
|
|
69 |
public static final int WAITTIME = 10000;
|
|
70 |
public static final int MAXWAITNUMBER = 180;
|
|
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";
|
|
74 |
public static final String WAITIMEPOPERTYNAME = "index.regenerate.start.waitingtime";
|
|
75 |
public static final String MAXATTEMPTSPROPERTYNAME = "index.regenerate.start.maxattempts";
|
|
76 | 76 |
|
77 | 77 |
private static int waitingTime = WAITTIME; |
78 | 78 |
private static int maxAttempts = MAXWAITNUMBER; |
... | ... | |
386 | 386 |
private void initSystemMetadataMap() throws FileNotFoundException, ServiceFailure{ |
387 | 387 |
int times = 0; |
388 | 388 |
if(systemMetadataMap == null) { |
389 |
while(true) { |
|
389 |
systemMetadataMap = DistributedMapsFactory.getSystemMetadataMap(); |
|
390 |
/*while(true) { |
|
390 | 391 |
try { |
391 | 392 |
systemMetadataMap = DistributedMapsFactory.getSystemMetadataMap(); |
392 | 393 |
break; |
... | ... | |
407 | 408 |
} |
408 | 409 |
} |
409 | 410 |
times++; |
410 |
} |
|
411 |
}*/
|
|
411 | 412 |
} |
412 | 413 |
} |
413 | 414 |
|
Also available in: Unified diff
Put the waiting mechanism for the hazelcast at the first place.