/** * See {@link #configure(Map)} * * @deprecated since 0.7.0; only used for legacy brooklyn types where constructor is called directly */ @Deprecated protected BrooklynObjectInternal configure() { return configure(Collections.emptyMap()); }
@Override public boolean addTag(Object tag) { boolean result; synchronized (tags) { result = tags.add(tag); } onTagsChanged(); return result; }
protected void instanceRebind(AbstractBrooklynObject instance) { instance.rebind(); }
@SuppressWarnings({ "unchecked", "rawtypes" }) protected void addRelations(RebindContext rebindContext, T memento) { for (Map.Entry<String,Set<String>> rEntry : memento.getRelations().entrySet()) { RelationshipType<? extends BrooklynObject, ? extends BrooklynObject> r = EntityRelations.lookup(instance.getManagementContext(), rEntry.getKey()); if (r==null) throw new IllegalStateException("Unsupported relationship -- "+rEntry.getKey() + " -- in "+memento); for (String itemId: rEntry.getValue()) { BrooklynObject item = rebindContext.lookup().lookup(null, itemId); if (item != null) { instance.relations().add((RelationshipType)r, item); } else { LOG.warn("Item not found; discarding item {} relation {} of entity {}({})", new Object[] {itemId, r, memento.getType(), memento.getId()}); rebindContext.getExceptionHandler().onDanglingUntypedItemRef(itemId); } } } }
@SuppressWarnings("unchecked") @Override public RelationSupportInternal<Location> relations() { return (RelationSupportInternal<Location>) super.relations(); }
@Override public void setCatalogItemIdAndSearchPath(String catalogItemId, List<String> ids) { setCatalogItemId(catalogItemId); synchronized (searchPath) { searchPath.clear(); searchPath.addAll(ids); } }
@Override public void init() { super.init(); loadExtension(); }
@Override public void run() { requestPersist(); } }
protected BrooklynDynamicType(Class<? extends T> clazz, AbstractT instance) { this.brooklynClass = checkNotNull(clazz, "brooklyn class"); this.instance = instance; // NB: official name is usually injected later, e.g. from AbstractEntity.setManagementContext this.name = (clazz.getCanonicalName() == null) ? clazz.getName() : clazz.getCanonicalName(); buildConfigKeys(clazz, null, configKeys); if (LOG.isTraceEnabled()) LOG.trace("Entity {} config keys: {}", (instance==null ? clazz.getName() : instance.getId()), Joiner.on(", ").join(configKeys.keySet())); }
protected void requestPersist() { if (getManagementContext() != null) { getManagementContext().getRebindManager().getChangeListener().onChanged(this); } else { // Might be nice to log this at debug but it gets hit a lot of times as locations // are created and destroyed for the API. It also might not be an error - the // management context might be null if the object is being recreated by persistence. if (log.isTraceEnabled() && !hasWarnedOfNoManagementContextWhenPersistRequested) { log.trace("Cannot fulfil request to persist {} because it has no management context. " + "This warning will not be logged for this object again.", this); hasWarnedOfNoManagementContextWhenPersistRequested = true; } } }
public AbstractBrooklynObject(Map<?, ?> properties) { _legacyConstruction = !InternalFactory.FactoryConstructionTracker.isConstructing(); if (!_legacyConstruction && properties != null && !properties.isEmpty()) { log.warn("Forcing use of deprecated old-style construction for {} because properties were " + "specified ({}); instead use specs (e.g. LocationSpec, EntitySpec, etc)", getClass().getName(), properties); if (log.isDebugEnabled()) log.debug("Source of use of old-style construction", new Throwable("Source of use of old-style construction")); _legacyConstruction = true; } // inherit any context for search purposes (though maybe that should be done when creating the spec?) addSearchPath(MutableList.<String>of().appendIfNotNull(ApiObjectsFactory.get().getCatalogItemIdFromContext())); // rely on sub-class to call configure(properties), because otherwise its fields will not have been initialised }
@SuppressWarnings("unchecked") @Override public RelationSupportInternal<Entity> relations() { return (RelationSupportInternal<Entity>) super.relations(); }
@Override public void stackCatalogItemId(String id) { if (null != id) { if (null != catalogItemId && !catalogItemId.equals(id)) { synchronized (searchPath) { Set<String> newPath = MutableSet.of(); newPath.add(catalogItemId); newPath.addAll(searchPath); searchPath.clear(); searchPath.addAll(newPath); } } setCatalogItemId(id); } }
/** * Default entity initialization sets ID sensors and calls {@link #initEnrichers()}. */ @Override public void init() { super.init(); initEnrichers(); if (Strings.isNonBlank(getConfig(DEFAULT_DISPLAY_NAME))) { setDefaultDisplayName(getConfig(DEFAULT_DISPLAY_NAME)); } sensors().set(ENTITY_ID, getId()); sensors().set(APPLICATION_ID, getApplicationId()); sensors().set(CATALOG_ID, getCatalogItemId()); }
protected void onTagsChanged() { requestPersist(); }
@Override public boolean addTags(Iterable<?> newTags) { boolean result; synchronized (tags) { result = Iterables.addAll(tags, newTags); } onTagsChanged(); return result; }
@Override public void rebind() { super.rebind(); loadExtension(); }
@Override public boolean removeTag(Object tag) { boolean result; synchronized (tags) { result = tags.remove(tag); } onTagsChanged(); return result; } }
@Override protected void onTagsChanged() { super.onTagsChanged(); getManagementSupport().getEntityChangeListener().onTagsChanged(); }