Tabnine Logo
JmxFeed.builder
Code IndexAdd Tabnine to your IDE (free)

How to use
builder
method
in
org.apache.brooklyn.feed.jmx.JmxFeed

Best Java code snippets using org.apache.brooklyn.feed.jmx.JmxFeed.builder (Showing top 20 results out of 315)

origin: org.apache.brooklyn/brooklyn-software-messaging

@Override
protected void connectSensors() {
  String queue = String.format("org.apache.activemq:type=Broker,brokerName=%s,destinationType=Queue,destinationName=%s", getBrokerName(), getName());
  
  jmxFeed = JmxFeed.builder()
      .entity(this)
      .helper(jmxHelper)
      .pollAttribute(new JmxAttributePollConfig<Integer>(QUEUE_DEPTH_MESSAGES)
          .objectName(queue)
          .attributeName("QueueSize"))
      .build();
}
origin: org.apache.brooklyn/brooklyn-software-messaging

@Override
protected void connectSensors() {
  String queue = format("org.apache.qpid:type=VirtualHost.Queue,VirtualHost=\"%s\",name=\"%s\"", virtualHost, getName());
  
  jmxFeed = JmxFeed.builder()
      .entity(this)
      .helper(jmxHelper)
      .pollAttribute(new JmxAttributePollConfig<Integer>(QUEUE_DEPTH_BYTES)
          .objectName(queue)
          .attributeName("QueueDepth"))
      .pollAttribute(new JmxAttributePollConfig<Integer>(QUEUE_DEPTH_MESSAGES)
          .objectName(queue)
          .attributeName("MessageCount"))
      .build();
}
origin: org.apache.brooklyn/brooklyn-software-base

@Test
public void testJmxOperationPolledForSensor() throws Exception {
  // This is awful syntax...
  final int opReturnVal = 123;
  final AtomicInteger invocationCount = new AtomicInteger();
  MBeanOperationInfo opInfo = new MBeanOperationInfo(opName, "my descr", new MBeanParameterInfo[0], Integer.class.getName(), MBeanOperationInfo.ACTION);
  GeneralisedDynamicMBean mbean = jmxService.registerMBean(
      Collections.emptyMap(), 
      ImmutableMap.of(opInfo, new Function<Object[], Integer>() {
          @Override
          public Integer apply(Object[] args) {
            invocationCount.incrementAndGet(); return opReturnVal;
          }}),
      objectName);
  feed = JmxFeed.builder()
      .entity(entity)
      .pollOperation(new JmxOperationPollConfig<Integer>(intAttribute)
          .objectName(objectName)
          .operationName(opName))
      .build();
  
  Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
    @Override
    public void run() {
      assertTrue(invocationCount.get() > 0, "invocationCount="+invocationCount);
      assertEquals(entity.getAttribute(intAttribute), (Integer)opReturnVal);
    }});
}
origin: org.apache.brooklyn/brooklyn-software-base

@Test
public void testJmxOperationWithArgPolledForSensor() throws Exception {
  // This is awful syntax...
  MBeanParameterInfo paramInfo = new MBeanParameterInfo("param1", String.class.getName(), "my param1");
  MBeanParameterInfo[] paramInfos = new MBeanParameterInfo[] {paramInfo};
  MBeanOperationInfo opInfo = new MBeanOperationInfo(opName, "my descr", paramInfos, String.class.getName(), MBeanOperationInfo.ACTION);
  GeneralisedDynamicMBean mbean = jmxService.registerMBean(
      Collections.emptyMap(), 
      ImmutableMap.of(opInfo, new Function<Object[], String>() {
          @Override
          public String apply(Object[] args) {
            return args[0]+"suffix";
          }}),
      objectName);
  
  feed = JmxFeed.builder()
      .entity(entity)
      .pollOperation(new JmxOperationPollConfig<String>(stringAttribute)
          .objectName(objectName)
          .operationName(opName)
          .operationParams(ImmutableList.of("myprefix")))
      .build();
  
  assertSensorEventually(stringAttribute, "myprefix"+"suffix", TIMEOUT_MS);
}
origin: org.apache.brooklyn/brooklyn-software-messaging

@Override     
protected void connectSensors() {
  sensors().set(BROKER_URL, String.format("tcp://%s:%d", getAttribute(HOSTNAME), getAttribute(OPEN_WIRE_PORT)));
  
  String brokerMbeanName = "org.apache.activemq:type=Broker,brokerName=" + getBrokerName();
  
  jmxFeed = JmxFeed.builder()
      .entity(this)
      .period(500, TimeUnit.MILLISECONDS)
      .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP)
          .objectName(brokerMbeanName)
          .attributeName("BrokerName")
          .onSuccess(Functions.forPredicate(Predicates.notNull()))
          .onFailureOrException(Functions.constant(false))
          .suppressDuplicates(true))
      .build();
}
origin: org.apache.brooklyn/brooklyn-software-base

  @Override
  public JmxFeed call() throws Exception {
    JmxHelper helper = new JmxHelper(entity);
    JmxFeed feed = JmxFeed.builder()
        .entity(entity)
        .period(period)
        .helper(helper)
        .pollAttribute(new JmxAttributePollConfig<T>(sensor)
            .objectName(objectName)
            .attributeName(attribute)
            .suppressDuplicates(Boolean.TRUE.equals(suppressDuplicates))
            .onFailureOrException(Functions.<T>constant((T) defaultValue)))
        .build();
    entity.addFeed(feed);
    return feed;
  }
})
origin: org.apache.brooklyn/brooklyn-software-base

@Test
public void testJmxNotificationSubscriptionForSensor() throws Exception {
  final String one = "notification.one", two = "notification.two";
  final StandardEmitterMBean mbean = jmxService.registerMBean(ImmutableList.of(one, two), objectName);
  final AtomicInteger sequence = new AtomicInteger(0);
  feed = JmxFeed.builder()
      .entity(entity)
      .subscribeToNotification(new JmxNotificationSubscriptionConfig<Integer>(intAttribute)
          .objectName(objectName)
          .notificationFilter(JmxNotificationFilters.matchesType(one)))
      .build();        
  // Notification updates the sensor
  // Note that subscription is done async, so can't just send notification immediately during test.
  Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
    @Override
    public void run() {
      sendNotification(mbean, one, sequence.getAndIncrement(), 123);
      assertEquals(entity.getAttribute(intAttribute), (Integer)123);
    }});
  
  // But other notification types are ignored
  sendNotification(mbean, two, sequence.getAndIncrement(), -1);
    
  Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
    @Override
    public void run() {
      assertEquals(entity.getAttribute(intAttribute), (Integer)123);
    }});
}

origin: org.apache.brooklyn/brooklyn-software-base

@Test
public void testJmxNotificationMultipleSubscriptionUsingListener() throws Exception {
  final String one = "notification.one";
  final String two = "notification.two";
  final StandardEmitterMBean mbean = jmxService.registerMBean(ImmutableList.of(one, two), objectName);
  final AtomicInteger sequence = new AtomicInteger(0);
  feed = JmxFeed.builder()
      .entity(entity)
      .subscribeToNotification(new JmxNotificationSubscriptionConfig<Integer>(intAttribute)
          .objectName(objectName)
          .notificationFilter(JmxNotificationFilters.matchesTypes(one, two)))
      .build();
  
  // Notification updates the sensor
  // Note that subscription is done async, so can't just send notification immediately during test.
  Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
    @Override
    public void run() {
      sendNotification(mbean, one, sequence.getAndIncrement(), 123);
      assertEquals(entity.getAttribute(intAttribute), (Integer)123);
    }});
  // And wildcard means other notifications also received
  sendNotification(mbean, two, sequence.getAndIncrement(), 456);
  assertSensorEventually(intAttribute, 456, TIMEOUT_MS);
}
origin: org.apache.brooklyn/brooklyn-software-base

@Test
public void testJmxNotificationSubscriptionForSensorParsingNotification() throws Exception {
  final String one = "notification.one", two = "notification.two";
  final StandardEmitterMBean mbean = jmxService.registerMBean(ImmutableList.of(one, two), objectName);
  final AtomicInteger sequence = new AtomicInteger(0);
  
  feed = JmxFeed.builder()
      .entity(entity)
      .subscribeToNotification(new JmxNotificationSubscriptionConfig<Integer>(intAttribute)
          .objectName(objectName)
          .notificationFilter(JmxNotificationFilters.matchesType(one))
          .onNotification(new Function<Notification, Integer>() {
            @Override
            public Integer apply(Notification notif) {
              return (Integer) notif.getUserData();
            }
          }))
      .build();
  
  
  // Notification updates the sensor
  // Note that subscription is done async, so can't just send notification immediately during test.
  Asserts.succeedsEventually(ImmutableMap.of("timeout", TIMEOUT_MS), new Runnable() {
    @Override
    public void run() {
      sendNotification(mbean, one, sequence.getAndIncrement(), 123);
      assertEquals(entity.getAttribute(intAttribute), (Integer)123);
    }});
}
origin: org.apache.brooklyn/brooklyn-software-base

@Override protected void connectSensors() {
  super.connectSensors();
  // Add a sensor that we can explicitly set in jmx
  feed = JmxFeed.builder()
    .entity(this)
    .pollAttribute(new JmxAttributePollConfig<String>(stringAttribute)
      .objectName(jmxObjectName)
      .attributeName(attributeName))
    .build();
}
origin: org.apache.brooklyn/brooklyn-software-base

@Test
public void testJmxAttributePollerReturnsMBeanAttribute() throws Exception {
  GeneralisedDynamicMBean mbean = jmxService.registerMBean(ImmutableMap.of(attributeName, 42), objectName);
  feed = JmxFeed.builder()
      .entity(entity)
      .pollAttribute(new JmxAttributePollConfig<Integer>(intAttribute)
          .objectName(objectName)
          .period(50)
          .attributeName(attributeName))
      .build();
  
  // Starts with value defined when registering...
  assertSensorEventually(intAttribute, 42, TIMEOUT_MS);
  // Change the value and check it updates
  mbean.updateAttributeValue(attributeName, 64);
  assertSensorEventually(intAttribute, 64, TIMEOUT_MS);
}
origin: org.apache.brooklyn/brooklyn-software-messaging

@Override
protected void connectSensors() {
  super.connectSensors();
  String serverInfoMBeanName = "org.apache.qpid:type=ServerInformation,name=ServerInformation";
  jmxFeed = JmxFeed.builder()
      .entity(this)
      .period(500, TimeUnit.MILLISECONDS)
      .pollAttribute(new JmxAttributePollConfig<Boolean>(SERVICE_UP)
          .objectName(serverInfoMBeanName)
          .attributeName("ProductVersion")
          .onSuccess(new Function<Object,Boolean>() {
              private boolean hasWarnedOfVersionMismatch;
              @Override public Boolean apply(Object input) {
                if (input == null) return false;
                if (!hasWarnedOfVersionMismatch && !getConfig(QpidBroker.SUGGESTED_VERSION).equals(input)) {
                  log.warn("Qpid version mismatch: ProductVersion is {}, requested version is {}", input, getConfig(QpidBroker.SUGGESTED_VERSION));
                  hasWarnedOfVersionMismatch = true;
                }
                return true;
              }})
          .onException(Functions.constant(false))
          .suppressDuplicates(true))
      .build();
}
origin: org.apache.brooklyn/brooklyn-software-base

feed = JmxFeed.builder()
    .entity(entity)
    .pollAttribute(new JmxAttributePollConfig<Map>(mapAttribute)
origin: org.apache.brooklyn/brooklyn-software-webapp

boolean retrieveUsageMetrics = getConfig(RETRIEVE_USAGE_METRICS);
jmxWebFeed = JmxFeed.builder()
    .entity(this)
    .period(3000, TimeUnit.MILLISECONDS)
origin: org.apache.brooklyn/brooklyn-software-messaging

@Override
protected void connectSensors() {
  connectServiceUpIsRunning();
  if (((JavaSoftwareProcessDriver)getDriver()).isJmxEnabled()) {
    jmxFeed = JmxFeed.builder()
      .entity(this)
      .period(500, TimeUnit.MILLISECONDS)
      .pollAttribute(new JmxAttributePollConfig<Long>(OUTSTANDING_REQUESTS)
          .objectName(ZOOKEEPER_MBEAN)
          .attributeName("OutstandingRequests")
          .onFailureOrException(Functions.constant(-1l)))
      .pollAttribute(new JmxAttributePollConfig<Long>(PACKETS_RECEIVED)
          .objectName(ZOOKEEPER_MBEAN)
          .attributeName("PacketsReceived")
          .onFailureOrException(Functions.constant(-1l)))
      .pollAttribute(new JmxAttributePollConfig<Long>(PACKETS_SENT)
          .objectName(ZOOKEEPER_MBEAN)
          .attributeName("PacketsSent")
          .onFailureOrException(Functions.constant(-1l)))
      .build();
  }
}
origin: org.apache.brooklyn/brooklyn-software-webapp

jmxFeed = JmxFeed.builder()
    .entity(this)
    .period(500, TimeUnit.MILLISECONDS)
origin: org.apache.brooklyn/brooklyn-software-webapp

String statsMbeanName = "org.mortbay.jetty.handler:type=atomicstatisticshandler,id=0";
jmxFeedJetty = JmxFeed.builder()
    .entity(this)
    .period(500, TimeUnit.MILLISECONDS)
origin: org.apache.brooklyn/brooklyn-software-base

  @Override
  public void start(Collection<? extends Location> locs) {
    // TODO Auto-generated method stub
    super.start(locs);
    
    sensors().set(Attributes.HOSTNAME, "localhost");
    sensors().set(UsesJmx.JMX_PORT, 
        LocalhostMachineProvisioningLocation.obtainPort(PortRanges.fromString("40123+")));
    // only supports no-agent, at the moment
    config().set(UsesJmx.JMX_AGENT_MODE, JmxAgentModes.NONE);
    sensors().set(UsesJmx.RMI_REGISTRY_PORT, -1);  // -1 means to use the JMX_PORT only
    ConfigToAttributes.apply(this, UsesJmx.JMX_CONTEXT);
    
    JmxFeed.Builder feedBuilder = JmxFeed.builder()
        .entity(this)
        .pollAttribute(new JmxAttributePollConfig<String>(SENSOR_STRING)
            .objectName(OBJECT_NAME)
            .period(50)
            .attributeName(JMX_ATTRIBUTE_NAME));
    if (getConfig(PRE_CREATE_JMX_HELPER)) {
      JmxHelper jmxHelper = new JmxHelper(this);
      feedBuilder.helper(jmxHelper);
    }
    addFeed(feedBuilder.build());
  }
}
origin: org.apache.brooklyn/brooklyn-software-base

@SuppressWarnings({"unchecked"})
public static JmxFeed.Builder getMxBeanSensorsBuilder(Entity entity, Duration jmxPollPeriod) {
  JmxFeed.Builder builder = JmxFeed.builder()
      .entity(entity)
      .period(jmxPollPeriod);
origin: org.apache.brooklyn/brooklyn-software-messaging

jmxFeed = JmxFeed.builder()
  .entity(this)
  .period(500, TimeUnit.MILLISECONDS)
org.apache.brooklyn.feed.jmxJmxFeedbuilder

Popular methods of JmxFeed

  • stop
  • <init>
  • getConfig
  • getEntity
  • getHelper
  • getJmxUri
  • getManagementContext
  • getPoller
  • initUniqueTag
  • registerAttributePoller
    Registers to poll a jmx-attribute for an ObjectName, where all the given configs are for that same O
  • registerOperationPoller
    Registers to poll a jmx-operation for an ObjectName, where all the given configs are for the same Ob
  • setConfig
  • registerOperationPoller,
  • setConfig,
  • setEntity,
  • start,
  • unregisterNotificationListener

Popular in Java

  • Start an intent from android
  • findViewById (Activity)
  • onRequestPermissionsResult (Fragment)
  • runOnUiThread (Activity)
  • OutputStream (java.io)
    A writable sink for bytes.Most clients will use output streams that write data to the file system (
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • LinkedList (java.util)
    Doubly-linked list implementation of the List and Dequeinterfaces. Implements all optional list oper
  • ResourceBundle (java.util)
    ResourceBundle is an abstract class which is the superclass of classes which provide Locale-specifi
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Top Sublime Text plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now