/** * Discover all service providers that are compatible with the service type * @param serviceType * @return * @throws IOException */ public Collection<ServiceDeclaration> getServiceDeclarations(Class<?> serviceType) throws IOException { return getServiceDeclarations(serviceType, false); }
void initCommands() throws IOException { for (ServiceDeclaration sd : ServiceDiscovery.getInstance().getServiceDeclarations(Command.class)) { try { Class<?> c = Class.forName(sd.getClassName()); try { Command command = (Command)c.getConstructor(Shell.class).newInstance(this); commands.put(command.getName(), command); } catch (NoSuchMethodException e) { Command command = (Command)c.newInstance(); commands.put(command.getName(), command); } } catch (Exception e) { e.printStackTrace(); } } }
private static ClassLoader getClassLoader(ServiceDiscovery discovery, Class<?> serviceType) { try { ServiceDeclaration sd = discovery.getServiceDeclaration(serviceType); if (sd != null) { return sd.loadClass().getClassLoader(); } } catch (Exception e) { // Ignore } return null; }
public void stop(BundleContext context) throws Exception { ServiceDiscovery.getInstance().setServiceDiscoverer(null); if (discoverer != null) { discoverer.stop(); discoverer = null; } }
private static ClassLoader parentClassLoader(Contribution contribution) { if (contribution.getClassLoader() != null) { return contribution.getClassLoader(); } ClassLoader parentClassLoader = ServiceDiscovery.getInstance().getContextClassLoader(); return parentClassLoader; }
private synchronized void loadWireProcessors() { if (loaded) { return; } try { Collection<ServiceDeclaration> sds = registry.getServiceDiscovery().getServiceDeclarations(RuntimeWireProcessor.class, true); sds = ServiceDiscovery.removeDuplicateDeclarations(sds); for (ServiceDeclaration sd : sds) { Class type = sd.loadClass(); Constructor constructor = null; RuntimeWireProcessor processor = null; try { constructor = type.getConstructor(ExtensionPointRegistry.class); processor = (RuntimeWireProcessor)constructor.newInstance(registry); } catch (NoSuchMethodException e) { constructor = type.getConstructor(); processor = (RuntimeWireProcessor)constructor.newInstance(); } if (processor != null) { addWireProcessor(processor); } } loaded = true; } catch (Throwable e) { throw new IllegalStateException(e); } }
Class<?> factoryClass = registry.getServiceDiscovery().getServiceDeclaration(bindingType).getClass(); if (factoryClass != null) { factory = (JavascriptProxyFactory) ServiceDiscovery.getInstance().getServiceDeclaration(bindingType); } catch (Exception e) { throw new IllegalArgumentException(e);
/** * Constructs a new registry. */ public DefaultExtensionPointRegistry() { this.discovery = ServiceDiscovery.getInstance(); }
private static List<ClassLoader> getClassLoaders(ServiceDiscovery discovery, Class<?>... serviceTypes) { List<ClassLoader> loaders = new ArrayList<ClassLoader>(); for (Class<?> serviceType : serviceTypes) { ClassLoader classLoader = getClassLoader(discovery, serviceType); if (classLoader != null && !loaders.contains(classLoader)) { loaders.add(classLoader); } } ClassLoader tccl = discovery.getContextClassLoader(); if (!loaders.contains(tccl)) { loaders.add(tccl); } return loaders; }
public Collection<ServiceDeclaration> getServiceDeclarations(String name, boolean byRanking) throws IOException { Collection<ServiceDeclaration> declarations = getServiceDiscoverer().getServiceDeclarations(name); // declarations = removeDuplicateDeclarations(declarations); // Check if any of the service declarations has attributes that are overrided if (!serviceAttributes.isEmpty()) { for (ServiceDeclaration declaration : declarations) { Map<String, String> attrs = getAttributes(name); if (attrs != null) { declaration.getAttributes().putAll(attrs); } } } if (!byRanking) { return declarations; } if (!declarations.isEmpty()) { List<ServiceDeclaration> declarationList = new ArrayList<ServiceDeclaration>(declarations); Collections.sort(declarationList, ServiceComparator.DESCENDING_ORDER); return declarationList; } else { return Collections.emptyList(); } }
public static ServiceDiscovery getInstance(ServiceDiscoverer discoverer) { return new ServiceDiscovery(discoverer); }
private synchronized void loadWireProcessors() { if (loaded) { return; } try { Collection<ServiceDeclaration> sds = registry.getServiceDiscovery().getServiceDeclarations(RuntimeWireProcessor.class, true); sds = ServiceDiscovery.removeDuplicateDeclarations(sds); for (ServiceDeclaration sd : sds) { Class type = sd.loadClass(); Constructor constructor = null; RuntimeWireProcessor processor = null; try { constructor = type.getConstructor(ExtensionPointRegistry.class); processor = (RuntimeWireProcessor)constructor.newInstance(registry); } catch (NoSuchMethodException e) { constructor = type.getConstructor(); processor = (RuntimeWireProcessor)constructor.newInstance(); } if (processor != null) { addWireProcessor(processor); } } loaded = true; } catch (Throwable e) { throw new IllegalStateException(e); } }
private static ClassLoader parentClassLoader(Contribution contribution) { if (contribution.getClassLoader() != null) { return contribution.getClassLoader(); } ClassLoader parentClassLoader = ServiceDiscovery.getInstance().getContextClassLoader(); return parentClassLoader; }
/** * Constructs a new registry. */ public DefaultExtensionPointRegistry() { this.discovery = ServiceDiscovery.getInstance(); }
public void start(BundleContext context) throws Exception { discoverer = new EquinoxServiceDiscoverer(context); ServiceDiscovery.getInstance().setServiceDiscoverer(discoverer); // logger.info("Equinox-based service discoverer is now configured."); }
private static List<ClassLoader> getClassLoaders(ServiceDiscovery discovery, Class<?>... serviceTypes) { List<ClassLoader> loaders = new ArrayList<ClassLoader>(); for (Class<?> serviceType : serviceTypes) { ClassLoader classLoader = getClassLoader(discovery, serviceType); if (classLoader != null && !loaders.contains(classLoader)) { loaders.add(classLoader); } } ClassLoader tccl = discovery.getContextClassLoader(); if (!loaders.contains(tccl)) { loaders.add(tccl); } return loaders; }
public Collection<ServiceDeclaration> getServiceDeclarations(String name, boolean byRanking) throws IOException { Collection<ServiceDeclaration> declarations = getServiceDiscoverer().getServiceDeclarations(name); // declarations = removeDuplicateDeclarations(declarations); // Check if any of the service declarations has attributes that are overrided if (!serviceAttributes.isEmpty()) { for (ServiceDeclaration declaration : declarations) { Map<String, String> attrs = getAttributes(name); if (attrs != null) { declaration.getAttributes().putAll(attrs); } } } if (!byRanking) { return declarations; } if (!declarations.isEmpty()) { List<ServiceDeclaration> declarationList = new ArrayList<ServiceDeclaration>(declarations); Collections.sort(declarationList, ServiceComparator.DESCENDING_ORDER); return declarationList; } else { return Collections.emptyList(); } }
public static ServiceDiscovery getInstance(ServiceDiscoverer discoverer) { return new ServiceDiscovery(discoverer); }
/** * Discover all service providers that are compatible with the service type * @param serviceType * @return * @throws IOException */ public Collection<ServiceDeclaration> getServiceDeclarations(Class<?> serviceType) throws IOException { return getServiceDeclarations(serviceType, false); }
void initCommands() throws IOException { for (ServiceDeclaration sd : ServiceDiscovery.getInstance().getServiceDeclarations(Command.class)) { try { Class<?> c = Class.forName(sd.getClassName()); try { Command command = (Command)c.getConstructor(Shell.class).newInstance(this); commands.put(command.getName(), command); } catch (NoSuchMethodException e) { Command command = (Command)c.newInstance(); commands.put(command.getName(), command); } } catch (Exception e) { e.printStackTrace(); } } }