You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/08/19 23:20:56 UTC
[22/62] [abbrv] incubator-brooklyn git commit: rename core’s o.a.b.entity to o.a.b.core.entity
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/EntityFunctions.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/EntityFunctions.java b/core/src/main/java/org/apache/brooklyn/entity/core/EntityFunctions.java
deleted file mode 100644
index f882877..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/EntityFunctions.java
+++ /dev/null
@@ -1,153 +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.brooklyn.entity.core;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.apache.brooklyn.api.entity.Application;
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntityLocal;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.objs.Identifiable;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.entity.lifecycle.ServiceStateLogic;
-import org.apache.brooklyn.util.core.flags.TypeCoercions;
-import org.apache.brooklyn.util.guava.Functionals;
-
-import com.google.common.base.Function;
-import com.google.common.base.Predicate;
-import com.google.common.base.Supplier;
-import com.google.common.base.Suppliers;
-import com.google.common.collect.Iterables;
-
-public class EntityFunctions {
-
- public static <T> Function<Entity, T> attribute(final AttributeSensor<T> attribute) {
- class GetEntityAttributeFunction implements Function<Entity, T> {
- @Override public T apply(Entity input) {
- return (input == null) ? null : input.getAttribute(attribute);
- }
- };
- return new GetEntityAttributeFunction();
- }
-
- public static <T> Function<Entity, T> config(final ConfigKey<T> key) {
- class GetEntityConfigFunction implements Function<Entity, T> {
- @Override public T apply(Entity input) {
- return (input == null) ? null : input.getConfig(key);
- }
- };
- return new GetEntityConfigFunction();
- }
-
- public static Function<Entity, String> displayName() {
- class GetEntityDisplayName implements Function<Entity, String> {
- @Override public String apply(Entity input) {
- return (input == null) ? null : input.getDisplayName();
- }
- };
- return new GetEntityDisplayName();
- }
-
- public static Function<Identifiable, String> id() {
- class GetIdFunction implements Function<Identifiable, String> {
- @Override public String apply(Identifiable input) {
- return (input == null) ? null : input.getId();
- }
- };
- return new GetIdFunction();
- }
-
- /** returns a function which sets the given sensors on the entity passed in,
- * with {@link Entities#UNCHANGED} and {@link Entities#REMOVE} doing those actions. */
- public static Function<Entity,Void> settingSensorsConstant(final Map<AttributeSensor<?>,Object> values) {
- checkNotNull(values, "values");
- class SettingSensorsConstantFunction implements Function<Entity, Void> {
- @SuppressWarnings({ "unchecked", "rawtypes" })
- @Override public Void apply(Entity input) {
- for (Map.Entry<AttributeSensor<?>,Object> entry : values.entrySet()) {
- AttributeSensor sensor = (AttributeSensor)entry.getKey();
- Object value = entry.getValue();
- if (value==Entities.UNCHANGED) {
- // nothing
- } else if (value==Entities.REMOVE) {
- ((EntityInternal)input).removeAttribute(sensor);
- } else {
- value = TypeCoercions.coerce(value, sensor.getTypeToken());
- ((EntityInternal)input).setAttribute(sensor, value);
- }
- }
- return null;
- }
- }
- return new SettingSensorsConstantFunction();
- }
-
- /** as {@link #settingSensorsConstant(Map)} but as a {@link Runnable} */
- public static Runnable settingSensorsConstant(final Entity entity, final Map<AttributeSensor<?>,Object> values) {
- checkNotNull(entity, "entity");
- checkNotNull(values, "values");
- return Functionals.runnable(Suppliers.compose(settingSensorsConstant(values), Suppliers.ofInstance(entity)));
- }
-
- public static <K,V> Function<Entity, Void> updatingSensorMapEntry(final AttributeSensor<Map<K,V>> mapSensor, final K key, final Supplier<? extends V> valueSupplier) {
- class UpdatingSensorMapEntryFunction implements Function<Entity, Void> {
- @Override public Void apply(Entity input) {
- ServiceStateLogic.updateMapSensorEntry((EntityLocal)input, mapSensor, key, valueSupplier.get());
- return null;
- }
- }
- return new UpdatingSensorMapEntryFunction();
- }
- public static <K,V> Runnable updatingSensorMapEntry(final Entity entity, final AttributeSensor<Map<K,V>> mapSensor, final K key, final Supplier<? extends V> valueSupplier) {
- return Functionals.runnable(Suppliers.compose(updatingSensorMapEntry(mapSensor, key, valueSupplier), Suppliers.ofInstance(entity)));
- }
-
- public static Supplier<Collection<Application>> applications(final ManagementContext mgmt) {
- class AppsSupplier implements Supplier<Collection<Application>> {
- @Override
- public Collection<Application> get() {
- return mgmt.getApplications();
- }
- }
- return new AppsSupplier();
- }
-
- public static Function<Entity, Location> locationMatching(Predicate<? super Location> filter) {
- return new LocationMatching(filter);
- }
-
- private static class LocationMatching implements Function<Entity, Location> {
- private Predicate<? super Location> filter;
-
- private LocationMatching() { /* for xstream */
- }
- public LocationMatching(Predicate<? super Location> filter) {
- this.filter = filter;
- }
- @Override public Location apply(Entity input) {
- return Iterables.find(input.getLocations(), filter);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/EntityInitializers.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/EntityInitializers.java b/core/src/main/java/org/apache/brooklyn/entity/core/EntityInitializers.java
deleted file mode 100644
index dfbe3b0..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/EntityInitializers.java
+++ /dev/null
@@ -1,49 +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.brooklyn.entity.core;
-
-import java.util.List;
-
-import org.apache.brooklyn.api.entity.EntityInitializer;
-import org.apache.brooklyn.api.entity.EntityLocal;
-
-import com.google.common.collect.ImmutableList;
-
-public class EntityInitializers {
-
- public static class AddTags implements EntityInitializer {
- public final List<Object> tags;
-
- public AddTags(Object... tags) {
- this.tags = ImmutableList.copyOf(tags);
- }
-
- @Override
- public void apply(EntityLocal entity) {
- for (Object tag: tags)
- entity.tags().addTag(tag);
- }
- }
-
-
- public static EntityInitializer addingTags(Object... tags) {
- return new AddTags(tags);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/EntityInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/EntityInternal.java b/core/src/main/java/org/apache/brooklyn/entity/core/EntityInternal.java
deleted file mode 100644
index 8978791..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/EntityInternal.java
+++ /dev/null
@@ -1,201 +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.brooklyn.entity.core;
-
-import java.util.Collection;
-import java.util.Map;
-
-import org.apache.brooklyn.api.effector.Effector;
-import org.apache.brooklyn.api.entity.EntityLocal;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.mgmt.ExecutionContext;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.mgmt.SubscriptionContext;
-import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
-import org.apache.brooklyn.api.mgmt.rebind.Rebindable;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.EntityMemento;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.api.sensor.Feed;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.mgmt.internal.EntityManagementSupport;
-import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
-import org.apache.brooklyn.entity.core.internal.EntityConfigMap;
-import org.apache.brooklyn.util.core.config.ConfigBag;
-
-import com.google.common.annotations.Beta;
-
-/**
- * Extended Entity interface with additional functionality that is purely-internal (i.e. intended
- * for the brooklyn framework only).
- */
-@Beta
-public interface EntityInternal extends BrooklynObjectInternal, EntityLocal, Rebindable {
-
- void addLocations(Collection<? extends Location> locations);
-
- void removeLocations(Collection<? extends Location> locations);
-
- void clearLocations();
-
- /**
- *
- * Like {@link EntityLocal#setAttribute(AttributeSensor, Object)}, except does not publish an attribute-change event.
- */
- <T> T setAttributeWithoutPublishing(AttributeSensor<T> sensor, T val);
-
- /**
- * @deprecated since 0.7.0; instead just use methods on {@link ConfigurationSupportInternal} returned by {@link #config()}
- */
- @Deprecated
- EntityConfigMap getConfigMap();
-
- /**
- * @return a read-only copy of all the config key/value pairs on this entity.
- *
- * @deprecated since 0.7.0; instead just use methods on {@link ConfigurationSupportInternal} returned by {@link #config()},
- * e.g. getBag().getAllConfigAsConfigKeyMap().
- */
- @Deprecated
- @Beta
- Map<ConfigKey<?>,Object> getAllConfig();
-
- /**
- * Returns a read-only view of all the config key/value pairs on this entity, backed by a string-based map,
- * including config names that did not match anything on this entity.
- *
- * @deprecated since 0.7.0; use {@link #config()}, such as {@code entity.config().getBag()}
- */
- @Deprecated
- ConfigBag getAllConfigBag();
-
- /**
- * Returns a read-only view of the local (i.e. not inherited) config key/value pairs on this entity,
- * backed by a string-based map, including config names that did not match anything on this entity.
- *
- * @deprecated since 0.7.0; use {@link #config()}, such as {@code entity.config().getLocalBag()}
- */
- @Deprecated
- ConfigBag getLocalConfigBag();
-
- @Beta
- Map<AttributeSensor, Object> getAllAttributes();
-
- @Beta
- void removeAttribute(AttributeSensor<?> attribute);
-
- /**
- *
- * @deprecated since 0.7.0; use {@link #config()}, such as {@code entity.config().refreshInheritedConfig()}
- */
- @Deprecated
- void refreshInheritedConfig();
-
- /**
- * Must be called before the entity is started.
- *
- * @return this entity (i.e. itself)
- */
- @Beta // for internal use only
- EntityInternal configure(Map flags);
-
- /**
- * @return Routings for accessing and inspecting the management context of the entity
- */
- EntityManagementSupport getManagementSupport();
-
- /**
- * Should be invoked at end-of-life to clean up the item.
- */
- @Beta
- void destroy();
-
- /**
- * Returns the management context for the entity. If the entity is not yet managed, some
- * operations on the management context will fail.
- *
- * Do not cache this object; instead call getManagementContext() each time you need to use it.
- */
- ManagementContext getManagementContext();
-
- /**
- * Returns the task execution context for the entity. If the entity is not yet managed, some
- * operations on the management context will fail.
- *
- * Do not cache this object; instead call getExecutionContext() each time you need to use it.
- */
- ExecutionContext getExecutionContext();
-
- SubscriptionContext getSubscriptionContext();
-
- /** returns the dynamic type corresponding to the type of this entity instance */
- @Beta
- EntityDynamicType getMutableEntityType();
-
- /** returns the effector registered against a given name */
- @Beta
- Effector<?> getEffector(String effectorName);
-
- FeedSupport feeds();
-
- /**
- * @since 0.7.0-M2
- * @deprecated since 0.7.0-M2; use {@link #feeds()}
- */
- @Deprecated
- FeedSupport getFeedSupport();
-
- Map<String, String> toMetadataRecord();
-
- /**
- * Users are strongly discouraged from calling or overriding this method.
- * It is for internal calls only, relating to persisting/rebinding entities.
- * This method may change (or be removed) in a future release without notice.
- */
- @Override
- @Beta
- RebindSupport<EntityMemento> getRebindSupport();
-
- /**
- * Can be called to request that the entity be persisted.
- * This persistence may happen asynchronously, or may not happen at all if persistence is disabled.
- */
- void requestPersist();
-
- public interface FeedSupport {
- Collection<Feed> getFeeds();
-
- /**
- * Adds the given feed to this entity. The feed will automatically be re-added on brooklyn restart.
- */
- <T extends Feed> T addFeed(T feed);
-
- /**
- * Removes the given feed from this entity.
- * @return True if the feed existed at this entity; false otherwise
- */
- boolean removeFeed(Feed feed);
-
- /**
- * Removes all feeds from this entity.
- * Use with caution as some entities automatically register feeds; this will remove those feeds as well.
- * @return True if any feeds existed at this entity; false otherwise
- */
- boolean removeAllFeeds();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/EntityPredicates.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/EntityPredicates.java b/core/src/main/java/org/apache/brooklyn/entity/core/EntityPredicates.java
deleted file mode 100644
index 3bd83b2..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/EntityPredicates.java
+++ /dev/null
@@ -1,451 +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.brooklyn.entity.core;
-
-import java.util.Collection;
-import java.util.regex.Pattern;
-
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.Group;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
-import org.apache.brooklyn.util.collections.CollectionFunctionals;
-import org.apache.brooklyn.util.guava.SerializablePredicate;
-import org.apache.brooklyn.util.javalang.Reflections;
-import org.apache.brooklyn.util.text.StringPredicates;
-
-import com.google.common.base.Objects;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-
-@SuppressWarnings("serial")
-public class EntityPredicates {
-
- public static Predicate<Entity> idEqualTo(final String val) {
- return idSatisfies(Predicates.equalTo(val));
- }
-
- public static Predicate<Entity> idSatisfies(final Predicate<? super String> condition) {
- return new IdSatisfies(condition);
- }
-
- protected static class IdSatisfies implements SerializablePredicate<Entity> {
- protected final Predicate<? super String> condition;
- protected IdSatisfies(Predicate<? super String> condition) {
- this.condition = condition;
- }
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && condition.apply(input.getId());
- }
- @Override
- public String toString() {
- return "idSatisfies("+condition+")";
- }
- }
-
- /** @deprecated since 0.7.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static <T> Predicate<Entity> idEqualToOld(final T val) {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && Objects.equal(input.getId(), val);
- }
- };
- }
-
- // ---------------------------
-
- public static Predicate<Entity> displayNameEqualTo(final String val) {
- return displayNameSatisfies(Predicates.equalTo(val));
- }
-
- public static Predicate<Entity> displayNameSatisfies(final Predicate<? super String> condition) {
- return new DisplayNameSatisfies(condition);
- }
-
- protected static class DisplayNameSatisfies implements SerializablePredicate<Entity> {
- protected final Predicate<? super String> condition;
- protected DisplayNameSatisfies(Predicate<? super String> condition) {
- this.condition = condition;
- }
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && condition.apply(input.getDisplayName());
- }
- @Override
- public String toString() {
- return "displayNameSatisfies("+condition+")";
- }
- }
-
- /** @deprecated since 0.7.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static <T> Predicate<Entity> displayNameEqualToOld(final T val) {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && Objects.equal(input.getDisplayName(), val);
- }
- };
- }
-
- /** @deprecated since 0.7.0 use {@link #displayNameSatisfies(Predicate)} to clarify this is *regex* matching
- * (passing {@link StringPredicates#matchesRegex(String)} as the predicate) */
- public static Predicate<Entity> displayNameMatches(final String regex) {
- return displayNameSatisfies(StringPredicates.matchesRegex(regex));
- }
-
- /** @deprecated since 0.7.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static class DisplayNameMatches implements SerializablePredicate<Entity> {
- private final String regex;
- DisplayNameMatches(String regex) {
- this.regex = regex;
- }
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null && input.getDisplayName() != null) && input.getDisplayName().matches(regex);
- }
- @Override
- public String toString() {
- return "DisplayNameMatches("+regex+")";
- }
- };
-
- // ---------------------------
-
- public static Predicate<Entity> applicationIdEqualTo(final String val) {
- return applicationIdSatisfies(Predicates.equalTo(val));
- }
-
- public static Predicate<Entity> applicationIdSatisfies(final Predicate<? super String> condition) {
- return new ApplicationIdSatisfies(condition);
- }
-
- protected static class ApplicationIdSatisfies implements SerializablePredicate<Entity> {
- protected final Predicate<? super String> condition;
- protected ApplicationIdSatisfies(Predicate<? super String> condition) {
- this.condition = condition;
- }
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && condition.apply(input.getApplicationId());
- }
- @Override
- public String toString() {
- return "applicationIdSatisfies("+condition+")";
- }
- }
-
- /** @deprecated since 0.7.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static Predicate<Entity> applicationIdEqualToOld(final String val) {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && val.equals(input.getApplicationId());
- }
- };
- }
-
- // ---------------------------
-
- public static <T> Predicate<Entity> attributeEqualTo(final AttributeSensor<T> attribute, final T val) {
- return attributeSatisfies(attribute, Predicates.equalTo(val));
- }
-
- public static <T> Predicate<Entity> attributeSatisfies(final AttributeSensor<T> attribute, final Predicate<T> condition) {
- return new AttributeSatisfies<T>(attribute, condition);
- }
-
- protected static class AttributeSatisfies<T> implements SerializablePredicate<Entity> {
- protected final AttributeSensor<T> attribute;
- protected final Predicate<T> condition;
- private AttributeSatisfies(AttributeSensor<T> attribute, Predicate<T> condition) {
- this.attribute = attribute;
- this.condition = condition;
- }
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && condition.apply(input.getAttribute(attribute));
- }
- @Override
- public String toString() {
- return "attributeSatisfies("+attribute.getName()+","+condition+")";
- }
- }
-
- /** @deprecated since 0.7.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static <T> Predicate<Entity> attributeEqualToOld(final AttributeSensor<T> attribute, final T val) {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && Objects.equal(input.getAttribute(attribute), val);
- }
- };
- }
-
- public static <T> Predicate<Entity> attributeNotEqualTo(final AttributeSensor<T> attribute, final T val) {
- return attributeSatisfies(attribute, Predicates.not(Predicates.equalTo(val)));
- }
-
- // ---------------------------
-
- public static <T> Predicate<Entity> configEqualTo(final ConfigKey<T> configKey, final T val) {
- return configSatisfies(configKey, Predicates.equalTo(val));
- }
-
- public static <T> Predicate<Entity> configSatisfies(final ConfigKey<T> configKey, final Predicate<T> condition) {
- return new ConfigKeySatisfies<T>(configKey, condition);
- }
-
- public static <T> Predicate<Entity> configEqualTo(final HasConfigKey<T> configKey, final T val) {
- return configEqualTo(configKey.getConfigKey(), val);
- }
-
- public static <T> Predicate<Entity> configSatisfies(final HasConfigKey<T> configKey, final Predicate<T> condition) {
- return new ConfigKeySatisfies<T>(configKey.getConfigKey(), condition);
- }
-
- protected static class ConfigKeySatisfies<T> implements SerializablePredicate<Entity> {
- protected final ConfigKey<T> configKey;
- protected final Predicate<T> condition;
- private ConfigKeySatisfies(ConfigKey<T> configKey, Predicate<T> condition) {
- this.configKey = configKey;
- this.condition = condition;
- }
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && condition.apply(input.getConfig(configKey));
- }
- @Override
- public String toString() {
- return "configKeySatisfies("+configKey.getName()+","+condition+")";
- }
- }
-
-
- /** @deprecated since 0.7.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static <T> Predicate<Entity> configEqualToOld(final ConfigKey<T> configKey, final T val) {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && Objects.equal(input.getConfig(configKey), val);
- }
- };
- }
-
- /** @deprecated since 0.7.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static <T> Predicate<Entity> configEqualToOld(final HasConfigKey<T> configKey, final T val) {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && Objects.equal(input.getConfig(configKey), val);
- }
- };
- }
-
- // ---------------------------
-
- /**
- * @param typeRegex a regular expression
- * @return true if any of the interfaces implemented by the entity (including those derived) match typeRegex.
- */
- public static Predicate<Entity> hasInterfaceMatching(String typeRegex) {
- return new ImplementsInterface(typeRegex);
- }
-
- protected static class ImplementsInterface implements SerializablePredicate<Entity> {
- protected final Pattern pattern;
-
- public ImplementsInterface(String typeRegex) {
- this.pattern = Pattern.compile(typeRegex);
- }
-
- @Override
- public boolean apply(@Nullable Entity input) {
- if (input == null) return false;
- for (Class<?> cls : Reflections.getAllInterfaces(input.getClass())) {
- if (pattern.matcher(cls.getName()).matches()) {
- return true;
- }
- }
- return false;
- }
- }
-
- // ---------------------------
-
- /**
- * Returns a predicate that determines if a given entity is a direct child of this {@code parent}.
- */
- public static Predicate<Entity> isChildOf(final Entity parent) {
- return new IsChildOf(parent);
- }
-
- // if needed, could add parentSatisfies(...)
-
- protected static class IsChildOf implements SerializablePredicate<Entity> {
- protected final Entity parent;
- protected IsChildOf(Entity parent) {
- this.parent = parent;
- }
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && Objects.equal(input.getParent(), parent);
- }
- @Override
- public String toString() {
- return "isChildOf("+parent+")";
- }
- }
-
- /** @deprecated since 0.7.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static <T> Predicate<Entity> isChildOfOld(final Entity parent) {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && Objects.equal(input.getParent(), parent);
- }
- };
- }
-
- // ---------------------------
-
- public static Predicate<Entity> isMemberOf(final Group group) {
- return new IsMemberOf(group);
- }
-
- protected static class IsMemberOf implements SerializablePredicate<Entity> {
- protected final Group group;
- protected IsMemberOf(Group group) {
- this.group = group;
- }
- @Override
- public boolean apply(@Nullable Entity input) {
- return (group != null) && (input != null) && group.hasMember(input);
- }
- @Override
- public String toString() {
- return "isMemberOf("+group+")";
- }
- }
-
- /** @deprecated since 0.7.0 kept only to allow conversion of anonymous inner classes */
- @SuppressWarnings("unused") @Deprecated
- private static <T> Predicate<Entity> isMemberOfOld(final Group group) {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && group.hasMember(input);
- }
- };
- }
-
- // ---------------------------
-
- /**
- * Create a predicate that matches any entity who has an exact match for the given location
- * (i.e. {@code entity.getLocations().contains(location)}).
- */
- public static <T> Predicate<Entity> locationsIncludes(Location location) {
- return locationsSatisfy(CollectionFunctionals.contains(location));
-
- }
-
- public static <T> Predicate<Entity> locationsSatisfy(final Predicate<Collection<Location>> condition) {
- return new LocationsSatisfy(condition);
- }
-
- protected static class LocationsSatisfy implements SerializablePredicate<Entity> {
- protected final Predicate<Collection<Location>> condition;
- protected LocationsSatisfy(Predicate<Collection<Location>> condition) {
- this.condition = condition;
- }
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && condition.apply(input.getLocations());
- }
- @Override
- public String toString() {
- return "locationsSatisfy("+condition+")";
- }
- }
-
- /** @deprecated since 0.7.0 use {@link #locationsIncludes(Location)} */
- @Deprecated
- public static <T> Predicate<Entity> withLocation(final Location location) {
- return locationsIncludes(location);
- }
-
- /** @deprecated since 0.7.0 use {@link #locationsIncludes(Location)}, introduced to allow deserialization of anonymous inner class */
- @SuppressWarnings("unused") @Deprecated
- private static <T> Predicate<Entity> withLocationOld(final Location location) {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && input.getLocations().contains(location);
- }
- };
- }
-
- // ---------------------------
-
- public static <T> Predicate<Entity> isManaged() {
- return new IsManaged();
- }
-
- protected static class IsManaged implements SerializablePredicate<Entity> {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && Entities.isManaged(input);
- }
- @Override
- public String toString() {
- return "isManaged()";
- }
- }
-
- /** @deprecated since 0.7.0 use {@link #isManaged()} */ @Deprecated
- public static <T> Predicate<Entity> managed() {
- return isManaged();
- }
-
- /** @deprecated since 0.7.0 use {@link #isManaged()}, introduced to allow deserialization of anonymous inner class */
- @SuppressWarnings("unused") @Deprecated
- private static <T> Predicate<Entity> managedOld() {
- return new SerializablePredicate<Entity>() {
- @Override
- public boolean apply(@Nullable Entity input) {
- return (input != null) && Entities.isManaged(input);
- }
- };
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/EntitySuppliers.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/EntitySuppliers.java b/core/src/main/java/org/apache/brooklyn/entity/core/EntitySuppliers.java
deleted file mode 100644
index 7d5640c..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/EntitySuppliers.java
+++ /dev/null
@@ -1,47 +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.brooklyn.entity.core;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.location.core.Machines;
-import org.apache.brooklyn.location.ssh.SshMachineLocation;
-
-import com.google.common.base.Supplier;
-
-public class EntitySuppliers {
-
- public static Supplier<SshMachineLocation> uniqueSshMachineLocation(Entity entity) {
- return new UniqueSshMchineLocation(entity);
- }
-
- private static class UniqueSshMchineLocation implements Supplier<SshMachineLocation> {
- private Entity entity;
-
- private UniqueSshMchineLocation() { /* for xstream */
- }
-
- private UniqueSshMchineLocation(Entity entity) {
- this.entity = entity;
- }
-
- @Override public SshMachineLocation get() {
- return Machines.findUniqueSshMachineLocation(entity.getLocations()).get();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/EntityTasks.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/EntityTasks.java b/core/src/main/java/org/apache/brooklyn/entity/core/EntityTasks.java
deleted file mode 100644
index e883065..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/EntityTasks.java
+++ /dev/null
@@ -1,81 +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.brooklyn.entity.core;
-
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.mgmt.Task;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.sensor.core.DependentConfiguration;
-import org.apache.brooklyn.util.collections.CollectionFunctionals;
-import org.apache.brooklyn.util.time.Duration;
-
-import com.google.common.base.Functions;
-import com.google.common.base.Predicate;
-import com.google.common.base.Predicates;
-
-/** Generally useful tasks related to entities */
-public class EntityTasks {
-
- /** creates an (unsubmitted) task which waits for the attribute to satisfy the given predicate,
- * returning false if it times out or becomes unmanaged */
- public static <T> Task<Boolean> testingAttributeEventually(Entity entity, AttributeSensor<T> sensor, Predicate<T> condition, Duration timeout) {
- return DependentConfiguration.builder().attributeWhenReady(entity, sensor)
- .readiness(condition)
- .postProcess(Functions.constant(true))
- .timeout(timeout)
- .onTimeoutReturn(false)
- .onUnmanagedReturn(false)
- .build();
- }
-
- /** creates an (unsubmitted) task which waits for the attribute to satisfy the given predicate,
- * throwing if it times out or becomes unmanaged */
- public static <T> Task<Boolean> requiringAttributeEventually(Entity entity, AttributeSensor<T> sensor, Predicate<T> condition, Duration timeout) {
- return DependentConfiguration.builder().attributeWhenReady(entity, sensor)
- .readiness(condition)
- .postProcess(Functions.constant(true))
- .timeout(timeout)
- .onTimeoutThrow()
- .onUnmanagedThrow()
- .build();
- }
-
- /** as {@link #testingAttributeEventually(Entity, AttributeSensor, Predicate, Duration) for multiple entities */
- public static <T> Task<Boolean> testingAttributeEventually(Iterable<Entity> entities, AttributeSensor<T> sensor, Predicate<T> condition, Duration timeout) {
- return DependentConfiguration.builder().attributeWhenReadyFromMultiple(entities, sensor, condition)
- .postProcess(Functions.constant(true))
- .timeout(timeout)
- .onTimeoutReturn(false)
- .onUnmanagedReturn(false)
- .postProcessFromMultiple(CollectionFunctionals.all(Predicates.equalTo(true)))
- .build();
- }
-
- /** as {@link #requiringAttributeEventually(Entity, AttributeSensor, Predicate, Duration) for multiple entities */
- public static <T> Task<Boolean> requiringAttributeEventually(Iterable<Entity> entities, AttributeSensor<T> sensor, Predicate<T> condition, Duration timeout) {
- return DependentConfiguration.builder().attributeWhenReadyFromMultiple(entities, sensor, condition)
- .postProcess(Functions.constant(true))
- .timeout(timeout)
- .onTimeoutThrow()
- .onUnmanagedThrow()
- .postProcessFromMultiple(CollectionFunctionals.all(Predicates.equalTo(true)))
- .build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/EntityTypeSnapshot.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/EntityTypeSnapshot.java b/core/src/main/java/org/apache/brooklyn/entity/core/EntityTypeSnapshot.java
deleted file mode 100644
index 82b58c8..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/EntityTypeSnapshot.java
+++ /dev/null
@@ -1,126 +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.brooklyn.entity.core;
-
-import java.util.Collection;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
-import java.util.Set;
-
-import org.apache.brooklyn.api.effector.Effector;
-import org.apache.brooklyn.api.effector.ParameterType;
-import org.apache.brooklyn.api.entity.EntityType;
-import org.apache.brooklyn.api.sensor.Sensor;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.objs.BrooklynTypeSnapshot;
-import org.apache.brooklyn.util.guava.Maybe;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Objects;
-import com.google.common.base.Objects.ToStringHelper;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-public class EntityTypeSnapshot extends BrooklynTypeSnapshot implements EntityType {
- private static final long serialVersionUID = 4670930188951106009L;
-
- private final Map<String, Sensor<?>> sensors;
- private final Set<Effector<?>> effectors;
- private final Set<Sensor<?>> sensorsSet;
-
- EntityTypeSnapshot(String name, Map<String, ConfigKey<?>> configKeys, Map<String, Sensor<?>> sensors, Collection<Effector<?>> effectors) {
- super(name, configKeys);
- this.sensors = ImmutableMap.copyOf(sensors);
- this.effectors = ImmutableSet.copyOf(effectors);
- this.sensorsSet = ImmutableSet.copyOf(this.sensors.values());
- }
-
- @Override
- public Set<Sensor<?>> getSensors() {
- return sensorsSet;
- }
-
- @Override
- public Set<Effector<?>> getEffectors() {
- return effectors;
- }
-
- @Override
- public Maybe<Effector<?>> getEffectorByName(String name) {
- for (Effector<?> contender : effectors) {
- if (name.equals(contender.getName()))
- return Maybe.<Effector<?>>of(contender);
- }
- return Maybe.<Effector<?>>absent("No effector matching '"+name+"'");
- }
-
- @Override
- public Effector<?> getEffector(String name, Class<?>... parameterTypes) {
- // TODO Could index for more efficient lookup (e.g. by name in a MultiMap, or using name+parameterTypes as a key)
- // TODO Looks for exact match; could go for what would be valid to call (i.e. if parameterType is sub-class of ParameterType.getParameterClass then ok)
- // TODO Could take into account ParameterType.getDefaultValue() for what can be omitted
-
- effectorLoop : for (Effector<?> contender : effectors) {
- if (name.equals(contender.getName())) {
- List<ParameterType<?>> contenderParameters = contender.getParameters();
- if (parameterTypes.length == contenderParameters.size()) {
- for (int i = 0; i < parameterTypes.length; i++) {
- if (parameterTypes[i] != contenderParameters.get(i).getParameterClass()) {
- continue effectorLoop;
- }
- }
- return contender;
- }
- }
- }
- throw new NoSuchElementException("No matching effector "+name+"("+Joiner.on(", ").join(parameterTypes)+") on entity "+getName());
- }
-
- @Override
- public Sensor<?> getSensor(String name) {
- return sensors.get(name);
- }
-
- @Override
- public boolean hasSensor(String name) {
- return sensors.containsKey(name);
- }
-
- @Override
- public int hashCode() {
- return Objects.hashCode(super.hashCode(), sensors, effectors);
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) return true;
- if (!(obj instanceof EntityTypeSnapshot)) return false;
- EntityTypeSnapshot o = (EntityTypeSnapshot) obj;
-
- return super.equals(obj) && Objects.equal(sensors, o.sensors) && Objects.equal(effectors, o.effectors);
- }
-
- @Override
- protected ToStringHelper toStringHelper() {
- return super.toStringHelper()
- .add("sensors", sensors)
- .add("effectors", effectors);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/EntityTypes.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/EntityTypes.java b/core/src/main/java/org/apache/brooklyn/entity/core/EntityTypes.java
deleted file mode 100644
index a5ee9e8..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/EntityTypes.java
+++ /dev/null
@@ -1,28 +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.brooklyn.entity.core;
-
-import org.apache.brooklyn.core.objs.BrooklynTypes;
-
-/**
- * @deprecated since 0.7.0; use {@link BrooklynTypes}
- */
-@Deprecated
-public class EntityTypes extends BrooklynTypes {
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/StartableApplication.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/StartableApplication.java b/core/src/main/java/org/apache/brooklyn/entity/core/StartableApplication.java
deleted file mode 100644
index 5a48c3a..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/StartableApplication.java
+++ /dev/null
@@ -1,25 +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.brooklyn.entity.core;
-
-import org.apache.brooklyn.api.entity.Application;
-import org.apache.brooklyn.entity.trait.Startable;
-
-public interface StartableApplication extends Application, Startable {
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/internal/ConfigMapViewWithStringKeys.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/internal/ConfigMapViewWithStringKeys.java b/core/src/main/java/org/apache/brooklyn/entity/core/internal/ConfigMapViewWithStringKeys.java
deleted file mode 100644
index 73678db..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/internal/ConfigMapViewWithStringKeys.java
+++ /dev/null
@@ -1,130 +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.brooklyn.entity.core.internal;
-
-import java.util.Collection;
-import java.util.LinkedHashSet;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.config.BasicConfigKey;
-
-import com.google.common.annotations.Beta;
-import com.google.common.collect.Sets;
-
-/**
- * Internal class that presents a view over a ConfigMap, so it looks like a Map (with the
- * keys being the config key names).
- */
-@Beta
-public class ConfigMapViewWithStringKeys implements Map<String,Object> {
-
- private org.apache.brooklyn.config.ConfigMap target;
-
- public ConfigMapViewWithStringKeys(org.apache.brooklyn.config.ConfigMap target) {
- this.target = target;
- }
-
- @Override
- public int size() {
- return target.getAllConfig().size();
- }
-
- @Override
- public boolean isEmpty() {
- return target.getAllConfig().isEmpty();
- }
-
- @Override
- public boolean containsKey(Object key) {
- return keySet().contains(key);
- }
-
- @Override
- public boolean containsValue(Object value) {
- return values().contains(value);
- }
-
- @Override
- public Object get(Object key) {
- return target.getConfig(new BasicConfigKey<Object>(Object.class, (String)key));
- }
-
- @Override
- public Object put(String key, Object value) {
- throw new UnsupportedOperationException("This view is read-only");
- }
-
- @Override
- public Object remove(Object key) {
- throw new UnsupportedOperationException("This view is read-only");
- }
-
- @Override
- public void putAll(Map<? extends String, ? extends Object> m) {
- throw new UnsupportedOperationException("This view is read-only");
- }
-
- @Override
- public void clear() {
- throw new UnsupportedOperationException("This view is read-only");
- }
-
- @Override
- public Set<String> keySet() {
- LinkedHashSet<String> result = Sets.newLinkedHashSet();
- Set<Map.Entry<ConfigKey<?>, Object>> set = target.getAllConfig().entrySet();
- for (final Map.Entry<ConfigKey<?>, Object> entry: set) {
- result.add(entry.getKey().getName());
- }
- return result;
- }
-
- @Override
- public Collection<Object> values() {
- return target.getAllConfig().values();
- }
-
- @Override
- public Set<Map.Entry<String, Object>> entrySet() {
- LinkedHashSet<Map.Entry<String, Object>> result = Sets.newLinkedHashSet();
- Set<Map.Entry<ConfigKey<?>, Object>> set = target.getAllConfig().entrySet();
- for (final Map.Entry<ConfigKey<?>, Object> entry: set) {
- result.add(new Map.Entry<String, Object>() {
- @Override
- public String getKey() {
- return entry.getKey().getName();
- }
-
- @Override
- public Object getValue() {
- return entry.getValue();
- }
-
- @Override
- public Object setValue(Object value) {
- return entry.setValue(value);
- }
- });
- }
- return result;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/internal/EntityConfigMap.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/internal/EntityConfigMap.java b/core/src/main/java/org/apache/brooklyn/entity/core/internal/EntityConfigMap.java
deleted file mode 100644
index 5cfea3c..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/internal/EntityConfigMap.java
+++ /dev/null
@@ -1,306 +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.brooklyn.entity.core.internal;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.apache.brooklyn.util.GroovyJavaMethods.elvis;
-
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-
-import org.apache.brooklyn.api.mgmt.ExecutionContext;
-import org.apache.brooklyn.api.mgmt.Task;
-import org.apache.brooklyn.config.ConfigInheritance;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.config.Sanitizer;
-import org.apache.brooklyn.core.config.StructuredConfigKey;
-import org.apache.brooklyn.core.config.internal.AbstractConfigMapImpl;
-import org.apache.brooklyn.entity.core.AbstractEntity;
-import org.apache.brooklyn.util.collections.MutableMap;
-import org.apache.brooklyn.util.core.config.ConfigBag;
-import org.apache.brooklyn.util.core.flags.FlagUtils;
-import org.apache.brooklyn.util.core.flags.SetFromFlag;
-import org.apache.brooklyn.util.core.flags.TypeCoercions;
-import org.apache.brooklyn.util.core.internal.ConfigKeySelfExtracting;
-import org.apache.brooklyn.util.guava.Maybe;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import com.google.common.base.Predicate;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-
-public class EntityConfigMap extends AbstractConfigMapImpl {
-
- private static final Logger LOG = LoggerFactory.getLogger(EntityConfigMap.class);
-
- /** entity against which config resolution / task execution will occur */
- private final AbstractEntity entity;
-
- /**
- * Map of configuration information that is defined at start-up time for the entity. These
- * configuration parameters are shared and made accessible to the "children" of this
- * entity.
- */
- private final Map<ConfigKey<?>,Object> inheritedConfig = Collections.synchronizedMap(new LinkedHashMap<ConfigKey<?>, Object>());
- // TODO do we really want to have *both* bags and maps for these? danger that they get out of synch.
- // have added some logic (Oct 2014) so that the same changes are applied to both, in most places at least;
- // i (alex) think we should prefer ConfigBag (the input keys don't matter, it is more a question of retrieval keys),
- // but first we need ConfigBag to support StructuredConfigKeys
- private final ConfigBag localConfigBag;
- private final ConfigBag inheritedConfigBag;
-
- public EntityConfigMap(AbstractEntity entity, Map<ConfigKey<?>, Object> storage) {
- this.entity = checkNotNull(entity, "entity must be specified");
- this.ownConfig = checkNotNull(storage, "storage map must be specified");
-
- // TODO store ownUnused in backing-storage
- this.localConfigBag = ConfigBag.newInstance();
- this.inheritedConfigBag = ConfigBag.newInstance();
- }
-
- @SuppressWarnings("unchecked")
- public <T> T getConfig(ConfigKey<T> key, T defaultValue) {
- // FIXME What about inherited task in config?!
- // alex says: think that should work, no?
- // FIXME What if someone calls getConfig on a task, before setting parent app?
- // alex says: not supported (throw exception, or return the task)
-
- // In case this entity class has overridden the given key (e.g. to set default), then retrieve this entity's key
- // TODO If ask for a config value that's not in our configKeys, should we really continue with rest of method and return key.getDefaultValue?
- // e.g. SshBasedJavaAppSetup calls setAttribute(JMX_USER), which calls getConfig(JMX_USER)
- // but that example doesn't have a default...
- ConfigKey<T> ownKey = entity!=null ? (ConfigKey<T>)elvis(entity.getEntityType().getConfigKey(key.getName()), key) : key;
-
- ConfigInheritance inheritance = key.getInheritance();
- if (inheritance==null) inheritance = ownKey.getInheritance();
- if (inheritance==null) {
- // TODO we could warn by introducing a temporary "ALWAYS_BUT_WARNING" instance
- inheritance = getDefaultInheritance();
- }
-
- // TODO We're notifying of config-changed because currently persistence needs to know when the
- // attributeWhenReady is complete (so it can persist the result).
- // Long term, we'll just persist tasks properly so the call to onConfigChanged will go!
-
- // Don't use groovy truth: if the set value is e.g. 0, then would ignore set value and return default!
- if (ownKey instanceof ConfigKeySelfExtracting) {
- Object rawval = ownConfig.get(key);
- T result = null;
- boolean complete = false;
- if (((ConfigKeySelfExtracting<T>)ownKey).isSet(ownConfig)) {
- ExecutionContext exec = entity.getExecutionContext();
- result = ((ConfigKeySelfExtracting<T>)ownKey).extractValue(ownConfig, exec);
- complete = true;
- } else if (isInherited(ownKey, inheritance) &&
- ((ConfigKeySelfExtracting<T>)ownKey).isSet(inheritedConfig)) {
- ExecutionContext exec = entity.getExecutionContext();
- result = ((ConfigKeySelfExtracting<T>)ownKey).extractValue(inheritedConfig, exec);
- complete = true;
- } else if (localConfigBag.containsKey(ownKey)) {
- // TODO configBag.get doesn't handle tasks/attributeWhenReady - it only uses TypeCoercions
- result = localConfigBag.get(ownKey);
- complete = true;
- } else if (isInherited(ownKey, inheritance) &&
- inheritedConfigBag.containsKey(ownKey)) {
- result = inheritedConfigBag.get(ownKey);
- complete = true;
- }
-
- if (rawval instanceof Task) {
- entity.getManagementSupport().getEntityChangeListener().onConfigChanged(key);
- }
- if (complete) {
- return result;
- }
- } else {
- LOG.warn("Config key {} of {} is not a ConfigKeySelfExtracting; cannot retrieve value; returning default", ownKey, this);
- }
- return TypeCoercions.coerce((defaultValue != null) ? defaultValue : ownKey.getDefaultValue(), key.getTypeToken());
- }
-
- private <T> boolean isInherited(ConfigKey<T> key) {
- return isInherited(key, key.getInheritance());
- }
- private <T> boolean isInherited(ConfigKey<T> key, ConfigInheritance inheritance) {
- if (inheritance==null) inheritance = getDefaultInheritance();
- return inheritance.isInherited(key, entity.getParent(), entity);
- }
- private ConfigInheritance getDefaultInheritance() {
- return ConfigInheritance.ALWAYS;
- }
-
- @Override
- public Maybe<Object> getConfigRaw(ConfigKey<?> key, boolean includeInherited) {
- if (ownConfig.containsKey(key)) return Maybe.of(ownConfig.get(key));
- if (includeInherited && inheritedConfig.containsKey(key)) return Maybe.of(inheritedConfig.get(key));
- return Maybe.absent();
- }
-
- /** an immutable copy of the config visible at this entity, local and inherited (preferring local) */
- public Map<ConfigKey<?>,Object> getAllConfig() {
- Map<ConfigKey<?>,Object> result = new LinkedHashMap<ConfigKey<?>,Object>(inheritedConfig.size()+ownConfig.size());
- result.putAll(inheritedConfig);
- result.putAll(ownConfig);
- return Collections.unmodifiableMap(result);
- }
-
- /** an immutable copy of the config defined at this entity, ie not inherited */
- public Map<ConfigKey<?>,Object> getLocalConfig() {
- Map<ConfigKey<?>,Object> result = new LinkedHashMap<ConfigKey<?>,Object>(ownConfig.size());
- result.putAll(ownConfig);
- return Collections.unmodifiableMap(result);
- }
-
- /** Creates an immutable copy of the config visible at this entity, local and inherited (preferring local), including those that did not match config keys */
- public ConfigBag getAllConfigBag() {
- return ConfigBag.newInstanceCopying(localConfigBag)
- .putAll(ownConfig)
- .putIfAbsent(inheritedConfig)
- .putIfAbsent(inheritedConfigBag)
- .seal();
- }
-
- /** Creates an immutable copy of the config defined at this entity, ie not inherited, including those that did not match config keys */
- public ConfigBag getLocalConfigBag() {
- return ConfigBag.newInstanceCopying(localConfigBag)
- .putAll(ownConfig)
- .seal();
- }
-
- @SuppressWarnings("unchecked")
- public Object setConfig(ConfigKey<?> key, Object v) {
- Object val = coerceConfigVal(key, v);
- Object oldVal;
- if (key instanceof StructuredConfigKey) {
- oldVal = ((StructuredConfigKey)key).applyValueToMap(val, ownConfig);
- // TODO ConfigBag does not handle structured config keys; quick fix is to remove (and should also remove any subkeys;
- // as it stands if someone set string a.b.c in the config bag then removed structured key a.b, then got a.b.c they'd get a vale);
- // long term fix is to support structured config keys in ConfigBag, at which point i think we could remove ownConfig altogether
- localConfigBag.remove(key);
- } else {
- oldVal = ownConfig.put(key, val);
- localConfigBag.put((ConfigKey<Object>)key, v);
- }
- entity.config().refreshInheritedConfigOfChildren();
- return oldVal;
- }
-
- public void setLocalConfig(Map<ConfigKey<?>, ?> vals) {
- ownConfig.clear();
- localConfigBag.clear();
- ownConfig.putAll(vals);
- localConfigBag.putAll(vals);
- }
-
- public void setInheritedConfig(Map<ConfigKey<?>, ?> valsO, ConfigBag configBagVals) {
- Map<ConfigKey<?>, ?> vals = filterUninheritable(valsO);
-
- inheritedConfig.clear();
- inheritedConfig.putAll(vals);
-
- // The configBagVals contains all inherited, including strings that did not match a config key on the parent.
- // They might match a config-key on this entity though, so need to check that:
- // - if it matches one of our keys, set it in inheritedConfig
- // - otherwise add it to our inheritedConfigBag
- Set<String> valKeyNames = Sets.newLinkedHashSet();
- for (ConfigKey<?> key : vals.keySet()) {
- valKeyNames.add(key.getName());
- }
- Map<String,Object> valsUnmatched = MutableMap.<String,Object>builder()
- .putAll(configBagVals.getAllConfig())
- .removeAll(valKeyNames)
- .build();
- inheritedConfigBag.clear();
- Map<ConfigKey<?>, SetFromFlag> annotatedConfigKeys = FlagUtils.getAnnotatedConfigKeys(entity.getClass());
- Map<String, ConfigKey<?>> renamedConfigKeys = Maps.newLinkedHashMap();
- for (Map.Entry<ConfigKey<?>, SetFromFlag> entry: annotatedConfigKeys.entrySet()) {
- String rename = entry.getValue().value();
- if (rename != null) {
- renamedConfigKeys.put(rename, entry.getKey());
- }
- }
- for (Map.Entry<String,Object> entry : valsUnmatched.entrySet()) {
- String name = entry.getKey();
- Object value = entry.getValue();
- ConfigKey<?> key = renamedConfigKeys.get(name);
- if (key == null) key = entity.getEntityType().getConfigKey(name);
- if (key != null) {
- if (!isInherited(key)) {
- // no-op
- } else if (inheritedConfig.containsKey(key)) {
- LOG.warn("Entity "+entity+" inherited duplicate config for key "+key+", via explicit config and string name "+name+"; using value of key");
- } else {
- inheritedConfig.put(key, value);
- }
- } else {
- // a config bag has discarded the keys, so we must assume default inheritance for things given that way
- // unless we can infer a key; not a big deal, as we should have the key in inheritedConfig for everything
- // which originated with a key ... but still, it would be nice to clean up the use of config bag!
- inheritedConfigBag.putStringKey(name, value);
- }
- }
- }
-
- private Map<ConfigKey<?>, ?> filterUninheritable(Map<ConfigKey<?>, ?> vals) {
- Map<ConfigKey<?>, Object> result = Maps.newLinkedHashMap();
- for (Map.Entry<ConfigKey<?>, ?> entry : vals.entrySet()) {
- if (isInherited(entry.getKey())) {
- result.put(entry.getKey(), entry.getValue());
- }
- }
- return result;
- }
-
- public void addToLocalBag(Map<String,?> vals) {
- localConfigBag.putAll(vals);
- // quick fix for problem that ownConfig can get out of synch
- ownConfig.putAll(localConfigBag.getAllConfigAsConfigKeyMap());
- }
-
- public void removeFromLocalBag(String key) {
- localConfigBag.remove(key);
- ownConfig.remove(key);
- }
-
- public void clearInheritedConfig() {
- inheritedConfig.clear();
- inheritedConfigBag.clear();
- }
-
- @Override
- public EntityConfigMap submap(Predicate<ConfigKey<?>> filter) {
- EntityConfigMap m = new EntityConfigMap(entity, Maps.<ConfigKey<?>, Object>newLinkedHashMap());
- for (Map.Entry<ConfigKey<?>,Object> entry: inheritedConfig.entrySet())
- if (filter.apply(entry.getKey()))
- m.inheritedConfig.put(entry.getKey(), entry.getValue());
- for (Map.Entry<ConfigKey<?>,Object> entry: ownConfig.entrySet())
- if (filter.apply(entry.getKey()))
- m.ownConfig.put(entry.getKey(), entry.getValue());
- return m;
- }
-
- @Override
- public String toString() {
- return super.toString()+"[own="+Sanitizer.sanitize(ownConfig)+"; inherited="+Sanitizer.sanitize(inheritedConfig)+"]";
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/core/internal/EntityTransientCopyInternal.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/core/internal/EntityTransientCopyInternal.java b/core/src/main/java/org/apache/brooklyn/entity/core/internal/EntityTransientCopyInternal.java
deleted file mode 100644
index bf1c29c..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/core/internal/EntityTransientCopyInternal.java
+++ /dev/null
@@ -1,121 +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.brooklyn.entity.core.internal;
-
-import java.util.Collection;
-import java.util.Map;
-
-import javax.annotation.Nullable;
-
-import org.apache.brooklyn.api.effector.Effector;
-import org.apache.brooklyn.api.entity.Application;
-import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntityType;
-import org.apache.brooklyn.api.entity.Group;
-import org.apache.brooklyn.api.location.Location;
-import org.apache.brooklyn.api.mgmt.ExecutionContext;
-import org.apache.brooklyn.api.mgmt.ManagementContext;
-import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
-import org.apache.brooklyn.api.mgmt.rebind.mementos.EntityMemento;
-import org.apache.brooklyn.api.objs.BrooklynObject.TagSupport;
-import org.apache.brooklyn.api.policy.Policy;
-import org.apache.brooklyn.api.sensor.AttributeSensor;
-import org.apache.brooklyn.api.sensor.Enricher;
-import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
-import org.apache.brooklyn.core.mgmt.internal.EntityManagementSupport;
-import org.apache.brooklyn.core.objs.proxy.EntityProxyImpl;
-import org.apache.brooklyn.entity.core.EntityInternal;
-import org.apache.brooklyn.entity.core.EntityInternal.FeedSupport;
-import org.apache.brooklyn.util.core.config.ConfigBag;
-import org.apache.brooklyn.util.guava.Maybe;
-
-import com.google.common.annotations.Beta;
-
-/**
- * Selected methods from {@link EntityInternal} and parents which are permitted
- * for entities being loaded in read-only mode, enforced by {@link EntityProxyImpl}.
- * <p>
- * Some of these methods do expose write capabilities, but such modifications are likely
- * to be temporary, discarded on next rebind. Callers must take care with any such invocations.
- * (The primary intent of this interface is to catch and prevent *most* such invocations!)
- */
-@Beta
-public interface EntityTransientCopyInternal {
-
- // TODO For feeds() and config(), need to ensure mutator methods on returned object are not invoked.
-
- // from Entity
-
- String getId();
- long getCreationTime();
- String getDisplayName();
- @Nullable String getIconUrl();
- EntityType getEntityType();
- Application getApplication();
- String getApplicationId();
- Entity getParent();
- Collection<Entity> getChildren();
- Collection<Policy> getPolicies();
- Collection<Enricher> getEnrichers();
- Collection<Group> getGroups();
- Collection<Location> getLocations();
- <T> T getAttribute(AttributeSensor<T> sensor);
- <T> T getConfig(ConfigKey<T> key);
- <T> T getConfig(HasConfigKey<T> key);
- Maybe<Object> getConfigRaw(ConfigKey<?> key, boolean includeInherited);
- Maybe<Object> getConfigRaw(HasConfigKey<?> key, boolean includeInherited);
- TagSupport tags();
- String getCatalogItemId();
-
-
- // from entity local
-
- @Deprecated <T> T getConfig(ConfigKey<T> key, T defaultValue);
- @Deprecated <T> T getConfig(HasConfigKey<T> key, T defaultValue);
-
-
- // from EntityInternal:
-
- @Deprecated EntityConfigMap getConfigMap();
- @Deprecated Map<ConfigKey<?>,Object> getAllConfig();
- // for rebind mainly:
- @Deprecated ConfigBag getAllConfigBag();
- @Deprecated ConfigBag getLocalConfigBag();
- @SuppressWarnings("rawtypes")
- Map<AttributeSensor, Object> getAllAttributes();
- EntityManagementSupport getManagementSupport();
- ManagementContext getManagementContext();
- Effector<?> getEffector(String effectorName);
- @Deprecated FeedSupport getFeedSupport();
- FeedSupport feeds();
- RebindSupport<EntityMemento> getRebindSupport();
- // for REST calls on read-only entities which want to resolve values
- ExecutionContext getExecutionContext();
- void setCatalogItemId(String id);
-
- /** more methods, but which are only on selected entities */
- public interface SpecialEntityTransientCopyInternal {
- // from Group
- Collection<Entity> getMembers();
- boolean hasMember(Entity member);
- Integer getCurrentSize();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c27cf1d0/core/src/main/java/org/apache/brooklyn/entity/drivers/BasicEntityDriverManager.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/entity/drivers/BasicEntityDriverManager.java b/core/src/main/java/org/apache/brooklyn/entity/drivers/BasicEntityDriverManager.java
deleted file mode 100644
index bd49935..0000000
--- a/core/src/main/java/org/apache/brooklyn/entity/drivers/BasicEntityDriverManager.java
+++ /dev/null
@@ -1,56 +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.brooklyn.entity.drivers;
-
-import org.apache.brooklyn.api.entity.drivers.DriverDependentEntity;
-import org.apache.brooklyn.api.entity.drivers.EntityDriver;
-import org.apache.brooklyn.api.entity.drivers.EntityDriverManager;
-import org.apache.brooklyn.api.location.Location;
-
-import com.google.common.annotations.Beta;
-
-public class BasicEntityDriverManager implements EntityDriverManager {
-
- private final RegistryEntityDriverFactory registry;
- private final ReflectiveEntityDriverFactory reflective;
-
- public BasicEntityDriverManager() {
- registry = new RegistryEntityDriverFactory();
- reflective = new ReflectiveEntityDriverFactory();
- }
-
- /** driver override mechanism; experimental @since 0.7.0 */
- @Beta
- public ReflectiveEntityDriverFactory getReflectiveDriverFactory() {
- return reflective;
- }
-
- public <D extends EntityDriver> void registerDriver(Class<D> driverInterface, Class<? extends Location> locationClazz, Class<? extends D> driverClazz) {
- registry.registerDriver(driverInterface, locationClazz, driverClazz);
- }
-
- @Override
- public <D extends EntityDriver> D build(DriverDependentEntity<D> entity, Location location){
- if (registry.hasDriver(entity, location)) {
- return registry.build(entity, location);
- } else {
- return reflective.build(entity, location);
- }
- }
-}
\ No newline at end of file