http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java ---------------------------------------------------------------------- diff --git a/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java b/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java deleted file mode 100644 index 8b6569f..0000000 --- a/etcd/src/test/java/org/apache/tamaya/etcd/EtcdPropertySourceTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.etcd; - -import org.apache.tamaya.spi.PropertyValue; -import org.junit.BeforeClass; -import org.junit.Test; - -import java.util.Map; - -import static org.junit.Assert.*; -import static org.junit.Assert.assertEquals; - -/** - * Created by atsticks on 07.01.16. - */ -public class EtcdPropertySourceTest { - - private final EtcdPropertySource propertySource = new EtcdPropertySource(); - - @BeforeClass - public static void setup(){ - System.setProperty("etcd.server.urls", "http://8.8.8.8:4001,http://192.168.99.105:4001"); - } - - @Test - public void testGetOrdinal() throws Exception { - assertEquals(1000, propertySource.getOrdinal()); - } - - @Test - public void testGetDefaultOrdinal() throws Exception { - assertEquals(1000, propertySource.getDefaultOrdinal()); - } - - @Test - public void testGetName() throws Exception { - assertEquals("etcd", propertySource.getName()); - } - - @Test - public void testGet() throws Exception { - Map<String,PropertyValue> props = propertySource.getProperties(); - for(Map.Entry<String,PropertyValue> en:props.entrySet()){ - assertNotNull("Key not found: " + en.getKey(), propertySource.get(en.getKey())); - } - } - - @Test - public void testGetProperties() throws Exception { - Map<String,PropertyValue> props = propertySource.getProperties(); - assertNotNull(props); - } - - @Test - public void testIsScannable() throws Exception { - assertTrue(propertySource.isScannable()); - } -} \ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/hazelcast/bnd.bnd ---------------------------------------------------------------------- diff --git a/hazelcast/bnd.bnd b/hazelcast/bnd.bnd deleted file mode 100644 index 22db283..0000000 --- a/hazelcast/bnd.bnd +++ /dev/null @@ -1,29 +0,0 @@ --buildpath: \ - osgi.annotation; version=6.0.0,\ - osgi.core; version=6.0,\ - osgi.cmpn; version=6.0 - --testpath: \ - ${junit} - -javac.source: 1.8 -javac.target: 1.8 - -Automatic-Module-Name: org.apache.tamaya.hazelcast -Bundle-Version: ${version}.${tstamp} -Bundle-Name: Apache Tamaya - Hazelcast Config -Bundle-SymbolicName: org.apache.tamaya.hazelcast -Bundle-Description: Apacha Tamaya Config - Hazelcast PropertySource -Bundle-Category: Implementation -Bundle-Copyright: (C) Apache Foundation -Bundle-License: Apache Licence version 2 -Bundle-Vendor: Apache Software Foundation -Bundle-ContactAddress: [email protected] -Bundle-DocURL: http://tamaya.apache.org -Export-Package: \ - org.apache.tamaya.hazelcast -Import-Package: \ - org.apache.tamaya,\ - org.apache.tamaya.spi -Export-Service: \ - org.apache.tamaya.spi.PropertySource http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/hazelcast/pom.xml ---------------------------------------------------------------------- diff --git a/hazelcast/pom.xml b/hazelcast/pom.xml deleted file mode 100644 index 834a808..0000000 --- a/hazelcast/pom.xml +++ /dev/null @@ -1,77 +0,0 @@ -<!-- - ~ Licensed to the Apache Software Foundation (ASF) under one - ~ or more contributor license agreements. See the NOTICE file - ~ distributed with this work for additional information - ~ regarding copyright ownership. The ASF licenses this file - ~ to you under the Apache License, Version 2.0 (the - ~ "License"); you may not use this file except in compliance - ~ with the License. You may obtain a copy of the License at - ~ - ~ http://www.apache.org/licenses/LICENSE-2.0 - ~ - ~ Unless required by applicable law or agreed to in writing, - ~ software distributed under the License is distributed on an - ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - ~ KIND, either express or implied. See the License for the - ~ specific language governing permissions and limitations - ~ under the License. - --> -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> - <modelVersion>4.0.0</modelVersion> - - <parent> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-sandbox</artifactId> - <version>0.4-incubating-SNAPSHOT</version> - <relativePath>..</relativePath> - </parent> - - <artifactId>tamaya-hazelcast_beta</artifactId> - <name>Apache Tamaya Modules - Hazelcast PropertySource</name> - <packaging>jar</packaging> - - <dependencies> - <dependency> - <groupId>junit</groupId> - <artifactId>junit</artifactId> - </dependency> - <dependency> - <groupId>org.hamcrest</groupId> - <artifactId>java-hamcrest</artifactId> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-core</artifactId> - <version>${project.parent.version}</version> - <scope>test</scope> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-api</artifactId> - <version>${project.parent.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-functions</artifactId> - <version>${project.parent.version}</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya</groupId> - <artifactId>tamaya-spisupport</artifactId> - <version>${project.parent.version}</version> - </dependency> - <dependency> - <groupId>com.hazelcast</groupId> - <artifactId>hazelcast</artifactId> - <version>3.5.2</version> - </dependency> - <dependency> - <groupId>org.apache.tamaya.ext</groupId> - <artifactId>tamaya-mutable-config</artifactId> - <version>${project.parent.version}</version> - <scope>provided</scope> - <optional>true</optional> - </dependency> - </dependencies> - -</project> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/hazelcast/src/main/java/org/apache/tamaya/hazelcast/HazelcastPropertySource.java ---------------------------------------------------------------------- diff --git a/hazelcast/src/main/java/org/apache/tamaya/hazelcast/HazelcastPropertySource.java b/hazelcast/src/main/java/org/apache/tamaya/hazelcast/HazelcastPropertySource.java deleted file mode 100644 index 1a716d3..0000000 --- a/hazelcast/src/main/java/org/apache/tamaya/hazelcast/HazelcastPropertySource.java +++ /dev/null @@ -1,232 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.tamaya.hazelcast; - -import com.hazelcast.config.Config; -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.IList; -import com.hazelcast.core.IMap; -import org.apache.tamaya.mutableconfig.ConfigChangeRequest; -import org.apache.tamaya.mutableconfig.spi.MutablePropertySource; -import org.apache.tamaya.spi.PropertyValue; -import org.apache.tamaya.spisupport.propertysource.BasePropertySource; - -import java.util.HashMap; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; - -/** - * Distributed Propertysource using a in-memory hazelcast cluster. - * Created by atsticks on 03.11.16. - * - * Basically all kind of property entris can be stored. Additionally this property source allows - * to pass additional getMeta-entries to control the TTL of the data in milliseconds. For illustration - * the following map will store {@code my.entry} with a TLL of 20000 milliseconds (20 seconds) and - * store {@code my.otherEntry} with infinite lifetime (as long as the cluster is alive): - * - * {@code - * my.entry=myvalue - * _my.entry.ttl=20000 - * my.otherEntry=1234 - * } - * - * By default a new hazelcast instance is created, but it is also possible to reuse an existing - * instance of pass a Hazelcast configuration instance. - */ -public class HazelcastPropertySource extends BasePropertySource -implements MutablePropertySource{ - /** The logger. */ - private static final Logger LOG = Logger.getLogger(HazelcastPropertySource.class.getName()); - /** The Hazelcast config map used. */ - private Map<String, String> configMap = new HashMap<>(); - /** The hazelcast API instance. */ - private HazelcastInstance hazelcastInstance; - /** The hazelcast map reference ID used, by default {@code tamaya.configuration}. */ - private String mapReference = "tamaya.configuration"; - /** Flag if this property source is read-only. */ - private boolean readOnly = false; - - /** - * Creates a new instance, hereby using {@code "Hazelcast"} as property source name and - * a default hazelcast backend created by calling {@link Hazelcast#newHazelcastInstance()}. - */ - public HazelcastPropertySource(){ - super("Hazelcast"); - this.hazelcastInstance = Hazelcast.newHazelcastInstance(); - } - - /** - * Creates a new instance, hereby using {@code "Hazelcast"} as property source name and the - * given hazelcast instance. - * @param hazelcastInstance the hazelcast instance, not null. - */ - public HazelcastPropertySource(HazelcastInstance hazelcastInstance){ - this("Hazelcast", hazelcastInstance); - } - - /** - * Creates a new instance, hereby using the given property source name and - * a default hazelcast backend created by calling {@link Hazelcast#newHazelcastInstance()}. - * @param name the property source name, not null. - */ - public HazelcastPropertySource(String name){ - super(name); - this.hazelcastInstance = Hazelcast.newHazelcastInstance(); - } - - /** - * Creates a new instance, hereby using the given property source name and - * a creating a new hazelcast backend using the given Hazelcast {@link Config}. - * @param config the hazelcast config, not null. - * @param name the property source name, not null. - */ - public HazelcastPropertySource(String name, Config config){ - super(name); - this.hazelcastInstance = Hazelcast.newHazelcastInstance(config); - } - - /** - * Creates a new instance, hereby using the given property source name and the - * hazelcast instance. - * @param name the property source name, not null. - * @param hazelcastInstance the hazelcast instance, not null. - */ - public HazelcastPropertySource(String name, HazelcastInstance hazelcastInstance){ - super(name); - this.hazelcastInstance = Objects.requireNonNull(hazelcastInstance); - } - - /** - * Setting the read-only flag for this instance. - * @param readOnly if true, the property source will not write back any changes to the - * hazelcast backend. - */ - public void setReadOnly(boolean readOnly){ - this.readOnly = readOnly; - } - - /** - * Flag to check if the property source is read-only. - * @return true, if the instance is read-only. - */ - public boolean isReadOnly(){ - return readOnly; - } - - /** - * Set the Hazelcast reference name for the Tamaya configuration Map. - * @param mapReference the map reference to be used, not null. - */ - public void setMapReference(String mapReference){ - this.mapReference = Objects.requireNonNull(mapReference); - } - - /** - * Get the Hazelcast reference name for the Tamaya configuration Map. - * @return the Hazelcast reference name for the Tamaya configuration Map, never null. - */ - public String getMapReference(){ - return mapReference; - } - - /** - * Get access to the hazelcast instance used. - * @return the hazelcast instance, not null. - */ - public HazelcastInstance getHazelcastInstance() { - return hazelcastInstance; - } - - @Override - public PropertyValue get(String key) { - Config hcConfig = hazelcastInstance.getConfig(); - String value = hcConfig.getProperty(key); - if(value==null){ - return null; - } - return PropertyValue.of(key, value, getName()) - .setMeta("backend", "Hazelcast") - .setMeta("instance", hcConfig.getInstanceName()) - .setMeta("mapReference", mapReference); - } - - @Override - public Map<String, PropertyValue> getProperties() { - Map<String,String> meta = new HashMap<>(); - meta.put("backend", "Hazelcast"); - meta.put("instance", hazelcastInstance.getConfig().getInstanceName()); - meta.put("mapReference", mapReference); - return PropertyValue.map(this.configMap, getName(), meta); - } - - /** - * Reloads the configuration map from Hazelcast completely. - */ - public void refresh() { - IMap<String,String> config = hazelcastInstance.getMap(mapReference); - Map<String, String> configMap = new HashMap<>(config); - this.configMap = configMap; - } - - @Override - public void applyChange(ConfigChangeRequest configChange) { - if(readOnly){ - return; - } - IMap<String,String> config = hazelcastInstance.getMap(mapReference); - for(Map.Entry<String, String> en: configChange.getAddedProperties().entrySet()){ - String metaVal = configChange.getAddedProperties().get("_" + en.getKey()+".ttl"); - if(metaVal!=null){ - try { - long ms = Long.parseLong(metaVal); - config.put(en.getKey(), en.getValue(), ms, TimeUnit.MILLISECONDS); - }catch(Exception e){ - LOG.log(Level.WARNING, "Failed to parse TTL in millis: " + metaVal + - " for '"+ en.getKey()+"'", e); - config.put(en.getKey(), en.getValue()); - } - }else { - config.put(en.getKey(), en.getValue()); - } - } - for(String key: configChange.getRemovedProperties()){ - config.remove(key); - } - IList<String> taList = hazelcastInstance.getList("_tamaya.transactions"); - taList.add(configChange.getTransactionID()); - config.put("_tamaya.transaction.lastId", configChange.getTransactionID(), 1, TimeUnit.DAYS); - config.put("_tamaya.transaction.startedAt", String.valueOf(configChange.getStartedAt()), 1, TimeUnit.DAYS); - config.flush(); - refresh(); - } - - @Override - protected String toStringValues() { - return super.toStringValues() + - "\n hazelcastInstance=" + hazelcastInstance + - "\n name='" + getName() + '\'' + - "\n mapReference='" + mapReference + '\'' + - "\n readOnly=" + readOnly + '\''; - } - -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/hazelcast/src/test/java/org/apache/tamaya/hazelcast/Test.java ---------------------------------------------------------------------- diff --git a/hazelcast/src/test/java/org/apache/tamaya/hazelcast/Test.java b/hazelcast/src/test/java/org/apache/tamaya/hazelcast/Test.java deleted file mode 100644 index c83df66..0000000 --- a/hazelcast/src/test/java/org/apache/tamaya/hazelcast/Test.java +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.apache.tamaya.hazelcast; - -import com.hazelcast.core.Hazelcast; -import com.hazelcast.core.HazelcastInstance; -import com.hazelcast.core.ITopic; - -import java.util.Date; - -/** - * Created by atsticks on 03.11.16. - */ -public class Test { - - public static void main(String[] args) { - HazelcastInstance hz = Hazelcast.newHazelcastInstance(); - ITopic<String> topic = hz.getTopic("foo"); -// topic.addMessageListener(System.out::println); - while(true){ - topic.publish("Hi from Anatole at " + new Date()); - } - } -} http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 3813fa7..8c80215 100644 --- a/pom.xml +++ b/pom.xml @@ -794,16 +794,13 @@ under the License. </build> <modules> - <module>collections</module> - <module>hazelcast</module> + <module>apache-commons</module> <module>jodatime</module> <module>usagetracker</module> <module>validation</module> <module>remote</module> <module>configured-sysprops</module> - <module>etcd</module> - <module>consul</module> <module>camel</module> <module>propertysources</module> <!--<module>ui</module>--> http://git-wip-us.apache.org/repos/asf/incubator-tamaya-sandbox/blob/e0d15cb2/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java ---------------------------------------------------------------------- diff --git a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java index 679ccf3..6edb411 100644 --- a/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java +++ b/validation/src/main/java/org/apache/tamaya/validation/internal/ConfiguredResourcesModelProviderSpi.java @@ -128,7 +128,7 @@ public class ConfiguredResourcesModelProviderSpi implements ModelProviderSpi, Cl Collection<URL> urls; if (RESOURCES_EXTENSION_AVAILABLE) { LOG.info("Using tamaya-resources extension to read model configuration from " + resources); - urls = ResourceResolver.current(classLoader).getResources(resources.split(",")); + urls = ResourceResolver.getInstance(classLoader).getResources(resources.split(",")); } else { LOG.info("Using default classloader resource location to read model configuration from " + resources); urls = new ArrayList<>();
