Return-Path: X-Original-To: apmail-tamaya-commits-archive@minotaur.apache.org Delivered-To: apmail-tamaya-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7B03D18C4F for ; Mon, 12 Oct 2015 06:03:09 +0000 (UTC) Received: (qmail 68057 invoked by uid 500); 12 Oct 2015 06:03:09 -0000 Delivered-To: apmail-tamaya-commits-archive@tamaya.apache.org Received: (qmail 68031 invoked by uid 500); 12 Oct 2015 06:03:09 -0000 Mailing-List: contact commits-help@tamaya.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@tamaya.incubator.apache.org Delivered-To: mailing list commits@tamaya.incubator.apache.org Received: (qmail 68022 invoked by uid 99); 12 Oct 2015 06:03:09 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Oct 2015 06:03:09 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id C8F75C0EC9 for ; Mon, 12 Oct 2015 06:03:08 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 1.791 X-Spam-Level: * X-Spam-Status: No, score=1.791 tagged_above=-999 required=6.31 tests=[KAM_ASCII_DIVIDERS=0.8, KAM_LAZY_DOMAIN_SECURITY=1, T_RP_MATCHES_RCVD=-0.01, URIBL_BLOCKED=0.001] autolearn=disabled Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id tC27gWR8OUFg for ; Mon, 12 Oct 2015 06:02:59 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with SMTP id 3C11A439B6 for ; Mon, 12 Oct 2015 06:02:58 +0000 (UTC) Received: (qmail 67481 invoked by uid 99); 12 Oct 2015 06:02:57 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 12 Oct 2015 06:02:57 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 2F4FDDFBD6; Mon, 12 Oct 2015 06:02:57 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: anatole@apache.org To: commits@tamaya.incubator.apache.org Date: Mon, 12 Oct 2015 06:03:03 -0000 Message-Id: In-Reply-To: <6bdc413d24654b58bb02539a9586e09f@git.apache.org> References: <6bdc413d24654b58bb02539a9586e09f@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [08/13] incubator-tamaya git commit: TAMAYA-116: Moved Sabot CDI module to extension section. Added docs. http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java b/sandbox/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java new file mode 100644 index 0000000..db567ac --- /dev/null +++ b/sandbox/integration/store-hazelcast/src/main/java/org/apache/tamaya/store/internal/HazelcastProprtyStoreProviderSpi.java @@ -0,0 +1,87 @@ +/* + * 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.store.internal; + +import com.hazelcast.config.Config; +import com.hazelcast.config.GroupConfig; +import com.hazelcast.core.Hazelcast; +import com.hazelcast.core.HazelcastInstance; +import org.apache.tamaya.spi.ServiceContextManager; +import org.apache.tamaya.store.PropertyStore; +import org.apache.tamaya.store.spi.PropertyStoreProviderSpi; + +import java.util.Map; +import java.util.ServiceLoader; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * SPI implmentation for a providing Hazelcast based PropertyStores. + */ +public class HazelcastProprtyStoreProviderSpi implements PropertyStoreProviderSpi { + private static final String CONFIG_CLASS_SYS_PROP = "tamaya.store.hazelcast.configClass"; + private static final String CONFIG_GROUP_SYS_PROP = "tamaya.store.hazelcast.groupName"; + + + + private static final Logger LOG = Logger.getLogger(HazelcastProprtyStoreProviderSpi.class.getName()); + + private HazelcastInstance store; + private Map stores = new ConcurrentHashMap<>(); + + public HazelcastProprtyStoreProviderSpi() { + String customConfig = System.getProperty(CONFIG_CLASS_SYS_PROP); + Config config = null; + if(customConfig!=null){ + try { + config = (Config)Class.forName(customConfig).newInstance(); + LOG.info("Successfully created custom store config for HazelCast store: " + customConfig); + } catch (Exception e) { + LOG.log(Level.SEVERE, "Failed to instantiate custom store config for HazelCast store: " + customConfig, e); + } + } + if(config==null){ + config = ServiceContextManager.getServiceContext().getService(Config.class); + } + if(config==null) { + config = new Config(); + GroupConfig gc = new GroupConfig(); + String groupName = System.getProperty(CONFIG_GROUP_SYS_PROP, "Tamaya"); + gc.setName(groupName); + config.setGroupConfig(gc); + } + LOG.info("Starting HazelCast storage with config: " + config); + store = Hazelcast.getOrCreateHazelcastInstance(config); + } + + @Override + public PropertyStore getPropertyStore(String storeId) { + HazelcastProprtyStore propertyStore = stores.get(storeId); + if(propertyStore==null){ + LOG.info("Creating new distributed configuration map in HazelCast store for " + storeId + "..."); + propertyStore = new HazelcastProprtyStore(store, storeId); + this.stores.put(storeId, propertyStore); + } + return propertyStore; + } + + + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/pom.xml ---------------------------------------------------------------------- diff --git a/sandbox/integration/store/pom.xml b/sandbox/integration/store/pom.xml new file mode 100644 index 0000000..d755551 --- /dev/null +++ b/sandbox/integration/store/pom.xml @@ -0,0 +1,54 @@ + + + 4.0.0 + + + org.apache.tamaya.ext + tamaya-integration-sandbox + 0.2-incubating-SNAPSHOT + + tamaya-store + Apache Tamaya Storage/Cache/Datagrid Integration + Integration with a Datagrid backend for distributed configuration. + jar + + + + org.apache.tamaya + tamaya-api + ${project.version} + + + org.apache.tamaya.ext + tamaya-spisupport + ${project.version} + + + org.apache.tamaya.ext + tamaya-events + ${project.version} + + + junit + junit + + + http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java new file mode 100644 index 0000000..d1d6adf --- /dev/null +++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStore.java @@ -0,0 +1,64 @@ +/* + * 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.store; + +import org.apache.tamaya.spi.PropertySource; + +import java.util.Map; + +/** + * Simple abstraction of a property synchronization backend. Most methods are similar + * to a {@link org.apache.tamaya.spi.PropertySource}, enhanced with methods for + * updating the property storage. + */ +public interface PropertyStore { + + /** + * Get the store's name. + * @return the name, never null. + */ + String getName(); + + /** + * Stores the given PropertySource into the store. + * @param propertySource + */ + void store(PropertySource propertySource); + + /** + * Read all properties. + * @return the properties from the remote store, never null. + */ + Map read(); + + /** + * Reads a single key fromt hthe store. + * @param key the key, not null. + * @return the value, or null. + */ + String read(String key); + + /** + * Determines if {@link #read()} returns all contained properties, or optionally only + * a subset of the accessible and defined properties are returned. + * @return true, if this store is scannable. + */ + boolean isScannable(); + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java new file mode 100644 index 0000000..dceb29a --- /dev/null +++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/PropertyStoreProvider.java @@ -0,0 +1,78 @@ +/* + * 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.store; + +import org.apache.tamaya.ConfigException; +import org.apache.tamaya.ConfigurationProvider; +import org.apache.tamaya.spi.PropertySource; +import org.apache.tamaya.spi.ServiceContextManager; +import org.apache.tamaya.store.spi.PropertyStoreProviderSpi; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.logging.Logger; + +/** + * Simple provider accessor singleton for accessing {@link PropertyStore} + * instances. + */ +public final class PropertyStoreProvider { + /** + * The logger used. + */ + private static final Logger LOG = Logger.getLogger(PropertyStoreProvider.class.getName()); + + + /** + * Singleton constructor. + */ + private PropertyStoreProvider() { + } + + + /** + * Access a {@link PropertyStore} using it's id. + * + * @param storeId the unique id of the store to use. + * @return + */ + public static PropertyStore getPropertyStore(String storeId) { + for (PropertyStoreProviderSpi propertyStoreProviderSpi : ServiceContextManager.getServiceContext() + .getServices(PropertyStoreProviderSpi.class)) { + PropertyStore store = propertyStoreProviderSpi.getPropertyStore(storeId); + if (store != null) { + LOG.finest("DataGrid '" + storeId + "' used: " + store); + return store; + } + } + throw new ConfigException("No such Store: " + storeId); + } + + /** + * Access a {@link PropertyStore} using it's id, hereby returning the most significant of the configured + * {@link PropertyStore} instances. + * + * @return the default PropertyStore instance. + */ + public static PropertyStore getDefaultPropertyStore() { + return getPropertyStore("default"); + } + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java new file mode 100644 index 0000000..c19fa45 --- /dev/null +++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/WritablePropertySource.java @@ -0,0 +1,66 @@ +/* + * 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.store; + +import org.apache.tamaya.spi.PropertySource; + +import java.util.Map; + +/** + * Simple abstraction of a property synchronization backend. Most methods are similar + * to a {@link org.apache.tamaya.spi.PropertySource}, enhanced with methods for + * updating the property storage. + */ +public interface WritablePropertySource extends PropertySource{ + + /** + * Loads the property source from its store.. + */ + void load(); + + /** + * Sets the store to the given properties, replacing all previous state. + * @param props the new properties. + */ + void setAll(Map props); + + /** + * Updates/adds all the given entries. + * @param props the entries to be added/updated. + */ + void putAll(Map props); + + /** + * Writes a single entry. + * @param key the key, not null. + * @param value the new value, not null. + */ + void put(String key, String value); + + /** + * Removes all entries. + */ + void clear(); + + /** + * Synchronize the current state with the remote version. + */ + void synch(); + +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java new file mode 100644 index 0000000..b3fe1ee --- /dev/null +++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/DefaultStoredPropertySource.java @@ -0,0 +1,137 @@ +/* + * 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.store.spi; + +import org.apache.tamaya.events.ConfigEventManager; +import org.apache.tamaya.events.FrozenPropertySource; +import org.apache.tamaya.events.delta.ChangeType; +import org.apache.tamaya.events.delta.PropertySourceChange; +import org.apache.tamaya.events.delta.PropertySourceChangeBuilder; +import org.apache.tamaya.spisupport.BasePropertySource; +import org.apache.tamaya.store.PropertyStore; +import org.apache.tamaya.store.WritablePropertySource; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * PropertySource that is connected to a {@link PropertyStore}. + */ +public class DefaultStoredPropertySource extends BasePropertySource + implements WritablePropertySource { + + /** + * The store to be used, not null. + */ + private PropertyStore propertyStore; + + /** + * The last version of stoarge data accessed. + */ + private String lastVersion; + + private Map properties = new HashMap<>(); + + + private FrozenPropertySource currentConfig; + + /** + * Creates a new property source. + * + * @param propertyStore the backend store. + * @param defaultOrdinal the default ordinal to be used. + */ + public DefaultStoredPropertySource(PropertyStore propertyStore, int defaultOrdinal) { + super(defaultOrdinal); + this.propertyStore = Objects.requireNonNull(propertyStore); + this.properties.putAll(this.propertyStore.read()); + } + + @Override + public void load() { + this.properties.clear(); + this.properties.putAll(this.propertyStore.read()); + synch(); + } + + @Override + public String getName() { + return this.propertyStore.getName(); + } + + @Override + public Map getProperties() { + return properties; + } + + @Override + public String get(String key) { + if (!propertyStore.isScannable()) { + return propertyStore.read(key); + } + return properties.get(key); + } + + @Override + public boolean isScannable() { + return propertyStore.isScannable(); + } + + @Override + public String toString() { + return "StoredPropertySource{" + + "propertyStore=" + propertyStore.getName() + + '}'; + } + + @Override + public void setAll(Map props) { + this.properties.clear(); + this.properties.putAll(props); + synch(); + } + + @Override + public void putAll(Map props) { + this.properties.putAll(props); + synch(); + } + + @Override + public void put(String key, String value) { + this.properties.put(key, value); + synch(); + } + + @Override + public void clear() { + this.properties.clear(); + synch(); + } + + @Override + public void synch() { + FrozenPropertySource newConfig = FrozenPropertySource.of(this); + PropertySourceChange change = PropertySourceChangeBuilder.of(currentConfig, ChangeType.UPDATED) + .addChanges(newConfig).build(); + currentConfig = newConfig; + ConfigEventManager.fireEvent(change); + } +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java new file mode 100644 index 0000000..1b20fc1 --- /dev/null +++ b/sandbox/integration/store/src/main/java/org/apache/tamaya/store/spi/PropertyStoreProviderSpi.java @@ -0,0 +1,34 @@ +/* + * 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.store.spi; + +import org.apache.tamaya.store.PropertyStore; + +/** + * Class, that provides access to PropertyStores to be used. + */ +public interface PropertyStoreProviderSpi { + + /** + * Access a {@link PropertyStore} using it's id. + * @param storeId the unique id of the store to use. + * @return + */ + PropertyStore getPropertyStore(String storeId); +} http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java b/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java deleted file mode 100644 index e260732..0000000 --- a/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedKafkaCluster.java +++ /dev/null @@ -1,138 +0,0 @@ -import kafka.server.KafkaConfig; -import kafka.server.KafkaServer; - -import java.io.File; -import java.io.FileNotFoundException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Properties; - -public class EmbeddedKafkaCluster { - private final List ports; - private final String zkConnection; - private final Properties baseProperties; - - private final String brokerList; - - private final List brokers; - private final List logDirs; - - public EmbeddedKafkaCluster(String zkConnection) { - this(zkConnection, new Properties()); - } - - public EmbeddedKafkaCluster(String zkConnection, Properties baseProperties) { - this(zkConnection, baseProperties, Collections.singletonList(-1)); - } - - public EmbeddedKafkaCluster(String zkConnection, Properties baseProperties, List ports) { - this.zkConnection = zkConnection; - this.ports = resolvePorts(ports); - this.baseProperties = baseProperties; - - this.brokers = new ArrayList(); - this.logDirs = new ArrayList(); - - this.brokerList = constructBrokerList(this.ports); - } - - private List resolvePorts(List ports) { - List resolvedPorts = new ArrayList(); - for (Integer port : ports) { - resolvedPorts.add(resolvePort(port)); - } - return resolvedPorts; - } - - private int resolvePort(int port) { - if (port == -1) { - return TestUtils.getAvailablePort(); - } - return port; - } - - private String constructBrokerList(List ports) { - StringBuilder sb = new StringBuilder(); - for (Integer port : ports) { - if (sb.length() > 0) { - sb.append(","); - } - sb.append("localhost:").append(port); - } - return sb.toString(); - } - - public void startup() { - for (int i = 0; i < ports.size(); i++) { - Integer port = ports.get(i); - File logDir = TestUtils.constructTempDir("kafka-local"); - - Properties properties = new Properties(); - properties.putAll(baseProperties); - properties.setProperty("zookeeper.connect", zkConnection); - properties.setProperty("broker.id", String.valueOf(i + 1)); - properties.setProperty("host.name", "localhost"); - properties.setProperty("port", Integer.toString(port)); - properties.setProperty("log.dir", logDir.getAbsolutePath()); - properties.setProperty("log.flush.interval.messages", String.valueOf(1)); - - KafkaServer broker = startBroker(properties); - - brokers.add(broker); - logDirs.add(logDir); - } - } - - - private KafkaServer startBroker(Properties props) { - KafkaServer server = new KafkaServer(new KafkaConfig(props), new SystemTime()); - server.startup(); - return server; - } - - public Properties getProps() { - Properties props = new Properties(); - props.putAll(baseProperties); - props.put("metadata.broker.list", brokerList); - props.put("zookeeper.connect", zkConnection); - return props; - } - - public String getBrokerList() { - return brokerList; - } - - public List getPorts() { - return ports; - } - - public String getZkConnection() { - return zkConnection; - } - - public void shutdown() { - for (KafkaServer broker : brokers) { - try { - broker.shutdown(); - } catch (Exception e) { - e.printStackTrace(); - } - } - for (File logDir : logDirs) { - try { - TestUtils.deleteFile(logDir); - } catch (FileNotFoundException e) { - e.printStackTrace(); - } - } - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("EmbeddedKafkaCluster{"); - sb.append("brokerList='").append(brokerList).append('\''); - sb.append('}'); - return sb.toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java ---------------------------------------------------------------------- diff --git a/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java b/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java deleted file mode 100644 index 54068fc..0000000 --- a/sandbox/integration/zookeeper/src/main/org/apache/tamaya/zookeeper/EmbeddedZookeeper.java +++ /dev/null @@ -1,95 +0,0 @@ -import org.apache.zookeeper.server.NIOServerCnxnFactory; -import org.apache.zookeeper.server.ServerCnxnFactory; -import org.apache.zookeeper.server.ZooKeeperServer; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.InetSocketAddress; - -public class EmbeddedZookeeper { - private int port = -1; - private int tickTime = 500; - - private ServerCnxnFactory factory; - private File snapshotDir; - private File logDir; - - public EmbeddedZookeeper() { - this(-1); - } - - public EmbeddedZookeeper(int port) { - this(port, 500); - } - - public EmbeddedZookeeper(int port, int tickTime) { - this.port = resolvePort(port); - this.tickTime = tickTime; - } - - private int resolvePort(int port) { - if (port == -1) { - return TestUtils.getAvailablePort(); - } - return port; - } - - public void startup() throws IOException{ - if (this.port == -1) { - this.port = TestUtils.getAvailablePort(); - } - this.factory = NIOServerCnxnFactory.createFactory(new InetSocketAddress("localhost", port), 1024); - this.snapshotDir = TestUtils.constructTempDir("embeeded-zk/snapshot"); - this.logDir = TestUtils.constructTempDir("embeeded-zk/log"); - - try { - factory.startup(new ZooKeeperServer(snapshotDir, logDir, tickTime)); - } catch (InterruptedException e) { - throw new IOException(e); - } - } - - - public void shutdown() { - factory.shutdown(); - try { - TestUtils.deleteFile(snapshotDir); - } catch (FileNotFoundException e) { - // ignore - } - try { - TestUtils.deleteFile(logDir); - } catch (FileNotFoundException e) { - // ignore - } - } - - public String getConnection() { - return "localhost:" + port; - } - - public void setPort(int port) { - this.port = port; - } - - public void setTickTime(int tickTime) { - this.tickTime = tickTime; - } - - public int getPort() { - return port; - } - - public int getTickTime() { - return tickTime; - } - - @Override - public String toString() { - final StringBuilder sb = new StringBuilder("EmbeddedZookeeper{"); - sb.append("connection=").append(getConnection()); - sb.append('}'); - return sb.toString(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-tamaya/blob/5e332cbc/sandbox/metamodels/pom.xml ---------------------------------------------------------------------- diff --git a/sandbox/metamodels/pom.xml b/sandbox/metamodels/pom.xml index fcc37ae..4a05846 100644 --- a/sandbox/metamodels/pom.xml +++ b/sandbox/metamodels/pom.xml @@ -34,6 +34,7 @@ under the License. simple + staged