Revision 6407
Added by Chris Jones over 13 years ago
src/edu/ucsb/nceas/metacat/dataone/hazelcast/HazelcastService.java | ||
---|---|---|
36 | 36 |
import com.hazelcast.core.Hazelcast; |
37 | 37 |
import com.hazelcast.core.HazelcastInstance; |
38 | 38 |
import com.hazelcast.core.IMap; |
39 |
import com.hazelcast.core.IdGenerator; |
|
39 | 40 |
import com.hazelcast.core.InstanceEvent; |
40 | 41 |
import com.hazelcast.core.InstanceListener; |
41 | 42 |
|
... | ... | |
61 | 62 |
/* The Hazelcast configuration */ |
62 | 63 |
private Config hzConfig; |
63 | 64 |
|
65 |
/* The task id namespace (for generating cluster-wide unqique task ids */ |
|
66 |
private String taskIds; |
|
67 |
|
|
68 |
/* The Hazelcast Id Genrator used to generate unique task ids */ |
|
69 |
IdGenerator idGenerator; |
|
70 |
|
|
64 | 71 |
/* |
65 | 72 |
* Constructor: Creates an instance of the hazelcast service. Since |
66 | 73 |
* this uses a singleton pattern, use getInstance() to gain the instance. |
... | ... | |
105 | 112 |
logMetacat.debug("HazelcastService.doRefresh() called."); |
106 | 113 |
|
107 | 114 |
try { |
108 |
File hzConfigFile = |
|
109 |
new File(PropertyService.getProperty("dataone.hazelcast.configFilePath")); |
|
110 |
hzConfig = new Config(); |
|
111 |
hzConfig.setConfigurationFile(hzConfigFile); |
|
112 |
hzMember = Hazelcast.init(hzConfig); |
|
115 |
File hzConfigFile = |
|
116 |
new File(PropertyService.getProperty("dataone.hazelcast.configFilePath")); |
|
117 |
hzConfig = new Config(); |
|
118 |
hzConfig.setConfigurationFile(hzConfigFile); |
|
119 |
hzMember = Hazelcast.init(hzConfig); |
|
120 |
taskIds = |
|
121 |
PropertyService.getProperty("dataone.hazelcast.storageCluster.tasksIdNamespace"); |
|
122 |
|
|
123 |
idGenerator = hzMember.getIdGenerator(taskIds); |
|
113 | 124 |
|
114 | 125 |
} catch (PropertyNotFoundException e) { |
115 |
String msg = "Couldn't find the Hazelcast configuration file.";
|
|
116 |
logMetacat.error(msg);
|
|
117 |
throw new ServiceException(msg);
|
|
126 |
String msg = "Couldn't find the Hazelcast configuration file.";
|
|
127 |
logMetacat.error(msg);
|
|
128 |
throw new ServiceException(msg);
|
|
118 | 129 |
|
119 | 130 |
} catch (IllegalStateException e) { |
120 | 131 |
|
121 |
String msg = "This instance of Hazelcast has already been created.";
|
|
122 |
logMetacat.error(msg);
|
|
123 |
throw new ServiceException(msg);
|
|
132 |
String msg = "This instance of Hazelcast has already been created.";
|
|
133 |
logMetacat.error(msg);
|
|
134 |
throw new ServiceException(msg);
|
|
124 | 135 |
|
125 | 136 |
} |
126 | 137 |
|
... | ... | |
135 | 146 |
*/ |
136 | 147 |
public boolean refreshable() { |
137 | 148 |
// TODO: Determine the consequences of restarting the Hazelcast instance |
138 |
// Set this to true if it's okay to drop from the cluster, lose the maps,
|
|
139 |
// and start back up again
|
|
140 |
return false;
|
|
149 |
// Set this to true if it's okay to drop from the cluster, lose the maps,
|
|
150 |
// and start back up again
|
|
151 |
return false;
|
|
141 | 152 |
|
142 | 153 |
} |
143 | 154 |
|
... | ... | |
154 | 165 |
/** |
155 | 166 |
* Listen for new Hazelcast member events |
156 | 167 |
*/ |
157 |
@Override
|
|
168 |
@Override
|
|
158 | 169 |
public void instanceCreated(InstanceEvent event) { |
159 |
logMetacat.info("New Hazelcast instance created: " +
|
|
160 |
event.getInstance().getId() + ", " +
|
|
161 |
event.getInstance().getInstanceType());
|
|
162 |
|
|
170 |
logMetacat.info("New Hazelcast instance created: " +
|
|
171 |
event.getInstance().getId() + ", " +
|
|
172 |
event.getInstance().getInstanceType());
|
|
173 |
|
|
163 | 174 |
} |
164 | 175 |
|
165 |
@Override
|
|
176 |
@Override
|
|
166 | 177 |
public void instanceDestroyed(InstanceEvent event) { |
167 |
logMetacat.info("Hazelcast instance removed: " +
|
|
168 |
event.getInstance().getId() + ", " +
|
|
169 |
event.getInstance().getInstanceType());
|
|
170 |
|
|
178 |
logMetacat.info("Hazelcast instance removed: " +
|
|
179 |
event.getInstance().getId() + ", " +
|
|
180 |
event.getInstance().getInstanceType());
|
|
181 |
|
|
171 | 182 |
} |
172 | 183 |
|
173 |
|
|
174 |
/**
|
|
175 |
* Refresh the Hazelcast service by restarting it
|
|
176 |
*/
|
|
177 |
@Override
|
|
184 |
|
|
185 |
/**
|
|
186 |
* Refresh the Hazelcast service by restarting it
|
|
187 |
*/
|
|
188 |
@Override
|
|
178 | 189 |
protected void doRefresh() throws ServiceException { |
179 | 190 |
|
180 |
// TODO: verify that the correct config file is still used
|
|
191 |
// TODO: verify that the correct config file is still used
|
|
181 | 192 |
Hazelcast.getLifecycleService().restart(); |
182 |
|
|
193 |
|
|
183 | 194 |
} |
184 | 195 |
|
185 | 196 |
} |
Also available in: Unified diff
Add in the Hazelcast Id generation namespace and an IdGenerator instance for task ids. Hazelcast will produce cluster-wide unique ids for the "task-ids" namespace, to be used when creating CNreplicationTask objects.