本文整理了Java中brooklyn.entity.basic.Entities
类的一些代码示例,展示了Entities
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Entities
类的具体详情如下:
包路径:brooklyn.entity.basic.Entities
类名称:Entities
[英]Convenience methods for working with entities.
Also see the various Methods classes for traits, such as StartableMethods for Startable implementations.
[中]使用实体的便捷方法。
另请参阅各种方法类以了解特性,例如用于Startable实现的StartableMethods。
代码示例来源:origin: io.brooklyn/brooklyn-core
/** convenience for starting an entity, esp a new Startable instance which has been created dynamically
* (after the application is started) */
public static void start(Entity e, Collection<? extends Location> locations) {
if (!isManaged(e) && !manage(e)) {
log.warn("Using discouraged mechanism to start management -- Entities.start(Application, Locations) -- caller should create and use the preferred management context");
startManagement(e);
}
if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.START,
MutableMap.of("locations", locations)).getUnchecked();
}
代码示例来源:origin: io.brooklyn/brooklyn-core
public static DownloadResolver newDownloader(EntityDriver driver) {
return newDownloader(driver, ImmutableMap.<String,Object>of());
}
代码示例来源:origin: io.brooklyn/brooklyn-software-messaging
@Override
public void init() {
super.init();
Entities.getRequiredUrlConfig(this, TEMPLATE_CONFIGURATION_URL);
}
代码示例来源:origin: io.brooklyn/brooklyn-core
/** convenience - invokes in parallel if multiple, but otherwise invokes the item directly */
public static Task<?> invokeEffector(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
final Effector<?> effector, final Map<String,?> parameters) {
if (Iterables.size(entitiesToCall)==1)
return invokeEffector(callingEntity, entitiesToCall.iterator().next(), effector, parameters);
else
return invokeEffectorList(callingEntity, entitiesToCall, effector, parameters);
}
/** convenience - invokes in parallel if multiple, but otherwise invokes the item directly */
代码示例来源:origin: io.brooklyn/brooklyn-core
/** stops, destroys, and unmanages the given entity -- does as many as are valid given the type and state */
public static void destroy(Entity e) {
if (isManaged(e)) {
if (e instanceof Startable) Entities.invokeEffector((EntityLocal)e, e, Startable.STOP).getUnchecked();
if (e instanceof EntityInternal) ((EntityInternal)e).destroy();
unmanage(e);
log.debug("destroyed and unmanaged "+e+"; mgmt now "+
(e.getApplicationId()==null ? "(no app)" : e.getApplication().getManagementContext())+" - managed? "+isManaged(e));
} else {
log.debug("skipping destroy of "+e+": not managed");
}
}
代码示例来源:origin: io.brooklyn/brooklyn-core
@Override
public boolean apply(@Nullable Entity input) {
return input != null && Entities.isManaged(input);
}
};
代码示例来源:origin: io.brooklyn/brooklyn-core
/** convenience - invokes in parallel if multiple, but otherwise invokes the item directly */
public static Task<?> invokeEffector(EntityLocal callingEntity, Iterable<? extends Entity> entitiesToCall,
final Effector<?> effector) {
return invokeEffector(callingEntity, entitiesToCall, effector, Collections.<String,Object>emptyMap());
}
代码示例来源:origin: io.brooklyn/brooklyn-core
/**
* @deprecated since 0.6; use {@link #addNode(Location)}, so can take that location into account when configuring node
*/
protected Entity addNode() {
Map<?,?> creation = Maps.newLinkedHashMap(getCustomChildFlags());
if (LOG.isDebugEnabled()) LOG.debug("Creating and adding a node to cluster {}({}) with properties {}", new Object[] {this, getId(), creation});
Entity entity = createNode(null, creation);
Entities.manage(entity);
addMember(entity);
return entity;
}
代码示例来源:origin: io.brooklyn/brooklyn-software-messaging
if (Entities.isManaged(this)) Entities.manage(zookeeper);
setAttribute(ZOOKEEPER, zookeeper);
if (Entities.isManaged(this)) Entities.manage(cluster);
setAttribute(CLUSTER, cluster);
代码示例来源:origin: io.brooklyn/brooklyn-core
@Override
public String toString() {
return super.toString()+"[own="+Entities.sanitize(ownConfig)+"; inherited="+Entities.sanitize(inheritedConfig)+"]";
}
代码示例来源:origin: io.brooklyn/brooklyn-core
/**
* Builds and manages the application, calling the user's {@link #doBuild()} method.
*
* @throws IllegalStateException If already managed, or if called during {@link #doBuild()}, or if
* multiple concurrent calls
*/
public final StartableApplication manage(ManagementContext managementContext) {
if (!inManage.compareAndSet(false, true)) {
throw new IllegalStateException("Concurrent and re-entrant calls to manage() forbidden on "+this);
}
try {
checkNotManaged();
this.app = managementContext.getEntityManager().createEntity(appSpec);
this.managementContext = managementContext;
doBuild();
Entities.startManagement(app, managementContext);
managed = true;
return app;
} finally {
inManage.set(false);
}
}
代码示例来源:origin: io.brooklyn/brooklyn-core
for (ConfigKey<?> it : sortConfigKeys(e.getEntityType().getConfigKeys())) {
Object v = ((EntityInternal)e).getConfigMap().getRawConfig(it);
if (!isTrivial(v)) {
out.append(currentIndentation+tab+tab+it.getName());
out.append(" = ");
if (isSecret(it.getName())) out.append("xxxxxxxx");
else if ((v instanceof Task) && ((Task<?>)v).isDone()) {
if (((Task<?>)v).isError()) {
for (Sensor<?> it : sortSensors(e.getEntityType().getSensors())) {
if (it instanceof AttributeSensor) {
Object v = e.getAttribute((AttributeSensor<?>)it);
if (!isTrivial(v)) {
out.append(currentIndentation+tab+tab+it.getName());
out.append(": ");
if (isSecret(it.getName())) out.append("xxxxxxxx");
else out.append(""+v);
out.append("\n");
dumpInfo(policy, out, currentIndentation+tab+tab+tab, tab);
dumpInfo(it, out, currentIndentation+tab, tab);
代码示例来源:origin: io.brooklyn/brooklyn-core
keyO.toString();
Object val = entry.getValue();
if (!isTrivial(val)) {
out.append(currentIndentation+tab+tab+key);
out.append(" = ");
if (isSecret(key)) out.append("xxxxxxxx");
else out.append(""+val);
out.append("\n");
for (Map.Entry<String,?> entry : sortMap(FlagUtils.getFieldsWithFlags(loc)).entrySet()) {
String key = entry.getKey();
Object val = entry.getValue();
if (!isTrivial(val)) {
out.append(currentIndentation+tab+tab+key);
out.append(" = ");
if (isSecret(key)) out.append("xxxxxxxx");
else out.append(""+val);
out.append("\n");
dumpInfo(it, out, currentIndentation+tab, tab);
代码示例来源:origin: io.brooklyn/brooklyn-core
/** stops, destroys, and unmanages all apps in the given context,
* and then terminates the management context */
public static void destroyAll(ManagementContext mgmt) {
Exception error = null;
if (mgmt instanceof NonDeploymentManagementContext) {
// log here because it is easy for tests to destroyAll(app.getMgmtContext())
// which will *not* destroy the mgmt context if the app has been stopped!
log.warn("Entities.destroyAll invoked on non-deployment "+mgmt+" - not likely to have much effect! " +
"(This usually means the mgmt context has been taken from entity has been destroyed. " +
"To destroy other things on the management context ensure you keep a handle to the context " +
"before the entity is destroyed, such as by creating the management context first.)");
}
if (!mgmt.isRunning()) return;
log.debug("destroying all apps in "+mgmt+": "+mgmt.getApplications());
for (Application app: mgmt.getApplications()) {
log.debug("destroying app "+app+" (managed? "+isManaged(app)+"; mgmt is "+mgmt+")");
try {
destroy(app);
log.debug("destroyed app "+app+"; mgmt now "+mgmt);
} catch (Exception e) {
log.warn("problems destroying app "+app+" (mgmt now "+mgmt+", will rethrow at least one exception): "+e);
if (error==null) error = e;
}
}
if (mgmt instanceof ManagementContextInternal)
((ManagementContextInternal)mgmt).terminate();
if (error!=null) throw Exceptions.propagate(error);
}
代码示例来源:origin: io.brooklyn/brooklyn-software-webapp
public synchronized void updateNeeded() {
if (updateNeeded) return;
updateNeeded = true;
LOG.debug("queueing an update-needed task for "+this+"; update will occur shortly");
Entities.submit(this, Tasks.builder().name("update-needed").body(new Runnable() {
@Override
public void run() {
if (updateNeeded)
AbstractControllerImpl.this.update();
}
}).build());
}
代码示例来源:origin: io.brooklyn/brooklyn-core
public static void dumpInfo(Iterable<? extends Entity> entities) {
for (Entity e : entities) {
dumpInfo(e);
}
}
代码示例来源:origin: io.brooklyn/brooklyn-core
public static void dumpInfo(Policy pol, Writer out, String currentIndentation, String tab) throws IOException {
out.append(currentIndentation+pol.toString()+"\n");
for (ConfigKey<?> key : sortConfigKeys(pol.getPolicyType().getConfigKeys())) {
Object val = ((AbstractPolicy)pol).getConfigMap().getRawConfig(key);
if (!isTrivial(val)) {
out.append(currentIndentation+tab+tab+key);
out.append(" = ");
if (isSecret(key.getName())) out.append("xxxxxxxx");
else out.append(""+val);
out.append("\n");
}
}
out.flush();
}
代码示例来源:origin: io.brooklyn/brooklyn-launcher
/** Launches the web console on the given port, and a Brooklyn application, with a single command.
* For readability and flexibility, clients may prefer the {@link #newLauncher()} builder-style syntax.
*
* @deprecated in 0.5; use newInstance().webconsolePort(port).shutdownOnExit(shutdownApp).webconsole(startWebConsole).application(app).start()
*/
@Deprecated
public static ManagementContext manage(final AbstractApplication app, int port, boolean shutdownApp, boolean startWebConsole) {
// Locate the management context
Entities.startManagement(app);
LocalManagementContext context = (LocalManagementContext) app.getManagementContext();
if (startWebConsole) {
try {
new BrooklynWebServer(context, port).start();
} catch (Exception e) {
LOG.warn("Failed to start Brooklyn web-console", e);
}
}
if (shutdownApp) Entities.invokeStopOnShutdown(app);
return context;
}
代码示例来源:origin: io.brooklyn/brooklyn-core
public static <K> Map<K,Object> sanitize(Map<K,?> input) {
Map<K,Object> result = Maps.newLinkedHashMap();
for (Map.Entry<K,?> e: input.entrySet()) {
if (isSecret(""+e.getKey())) result.put(e.getKey(), "xxxxxxxx");
else result.put(e.getKey(), e.getValue());
}
return result;
}
代码示例来源:origin: io.brooklyn/brooklyn-core
/**
* stops, destroys, and unmanages the given application -- and terminates the mangaement context;
* does as many as are valid given the type and state
* @deprecated since 0.6.0 use destroy(Application) if you DONT want to destroy the mgmt context,
* or destroy(app.getManagementContext()) if you want to destory everything in the app's mgmt context
*/
@Deprecated
public static void destroyAll(Application app) {
if (isManaged(app)) {
ManagementContext managementContext = app.getManagementContext();
if (app instanceof Startable) Entities.invokeEffector((EntityLocal)app, app, Startable.STOP).getUnchecked();
if (app instanceof AbstractEntity) ((AbstractEntity)app).destroy();
unmanage(app);
if (managementContext instanceof ManagementContextInternal) ((ManagementContextInternal)managementContext).terminate();
}
}
内容来源于网络,如有侵权,请联系作者删除!