/** * 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; }
/** * @return the instance name. */ public String getName() { return architecture.getInstanceDescription().getName(); }
/** * 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"; } }
/** * @return the raw architecture. */ public String getArchitecture() { return architecture.getInstanceDescription().getDescription() .toString().replace("\t", " ").replace(" ", " "); }
/** * Gets the instance list created by the given factory. * @param archs the list of instance architectures * @param factory the factory name * @return the list containing the created instances (name) */ public static List<String> getInstanceList(List<Architecture> archs, String factory) { List<String> list = new ArrayList<String>(); for (Architecture arch : archs) { // Cannot be null, an empty list is returned. String n = arch.getInstanceDescription().getComponentDescription().getName(); if (factory.equals(n)) { list.add(arch.getInstanceDescription().getName()); } } return list; }
/** * Prints instance description. * @param name : instance name * @param out : default print stream * @param err : error print stream (if the instance is not found) */ private void printInstance(String name, PrintStream out, PrintStream err) { for (int i = 0; i < m_archs.length; i++) { InstanceDescription instance = m_archs[i].getInstanceDescription(); if (instance.getName().equalsIgnoreCase(name)) { out.println(instance.getDescription()); return; } } err.println("Instance " + name + " not found"); }
/** * @return the factory's name. */ public String getFactory() { return architecture.getInstanceDescription().getComponentDescription().getName(); }
/** * @return the list of provided services */ public List<ProvidedServiceModel> getServices() { ProvidedServiceHandlerDescription pshd = (ProvidedServiceHandlerDescription) architecture.getInstanceDescription().getHandlerDescription("org" + ".apache.felix.ipojo:provides"); if (pshd == null) { return Collections.emptyList(); } else { List<ProvidedServiceModel> list = new ArrayList<>(pshd.getProvidedServices().length); for (ProvidedServiceDescription description : pshd.getProvidedServices()) { list.add(new ProvidedServiceModel(description)); } return list; } }
/** * @return the list of required services */ public List<ServiceDependencyModel> getDependencies() { DependencyHandlerDescription handler = (DependencyHandlerDescription) architecture.getInstanceDescription() .getHandlerDescription("org.apache.felix.ipojo:requires"); if (handler == null) { return Collections.emptyList(); } else { List<ServiceDependencyModel> list = new ArrayList<>(handler.getDependencies().length); for (DependencyDescription dependency : handler.getDependencies()) { list.add(new ServiceDependencyModel(dependency)); } return list; } }
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; }
/** * 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"); } } }
InstanceDescription id = m_arch.getInstanceDescription(); if (id.getName().equalsIgnoreCase(instance)) { sb.append(id.getDescription());
StringBuilder buffer = new StringBuilder(); 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()));
/** * Gets the list of contained instance in the described instance. * This list contains only instances who exposed their architecture. * @return the list of contained instances. */ public InstanceDescription[] getContainedInstances() { // Get instances description of internal instance ServiceContext internal = ((CompositeManager) m_instance).getServiceContext(); try { ServiceReference[] refs = internal.getServiceReferences(Architecture.class.getName(), null); if (refs != null) { InstanceDescription[] desc = new InstanceDescription[refs.length]; for (int i = 0; i < refs.length; i++) { Architecture arch = (Architecture) internal.getService(refs[i]); desc[i] = arch.getInstanceDescription(); internal.ungetService(refs[i]); } return desc; } } catch (InvalidSyntaxException e) { // Cannot happen } return new InstanceDescription[0]; }
/** * Gets the list of contained instance in the described instance. * This list contains only instances who exposed their architecture. * @return the list of contained instances. */ public InstanceDescription[] getContainedInstances() { // Get instances description of internal instance ServiceContext internal = ((CompositeManager) m_instance).getServiceContext(); try { ServiceReference[] refs = internal.getServiceReferences(Architecture.class.getName(), null); if (refs != null) { InstanceDescription[] desc = new InstanceDescription[refs.length]; for (int i = 0; i < refs.length; i++) { Architecture arch = (Architecture) internal.getService(refs[i]); desc[i] = arch.getInstanceDescription(); internal.ungetService(refs[i]); } return desc; } } catch (InvalidSyntaxException e) { // Cannot happen } return new InstanceDescription[0]; }
/** * 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(); }
if (arch.getInstanceDescription().getName().equals(name)) { instance = arch.getInstanceDescription();