List of usage examples for java.util.concurrent ExecutorService execute
void execute(Runnable command);
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
public void importSpineAnimationsIntoProject(final Array<FileHandle> fileHandles, ProgressHandler progressHandler) { if (fileHandles == null) { return;/*from ww w. j a v a 2 s . co m*/ } handler = progressHandler; currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { for (FileHandle handle : fileHandles) { File copiedFile = importExternalAnimationIntoProject(handle); if (copiedFile.getName().toLowerCase().endsWith(".atlas")) { ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME); resolutionManager.resizeSpineAnimationForAllResolutions(copiedFile, currentProjectInfoVO); } else if (copiedFile.getName().toLowerCase().endsWith(".scml")) { //resizeSpriterAnimationForAllResolutions(copiedFile, currentProjectInfoVO); } } }); executor.execute(() -> { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); }); executor.shutdown(); }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
public void importShaderIntoProject(Array<FileHandle> files, ProgressHandler progressHandler) { if (files == null) { return;/*from w ww .j a v a2 s . c om*/ } handler = progressHandler; currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { for (FileHandle handle : files) { // check if shaders folder exists String shadersPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/shaders"; File destination = new File(currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/shaders/" + handle.name()); try { FileUtils.forceMkdir(new File(shadersPath)); FileUtils.copyFile(handle.file(), destination); } catch (IOException e) { e.printStackTrace(); } } }); executor.execute(() -> { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); }); executor.shutdown(); }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
public void importFontIntoProject(Array<FileHandle> fileHandles, ProgressHandler progressHandler) { if (fileHandles == null) { return;//from www. j a v a 2s . c om } String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/freetypefonts"; handler = progressHandler; float perCopyPercent = 95.0f / fileHandles.size; for (FileHandle fileHandle : fileHandles) { if (!Overlap2DUtils.TTF_FILTER.accept(null, fileHandle.name())) { continue; } try { File target = new File(targetPath); if (!target.exists()) { File newFile = new File(targetPath); newFile.mkdir(); } File fileTarget = new File(targetPath + "/" + fileHandle.name()); FileUtils.copyFile(fileHandle.file(), fileTarget); } catch (IOException e) { e.printStackTrace(); } System.out.println(perCopyPercent); changePercentBy(perCopyPercent); ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); }); executor.shutdown(); } }
From source file:org.kurento.test.base.BrowserTest.java
@Before public void setupBrowserTest() throws InterruptedException { if (testScenario != null && testScenario.getBrowserMap() != null && testScenario.getBrowserMap().size() > 0) { ExecutorService executor = Executors.newFixedThreadPool(testScenario.getBrowserMap().size()); final AbortableCountDownLatch latch = new AbortableCountDownLatch(testScenario.getBrowserMap().size()); for (final String browserKey : testScenario.getBrowserMap().keySet()) { executor.execute(new Runnable() { @Override//from w w w. j a va 2 s .com public void run() { try { Browser browser = testScenario.getBrowserMap().get(browserKey); int timeout = getProperty(TEST_URL_TIMEOUT_PROPERTY, TEST_URL_TIMEOUT_DEFAULT); URL url = browser.getUrl(); if (!testScenario.getUrlList().contains(url)) { waitForHostIsReachable(url, timeout); testScenario.getUrlList().add(url); } initBrowser(browserKey, browser); latch.countDown(); } catch (Throwable t) { latch.abort("Exception setting up test. A browser could not be initialised", t); t.printStackTrace(); } } }); } latch.await(); } }
From source file:com.oneops.boo.workflow.BuildAllPlatforms.java
/** * Right now support components with two layers config. * * @param platformName Platform name.//from w w w . j ava2s . c o m * @param componentName Component name. * @param attributes Component variables. * @throws OneOpsClientAPIException the one ops client API exception */ @SuppressWarnings({ "unchecked", "rawtypes" }) private void updateComponentVariables(String platformName, String componentName, Map<String, Object> attributes) throws OneOpsClientAPIException { // Create thread pool to add users parallel ExecutorService executor = Executors.newFixedThreadPool(numOfThreads); for (Map.Entry<String, Object> entry : attributes.entrySet()) { String key = entry.getKey(); Object value = entry.getValue(); // Another Map, so key is ciName if (value instanceof Map) { Map<String, String> attris = (Map<String, String>) value; if (attris.containsKey(Constants.AUTHO_KEYS)) { Runnable worker = new UpdateComponentTask(this, platformName, componentName, key, attris); executor.execute(worker); } else { this.updateComponentVariablesInternal(platformName, componentName, key, attris); } } else if (value instanceof String) { Map<String, String> att = (Map) attributes; if (att.containsKey(Constants.AUTHO_KEYS)) { Runnable worker = new UpdateComponentTask(this, platformName, componentName, key, att); executor.execute(worker); } else { this.updateComponentVariablesInternal(platformName, componentName, componentName, att); } break; } } executor.shutdown(); while (!executor.isTerminated()) { Uninterruptibles.sleepUninterruptibly(10, TimeUnit.MILLISECONDS); } }
From source file:com.uwsoft.editor.data.manager.DataManager.java
public void importExternalSpriteAnimationsIntoProject(final ArrayList<File> files, ProgressHandler progressHandler) { if (files.size() == 0) { return;// ww w . j a va 2 s. c o m } handler = progressHandler; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(new Runnable() { @Override public void run() { String newAnimName = null; String rawFileName = files.get(0).getName(); String fileExtension = FilenameUtils.getExtension(rawFileName); if (fileExtension.equals("png")) { Settings settings = new Settings(); settings.square = true; settings.flattenPaths = true; TexturePacker texturePacker = new TexturePacker(settings); FileHandle pngsDir = new FileHandle(files.get(0).getParentFile().getAbsolutePath()); for (FileHandle entry : pngsDir.list(new PngFilenameFilter())) { texturePacker.addImage(entry.file()); } String fileNameWithoutExt = FilenameUtils.removeExtension(rawFileName); String fileNameWithoutFrame = fileNameWithoutExt.replaceAll("\\d*$", ""); String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutFrame; File targetDir = new File(targetPath); if (targetDir.exists()) { try { FileUtils.deleteDirectory(targetDir); } catch (IOException e) { e.printStackTrace(); } } texturePacker.pack(targetDir, fileNameWithoutFrame); newAnimName = fileNameWithoutFrame; } else { for (File file : files) { try { ArrayList<File> imgs = getAtlasPages(file); String fileNameWithoutExt = FilenameUtils.removeExtension(file.getName()); String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/sprite-animations" + File.separator + fileNameWithoutExt; File targetDir = new File(targetPath); if (targetDir.exists()) { FileUtils.deleteDirectory(targetDir); } for (File img : imgs) { FileUtils.copyFileToDirectory(img, targetDir); } FileUtils.copyFileToDirectory(file, targetDir); newAnimName = fileNameWithoutExt; } catch (IOException e) { e.printStackTrace(); } } } if (newAnimName != null) { resolutionManager.resizeSpriteAnimationForAllResolutions(newAnimName, currentProjectInfoVO); } } }); executor.execute(new Runnable() { @Override public void run() { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); } }); executor.shutdown(); }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
public void importParticlesIntoProject(final Array<FileHandle> fileHandles, ProgressHandler progressHandler) { if (fileHandles == null) { return;// w w w.j a v a2 s . c om } final String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/particles"; handler = progressHandler; currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { Array<FileHandle> imgs = new Array<>(); for (FileHandle fileHandle : fileHandles) { if (!fileHandle.isDirectory() && fileHandle.exists()) { try { //copy images boolean allImagesFound = addParticleEffectImages(fileHandle, imgs); if (allImagesFound) { // copy the fileHandle String newName = fileHandle.name(); File target = new File(targetPath + "/" + newName); FileUtils.copyFile(fileHandle.file(), target); } } catch (Exception e) { //e.printStackTrace(); //System.out.println("Error importing particles"); //showError("Error importing particles \n Particle Atals not found \n Please place particle atlas and particle effect fileHandle in the same directory "); } } } if (imgs.size > 0) { copyImageFilesForAllResolutionsIntoProject(imgs, false); } ResolutionManager resolutionManager = facade.retrieveProxy(ResolutionManager.NAME); resolutionManager.rePackProjectImagesForAllResolutions(); }); executor.execute(() -> { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); }); executor.shutdown(); }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
public void importStyleIntoProject(final FileHandle handle, ProgressHandler progressHandler) { if (handle == null) { return;//from w ww. j a va 2s .c o m } final String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/styles"; FileHandle fileHandle = Gdx.files.absolute(handle.path()); final MySkin skin = new MySkin(fileHandle); handler = progressHandler; currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { for (int i = 0; i < skin.fontFiles.size(); i++) { File copyFontFile = new File(handle.path(), skin.fontFiles.get(i) + ".fnt"); File copyImageFile = new File(handle.path(), skin.fontFiles.get(i) + ".png"); if (!handle.isDirectory() && handle.exists() && copyFontFile.isFile() && copyFontFile.exists() && copyImageFile.isFile() && copyImageFile.exists()) { File fileTarget = new File(targetPath + "/" + handle.name()); File fontTarget = new File(targetPath + "/" + copyFontFile.getName()); File imageTarget = new File(targetPath + "/" + copyImageFile.getName()); try { FileUtils.copyFile(handle.file(), fileTarget); FileUtils.copyFile(copyFontFile, fontTarget); FileUtils.copyFile(copyImageFile, imageTarget); } catch (IOException e) { // TODO Auto-generated catch block System.err.println(e.getMessage()); e.printStackTrace(); } } else { System.err.println("SOME FILES ARE MISSING"); } } }); executor.execute(new Runnable() { @Override public void run() { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); } }); executor.shutdown(); }
From source file:com.uwsoft.editor.proxy.ProjectManager.java
public void importShaderIntoProject(Array<FileHandle> files, ProgressHandler progressHandler) { if (files == null) { return;//from w w w .java 2 s. co m } handler = progressHandler; currentPercent = 0; ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { for (FileHandle handle : files) { // check if shaders folder exists String shadersPath = currentProjectPath + "/assets/shaders"; File destination = new File(currentProjectPath + "/assets/shaders/" + handle.name()); try { FileUtils.forceMkdir(new File(shadersPath)); FileUtils.copyFile(handle.file(), destination); } catch (IOException e) { e.printStackTrace(); } } }); executor.execute(() -> { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); }); executor.shutdown(); }
From source file:com.uwsoft.editor.proxy.ProjectManager.java
public void importFontIntoProject(Array<FileHandle> fileHandles, ProgressHandler progressHandler) { if (fileHandles == null) { return;// w w w . j a va 2 s .c o m } String targetPath = currentProjectPath + "/assets/orig/freetypefonts"; handler = progressHandler; float perCopyPercent = 95.0f / fileHandles.size; for (FileHandle fileHandle : fileHandles) { if (!Overlap2DUtils.TTF_FILTER.accept(null, fileHandle.name())) { continue; } try { File target = new File(targetPath); if (!target.exists()) { File newFile = new File(targetPath); newFile.mkdir(); } File fileTarget = new File(targetPath + "/" + fileHandle.name()); FileUtils.copyFile(fileHandle.file(), fileTarget); } catch (IOException e) { e.printStackTrace(); } System.out.println(perCopyPercent); changePercentBy(perCopyPercent); ExecutorService executor = Executors.newSingleThreadExecutor(); executor.execute(() -> { changePercentBy(100 - currentPercent); try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } handler.progressComplete(); }); executor.shutdown(); } }