/** * Gets the number of invalid instances. * @param archs the instance architecture list * @return the number of invalid instances. */ public static int getInvalidInstancesCount(List<Architecture> archs) { int i = 0; for (Architecture a : archs) { // Cannot be null, an empty list is returned. if (a.getInstanceDescription().getState() == ComponentInstance.INVALID) { i ++; } } return i; }
/** * Gets the number of valid instances. * @param archs the instance architecture list * @return the number of valid instances. */ public static int getValidInstancesCount(List<Architecture> archs) { int i = 0; for (Architecture a : archs) { // Cannot be null, an empty list is returned. if (a.getInstanceDescription().getState() == ComponentInstance.VALID) { i ++; } } return i; }
/** * @return the instance's state. */ public String getState() { switch (architecture.getInstanceDescription().getState()) { case ComponentInstance.DISPOSED: return "DISPOSED"; case ComponentInstance.INVALID: return "INVALID"; case ComponentInstance.VALID: return "VALID"; case ComponentInstance.STOPPED: return "STOPPED"; default: return "UNKNOWN"; } }
/** * Prints instance list. * @param out : default print stream */ private void printInstances(PrintStream out) { for (int i = 0; i < m_archs.length; i++) { InstanceDescription instance = m_archs[i].getInstanceDescription(); if (instance.getState() == ComponentInstance.VALID) { out.println("Instance " + instance.getName() + " -> valid"); } if (instance.getState() == ComponentInstance.INVALID) { out.println("Instance " + instance.getName() + " -> invalid"); } if (instance.getState() == ComponentInstance.STOPPED) { out.println("Instance " + instance.getName() + " -> stopped"); } } }
/** * Creates the Json representation for an invalid controller. * * @param description the instance's description * @param json the json service * @return the json representation */ public static JsonNode from(InstanceDescription description, Json json) { ObjectNode node = json.newObject(); node.put("classname", description.getComponentDescription().getName()) .put("invalid", description.getState() == ComponentInstance.INVALID) .put("reason", extractInvalidityReason(description)); return node; }
private List<InstanceDescription> getInvalidControllers() { List<InstanceDescription> invalid = new ArrayList<>(); for (Architecture architecture : architectures) { final InstanceDescription description = architecture.getInstanceDescription(); // Is it invalid ? if (description.getState() == ComponentInstance.INVALID) { // Is it a controller ProvidedServiceHandlerDescription hd = (ProvidedServiceHandlerDescription) description.getHandlerDescription("org.apache.felix.ipojo:provides"); if (hd != null) { for (ProvidedServiceDescription psd : hd.getProvidedServices()) { if (Arrays.asList(psd.getServiceSpecifications()).contains(org.wisdom.api.Controller.class .getName())) { invalid.add(description); } } } } } return invalid; }
for (Architecture m_arch : m_archs) { InstanceDescription instance = m_arch.getInstanceDescription(); if (instance.getState() == ComponentInstance.VALID) { buffer.append(format("Instance %s -> valid%n", instance.getName())); if (instance.getState() == ComponentInstance.INVALID) { buffer.append(format("Instance %s -> invalid%n", instance.getName())); if (instance.getState() == ComponentInstance.STOPPED) { buffer.append(format("Instance %s -> stopped%n", instance.getName()));
instance.addAttribute(new Attribute("name", getName())); // Name int state = getState(); if (state == ComponentInstance.STOPPED) { instance.addAttribute(new Attribute("state", "stopped"));
instance.addAttribute(new Attribute("name", getName())); // Name int state = getState(); if (state == ComponentInstance.STOPPED) { instance.addAttribute(new Attribute("state", "stopped"));
/** * Writes the JSON object containing the info for all instances. * @param pw the writer where the json object is printed. * @throws IOException the JSON object cannot be written */ private void getAllInstances(JSONWriter pw) throws IOException { pw.object(); // Statline: pw.key("count"); pw.value( m_archs.size()); pw.key("valid_count"); pw.value( StateUtils.getValidInstancesCount(m_archs)); pw.key("invalid_count"); pw.value( StateUtils.getInvalidInstancesCount(m_archs)); // End statline pw.key("data"); pw.array(); for (Architecture arch : m_archs) { pw.object(); pw.key("name"); pw.value(arch.getInstanceDescription().getName()); pw.key("factory"); pw.value(arch.getInstanceDescription().getComponentDescription().getName()); pw.key("state"); pw.value(StateUtils.getInstanceState(arch.getInstanceDescription().getState())); pw.endObject(); } pw.endArray(); pw.endObject(); }
pw.value(instance.getName()); pw.key("state"); pw.value(StateUtils.getInstanceState(instance.getState())); pw.key("factory"); pw.value(instance.getComponentDescription().getName());