@Test public void testGetPlatformCapabilities() throws Exception { PlatformCapability[] pCaps = systemCapabilities.getPlatformCapabilities(new DynamicConfiguration()); Assert.assertTrue("Expected at least 7", pCaps.length>=7); ProcessorArchitecture processorArchitecture = getCapability(ProcessorArchitecture.class, pCaps); Assert.assertNotNull(processorArchitecture); log(processorArchitecture); OperatingSystem operatingSystem = getCapability(OperatingSystem.class, pCaps); Assert.assertNotNull(operatingSystem); log(operatingSystem); TCPConnectivity tcpip = getCapability(TCPConnectivity.class, pCaps); Assert.assertNotNull(tcpip); log(tcpip); StorageCapability storage = getCapability(StorageCapability.class, pCaps); Assert.assertNotNull(storage); log(storage); Memory memory = getCapability(Memory.class, pCaps); Assert.assertNotNull(memory); log(memory); SystemMemory systemMemory = getCapability(SystemMemory.class, pCaps); Assert.assertNotNull(systemMemory); log(systemMemory); J2SESupport java = getCapability(J2SESupport.class, pCaps); Assert.assertNotNull(java); log(java); }
public PlatformCapability[] getPlatformCapabilities(Configuration config) { List<PlatformCapability> platforms = new ArrayList<>(); try { ProcessorArchitecture processor = new ProcessorArchitecture(); platforms.add(processor); PlatformCapability operatingSystem = new OperatingSystem(); platforms.add(operatingSystem); PlatformCapability tcpIP = new TCPConnectivity(); platforms.add(tcpIP); PlatformCapability j2se = new J2SESupport(); platforms.add(j2se); PlatformCapability[] pCaps = (PlatformCapability[])config.getEntry(COMPONENT, "platformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); List<PlatformCapability> platformCapabilityList = new ArrayList<>(Arrays.asList(pCaps)); PlatformCapability[] addCaps = (PlatformCapability[])config.getEntry(COMPONENT, "addPlatformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); platformCapabilityList.addAll(Arrays.asList(addCaps)); PlatformLoader loader = new PlatformLoader(); pCaps = createPlatformCapabilities(loader.getDefaultPlatform(getRioHome())); platformCapabilityList.addAll(Arrays.asList(pCaps)); String platformDir = getPlatformConfigurationDirectory(config); if(platformDir!=null) { PlatformCapability[] caps = parsePlatformConfig(loader, platformDir); platformCapabilityList.addAll(Arrays.asList(caps)); } else { logger.warn("Unable to establish the platform configuration directory, most likely RIO_HOME is not set."); } pCaps = platformCapabilityList.toArray(new PlatformCapability[0]); for (PlatformCapability pCap : pCaps) { if (pCap.getClass().getName().equals(RIO)) { if (getRioHome() != null) { pCap.setPath(getRioHome()); } } platforms.add(pCap); } PlatformCapability storage = findCapability(platforms, STORAGE); if(storage==null) { storage = getPlatformCapability(STORAGE); platforms.add(storage); } PlatformCapability memory = findCapability(platforms, MEMORY); if(memory == null) { memory = getPlatformCapability(MEMORY); platforms.add(memory); } PlatformCapability systemMemory = findCapability(platforms, SYSTEM_MEMORY); if(systemMemory == null) { systemMemory = getPlatformCapability(SYSTEM_MEMORY); platforms.add(systemMemory); } String nativeLibDirs = System.getProperty(NATIVE_LIBS); List<File> dirList = new ArrayList<>(); if(nativeLibDirs!=null && nativeLibDirs.length()>0) { StringTokenizer st = new StringTokenizer(nativeLibDirs, File.pathSeparator+" "); while(st.hasMoreTokens()) { String dirName = st.nextToken(); File dir = new File(dirName); if(dir.isDirectory() && dir.canRead()) { dirList.add(dir); if(logger.isDebugEnabled()) logger.debug("Adding directory [{}] to check for native libraries", dirName); } else { logger.warn("Invalid directory name or access permissions to check for native libraries [{}]. Continuing ...", dirName); } } final String[] libExtensions = getLibExtensions(); File[] dirs = dirList.toArray(new File[0]); for (File dir : dirs) { File[] files = dir.listFiles(pathName -> { try { if(FileUtils.isSymbolicLink(pathName)) { return false; } } catch (IOException e) { logger.warn( "Trying to determine whether the file is a symbolic link", e); } boolean matches = false; for(String libExtension : libExtensions) { if(pathName.getName().endsWith(libExtension)) { matches = true; break; } } return matches; }); if (files != null) { for (File file : files) { String fileName = file.getName(); int index = fileName.lastIndexOf("."); if (index != -1) { if (logger.isDebugEnabled()) logger.debug("Create NativeLibrarySupport object for [{}]", fileName); PlatformCapability nLib = getPlatformCapability(NATIVE_LIB_CLASS); String name; name = fileName.substring(0, index); nLib.define(NativeLibrarySupport.NAME, name); nLib.define(NativeLibrarySupport.FILENAME, fileName); nLib.setPath(dir.getCanonicalPath()); platforms.add(nLib); } else { logger.warn("Illegal Shared Library name=" + fileName); } } } } } } catch(Throwable t) { logger.error("Getting PlatformCapability objects", t); } return platforms.toArray(new PlatformCapability[0]); }
SystemCapabilities implements SystemCapabilitiesLoader { public PlatformCapability[] getPlatformCapabilities(Configuration config) { List<PlatformCapability> platforms = new ArrayList<>(); try { ProcessorArchitecture processor = new ProcessorArchitecture(); platforms.add(processor); PlatformCapability operatingSystem = new OperatingSystem(); platforms.add(operatingSystem); PlatformCapability tcpIP = new TCPConnectivity(); platforms.add(tcpIP); PlatformCapability j2se = new J2SESupport(); platforms.add(j2se); PlatformCapability[] pCaps = (PlatformCapability[])config.getEntry(COMPONENT, "platformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); List<PlatformCapability> platformCapabilityList = new ArrayList<>(Arrays.asList(pCaps)); PlatformCapability[] addCaps = (PlatformCapability[])config.getEntry(COMPONENT, "addPlatformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); platformCapabilityList.addAll(Arrays.asList(addCaps)); PlatformLoader loader = new PlatformLoader(); pCaps = createPlatformCapabilities(loader.getDefaultPlatform(getRioHome())); platformCapabilityList.addAll(Arrays.asList(pCaps)); String platformDir = getPlatformConfigurationDirectory(config); if(platformDir!=null) { PlatformCapability[] caps = parsePlatformConfig(loader, platformDir); platformCapabilityList.addAll(Arrays.asList(caps)); } else { logger.warn("Unable to establish the platform configuration directory, most likely RIO_HOME is not set."); } pCaps = platformCapabilityList.toArray(new PlatformCapability[0]); for (PlatformCapability pCap : pCaps) { if (pCap.getClass().getName().equals(RIO)) { if (getRioHome() != null) { pCap.setPath(getRioHome()); } } platforms.add(pCap); } PlatformCapability storage = findCapability(platforms, STORAGE); if(storage==null) { storage = getPlatformCapability(STORAGE); platforms.add(storage); } PlatformCapability memory = findCapability(platforms, MEMORY); if(memory == null) { memory = getPlatformCapability(MEMORY); platforms.add(memory); } PlatformCapability systemMemory = findCapability(platforms, SYSTEM_MEMORY); if(systemMemory == null) { systemMemory = getPlatformCapability(SYSTEM_MEMORY); platforms.add(systemMemory); } String nativeLibDirs = System.getProperty(NATIVE_LIBS); List<File> dirList = new ArrayList<>(); if(nativeLibDirs!=null && nativeLibDirs.length()>0) { StringTokenizer st = new StringTokenizer(nativeLibDirs, File.pathSeparator+" "); while(st.hasMoreTokens()) { String dirName = st.nextToken(); File dir = new File(dirName); if(dir.isDirectory() && dir.canRead()) { dirList.add(dir); if(logger.isDebugEnabled()) logger.debug("Adding directory [{}] to check for native libraries", dirName); } else { logger.warn("Invalid directory name or access permissions to check for native libraries [{}]. Continuing ...", dirName); } } final String[] libExtensions = getLibExtensions(); File[] dirs = dirList.toArray(new File[0]); for (File dir : dirs) { File[] files = dir.listFiles(pathName -> { try { if(FileUtils.isSymbolicLink(pathName)) { return false; } } catch (IOException e) { logger.warn( "Trying to determine whether the file is a symbolic link", e); } boolean matches = false; for(String libExtension : libExtensions) { if(pathName.getName().endsWith(libExtension)) { matches = true; break; } } return matches; }); if (files != null) { for (File file : files) { String fileName = file.getName(); int index = fileName.lastIndexOf("."); if (index != -1) { if (logger.isDebugEnabled()) logger.debug("Create NativeLibrarySupport object for [{}]", fileName); PlatformCapability nLib = getPlatformCapability(NATIVE_LIB_CLASS); String name; name = fileName.substring(0, index); nLib.define(NativeLibrarySupport.NAME, name); nLib.define(NativeLibrarySupport.FILENAME, fileName); nLib.setPath(dir.getCanonicalPath()); platforms.add(nLib); } else { logger.warn("Illegal Shared Library name=" + fileName); } } } } } } catch(Throwable t) { logger.error("Getting PlatformCapability objects", t); } return platforms.toArray(new PlatformCapability[0]); } }
SystemCapabilities implements SystemCapabilitiesLoader { public PlatformCapability[] getPlatformCapabilities(Configuration config) { List<PlatformCapability> platforms = new ArrayList<>(); try { ProcessorArchitecture processor = new ProcessorArchitecture(); platforms.add(processor); PlatformCapability operatingSystem = new OperatingSystem(); platforms.add(operatingSystem); PlatformCapability tcpIP = new TCPConnectivity(); platforms.add(tcpIP); PlatformCapability j2se = new J2SESupport(); platforms.add(j2se); PlatformCapability[] pCaps = (PlatformCapability[])config.getEntry(COMPONENT, "platformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); List<PlatformCapability> platformCapabilityList = new ArrayList<>(Arrays.asList(pCaps)); PlatformCapability[] addCaps = (PlatformCapability[])config.getEntry(COMPONENT, "addPlatformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); platformCapabilityList.addAll(Arrays.asList(addCaps)); PlatformLoader loader = new PlatformLoader(); pCaps = createPlatformCapabilities(loader.getDefaultPlatform(getRioHome())); platformCapabilityList.addAll(Arrays.asList(pCaps)); String platformDir = getPlatformConfigurationDirectory(config); if(platformDir!=null) { PlatformCapability[] caps = parsePlatformConfig(loader, platformDir); platformCapabilityList.addAll(Arrays.asList(caps)); } else { logger.warn("Unable to establish the platform configuration directory, most likely RIO_HOME is not set."); } pCaps = platformCapabilityList.toArray(new PlatformCapability[0]); for (PlatformCapability pCap : pCaps) { if (pCap.getClass().getName().equals(RIO)) { if (getRioHome() != null) { pCap.setPath(getRioHome()); } } platforms.add(pCap); } PlatformCapability storage = findCapability(platforms, STORAGE); if(storage==null) { storage = getPlatformCapability(STORAGE); platforms.add(storage); } PlatformCapability memory = findCapability(platforms, MEMORY); if(memory == null) { memory = getPlatformCapability(MEMORY); platforms.add(memory); } PlatformCapability systemMemory = findCapability(platforms, SYSTEM_MEMORY); if(systemMemory == null) { systemMemory = getPlatformCapability(SYSTEM_MEMORY); platforms.add(systemMemory); } String nativeLibDirs = System.getProperty(NATIVE_LIBS); List<File> dirList = new ArrayList<>(); if(nativeLibDirs!=null && nativeLibDirs.length()>0) { StringTokenizer st = new StringTokenizer(nativeLibDirs, File.pathSeparator+" "); while(st.hasMoreTokens()) { String dirName = st.nextToken(); File dir = new File(dirName); if(dir.isDirectory() && dir.canRead()) { dirList.add(dir); if(logger.isDebugEnabled()) logger.debug("Adding directory [{}] to check for native libraries", dirName); } else { logger.warn("Invalid directory name or access permissions to check for native libraries [{}]. Continuing ...", dirName); } } final String[] libExtensions = getLibExtensions(); File[] dirs = dirList.toArray(new File[0]); for (File dir : dirs) { File[] files = dir.listFiles(pathName -> { try { if(FileUtils.isSymbolicLink(pathName)) { return false; } } catch (IOException e) { logger.warn( "Trying to determine whether the file is a symbolic link", e); } boolean matches = false; for(String libExtension : libExtensions) { if(pathName.getName().endsWith(libExtension)) { matches = true; break; } } return matches; }); if (files != null) { for (File file : files) { String fileName = file.getName(); int index = fileName.lastIndexOf("."); if (index != -1) { if (logger.isDebugEnabled()) logger.debug("Create NativeLibrarySupport object for [{}]", fileName); PlatformCapability nLib = getPlatformCapability(NATIVE_LIB_CLASS); String name; name = fileName.substring(0, index); nLib.define(NativeLibrarySupport.NAME, name); nLib.define(NativeLibrarySupport.FILENAME, fileName); nLib.setPath(dir.getCanonicalPath()); platforms.add(nLib); } else { logger.warn("Illegal Shared Library name=" + fileName); } } } } } } catch(Throwable t) { logger.error("Getting PlatformCapability objects", t); } return platforms.toArray(new PlatformCapability[0]); }  }
SystemCapabilities implements SystemCapabilitiesLoader { public PlatformCapability[] getPlatformCapabilities(Configuration config) { List<PlatformCapability> platforms = new ArrayList<>(); try { ProcessorArchitecture processor = new ProcessorArchitecture(); platforms.add(processor); PlatformCapability operatingSystem = new OperatingSystem(); platforms.add(operatingSystem); PlatformCapability tcpIP = new TCPConnectivity(); platforms.add(tcpIP); PlatformCapability j2se = new J2SESupport(); platforms.add(j2se); PlatformCapability[] pCaps = (PlatformCapability[])config.getEntry(COMPONENT, "platformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); List<PlatformCapability> platformCapabilityList = new ArrayList<>(Arrays.asList(pCaps)); PlatformCapability[] addCaps = (PlatformCapability[])config.getEntry(COMPONENT, "addPlatformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); platformCapabilityList.addAll(Arrays.asList(addCaps)); PlatformLoader loader = new PlatformLoader(); pCaps = createPlatformCapabilities(loader.getDefaultPlatform(getRioHome())); platformCapabilityList.addAll(Arrays.asList(pCaps)); String platformDir = getPlatformConfigurationDirectory(config); if(platformDir!=null) { PlatformCapability[] caps = parsePlatformConfig(loader, platformDir); platformCapabilityList.addAll(Arrays.asList(caps)); } else { logger.warn("Unable to establish the platform configuration directory, most likely RIO_HOME is not set."); } pCaps = platformCapabilityList.toArray(new PlatformCapability[0]); for (PlatformCapability pCap : pCaps) { if (pCap.getClass().getName().equals(RIO)) { if (getRioHome() != null) { pCap.setPath(getRioHome()); } } platforms.add(pCap); } PlatformCapability storage = findCapability(platforms, STORAGE); if(storage==null) { storage = getPlatformCapability(STORAGE); platforms.add(storage); } PlatformCapability memory = findCapability(platforms, MEMORY); if(memory == null) { memory = getPlatformCapability(MEMORY); platforms.add(memory); } PlatformCapability systemMemory = findCapability(platforms, SYSTEM_MEMORY); if(systemMemory == null) { systemMemory = getPlatformCapability(SYSTEM_MEMORY); platforms.add(systemMemory); } String nativeLibDirs = System.getProperty(NATIVE_LIBS); List<File> dirList = new ArrayList<>(); if(nativeLibDirs!=null && nativeLibDirs.length()>0) { StringTokenizer st = new StringTokenizer(nativeLibDirs, File.pathSeparator+" "); while(st.hasMoreTokens()) { String dirName = st.nextToken(); File dir = new File(dirName); if(dir.isDirectory() && dir.canRead()) { dirList.add(dir); if(logger.isDebugEnabled()) logger.debug("Adding directory [{}] to check for native libraries", dirName); } else { logger.warn("Invalid directory name or access permissions to check for native libraries [{}]. Continuing ...", dirName); } } final String[] libExtensions = getLibExtensions(); File[] dirs = dirList.toArray(new File[0]); for (File dir : dirs) { File[] files = dir.listFiles(pathName -> { try { if(FileUtils.isSymbolicLink(pathName)) { return false; } } catch (IOException e) { logger.warn( "Trying to determine whether the file is a symbolic link", e); } boolean matches = false; for(String libExtension : libExtensions) { if(pathName.getName().endsWith(libExtension)) { matches = true; break; } } return matches; }); if (files != null) { for (File file : files) { String fileName = file.getName(); int index = fileName.lastIndexOf("."); if (index != -1) { if (logger.isDebugEnabled()) logger.debug("Create NativeLibrarySupport object for [{}]", fileName); PlatformCapability nLib = getPlatformCapability(NATIVE_LIB_CLASS); String name; name = fileName.substring(0, index); nLib.define(NativeLibrarySupport.NAME, name); nLib.define(NativeLibrarySupport.FILENAME, fileName); nLib.setPath(dir.getCanonicalPath()); platforms.add(nLib); } else { logger.warn("Illegal Shared Library name=" + fileName); } } } } } } catch(Throwable t) { logger.error("Getting PlatformCapability objects", t); } return platforms.toArray(new PlatformCapability[0]); }  MeasurableCapability[] getMeasurableCapabilities(Configuration config); PlatformCapability[] getPlatformCapabilities(Configuration config); Map<String, String> getPlatformCapabilityNameTable(); String getPlatformConfigurationDirectory(Configuration config); }
SystemCapabilities implements SystemCapabilitiesLoader { public PlatformCapability[] getPlatformCapabilities(Configuration config) { List<PlatformCapability> platforms = new ArrayList<>(); try { ProcessorArchitecture processor = new ProcessorArchitecture(); platforms.add(processor); PlatformCapability operatingSystem = new OperatingSystem(); platforms.add(operatingSystem); PlatformCapability tcpIP = new TCPConnectivity(); platforms.add(tcpIP); PlatformCapability j2se = new J2SESupport(); platforms.add(j2se); PlatformCapability[] pCaps = (PlatformCapability[])config.getEntry(COMPONENT, "platformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); List<PlatformCapability> platformCapabilityList = new ArrayList<>(Arrays.asList(pCaps)); PlatformCapability[] addCaps = (PlatformCapability[])config.getEntry(COMPONENT, "addPlatformCapabilities", PlatformCapability[].class, new PlatformCapability[0]); platformCapabilityList.addAll(Arrays.asList(addCaps)); PlatformLoader loader = new PlatformLoader(); pCaps = createPlatformCapabilities(loader.getDefaultPlatform(getRioHome())); platformCapabilityList.addAll(Arrays.asList(pCaps)); String platformDir = getPlatformConfigurationDirectory(config); if(platformDir!=null) { PlatformCapability[] caps = parsePlatformConfig(loader, platformDir); platformCapabilityList.addAll(Arrays.asList(caps)); } else { logger.warn("Unable to establish the platform configuration directory, most likely RIO_HOME is not set."); } pCaps = platformCapabilityList.toArray(new PlatformCapability[0]); for (PlatformCapability pCap : pCaps) { if (pCap.getClass().getName().equals(RIO)) { if (getRioHome() != null) { pCap.setPath(getRioHome()); } } platforms.add(pCap); } PlatformCapability storage = findCapability(platforms, STORAGE); if(storage==null) { storage = getPlatformCapability(STORAGE); platforms.add(storage); } PlatformCapability memory = findCapability(platforms, MEMORY); if(memory == null) { memory = getPlatformCapability(MEMORY); platforms.add(memory); } PlatformCapability systemMemory = findCapability(platforms, SYSTEM_MEMORY); if(systemMemory == null) { systemMemory = getPlatformCapability(SYSTEM_MEMORY); platforms.add(systemMemory); } String nativeLibDirs = System.getProperty(NATIVE_LIBS); List<File> dirList = new ArrayList<>(); if(nativeLibDirs!=null && nativeLibDirs.length()>0) { StringTokenizer st = new StringTokenizer(nativeLibDirs, File.pathSeparator+" "); while(st.hasMoreTokens()) { String dirName = st.nextToken(); File dir = new File(dirName); if(dir.isDirectory() && dir.canRead()) { dirList.add(dir); if(logger.isDebugEnabled()) logger.debug("Adding directory [{}] to check for native libraries", dirName); } else { logger.warn("Invalid directory name or access permissions to check for native libraries [{}]. Continuing ...", dirName); } } final String[] libExtensions = getLibExtensions(); File[] dirs = dirList.toArray(new File[0]); for (File dir : dirs) { File[] files = dir.listFiles(pathName -> { try { if(FileUtils.isSymbolicLink(pathName)) { return false; } } catch (IOException e) { logger.warn( "Trying to determine whether the file is a symbolic link", e); } boolean matches = false; for(String libExtension : libExtensions) { if(pathName.getName().endsWith(libExtension)) { matches = true; break; } } return matches; }); if (files != null) { for (File file : files) { String fileName = file.getName(); int index = fileName.lastIndexOf("."); if (index != -1) { if (logger.isDebugEnabled()) logger.debug("Create NativeLibrarySupport object for [{}]", fileName); PlatformCapability nLib = getPlatformCapability(NATIVE_LIB_CLASS); String name; name = fileName.substring(0, index); nLib.define(NativeLibrarySupport.NAME, name); nLib.define(NativeLibrarySupport.FILENAME, fileName); nLib.setPath(dir.getCanonicalPath()); platforms.add(nLib); } else { logger.warn("Illegal Shared Library name=" + fileName); } } } } } } catch(Throwable t) { logger.error("Getting PlatformCapability objects", t); } return platforms.toArray(new PlatformCapability[0]); }  MeasurableCapability[] getMeasurableCapabilities(Configuration config); PlatformCapability[] getPlatformCapabilities(Configuration config); Map<String, String> getPlatformCapabilityNameTable(); String getPlatformConfigurationDirectory(Configuration config); static final String COMPONENT; static final String CAPABILITY; static final String NATIVE_LIBS; static final String PROCESSOR; static final String OPSYS; static final String TCPIP; static final String J2SE; static final String MEMORY; static final String SYSTEM_MEMORY; static final String STORAGE; static final String NATIVE_LIB_CLASS; static final String RIO; }