brooklyn.entity.messaging.qpid.QpidBrokerImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of brooklyn-software-messaging Show documentation
Show all versions of brooklyn-software-messaging Show documentation
Brooklyn entities for messaging software processes
package brooklyn.entity.messaging.qpid;
import static java.lang.String.format;
import java.io.IOException;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import brooklyn.entity.basic.Entities;
import brooklyn.entity.messaging.jms.JMSBrokerImpl;
import brooklyn.entity.proxying.EntitySpecs;
import brooklyn.event.feed.jmx.JmxAttributePollConfig;
import brooklyn.event.feed.jmx.JmxFeed;
import brooklyn.event.feed.jmx.JmxHelper;
import brooklyn.util.exceptions.Exceptions;
import com.google.common.base.Function;
import com.google.common.base.Functions;
import com.google.common.base.Objects.ToStringHelper;
/**
* An {@link brooklyn.entity.Entity} that represents a single Qpid broker instance, using AMQP 0-10.
*/
public class QpidBrokerImpl extends JMSBrokerImpl implements QpidBroker {
private static final Logger log = LoggerFactory.getLogger(QpidBrokerImpl.class);
private volatile JmxFeed jmxFeed;
public QpidBrokerImpl() {
super();
}
public String getVirtualHost() { return getAttribute(VIRTUAL_HOST_NAME); }
public String getAmqpVersion() { return getAttribute(AMQP_VERSION); }
public Integer getAmqpPort() { return getAttribute(AMQP_PORT); }
public void setBrokerUrl() {
String urlFormat = "amqp://guest:guest@/%s?brokerlist='tcp://%s:%d'";
setAttribute(BROKER_URL, format(urlFormat, getAttribute(VIRTUAL_HOST_NAME), getAttribute(HOSTNAME), getAttribute(AMQP_PORT)));
}
public void waitForServiceUp(long duration, TimeUnit units) {
super.waitForServiceUp(duration, units);
// Also wait for the MBean to exist (as used when creating queue/topic)
JmxHelper helper = new JmxHelper(this);
try {
String virtualHost = getConfig(QpidBroker.VIRTUAL_HOST_NAME);
ObjectName virtualHostManager = new ObjectName(format("org.apache.qpid:type=VirtualHost.VirtualHostManager,VirtualHost=\"%s\"", virtualHost));
helper.connect();
helper.assertMBeanExistsEventually(virtualHostManager, units.toMillis(duration));
} catch (MalformedObjectNameException e) {
throw Exceptions.propagate(e);
} catch (IOException e) {
throw Exceptions.propagate(e);
} finally {
if (helper != null) helper.disconnect();
}
}
public QpidQueue createQueue(Map properties) {
QpidQueue result = addChild(EntitySpecs.spec(QpidQueue.class).configure(properties));
Entities.manage(result);
result.create();
return result;
}
public QpidTopic createTopic(Map properties) {
QpidTopic result = addChild(EntitySpecs.spec(QpidTopic.class).configure(properties));
Entities.manage(result);
result.create();
return result;
}
@Override
public Class getDriverInterface() {
return QpidDriver.class;
}
@Override
protected void connectSensors() {
String serverInfoMBeanName = "org.apache.qpid:type=ServerInformation,name=ServerInformation";
jmxFeed = JmxFeed.builder()
.entity(this)
.period(500, TimeUnit.MILLISECONDS)
.pollAttribute(new JmxAttributePollConfig(SERVICE_UP)
.objectName(serverInfoMBeanName)
.attributeName("ProductVersion")
.onSuccess(new Function