List of usage examples for java.util.concurrent Executors newSingleThreadExecutor
public static ExecutorService newSingleThreadExecutor()
From source file:de.mendelson.comm.as2.client.AS2Gui.java
@Override public void loggedIn(User user) { super.loggedIn(user); try {/*from ww w.j a v a 2 s. c o m*/ this.configConnection = DBDriverManager.getConnectionWithoutErrorHandling(DBDriverManager.DB_CONFIG, this.host); this.runtimeConnection = DBDriverManager.getConnectionWithoutErrorHandling(DBDriverManager.DB_RUNTIME, this.host); } catch (Exception e) { JOptionPane.showMessageDialog(AS2Gui.this, this.rb.getResourceString("dbconnection.failed.message", e.getMessage()), this.rb.getResourceString("dbconnection.failed.title"), JOptionPane.ERROR_MESSAGE); System.exit(1); } this.as2StatusBar.setConnectedHost(this.host); //start the table update thread Executors.newSingleThreadExecutor().submit(this.refreshThread); }
From source file:com.uwsoft.editor.proxy.ProjectManager.java
public void importFontIntoProject(Array<FileHandle> fileHandles, ProgressHandler progressHandler) { if (fileHandles == null) { return;/* w ww .j ava 2 s . c om*/ } 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(); } }
From source file:de.innovationgate.wgpublisher.filter.WGAFilter.java
public void initFilterChain() { Executors.newSingleThreadExecutor().execute(new Runnable() { @Override/*from w ww. j a v a 2s . co m*/ public void run() { setupFilterChain(); } }); }
From source file:com.streamsets.pipeline.stage.origin.kafka.TestKafkaSource.java
@Test public void testAutoOffsetResetSmallestConfig() throws Exception { CountDownLatch startLatch = new CountDownLatch(1); ExecutorService executorService = Executors.newSingleThreadExecutor(); CountDownLatch countDownLatch = new CountDownLatch(1); executorService.submit(new ProducerRunnable(TOPIC11, SINGLE_PARTITION, producer, startLatch, DataType.LOG_STACK_TRACE, null, 10, countDownLatch)); // produce all 10 records first before starting the source(KafkaConsumer) startLatch.countDown();/*from w w w . ja va 2 s . co m*/ countDownLatch.await(); KafkaConfigBean conf = new KafkaConfigBean(); conf.metadataBrokerList = sdcKafkaTestUtil.getMetadataBrokerURI(); conf.topic = TOPIC11; conf.consumerGroup = CONSUMER_GROUP; conf.zookeeperConnect = zkConnect; conf.maxBatchSize = 100; conf.maxWaitTime = 10000; conf.kafkaConsumerConfigs = null; conf.produceSingleRecordPerMessage = false; conf.dataFormat = DataFormat.LOG; conf.dataFormatConfig.charset = "UTF-8"; conf.dataFormatConfig.removeCtrlChars = false; conf.dataFormatConfig.logMode = LogMode.LOG4J; conf.dataFormatConfig.logMaxObjectLen = 10000; conf.dataFormatConfig.retainOriginalLine = true; conf.dataFormatConfig.customLogFormat = null; conf.dataFormatConfig.regex = null; conf.dataFormatConfig.fieldPathsToGroupName = null; conf.dataFormatConfig.grokPatternDefinition = null; conf.dataFormatConfig.grokPattern = null; conf.dataFormatConfig.onParseError = OnParseError.INCLUDE_AS_STACK_TRACE; conf.dataFormatConfig.maxStackTraceLines = 100; conf.dataFormatConfig.enableLog4jCustomLogFormat = false; conf.dataFormatConfig.log4jCustomLogFormat = null; SourceRunner sourceRunner = new SourceRunner.Builder(StandaloneKafkaSource.class, createSource(conf)) .addOutputLane("lane") // Set mode to preview .setPreview(true).build(); sourceRunner.runInit(); List<Record> records = new ArrayList<>(); StageRunner.Output output = getOutputAndRecords(sourceRunner, 10, "lane", records); shutDownExecutorService(executorService); String newOffset = output.getNewOffset(); Assert.assertNull(newOffset); Assert.assertEquals(10, records.size()); }
From source file:com.uwsoft.editor.proxy.ProjectManager.java
public void importStyleIntoProject(final FileHandle handle, ProgressHandler progressHandler) { if (handle == null) { return;/* w w w . j av a 2s . c o m*/ } final String targetPath = currentProjectPath + "/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.o2d.pkayjava.editor.proxy.ProjectManager.java
public void importFontIntoProject(Array<FileHandle> fileHandles, ProgressHandler progressHandler) { if (fileHandles == null) { return;//from w w w. jav a 2s . com } 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:com.uwsoft.editor.data.manager.DataManager.java
public void importExternalFontIntoProject(ArrayList<File> externalfiles, ProgressHandler progressHandler) { String targetPath = currentWorkingPath + "/" + currentProjectVO.projectName + "/assets/orig/freetypefonts"; TffFilenameFilter ttfFilenameFilter = new TffFilenameFilter(); handler = progressHandler;//from w w w.j av a2s.c om float perCopyPercent = 95.0f / externalfiles.size(); for (File file : externalfiles) { if (!ttfFilenameFilter.accept(null, file.getName())) { continue; } try { File target = new File(targetPath); if (!target.exists()) { File newFile = new File(targetPath); newFile.mkdir(); } File fileTarget = new File(targetPath + "/" + file.getName()); FileUtils.copyFile(file, fileTarget); } catch (IOException e) { e.printStackTrace(); } System.out.println(perCopyPercent); changePercentBy(perCopyPercent); ExecutorService executor = Executors.newSingleThreadExecutor(); 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:hudson.plugins.sshslaves.SSHLauncher.java
/** * {@inheritDoc}/* ww w. j av a 2 s. co m*/ */ @Override public synchronized void launch(final SlaveComputer computer, final TaskListener listener) throws InterruptedException { connection = new Connection(host, port); ExecutorService executorService = Executors.newSingleThreadExecutor(); Set<Callable<Boolean>> callables = new HashSet<Callable<Boolean>>(); callables.add(new Callable<Boolean>() { public Boolean call() throws InterruptedException { Boolean rval = Boolean.FALSE; try { openConnection(listener); verifyNoHeaderJunk(listener); reportEnvironment(listener); String java = resolveJava(computer, listener); final String workingDirectory = getWorkingDirectory(computer); if (workingDirectory == null) { listener.error("Cannot get the working directory for " + computer); return Boolean.FALSE; } copySlaveJar(listener, workingDirectory); startSlave(computer, listener, java, workingDirectory); PluginImpl.register(connection); rval = Boolean.TRUE; } catch (RuntimeException e) { e.printStackTrace(listener.error(Messages.SSHLauncher_UnexpectedError())); } catch (Error e) { e.printStackTrace(listener.error(Messages.SSHLauncher_UnexpectedError())); } catch (IOException e) { e.printStackTrace(listener.getLogger()); } finally { return rval; } } }); final Node node = computer.getNode(); final String nodeName = node != null ? node.getNodeName() : "unknown"; try { long time = System.currentTimeMillis(); List<Future<Boolean>> results; if (this.getLaunchTimeoutMillis() > 0) { results = executorService.invokeAll(callables, this.getLaunchTimeoutMillis(), TimeUnit.MILLISECONDS); } else { results = executorService.invokeAll(callables); } long duration = System.currentTimeMillis() - time; Boolean res; try { res = results.get(0).get(); } catch (ExecutionException e) { res = Boolean.FALSE; } if (!res) { System.out.println( Messages.SSHLauncher_LaunchFailedDuration(getTimestamp(), nodeName, host, duration)); listener.getLogger().println(getTimestamp() + " Launch failed - cleaning up connection"); cleanupConnection(listener); } else { System.out.println( Messages.SSHLauncher_LaunchCompletedDuration(getTimestamp(), nodeName, host, duration)); } executorService.shutdown(); } catch (InterruptedException e) { System.out.println(Messages.SSHLauncher_LaunchFailed(getTimestamp(), nodeName, host)); } }
From source file:com.o2d.pkayjava.editor.proxy.ProjectManager.java
public void importStyleIntoProject(final FileHandle handle, ProgressHandler progressHandler) { if (handle == null) { return;/*from ww w . j a va 2s. c om*/ } 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(); }