List of usage examples for java.util.concurrent.atomic AtomicInteger intValue
public int intValue()
From source file:org.wildfly.security.tool.FileSystemRealmCommand.java
/** * Handles input being given as a descriptor file * * @throws Exception Exception to be handled by Elytron Tool *///from w w w . java2 s . c om private void parseDescriptorFile(String file) throws Exception { Path path = Paths.get(file); if (!path.toFile().exists()) { errorHandler(ElytronToolMessages.msg.fileNotFound(file)); } Descriptor descriptor = new Descriptor(); AtomicInteger count = new AtomicInteger(1); try (Stream<String> stream = Files.lines(path)) { stream.forEach(line -> { if (line.equals("")) { findMissingRequiredValuesAndSetValues(count.intValue(), descriptor); copyAddResetDescriptor(descriptor); count.getAndIncrement(); } else { // Since Windows URIs have a colon, only split at first occurrence String[] parts = line.split(":", 2); String option = parts[0]; String arg = parts[1]; switch (option) { case USERS_FILE_PARAM: descriptor.setUsersFile(arg); break; case ROLES_FILE_PARAM: descriptor.setRolesFile(arg); break; case OUTPUT_LOCATION_PARAM: descriptor.setOutputLocation(arg); break; case FILESYSTEM_REALM_NAME_PARAM: descriptor.setFileSystemRealmName(arg); break; case SECURITY_DOMAIN_NAME_PARAM: descriptor.setSecurityDomainName(arg); break; } } }); } catch (IOException e) { errorHandler(e); } int currentCount = count.intValue(); findMissingRequiredValuesAndSetValues(currentCount, descriptor); copyAddResetDescriptor(descriptor); if (summaryMode) { printDescriptorBlocks(currentCount); } count.getAndIncrement(); }
From source file:org.wso2.extension.siddhi.map.text.sinkmapper.TextCustomSinkMapperTestCase.java
@Test public void fileSinkTest() throws InterruptedException { log.info("test text custom map with file io"); AtomicInteger count = new AtomicInteger(); ClassLoader classLoader = TextDefaultSinkMapperTestCase.class.getClassLoader(); String rootPath = classLoader.getResource("files").getFile(); String sinkUri = rootPath + "/sink"; String streams = "" + "@App:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='file', @map(type='text' , @payload('Stock price of {{symbol}} is {{price}}')), " + "append='false', " + "file.uri='" + sinkUri + "/{{symbol}}.txt') " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream"); siddhiAppRuntime.start();//from ww w . j a v a 2 s .co m stockStream.send(new Object[] { "WSO2", 55.6f, 100L }); stockStream.send(new Object[] { "IBM", 57.678f, 100L }); stockStream.send(new Object[] { "GOOGLE", 50f, 100L }); stockStream.send(new Object[] { "REDHAT", 50f, 100L }); Thread.sleep(100); ArrayList<String> symbolNames = new ArrayList<>(); symbolNames.add("WSO2.txt"); symbolNames.add("IBM.txt"); symbolNames.add("GOOGLE.txt"); symbolNames.add("REDHAT.txt"); File sink = new File(sinkUri); if (sink.isDirectory()) { for (File file : sink.listFiles()) { if (symbolNames.contains(file.getName())) { count.incrementAndGet(); } } AssertJUnit.assertEquals(4, count.intValue()); } else { AssertJUnit.fail(sinkUri + " is not a directory."); } Thread.sleep(1000); siddhiAppRuntime.shutdown(); File sinkRoot = new File(sinkUri); try { FileUtils.deleteDirectory(sinkRoot); } catch (IOException e) { throw new TestException("Failed to delete files in due to " + e.getMessage(), e); } }
From source file:org.wso2.extension.siddhi.map.text.sinkmapper.TextCustomSinkMapperTestCase.java
@Test public void fileSinkTestGroup() throws InterruptedException { log.info("test text default map with file io"); AtomicInteger count = new AtomicInteger(); ClassLoader classLoader = TextDefaultSinkMapperTestCase.class.getClassLoader(); String rootPath = classLoader.getResource("files").getFile(); String sinkUri = rootPath + "/sink"; String streams = "" + "@App:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='file', @map(type='text',event.grouping.enabled='true', @payload('Stock price of " + "{{symbol}} is {{price}}')" + "), append='false', " + "file.uri='" + sinkUri + "/{{symbol}}.txt') " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream"); siddhiAppRuntime.start();//from w w w . j a v a2 s . c o m ArrayList<org.wso2.siddhi.core.event.Event> arrayListWSO2 = new ArrayList<>(100); for (int j = 0; j < 5; j++) { arrayListWSO2.add(new org.wso2.siddhi.core.event.Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 10 })); } ArrayList<org.wso2.siddhi.core.event.Event> arrayListIBM = new ArrayList<>(100); for (int j = 0; j < 5; j++) { arrayListIBM.add(new org.wso2.siddhi.core.event.Event(System.currentTimeMillis(), new Object[] { "IBM", 75.6f, 10 })); } stockStream.send(arrayListWSO2.toArray(new org.wso2.siddhi.core.event.Event[5])); stockStream.send(arrayListIBM.toArray(new org.wso2.siddhi.core.event.Event[5])); Thread.sleep(100); ArrayList<String> symbolNames = new ArrayList<>(); symbolNames.add("WSO2.txt"); symbolNames.add("IBM.txt"); symbolNames.add("GOOGLE.txt"); symbolNames.add("REDHAT.txt"); File sink = new File(sinkUri); if (sink.isDirectory()) { for (File file : sink.listFiles()) { if (symbolNames.contains(file.getName())) { count.incrementAndGet(); } } AssertJUnit.assertEquals(2, count.intValue()); } else { AssertJUnit.fail(sinkUri + " is not a directory."); } Thread.sleep(1000); siddhiAppRuntime.shutdown(); File sinkRoot = new File(sinkUri); try { FileUtils.deleteDirectory(sinkRoot); } catch (IOException e) { throw new TestException("Failed to delete files in due to " + e.getMessage(), e); } }
From source file:org.wso2.extension.siddhi.map.text.sinkmapper.TextDefaultSinkMapperTestCase.java
@Test public void fileSinkTestSingle() throws InterruptedException { log.info("test text default map with file io"); AtomicInteger count = new AtomicInteger(); ClassLoader classLoader = TextDefaultSinkMapperTestCase.class.getClassLoader(); String rootPath = classLoader.getResource("files").getFile(); String sinkUri = rootPath + "/sink"; String streams = "" + "@App:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='file', @map(type='text'), append='false', " + "file.uri='" + sinkUri + "/{{symbol}}.txt') " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream"); siddhiAppRuntime.start();//from w ww .j a va2 s . c om stockStream.send(new Object[] { "WSO2", 55.6f, 100L }); stockStream.send(new Object[] { "IBM", 57.678f, 100L }); stockStream.send(new Object[] { "GOOGLE", 50f, 100L }); stockStream.send(new Object[] { "REDHAT", 50f, 100L }); Thread.sleep(100); ArrayList<String> symbolNames = new ArrayList<>(); symbolNames.add("WSO2.txt"); symbolNames.add("IBM.txt"); symbolNames.add("GOOGLE.txt"); symbolNames.add("REDHAT.txt"); File sink = new File(sinkUri); if (sink.isDirectory()) { for (File file : sink.listFiles()) { if (symbolNames.contains(file.getName())) { count.incrementAndGet(); } } AssertJUnit.assertEquals(4, count.intValue()); } else { AssertJUnit.fail(sinkUri + " is not a directory."); } Thread.sleep(1000); siddhiAppRuntime.shutdown(); File sinkRoot = new File(sinkUri); try { FileUtils.deleteDirectory(sinkRoot); } catch (IOException e) { throw new TestException("Failed to delete files in due to " + e.getMessage(), e); } }
From source file:org.wso2.extension.siddhi.map.text.sinkmapper.TextDefaultSinkMapperTestCase.java
@Test public void fileSinkTestGroup() throws InterruptedException { log.info("test text default map with file io"); AtomicInteger count = new AtomicInteger(); ClassLoader classLoader = TextDefaultSinkMapperTestCase.class.getClassLoader(); String rootPath = classLoader.getResource("files").getFile(); String sinkUri = rootPath + "/sink"; String streams = "" + "@App:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='file', @map(type='text',event.grouping.enabled='true'" + "), append='false', " + "file.uri='" + sinkUri + "/{{symbol}}.txt') " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream"); siddhiAppRuntime.start();/*from w w w. j av a2s . com*/ ArrayList<org.wso2.siddhi.core.event.Event> arrayListWSO2 = new ArrayList<>(100); for (int j = 0; j < 5; j++) { arrayListWSO2.add(new org.wso2.siddhi.core.event.Event(System.currentTimeMillis(), new Object[] { "WSO2", 55.6f, 10 })); } ArrayList<org.wso2.siddhi.core.event.Event> arrayListIBM = new ArrayList<>(100); for (int j = 0; j < 5; j++) { arrayListIBM.add(new org.wso2.siddhi.core.event.Event(System.currentTimeMillis(), new Object[] { "IBM", 75.6f, 10 })); } stockStream.send(arrayListWSO2.toArray(new org.wso2.siddhi.core.event.Event[5])); stockStream.send(arrayListIBM.toArray(new org.wso2.siddhi.core.event.Event[5])); Thread.sleep(100); ArrayList<String> symbolNames = new ArrayList<>(); symbolNames.add("WSO2.txt"); symbolNames.add("IBM.txt"); File sink = new File(sinkUri); if (sink.isDirectory()) { for (File file : sink.listFiles()) { if (symbolNames.contains(file.getName())) { count.incrementAndGet(); } } AssertJUnit.assertEquals(2, count.intValue()); } else { AssertJUnit.fail(sinkUri + " is not a directory."); } Thread.sleep(1000); siddhiAppRuntime.shutdown(); File sinkRoot = new File(sinkUri); try { FileUtils.deleteDirectory(sinkRoot); } catch (IOException e) { throw new TestException("Failed to delete files in due to " + e.getMessage(), e); } }
From source file:org.wso2.extension.siddhi.map.text.sinkmapper.TextDefaultSinkMapperTestCase.java
@Test public void fileSinkTestNewLineCharacter() throws InterruptedException { log.info("test text default map with file io"); AtomicInteger count = new AtomicInteger(); ClassLoader classLoader = TextDefaultSinkMapperTestCase.class.getClassLoader(); String rootPath = classLoader.getResource("files").getFile(); String sinkUri = rootPath + "/sink"; String streams = "" + "@App:name('TestSiddhiApp')" + "define stream FooStream (symbol string, price float, volume long); " + "@sink(type='file', @map(type='text',event.grouping.enabled='true'," + "delimiter='#######',new" + ".line.character='\\r\\n'), append='false', " + "file.uri='" + sinkUri + "/{{symbol}}.txt') " + "define stream BarStream (symbol string, price float, volume long); "; String query = "" + "from FooStream " + "select * " + "insert into BarStream; "; SiddhiManager siddhiManager = new SiddhiManager(); SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(streams + query); InputHandler stockStream = siddhiAppRuntime.getInputHandler("FooStream"); siddhiAppRuntime.start();/* w ww . j av a 2s . co m*/ stockStream.send(new Object[] { "WSO2", 55.6f, 100L }); stockStream.send(new Object[] { "IBM", 57.678f, 100L }); stockStream.send(new Object[] { "GOOGLE", 50f, 100L }); stockStream.send(new Object[] { "REDHAT", 50f, 100L }); Thread.sleep(100); ArrayList<String> symbolNames = new ArrayList<>(); symbolNames.add("WSO2.txt"); symbolNames.add("IBM.txt"); symbolNames.add("GOOGLE.txt"); symbolNames.add("REDHAT.txt"); File sink = new File(sinkUri); if (sink.isDirectory()) { for (File file : sink.listFiles()) { if (symbolNames.contains(file.getName())) { count.incrementAndGet(); } } AssertJUnit.assertEquals(4, count.intValue()); } else { AssertJUnit.fail(sinkUri + " is not a directory."); } Thread.sleep(1000); siddhiAppRuntime.shutdown(); File sinkRoot = new File(sinkUri); try { FileUtils.deleteDirectory(sinkRoot); } catch (IOException e) { throw new TestException("Failed to delete files in due to " + e.getMessage(), e); } }