@Test public void testCreatesProxyImplementingAdditionalInterfaces() throws Exception { EntitySpec<Application> spec = EntitySpec.create(Application.class).impl(MyApplicationImpl.class).additionalInterfaces(MyInterface.class); Application app = factory.createEntity(spec, Optional.absent()); Application proxy = factory.createEntityProxy(spec, app); assertFalse(proxy instanceof MyApplicationImpl, "proxy="+proxy); assertTrue(proxy instanceof Application, "proxy="+proxy); assertTrue(proxy instanceof MyInterface, "proxy="+proxy); assertTrue(proxy instanceof EntityProxy, "proxy="+proxy); }
@SuppressWarnings({ "rawtypes", "unchecked" }) private <T extends Entity> org.apache.brooklyn.api.entity.EntitySpec<?> toCoreEntitySpec(Class<T> clazz, String name, Map<String,String> configO, String catalogItemId) { Map<String, String> config = (configO == null) ? Maps.<String,String>newLinkedHashMap() : Maps.newLinkedHashMap(configO); org.apache.brooklyn.api.entity.EntitySpec<? extends Entity> result; if (clazz.isInterface()) { result = org.apache.brooklyn.api.entity.EntitySpec.create(clazz); } else { // If this is a concrete class, particularly for an Application class, we want the proxy // to expose all interfaces it implements. Class interfaceclazz = (Application.class.isAssignableFrom(clazz)) ? Application.class : Entity.class; Set<Class<?>> additionalInterfaceClazzes = Reflections.getInterfacesIncludingClassAncestors(clazz); result = org.apache.brooklyn.api.entity.EntitySpec.create(interfaceclazz).impl(clazz).additionalInterfaces(additionalInterfaceClazzes); } result.catalogItemId(catalogItemId); if (!Strings.isEmpty(name)) result.displayName(name); result.configure( convertFlagsToKeys(result.getImplementation(), config) ); return result; }
@Override protected Entity createMysql() { return app.createAndManageChild(EntitySpec.create(Entity.class, ChefSoloDriverToyMySqlEntity.class). additionalInterfaces(SoftwareProcess.class)); }
@Override protected Entity createMysql() { return app.createAndManageChild(EntitySpec.create(Entity.class, ChefSoloDriverToyMySqlEntity.class). additionalInterfaces(SoftwareProcess.class)); }
return EntitySpec.create(Application.class) .impl((Class<? extends Application>) clazz) .additionalInterfaces(Reflections.getAllInterfaces(clazz)); childSpec = EntitySpec.create(Entity.class) .impl((Class<? extends Application>) clazz) .additionalInterfaces(Reflections.getAllInterfaces(clazz));
private EntitySpec<?> resolveInternal(String localType, BrooklynClassLoadingContext loader) { Maybe<Class<? extends Entity>> javaTypeMaybe = tryLoadJavaType(localType, loader); if (javaTypeMaybe.isAbsent()) throw new IllegalStateException("Could not find "+localType, Maybe.getException(javaTypeMaybe)); Class<? extends Entity> javaType = javaTypeMaybe.get(); EntitySpec<? extends Entity> spec; if (javaType.isInterface()) { spec = EntitySpec.create(javaType); } else { // If this is a concrete class, particularly for an Application class, we want the proxy // to expose all interfaces it implements. Class<? extends Entity> interfaceclazz = (Application.class.isAssignableFrom(javaType)) ? Application.class : Entity.class; List<Class<?>> additionalInterfaceClazzes = Reflections.getAllInterfaces(javaType); @SuppressWarnings({ "rawtypes", "unchecked" }) EntitySpec<?> rawSpec = EntitySpec.create(interfaceclazz) .impl((Class) javaType) .additionalInterfaces(additionalInterfaceClazzes); spec = rawSpec; } spec.stackCatalogItemId(CatalogUtils.getCatalogItemIdFromLoader(loader)); return spec; }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); jmxObjectName = new ObjectName(objectName); // Create an entity and configure it with the above JMX service entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(TestEntityWithJmx.class).additionalInterfaces(UsesJmx.class)); app.start(ImmutableList.of(new SimulatedLocation())); jmxHelper = new JmxHelper(entity); jmxService = new JmxService(entity); }
private org.apache.brooklyn.api.entity.EntitySpec<? extends Entity> toCoreEntitySpec(org.apache.brooklyn.rest.domain.EntitySpec spec) { String type = spec.getType(); String name = spec.getName(); Map<String, String> config = (spec.getConfig() == null) ? Maps.<String,String>newLinkedHashMap() : Maps.newLinkedHashMap(spec.getConfig()); FindItemAndClass itemAndClass = new FindItemAndClass().inferFrom(type); final Class<? extends Entity> clazz = itemAndClass.clazz; org.apache.brooklyn.api.entity.EntitySpec<? extends Entity> result; if (clazz.isInterface()) { result = org.apache.brooklyn.api.entity.EntitySpec.create(clazz); } else { result = org.apache.brooklyn.api.entity.EntitySpec.create(Entity.class).impl(clazz).additionalInterfaces(Reflections.getAllInterfaces(clazz)); } result.catalogItemId(itemAndClass.catalogItemId); if (!Strings.isEmpty(name)) result.displayName(name); result.configure( convertFlagsToKeys(result.getType(), config) ); configureRenderingMetadata(spec, result); return result; }
@BeforeMethod(alwaysRun=true) @Override public void setUp() throws Exception { super.setUp(); // Create an entity and configure it with the above JMX service entity = app.createAndManageChild(EntitySpec.create(TestEntity.class).impl(TestEntityWithJmx.class).additionalInterfaces(UsesJmx.class)); app.start(ImmutableList.of(new SimulatedLocation())); jmxHelper = new JmxHelper(entity); jmxService = new JmxService(entity); }
@Override protected EntitySpec<T> copyFrom(EntitySpec<T> otherSpec) { super.copyFrom(otherSpec) .additionalInterfaces(otherSpec.getAdditionalInterfaces()) .policySpecs(otherSpec.getPolicySpecs()) .policies(otherSpec.getPolicies()) .enricherSpecs(otherSpec.getEnricherSpecs()) .enrichers(otherSpec.getEnrichers()) .addInitializers(otherSpec.getInitializers()) .children(copyFromSpecs(otherSpec.getChildren())) .members(otherSpec.getMembers()) .groups(otherSpec.getGroups()) .locationSpecs(otherSpec.getLocationSpecs()) .locations(otherSpec.getLocations()); if (otherSpec.getParent() != null) parent(otherSpec.getParent()); if (otherSpec.getImplementation() != null) impl(otherSpec.getImplementation()); return this; }