use of org.apache.sling.discovery.InstanceFilter in project sling by apache.
the class DefaultTopologyViewTest method testFind.
@Test
public void testFind() throws Exception {
DefaultTopologyView newView = TopologyHelper.createTopologyView(UUID.randomUUID().toString(), UUID.randomUUID().toString());
TopologyHelper.createAndAddInstanceDescription(newView, newView.getClusterViews().iterator().next());
try {
newView.findInstances(null);
fail("should complain");
} catch (IllegalArgumentException iae) {
// ok
}
final DefaultInstanceDescription id = TopologyHelper.createAndAddInstanceDescription(newView, newView.getClusterViews().iterator().next());
TopologyHelper.createAndAddInstanceDescription(newView, newView.getClusterViews().iterator().next());
assertEquals(4, newView.findInstances(new InstanceFilter() {
public boolean accept(InstanceDescription instance) {
return true;
}
}).size());
assertEquals(1, newView.findInstances(new InstanceFilter() {
public boolean accept(InstanceDescription instance) {
return instance.getSlingId().equals(id.getSlingId());
}
}).size());
assertEquals(1, newView.findInstances(new InstanceFilter() {
public boolean accept(InstanceDescription instance) {
return instance.isLeader();
}
}).size());
assertEquals(1, newView.findInstances(new InstanceFilter() {
boolean first = true;
public boolean accept(InstanceDescription instance) {
if (!first) {
return false;
}
first = false;
return true;
}
}).size());
}
use of org.apache.sling.discovery.InstanceFilter in project sling by apache.
the class TopologyWebConsolePlugin method renderProperties.
/**
* Render the properties page of a particular instance
*/
private void renderProperties(final PrintWriter pw, final String contextPath, final String nodeId) {
if (logger.isDebugEnabled()) {
logger.debug("renderProperties: nodeId=" + nodeId);
}
final TopologyView tv = this.currentView;
@SuppressWarnings("unchecked") Set<InstanceDescription> instances = (tv == null ? (Set<InstanceDescription>) Collections.EMPTY_SET : tv.findInstances(new InstanceFilter() {
@Override
public boolean accept(InstanceDescription instance) {
String slingId = instance.getSlingId();
if (logger.isDebugEnabled()) {
logger.debug("renderProperties/picks: slingId={}", slingId);
}
return (slingId.equals(nodeId));
}
}));
if (instances != null && instances.size() == 1) {
InstanceDescription instance = instances.iterator().next();
pw.println("Properties of " + instance.getSlingId() + ":<br/>");
pw.println("<table class=\"adapters nicetable ui-widget tablesorter\">");
pw.println("<thead>");
pw.println("<tr>");
pw.println("<th class=\"header ui-widget-header\">Key</th>");
pw.println("<th class=\"header ui-widget-header\">Value</th>");
pw.println("</tr>");
pw.println("</thead>");
pw.println("<tbody>");
boolean odd = true;
for (Iterator<Entry<String, String>> it = instance.getProperties().entrySet().iterator(); it.hasNext(); ) {
Entry<String, String> entry = it.next();
String oddEven = odd ? "odd" : "even";
odd = !odd;
pw.println("<tr class=\"" + oddEven + " ui-state-default\">");
pw.println("<td>" + entry.getKey() + "</td>");
pw.println("<td>" + entry.getValue() + "</td>");
pw.println("</tr>");
}
pw.println("</tbody>");
pw.println("</table>");
}
}
use of org.apache.sling.discovery.InstanceFilter in project sling by apache.
the class TopologyWebConsolePlugin method renderProperties.
/**
* Render the properties page of a particular instance
*/
private void renderProperties(final PrintWriter pw, final String contextPath, final String nodeId) {
if (logger.isDebugEnabled()) {
logger.debug("renderProperties: nodeId=" + nodeId);
}
final TopologyView tv = this.currentView;
@SuppressWarnings("unchecked") Set<InstanceDescription> instances = (tv == null ? (Set<InstanceDescription>) Collections.EMPTY_SET : tv.findInstances(new InstanceFilter() {
@Override
public boolean accept(InstanceDescription instance) {
String slingId = instance.getSlingId();
if (logger.isDebugEnabled()) {
logger.debug("renderProperties/picks: slingId={}", slingId);
}
return (slingId.equals(nodeId));
}
}));
if (instances != null && instances.size() == 1) {
InstanceDescription instance = instances.iterator().next();
pw.println("Properties of " + instance.getSlingId() + ":<br/>");
pw.println("<table class=\"adapters nicetable ui-widget tablesorter\">");
pw.println("<thead>");
pw.println("<tr>");
pw.println("<th class=\"header ui-widget-header\">Key</th>");
pw.println("<th class=\"header ui-widget-header\">Value</th>");
pw.println("</tr>");
pw.println("</thead>");
pw.println("<tbody>");
boolean odd = true;
for (Iterator<Entry<String, String>> it = instance.getProperties().entrySet().iterator(); it.hasNext(); ) {
Entry<String, String> entry = it.next();
String oddEven = odd ? "odd" : "even";
odd = !odd;
pw.println("<tr class=\"" + oddEven + " ui-state-default\">");
pw.println("<td>" + entry.getKey() + "</td>");
pw.println("<td>" + entry.getValue() + "</td>");
pw.println("</tr>");
}
pw.println("</tbody>");
pw.println("</table>");
}
}
Aggregations