Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Ability to correctly receive messages from the inventory.
Browse files Browse the repository at this point in the history
  • Loading branch information
metlos authored and jkremser committed Apr 13, 2015
1 parent 78e6f96 commit a6d6015
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
6 changes: 6 additions & 0 deletions modules/pinger/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.hawkular.inventory</groupId>
<artifactId>bus-api</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.hawkular.metrics</groupId>
<artifactId>clients-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
*/
package org.hawkular.component.pinger;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.hawkular.bus.common.SimpleBasicMessage;
import org.hawkular.bus.common.consumer.BasicMessageListener;
import org.hawkular.inventory.api.model.Resource;
import org.hawkular.inventory.api.observable.Action;
import org.hawkular.inventory.bus.api.ResourceEvent;

import javax.ejb.ActivationConfigProperty;
import javax.ejb.EJB;
Expand All @@ -39,19 +38,18 @@
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "entityType = 'resource'")
})
@SuppressWarnings("unused")
public class NotificationReceiver extends BasicMessageListener<SimpleBasicMessage> {
public class NotificationReceiver extends BasicMessageListener<ResourceEvent> {


@EJB PingManager pingManager;

@Override
public void onBasicMessage(SimpleBasicMessage message) {
public void onBasicMessage(ResourceEvent message) {

try {

Log.LOG.debugf("Received message: %s", message);

String payload = message.getMessage();
Map<String, String> details = message.getHeaders();
String action;
if (details != null) {
Expand All @@ -62,18 +60,17 @@ public void onBasicMessage(SimpleBasicMessage message) {
return;
}

Gson gson = new GsonBuilder().create();
Resource resource = message.getObject();

Resource resource = gson.fromJson(payload, Resource.class);
if (!"URL".equals(resource.getType().getId())) {
return;
}
String url = (String) resource.getProperties().get("url");
PingDestination destination = new PingDestination(resource.getId(), url);

if ("created".equals(action)) {
if (message.getAction() == Action.Enumerated.CREATED) {
pingManager.addDestination(destination);
} else if ("deleted".equals(action)) {
} else if (message.getAction() == Action.Enumerated.DELETED) {
pingManager.removeDestination(destination);
}

Expand Down

0 comments on commit a6d6015

Please sign in to comment.