List of usage examples for java.util.concurrent.atomic AtomicBoolean AtomicBoolean
public AtomicBoolean(boolean initialValue)
From source file:org.jooq.example.TransactionTest.java
@Test public void testjOOQTransactionsNested() { AtomicBoolean rollback1 = new AtomicBoolean(false); AtomicBoolean rollback2 = new AtomicBoolean(false); try {//from ww w . ja va 2 s . co m // If using Spring transactions, we don't need the c1 reference dsl.transaction(c1 -> { // The first insertion will work dsl.insertInto(BOOK).set(BOOK.ID, 5).set(BOOK.AUTHOR_ID, 1).set(BOOK.TITLE, "Book 5").execute(); assertEquals(5, dsl.fetchCount(BOOK)); try { // Nest transactions using Spring. This should create a savepoint, right here // If using Spring transactions, we don't need the c2 reference dsl.transaction(c2 -> { // The second insertion shouldn't work for (int i = 0; i < 2; i++) dsl.insertInto(BOOK).set(BOOK.ID, 6).set(BOOK.AUTHOR_ID, 1).set(BOOK.TITLE, "Book 6") .execute(); Assert.fail(); }); } catch (DataAccessException e) { rollback1.set(true); } // We should've rolled back to the savepoint assertEquals(5, dsl.fetchCount(BOOK)); throw new org.jooq.exception.DataAccessException("Rollback"); }); } // Upon the constraint violation, the transaction must already have been rolled back catch (org.jooq.exception.DataAccessException e) { assertEquals("Rollback", e.getMessage()); rollback2.set(true); } assertEquals(4, dsl.fetchCount(BOOK)); assertTrue(rollback2.get()); assertTrue(rollback2.get()); }
From source file:com.tobedevoured.json.SimpleStreamTest.java
@Test public void testCallback() throws StreamException { final AtomicBoolean isCalledBack = new AtomicBoolean(false); simpleStream.setCallback(new Function<Object, Object>() { @Override/*w w w . j ava 2 s . co m*/ public Object apply(Object entity) { assertNotNull(entity); isCalledBack.set(true); return null; } }); simpleStream.stream("{\"test\": \"this is a test\"} [1,2,3]"); List entities = simpleStream.flush(); assertTrue("callback was called", isCalledBack.get()); Map<String, String> expectedEntity = ImmutableMap.of("test", "this is a test"); assertEquals(expectedEntity, entities.get(0)); assertEquals(Arrays.asList(1L, 2L, 3L), entities.get(1)); }
From source file:architecture.ee.plugin.impl.PluginManagerImpl.java
protected PluginManagerImpl() { pluginListeners = new HashSet<PluginListener>(); pluginProperties = new ConcurrentHashMap<String, PluginProperties>(); bundleCache = new ConcurrentHashMap<Locale, List<ResourceBundle>>(); initialized = new AtomicBoolean(false); pluginDirectory = ApplicationHelper.getRepository().getFile("plugins"); plugins = new ConcurrentHashMap<String, Plugin>(); brokenPlugins = new ConcurrentHashMap<String, String>(); brokenPluginUpgradeExceptions = new ConcurrentHashMap<String, List<Exception>>(); pluginDirs = new ConcurrentHashMap<Plugin, File>(); classloaders = new ConcurrentHashMap<Object, PluginClassLoader>(); pluginMeta = new ConcurrentHashMap<Object, PluginMetaData>(); devPlugins = new HashSet<String>(); customURLMapperList = Collections.synchronizedList(new ArrayList()); }
From source file:com.qwazr.utils.json.DirectoryJsonManager.java
protected T get(String name) throws IOException { File file = getFile(name);/* ww w .j av a2 s . c o m*/ rwl.readLock().lock(); try { AtomicBoolean mustBeEvaluated = new AtomicBoolean(false); T item = getNoLock(file, name, mustBeEvaluated); if (!mustBeEvaluated.get()) return item; } finally { rwl.readLock().unlock(); } rwl.writeLock().lock(); try { return getNoLock(file, name, null); } finally { rwl.writeLock().unlock(); } }
From source file:com.xylocore.cassandra.query.SharedResultSetProcessor.java
/** * FILLIN/* w w w . j av a2 s .c o m*/ * * @param aExecutionContext * @param aExecutor * @param aCompletionNotifier */ SharedResultSetProcessor(PagedQueryExecutionContext<T> aExecutionContext, Executor aExecutor, ResultSetCompletionNotifier<T> aCompletionNotifier) { Validate.notNull(aExecutionContext); Validate.notNull(aCompletionNotifier); executionContext = aExecutionContext; executor = aExecutor; completionNotifier = aCompletionNotifier; availableTasks = new ConcurrentLinkedQueue<>(); availableTaskCount = new AtomicInteger(aExecutionContext.getConcurrencyLevel()); state = new AtomicReference<>(State.Inactive); workTasksLocked = new AtomicBoolean(false); fetchFuture = null; completed = false; resultSet = null; currentWorkTask = null; for (int i = 0, ci = aExecutionContext.getConcurrencyLevel(); i < ci; i++) { WorkTask myWorkTask = new WorkTask(i); availableTasks.offer(myWorkTask); } }
From source file:com.comcast.viper.flume2storm.connection.receptor.KryoNetEventReceptor.java
/** * @param connectionParams//from w w w . jav a 2 s .c om * Connection parameters to the {@link KryoNetEventSender} * @param kryoNetParams * Generic parameters of the {@link KryoNetEventReceptor} */ public KryoNetEventReceptor(final KryoNetConnectionParameters connectionParams, KryoNetParameters kryoNetParams) { Preconditions.checkNotNull(connectionParams); this.kryoNetParameters = kryoNetParams; this.connectionParams = connectionParams; stats = new EventReceptorStats(connectionParams.getId()); listeners = new AtomicReference<>(ImmutableList.copyOf(new ArrayList<EventReceptorListener>())); events = new ConcurrentLinkedQueue<F2SEvent>(); keepRunning = new AtomicBoolean(false); nextConnectionTime = new AtomicReference<Instant>(new Instant(0)); }
From source file:biz.ganttproject.impex.csv.CsvImportTest.java
public void testIncompleteHeader() throws IOException { String header = "A, B"; String data = "a1, b1"; final AtomicBoolean wasCalled = new AtomicBoolean(false); RecordGroup recordGroup = new RecordGroup("ABC", ImmutableSet.<String>of("A", "B", "C"), // all fields ImmutableSet.<String>of("A", "B")) { // mandatory fields @Override//from w w w. jav a 2 s. c o m protected boolean doProcess(CSVRecord record) { if (!super.doProcess(record)) { return false; } wasCalled.set(true); assertEquals("a1", record.get("A")); assertEquals("b1", record.get("B")); return true; } }; GanttCSVOpen importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(header, data)), recordGroup); importer.load(); assertTrue(wasCalled.get()); }
From source file:org.piraso.server.service.ResponseLoggerServiceImplTest.java
@Test public void testWaitAndStop() throws Exception { final AtomicBoolean fail = new AtomicBoolean(false); ExecutorService executor = Executors.newFixedThreadPool(2); Runnable startServiceRunnable = new Runnable() { public void run() { try { service.start();//from w w w. ja va 2s. c o m } catch (Exception e) { fail.set(true); e.printStackTrace(); } } }; Runnable logMessagesRunnable = new Runnable() { public void run() { try { service.stopAndWait(3000l); } catch (Exception e) { fail.set(true); e.printStackTrace(); } } }; Future future = executor.submit(startServiceRunnable); executor.submit(logMessagesRunnable); future.get(); executor.shutdown(); if (fail.get()) { fail("failure see exception trace."); } // no harm invoking it again service.stopAndWait(1000l); assertFalse(service.isAlive()); }
From source file:org.piraso.server.spring.web.PirasoServletTest.java
@Test public void testStartStopSuccess() throws IOException, ServletException, ExecutionException, InterruptedException { final AtomicBoolean fail = new AtomicBoolean(false); request.addParameter("service", "start"); request.addParameter("preferences", mapper.writeValueAsString(new Preferences())); ExecutorService executor = Executors.newFixedThreadPool(2); Runnable startServiceRunnable = new Runnable() { public void run() { try { servlet.handleRequest(request, response); } catch (Exception e) { fail.set(true);//from ww w .j a v a 2s. co m e.printStackTrace(); } } }; Runnable logMessagesRunnable = new Runnable() { public void run() { try { MockHttpServletRequest request = CommonMockObjects.mockRequest(MONITORED_ADDR); request.addParameter("activity_uuid", "1"); request.addParameter("service", "stop"); // wait till service is available while (registry.getLogger(registry.createOrGetUser(pirasoRequest)) == null) { Thread.sleep(100l); } servlet.handleRequest(request, new MockHttpServletResponse()); } catch (Exception e) { fail.set(true); e.printStackTrace(); } } }; Future future = executor.submit(startServiceRunnable); executor.submit(logMessagesRunnable); future.get(); executor.shutdown(); }
From source file:net.sourceforge.ganttproject.io.CsvImportTest.java
public void testSkipUntilFirstHeader() throws IOException { String notHeader = "FOO, BAR, A"; String header = "A, B"; String data = "a1, b1"; final AtomicBoolean wasCalled = new AtomicBoolean(false); GanttCSVOpen.RecordGroup recordGroup = new GanttCSVOpen.RecordGroup("ABC", ImmutableSet.<String>of("A", "B")) { @Override//from w w w. j a v a 2 s .com protected boolean doProcess(CSVRecord record) { wasCalled.set(true); assertEquals("a1", record.get("A")); assertEquals("b1", record.get("B")); return true; } }; GanttCSVOpen importer = new GanttCSVOpen(createSupplier(Joiner.on('\n').join(notHeader, header, data)), recordGroup); importer.load(); assertTrue(wasCalled.get()); assertEquals(1, importer.getSkippedLineCount()); }