List of usage examples for java.util.function BooleanSupplier getAsBoolean
boolean getAsBoolean();
From source file:org.codice.ddf.migration.util.MigratableUtil.java
private void copy(Path sourceFile, Path exportDirectory, Collection<MigrationWarning> warnings, BooleanSupplier isSourceMigratable) throws MigrationException { notNull(sourceFile, "Source file cannot be null"); notNull(exportDirectory, "Destination cannot be null"); notNull(warnings, "Warning collection cannot be null"); try {// w w w . j ava 2 s . com if (isSourceMigratable.getAsBoolean()) { FileUtils.copyFile(sourceFile.toFile(), exportDirectory.resolve(sourceFile).toFile()); } } catch (IOException e) { String message = String.format("Unable to copy [%s] to [%s]", sourceFile.toString(), exportDirectory.toString()); LOGGER.error(message, e); throw new ExportMigrationException(message, e); } }
From source file:org.jitsi.meet.test.base.Participant.java
/** * Waits for a condition./*from w w w . j a v a 2 s.co m*/ * * @param condition a {@link BooleanSupplier} which return {@code true} when * the condition has been met. * @param timeoutSeconds a timeout in seconds. * @param label a label which will appear in a timeout exception when * the condition is not met withing the time limit. */ public void waitForCondition(final BooleanSupplier condition, int timeoutSeconds, String label) { TestUtils.waitForCondition(driver, timeoutSeconds, new ExpectedCondition<Boolean>() { @Override public Boolean apply(WebDriver webDriver) { return condition.getAsBoolean(); } @Override public String toString() { return label; } }); }
From source file:com.addthis.hydra.data.tree.nonconcurrent.NonConcurrentTree.java
/** * Iteratively delete all the children of the input node. * Use a non-negative value for the counter parameter to * tally the nodes that have been deleted. Use a negative * value to disable logging of the number of deleted nodes. * * @param rootNode root of the subtree to delete *///w w w .j a v a 2s.c o m void deleteSubTree(NonConcurrentTreeNode rootNode, MutableLong totalCount, MutableLong nodeCount, BooleanSupplier terminationCondition) { long nodeDB = rootNode.nodeDB(); IPageDB.Range<DBKey, NonConcurrentTreeNode> range = fetchNodeRange(nodeDB); DBKey endRange; boolean reschedule; try { while (range.hasNext() && !terminationCondition.getAsBoolean()) { totalCount.increment(); if ((totalCount.longValue() % deletionLogInterval) == 0) { log.info("Deleted {} total nodes in {} trash nodes from the trash.", totalCount.longValue(), nodeCount.longValue()); } Map.Entry<DBKey, NonConcurrentTreeNode> entry = range.next(); NonConcurrentTreeNode next = entry.getValue(); if (next.hasNodes() && !next.isAlias()) { deleteSubTree(next, totalCount, nodeCount, terminationCondition); } } if (range.hasNext()) { endRange = range.next().getKey(); reschedule = true; } else { endRange = new DBKey(nodeDB + 1); reschedule = false; } } finally { range.close(); } source.remove(new DBKey(nodeDB), endRange); if (reschedule) { markForChildDeletion(rootNode); } }
From source file:net.mozq.picto.core.ProcessCore.java
public static void findFiles(ProcessCondition processCondition, Consumer<ProcessData> processDataSetter, BooleanSupplier processStopper) throws IOException { Set<FileVisitOption> fileVisitOptionSet; if (processCondition.isFollowLinks()) { fileVisitOptionSet = EnumSet.of(FileVisitOption.FOLLOW_LINKS); } else {/* w ww. j a va 2 s . c o m*/ fileVisitOptionSet = Collections.emptySet(); } Files.walkFileTree(processCondition.getSrcRootPath(), fileVisitOptionSet, processCondition.getDept(), new SimpleFileVisitor<Path>() { @Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { if (processStopper.getAsBoolean()) { return FileVisitResult.TERMINATE; } return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (attrs.isDirectory()) { return FileVisitResult.SKIP_SUBTREE; } if (processStopper.getAsBoolean()) { return FileVisitResult.TERMINATE; } if (!processCondition.getPathFilter().accept(file, attrs)) { return FileVisitResult.SKIP_SUBTREE; } Path rootRelativeSubPath = processCondition.getSrcRootPath().relativize(file.getParent()); ImageMetadata imageMetadata = getImageMetadata(file); Date baseDate; if (processCondition.isChangeFileCreationDate() || processCondition.isChangeFileModifiedDate() || processCondition.isChangeFileAccessDate() || processCondition.isChangeExifDate()) { baseDate = getBaseDate(processCondition, file, attrs, imageMetadata); } else { baseDate = null; } String destSubPathname = processCondition.getDestSubPathFormat().format(varName -> { try { switch (varName) { case "Now": return new Date(); case "ParentSubPath": return rootRelativeSubPath.toString(); case "FileName": return file.getFileName().toString(); case "BaseName": return FileUtilz.getBaseName(file.getFileName().toString()); case "Extension": return FileUtilz.getExt(file.getFileName().toString()); case "Size": return Long.valueOf(Files.size(file)); case "CreationDate": return (processCondition.isChangeFileCreationDate()) ? baseDate : new Date(attrs.creationTime().toMillis()); case "ModifiedDate": return (processCondition.isChangeFileModifiedDate()) ? baseDate : new Date(attrs.lastModifiedTime().toMillis()); case "AccessDate": return (processCondition.isChangeFileAccessDate()) ? baseDate : new Date(attrs.lastAccessTime().toMillis()); case "PhotoTakenDate": return (processCondition.isChangeExifDate()) ? baseDate : getPhotoTakenDate(file, imageMetadata); case "Width": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_WIDTH); case "Height": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXIF_IMAGE_LENGTH); case "FNumber": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FNUMBER); case "Aperture": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_APERTURE_VALUE); case "MaxAperture": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_MAX_APERTURE_VALUE); case "ISO": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_ISO); case "FocalLength": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FOCAL_LENGTH); // ? case "FocalLength35mm": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_FOCAL_LENGTH_IN_35MM_FORMAT); case "ShutterSpeed": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_SHUTTER_SPEED_VALUE); case "Exposure": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE); // case "ExposureTime": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_TIME); // case "ExposureMode": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_MODE); case "ExposureProgram": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_EXPOSURE_PROGRAM); case "Brightness": return getEXIFDoubleValue(imageMetadata, ExifTagConstants.EXIF_TAG_BRIGHTNESS_VALUE); case "WhiteBalance": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_WHITE_BALANCE_1); case "LightSource": return getEXIFIntValue(imageMetadata, ExifTagConstants.EXIF_TAG_LIGHT_SOURCE); case "Lens": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS); case "LensMake": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MAKE); case "LensModel": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_MODEL); case "LensSerialNumber": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_LENS_SERIAL_NUMBER); case "Make": return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MAKE); case "Model": return getEXIFStringValue(imageMetadata, TiffTagConstants.TIFF_TAG_MODEL); case "SerialNumber": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_SERIAL_NUMBER); case "Software": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_SOFTWARE); case "ProcessingSoftware": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_PROCESSING_SOFTWARE); case "OwnerName": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_OWNER_NAME); case "CameraOwnerName": return getEXIFStringValue(imageMetadata, ExifTagConstants.EXIF_TAG_CAMERA_OWNER_NAME); case "GPSLat": return getEXIFGpsLat(imageMetadata); case "GPSLatDeg": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 0); case "GPSLatMin": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 1); case "GPSLatSec": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE, 2); case "GPSLatRef": return getEXIFStringValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LATITUDE_REF); case "GPSLon": return getEXIFGpsLon(imageMetadata); case "GPSLonDeg": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 0); case "GPSLonMin": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 1); case "GPSLonSec": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE, 2); case "GPSLonRef": return getEXIFStringValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_LONGITUDE_REF); case "GPSAlt": return getEXIFDoubleValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE); case "GPSAltRef": return getEXIFIntValue(imageMetadata, GpsTagConstants.GPS_TAG_GPS_ALTITUDE_REF); default: throw new PictoInvalidDestinationPathException(Messages .getString("message.warn.invalid.destSubPath.varName", varName)); } } catch (PictoException e) { throw e; } catch (Exception e) { throw new PictoInvalidDestinationPathException( Messages.getString("message.warn.invalid.destSubPath.pattern"), e); } }); Path destSubPath = processCondition.getDestRootPath().resolve(destSubPathname).normalize(); if (!destSubPath.startsWith(processCondition.getDestRootPath())) { throw new PictoInvalidDestinationPathException( Messages.getString("message.warn.invalid.destination.path", destSubPath)); } ProcessData processData = new ProcessData(); processData.setSrcPath(file); processData.setSrcFileAttributes(attrs); processData.setDestPath(destSubPath); processData.setBaseDate(baseDate); processDataSetter.accept(processData); return FileVisitResult.CONTINUE; } }); }
From source file:com.addthis.hydra.data.tree.nonconcurrent.NonConcurrentTree.java
@Override public void foregroundNodeDeletion(BooleanSupplier terminationCondition) { IPageDB.Range<DBKey, NonConcurrentTreeNode> range = fetchNodeRange(treeTrashNode.nodeDB()); Map.Entry<DBKey, NonConcurrentTreeNode> entry; MutableLong totalCount = new MutableLong(); MutableLong nodeCount = new MutableLong(); try {/*from ww w .j ava 2 s. c o m*/ while (range.hasNext() && !terminationCondition.getAsBoolean()) { entry = range.next(); if (entry != null) { NonConcurrentTreeNode node = entry.getValue(); NonConcurrentTreeNode prev = source.remove(entry.getKey()); if (prev != null) { deleteSubTree(node, totalCount, nodeCount, terminationCondition); nodeCount.increment(); treeTrashNode.incrementCounter(); } } } } finally { range.close(); } }
From source file:fr.treeptik.cloudunit.docker.DockerContainerJSON.java
public DockerContainer start(DockerContainer dockerContainer, String hostIp) throws DockerJSONException { URI uri = null;//from w w w . ja v a 2 s .c om try { uri = new URIBuilder().setScheme(dockerEndpointMode).setHost(hostIp) .setPath("/containers/" + dockerContainer.getName() + "/start").build(); JSONObject config = new JSONObject(); config.put("Privileged", Boolean.FALSE); config.put("PublishAllPorts", Boolean.TRUE); JSONArray link = new JSONArray(); if (dockerContainer.getLinks() != null) { link.addAll(dockerContainer.getLinks()); config.put("Links", link); } if (dockerContainer.getVolumesFrom() != null) { JSONArray listVolumesFrom = new JSONArray(); if (dockerContainer.getVolumesFrom() != null) { for (int i = 0, iMax = dockerContainer.getVolumesFrom().size(); i < iMax; i++) { listVolumesFrom.add(dockerContainer.getVolumesFrom().get(i)); } } config.put("VolumesFrom", listVolumesFrom); } if (dockerContainer.getPortsToOpen() != null) { JSONObject portsBinding = new JSONObject(); dockerContainer.getPortsToOpen().stream().map(t -> t.toString() + "/tcp").forEach( t -> portsBinding.put(t, Arrays.asList((new JSONObject(new HashMap<String, String>() { private static final long serialVersionUID = 1L; { put("HostPort", portUtils.getARandomHostPorts(hostIp).toString()); put("HostIp", "0.0.0.0"); } }))))); config.put("PortBindings", portsBinding); } // ajout des volumes provenant de l'hote final List volumes = new ArrayList<String>() { { add("/etc/localtime:/etc/localtime:ro"); add("/etc/timezone:/etc/timezone:ro"); } }; BooleanSupplier isRunningIntoKVM = () -> "true".equalsIgnoreCase(System.getenv().get("CU_KVM")); if (isRunningIntoKVM.getAsBoolean()) { volumes.add("/dev/urandom:/dev/urandom"); } Predicate<String> isContainerGit = s -> s.contains("-git-"); if (isContainerGit.test(dockerContainer.getName())) { volumes.add("/var/log/cloudunit/git/auth-" + dockerContainer.getId() + ":/var/log/cloudunit"); } config.put("Binds", volumes); /** * Gestion du binding de port */ JSONObject portBindsConfigJSONFinal = new JSONObject(); if (dockerContainer.getPortBindings() != null) { /** * pour chaque ports Binder (ex: 53/udp) on rcupre le * tableau avec les deux maps ex :- map1 = HostIp , 172.17.42.1 * - map2 = HostPort , 53 */ for (Map.Entry<String, Map<String, String>[]> portKey : dockerContainer.getPortBindings() .entrySet()) { logger.info("port/protocol to configure : " + portKey.getKey()); // On convertie le tableau en list pour itrer dessus List<Map<String, String>> listOfMapsConfig = Arrays.asList(portKey.getValue()); JSONObject portConfigJSON = new JSONObject(); for (Map<String, String> portConfigMap : listOfMapsConfig) { JSONArray portConfigJSONArray = new JSONArray(); // transfert HostIP and HostPort avec leur valeurs dans // un JSONArray for (Entry<String, String> hostBindingMap : portConfigMap.entrySet()) { logger.info(hostBindingMap.getKey() + " : " + hostBindingMap.getValue()); portConfigJSON.put(hostBindingMap.getKey(), hostBindingMap.getValue()); portConfigJSONArray.add(portConfigJSON); } portBindsConfigJSONFinal.put(portKey.getKey(), portConfigJSONArray); config.put("PortBindings", portBindsConfigJSONFinal); } } } int statusCode = client.sendPostForStart(uri, config.toJSONString(), "application/json"); switch (statusCode) { case 304: throw new WarningDockerJSONException("container already started"); case 404: throw new ErrorDockerJSONException("docker : no such container"); case 500: throw new ErrorDockerJSONException("docker : error server"); } dockerContainer = this.findOne(dockerContainer.getName(), hostIp); } catch (URISyntaxException | IOException e) { StringBuilder msgError = new StringBuilder(256); msgError.append(dockerContainer).append(",hostIP=").append(hostIp).append(",uri=").append(uri); logger.error("" + msgError, e); throw new FatalDockerJSONException("docker : error fatal"); } return dockerContainer; }
From source file:com.addthis.hydra.data.tree.concurrent.ConcurrentTree.java
/** * Recursively delete all the children of the input node. * Use a non-negative value for the counter parameter to * tally the nodes that have been deleted. Use a negative * value to disable logging of the number of deleted nodes. * * @param rootNode root of the subtree to delete *///from www .java 2 s . c o m void deleteSubTree(ConcurrentTreeNode rootNode, MutableLong totalCount, MutableLong nodeCount, BooleanSupplier terminationCondition, Logger deletionLogger) { long nodeDB = rootNode.nodeDB(); IPageDB.Range<DBKey, ConcurrentTreeNode> range = fetchNodeRange(nodeDB); DBKey endRange; boolean reschedule; try { while (range.hasNext() && !terminationCondition.getAsBoolean()) { totalCount.increment(); if ((totalCount.longValue() % deletionLogInterval) == 0) { deletionLogger.info("Deleted {} total nodes in {} trash nodes from the trash.", totalCount.longValue(), nodeCount.longValue()); } Map.Entry<DBKey, ConcurrentTreeNode> entry = range.next(); ConcurrentTreeNode next = entry.getValue(); if (next.hasNodes() && !next.isAlias()) { deleteSubTree(next, totalCount, nodeCount, terminationCondition, deletionLogger); } String name = entry.getKey().rawKey().toString(); CacheKey key = new CacheKey(nodeDB, name); ConcurrentTreeNode cacheNode = cache.remove(key); /* Mark the node as deleted so that it will not be * pushed to disk when removed from the eviction queue. */ if (cacheNode != null) { cacheNode.markDeleted(); } } if (range.hasNext()) { endRange = range.next().getKey(); reschedule = true; } else { endRange = new DBKey(nodeDB + 1); reschedule = false; } } finally { range.close(); } source.remove(new DBKey(nodeDB), endRange); if (reschedule) { markForChildDeletion(rootNode); } }