brooklyn.entity.nosql.redis.RedisClusterImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brooklyn-software-nosql Show documentation
Show all versions of brooklyn-software-nosql Show documentation
Brooklyn entities for NoSQL data store software entities
package brooklyn.entity.nosql.redis;
import java.util.Collection;
import brooklyn.entity.Entity;
import brooklyn.entity.basic.AbstractEntity;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.group.DynamicCluster;
import brooklyn.entity.proxying.EntitySpec;
import brooklyn.entity.trait.Startable;
import brooklyn.location.Location;
public class RedisClusterImpl extends AbstractEntity implements RedisCluster {
protected RedisStore master;
protected DynamicCluster slaves;
public RedisClusterImpl() {
}
@Override
public RedisStore getMaster() {
return master;
}
@Override
public DynamicCluster getSlaves() {
return slaves;
}
@Override
public void start(Collection extends Location> locations) {
master = addChild(EntitySpec.create(RedisStore.class));
Entities.manage(master);
master.start(locations);
slaves = addChild(EntitySpec.create(DynamicCluster.class)
.configure(DynamicCluster.MEMBER_SPEC, EntitySpec.create(RedisSlave.class).configure(RedisSlave.MASTER, master)));
slaves.start(locations);
setAttribute(Startable.SERVICE_UP, calculateServiceUp());
}
@Override
public void stop() {
if (slaves != null) slaves.stop();
if (master != null) master.stop();
setAttribute(Startable.SERVICE_UP, false);
}
@Override
public void restart() {
throw new UnsupportedOperationException();
}
protected boolean calculateServiceUp() {
boolean up = false;
for (Entity member : slaves.getMembers()) {
if (Boolean.TRUE.equals(member.getAttribute(SERVICE_UP))) up = true;
}
return up;
}
}