use of java.util.HashSet in project disconf by knightliao.
the class ReloadingPropertyPlaceholderConfigurer method propertiesReloaded.
/**
* 当配置更新时,被调用
*
* @param event
*/
public void propertiesReloaded(PropertiesReloadedEvent event) {
Properties oldProperties = lastMergedProperties;
try {
//
Properties newProperties = mergeProperties();
//
// 获取哪些 dynamic property 被影响
//
Set<String> placeholders = placeholderToDynamics.keySet();
Set<DynamicProperty> allDynamics = new HashSet<DynamicProperty>();
for (String placeholder : placeholders) {
String newValue = newProperties.getProperty(placeholder);
String oldValue = oldProperties.getProperty(placeholder);
if (newValue != null && !newValue.equals(oldValue) || newValue == null && oldValue != null) {
if (logger.isInfoEnabled()) {
logger.info("Property changed detected: " + placeholder + (newValue != null ? "=" + newValue : " removed"));
}
List<DynamicProperty> affectedDynamics = placeholderToDynamics.get(placeholder);
allDynamics.addAll(affectedDynamics);
}
}
//
// 获取受影响的beans
//
Map<String, List<DynamicProperty>> dynamicsByBeanName = new HashMap<String, List<DynamicProperty>>();
Map<String, Object> beanByBeanName = new HashMap<String, Object>();
for (DynamicProperty dynamic : allDynamics) {
String beanName = dynamic.getBeanName();
List<DynamicProperty> l = dynamicsByBeanName.get(beanName);
if (l == null) {
dynamicsByBeanName.put(beanName, (l = new ArrayList<DynamicProperty>()));
Object bean = null;
try {
bean = applicationContext.getBean(beanName);
beanByBeanName.put(beanName, bean);
} catch (BeansException e) {
// keep dynamicsByBeanName list, warn only once.
logger.error("Error obtaining bean " + beanName, e);
}
//
try {
if (bean instanceof IReconfigurationAware) {
// hello!
((IReconfigurationAware) bean).beforeReconfiguration();
}
} catch (Exception e) {
logger.error("Error calling beforeReconfiguration on " + beanName, e);
}
}
l.add(dynamic);
}
//
// 处理受影响的bean
//
Collection<String> beanNames = dynamicsByBeanName.keySet();
for (String beanName : beanNames) {
Object bean = beanByBeanName.get(beanName);
if (// problems obtaining bean, earlier
bean == null) {
continue;
}
BeanWrapper beanWrapper = new BeanWrapperImpl(bean);
// for all affected ...
List<DynamicProperty> dynamics = dynamicsByBeanName.get(beanName);
for (DynamicProperty dynamic : dynamics) {
String propertyName = dynamic.getPropertyName();
String unparsedValue = dynamic.getUnparsedValue();
// obtain an updated value, including dependencies
String newValue;
removeDynamic(dynamic);
currentBeanName = beanName;
currentPropertyName = propertyName;
try {
newValue = parseStringValue(unparsedValue, newProperties, new HashSet());
} finally {
currentBeanName = null;
currentPropertyName = null;
}
if (logger.isInfoEnabled()) {
logger.info("Updating property " + beanName + "." + propertyName + " to " + newValue);
}
// assign it to the bean
try {
beanWrapper.setPropertyValue(propertyName, newValue);
} catch (BeansException e) {
logger.error("Error setting property " + beanName + "." + propertyName + " to " + newValue, e);
}
}
}
//
for (String beanName : beanNames) {
Object bean = beanByBeanName.get(beanName);
try {
if (bean instanceof IReconfigurationAware) {
((IReconfigurationAware) bean).afterReconfiguration();
}
} catch (Exception e) {
logger.error("Error calling afterReconfiguration on " + beanName, e);
}
}
} catch (IOException e) {
logger.error("Error trying to reload net.unicon.iamlabs.spring.properties.example.net.unicon.iamlabs" + ".spring" + ".properties: " + e.getMessage(), e);
}
}
use of java.util.HashSet in project eweb4j-framework by laiweiwei.
the class FileUtil method getJars.
public static Collection<String> getJars() {
Collection<String> jars = new HashSet<String>();
Enumeration<URL> urls;
try {
urls = FileUtil.class.getClassLoader().getResources("META-INF/MANIFEST.MF");
while (urls.hasMoreElements()) {
URL url = (URL) urls.nextElement();
String path = url.getFile().replace("file:/", "").replace("!/META-INF/MANIFEST.MF", "");
jars.add(CommonUtil.uriDecoding(path));
}
File jarDir = new File(getLib());
if (jarDir.isDirectory() && jarDir.exists()) {
for (File jar : jarDir.listFiles()) {
jars.add(CommonUtil.uriDecoding(jar.getAbsolutePath()));
}
}
} catch (IOException e) {
e.printStackTrace();
}
return jars;
}
use of java.util.HashSet in project marine-api by ktuukkan.
the class SentenceReader method fireSentenceEvent.
/**
* Dispatch data to all listeners.
*
* @param sentence sentence string.
*/
void fireSentenceEvent(Sentence sentence) {
String type = sentence.getSentenceId();
Set<SentenceListener> targets = new HashSet<SentenceListener>();
if (listeners.containsKey(type)) {
targets.addAll(listeners.get(type));
}
if (listeners.containsKey(DISPATCH_ALL)) {
targets.addAll(listeners.get(DISPATCH_ALL));
}
for (SentenceListener listener : targets) {
try {
SentenceEvent se = new SentenceEvent(this, sentence);
listener.sentenceRead(se);
} catch (Exception e) {
LOGGER.log(Level.WARNING, LOG_MSG, e);
}
}
}
use of java.util.HashSet in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementVertexNoPropertiesWithKeysNoTypes.
@Test
public void jsonFromElementVertexNoPropertiesWithKeysNoTypes() throws JSONException {
Vertex v = this.graph.addVertex(1);
v.setProperty("x", "X");
v.setProperty("y", "Y");
v.setProperty("z", "Z");
Set<String> propertiesToInclude = new HashSet<String>();
propertiesToInclude.add("y");
JSONObject json = GraphSONUtility.jsonFromElement(v, propertiesToInclude, GraphSONMode.NORMAL);
Assert.assertNotNull(json);
Assert.assertTrue(json.has(GraphSONTokens._ID));
Assert.assertEquals(1, json.optInt(GraphSONTokens._ID));
Assert.assertTrue(json.has(GraphSONTokens._TYPE));
Assert.assertEquals("vertex", json.optString(GraphSONTokens._TYPE));
Assert.assertFalse(json.has("x"));
Assert.assertFalse(json.has("z"));
Assert.assertTrue(json.has("y"));
}
use of java.util.HashSet in project blueprints by tinkerpop.
the class GraphSONUtilityTest method jsonFromElementVertexIntIterablePropertiesNoKeysWithTypes.
@Test
public void jsonFromElementVertexIntIterablePropertiesNoKeysWithTypes() throws JSONException {
Vertex v = this.graph.addVertex(1);
Set<Integer> list = new HashSet<Integer>();
list.add(0);
list.add(1);
list.add(2);
v.setProperty("keyList", list);
JSONObject json = GraphSONUtility.jsonFromElement(v, null, GraphSONMode.EXTENDED);
Assert.assertNotNull(json);
Assert.assertTrue(json.has(GraphSONTokens._ID));
Assert.assertEquals(1, json.optInt(GraphSONTokens._ID));
Assert.assertTrue(json.has("keyList"));
JSONObject listWithTypeAsJson = json.optJSONObject("keyList");
Assert.assertNotNull(listWithTypeAsJson);
Assert.assertTrue(listWithTypeAsJson.has(GraphSONTokens.TYPE));
Assert.assertEquals(GraphSONTokens.TYPE_LIST, listWithTypeAsJson.optString(GraphSONTokens.TYPE));
Assert.assertTrue(listWithTypeAsJson.has(GraphSONTokens.VALUE));
JSONArray listAsJSON = listWithTypeAsJson.optJSONArray(GraphSONTokens.VALUE);
Assert.assertNotNull(listAsJSON);
Assert.assertEquals(3, listAsJSON.length());
for (int ix = 0; ix < listAsJSON.length(); ix++) {
JSONObject valueAsJson = listAsJSON.optJSONObject(ix);
Assert.assertNotNull(valueAsJson);
Assert.assertTrue(valueAsJson.has(GraphSONTokens.TYPE));
Assert.assertEquals(GraphSONTokens.TYPE_INTEGER, valueAsJson.optString(GraphSONTokens.TYPE));
Assert.assertTrue(valueAsJson.has(GraphSONTokens.VALUE));
Assert.assertEquals(ix, valueAsJson.optInt(GraphSONTokens.VALUE));
}
}
Aggregations