List of usage examples for java.util.concurrent.atomic AtomicInteger set
public final void set(int newValue)
From source file:org.alfresco.tools.RenameUser.java
@Override protected int execute() throws ToolException { // Used for ability to be final and have a set final AtomicInteger status = new AtomicInteger(0); BatchProcessWorker<User> worker = new BatchProcessWorkerAdaptor<User>() { public void process(final User user) throws Throwable { RunAsWork<Void> runAsWork = new RunAsWork<Void>() { @Override//from w ww. ja v a 2s .c o m public Void doWork() throws Exception { try { renameUser(user.getOldUsername(), user.getNewUsername()); } catch (Throwable t) { status.set(handleError(t)); } return null; } }; AuthenticationUtil.runAs(runAsWork, context.getUsername()); } }; // Use 2 threads, 20 User objects per transaction. Log every 100 entries. BatchProcessor<User> processor = new BatchProcessor<User>("HomeFolderProviderSynchronizer", getServiceRegistry().getTransactionService().getRetryingTransactionHelper(), new WorkProvider(context), 2, 20, null, logger, 100); processor.process(worker, true); return status.get(); }
From source file:org.polymap.core.project.operations.SetLayerBoundsOperation.java
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { // obtain bounds try {//from w w w . j ava 2s . c o m monitor.beginTask(getLabel(), 3); monitor.subTask("Obtaining bounds"); result = obtainBoundsFromResources(layer, crs, monitor); monitor.worked(1); } catch (Exception e) { throw new ExecutionException("Failure obtaining bounds", e); } // transform if (result != null && !result.isNull()) { if (crs != null) { try { monitor.subTask("Transforming bounds"); result = result.transform(crs, true); monitor.worked(1); } catch (Exception fe) { throw new ExecutionException("failure to transform layer bounds", fe); } } } else { result = new ReferencedEnvelope(new Envelope(), null); } // set map extent monitor.subTask("Setting map extent"); // check if outside map maxExtent final AtomicInteger dialogResult = new AtomicInteger(SWT.OK); ReferencedEnvelope mapMaxExtent = layer.getMap().getMaxExtent(); if (mapMaxExtent != null && !mapMaxExtent.covers(result)) { Polymap.getSessionDisplay().syncExec(new Runnable() { public void run() { MessageBox mbox = new MessageBox( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.OK | SWT.CANCEL | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL); mbox.setMessage(i18n("dialogMsg", result.getMinX(), result.getMaxX(), result.getMinY(), result.getMaxY())); mbox.setText(getLabel()); dialogResult.set(mbox.open()); } }); } if (dialogResult.get() == SWT.OK) { oldExtent = layer.getMap().getExtent(); layer.getMap().setExtent(result); monitor.done(); return Status.OK_STATUS; } else { return Status.CANCEL_STATUS; } }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexAugmentTest.java
@Test public void skipDefaultOnlyUsingAugmentors() throws Exception { //setup repo and index NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); Tree prop = props.addChild("foo1"); prop.setProperty(LuceneIndexConstants.PROP_INDEX, true); prop = props.addChild("foo2"); prop.setProperty(LuceneIndexConstants.PROP_NAME, "subChild/foo2"); prop.setProperty(LuceneIndexConstants.PROP_INDEX, true); root.commit();//from w w w . j a va 2 s. c o m //setup augmentors final AtomicInteger indexingCounter = new AtomicInteger(0); factory.indexFieldProvider = new IndexFieldProvider() { @Nonnull @Override public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) { indexingCounter.incrementAndGet(); return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition); } @Nonnull @Override public Set<String> getSupportedTypes() { return Collections.singleton(TestUtil.NT_TEST); } }; final AtomicInteger queryingCounter = new AtomicInteger(0); factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() { @Override public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) { queryingCounter.set(1); return null; } @Nonnull @Override public Set<String> getSupportedTypes() { return Collections.singleton(TestUtil.NT_TEST); } }; //add content Tree node1 = createNodeWithType(root.getTree("/"), "node1", TestUtil.NT_TEST); node1.setProperty("foo1", "bar1"); node1.addChild("subChild").setProperty("foo2", "bar2"); root.commit(); //indexing assertions assertEquals("Indexing augment should get called once", 1, indexingCounter.get()); assertEquals("No docs should get indexed (augmentor hasn't added any field)", 0, getSearcher().getIndexReader().numDocs()); String query = "EXPLAIN SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [foo1]='bar1'"; List<String> paths = executeQuery(query, SQL2); assertTrue("indexed prop name shouldn't decide query plan (" + paths.get(0) + ")", paths.get(0).contains("/* no-index ")); query = "EXPLAIN SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [subChild/foo2]='bar2'"; paths = executeQuery(query, SQL2); assertTrue("indexed prop name shouldn't decide query plan (" + paths.get(0) + ")", paths.get(0).contains("/* no-index ")); }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexAugmentTest.java
@Test public void propertyIndexUsingAugmentors() throws Exception { //setup repo and index NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); TestUtil.enablePropertyIndex(props, "foo1", false); TestUtil.enablePropertyIndex(props, "subChild/foo2", false); root.commit();/*from ww w.ja v a2s . co m*/ //setup augmentors final AtomicInteger indexingCounter = new AtomicInteger(0); factory.indexFieldProvider = new IndexFieldProvider() { @Nonnull @Override public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) { indexingCounter.incrementAndGet(); return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition); } @Nonnull @Override public Set<String> getSupportedTypes() { return Collections.singleton(TestUtil.NT_TEST); } }; final AtomicInteger queryingCounter = new AtomicInteger(0); factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() { @Override public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) { queryingCounter.set(1); return null; } @Nonnull @Override public Set<String> getSupportedTypes() { return Collections.singleton(TestUtil.NT_TEST); } }; //add content Tree node1 = createNodeWithType(root.getTree("/"), "node1", TestUtil.NT_TEST); node1.setProperty("foo1", "bar1"); node1.addChild("subChild").setProperty("foo2", "bar2"); root.commit(); //indexing assertions assertEquals("Indexing augment should get called once", 1, indexingCounter.get()); String query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [foo1]='bar1'"; executeQuery(query, SQL2); assertEquals("Query augmentor should not get called for property constraints", 0, queryingCounter.get()); query = "EXPLAIN " + query; List<String> paths = executeQuery(query, SQL2, false); assertTrue("property index should have made the index selected (" + paths.get(0) + ")", paths.get(0).contains("/* lucene:test-index(")); query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE [subChild/foo2]='bar2'"; executeQuery(query, SQL2); assertEquals("Query augmentor should not get called for property constraints", 0, queryingCounter.get()); query = "EXPLAIN " + query; paths = executeQuery(query, SQL2); assertTrue("property index should have made the index selected (" + paths.get(0) + ")", paths.get(0).contains("/* lucene:test-index(")); }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexAugmentTest.java
@Test public void fulltextIndexUsingAugmentors() throws Exception { //setup repo and index NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); TestUtil.enableForFullText(props, "foo1"); TestUtil.enableForFullText(props, "subChild/foo2"); root.commit();//from w ww. ja v a2 s .c o m //setup augmentors final AtomicInteger indexingCounter = new AtomicInteger(0); factory.indexFieldProvider = new IndexFieldProvider() { @Nonnull @Override public Iterable<Field> getAugmentedFields(String path, NodeState document, NodeState indexDefinition) { indexingCounter.incrementAndGet(); return IndexFieldProvider.DEFAULT.getAugmentedFields(path, document, indexDefinition); } @Nonnull @Override public Set<String> getSupportedTypes() { return Collections.singleton(TestUtil.NT_TEST); } }; final AtomicInteger queryingCounter = new AtomicInteger(0); factory.fulltextQueryTermsProvider = new FulltextQueryTermsProvider() { @Override public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) { queryingCounter.set(1); return null; } @Nonnull @Override public Set<String> getSupportedTypes() { return Collections.singleton(TestUtil.NT_TEST); } }; //add content Tree node1 = createNodeWithType(root.getTree("/"), "node1", TestUtil.NT_TEST); node1.setProperty("foo1", "bar1"); node1.addChild("subChild").setProperty("foo2", "bar2"); root.commit(); //indexing assertions assertEquals("Indexing augment should get called once", 1, indexingCounter.get()); String query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE CONTAINS(*, 'bar1')"; executeQuery(query, SQL2); assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get()); queryingCounter.set(0); query = "EXPLAIN " + query; List<String> paths = executeQuery(query, SQL2, false); assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get()); assertTrue("property index should have made the index selected (" + paths.get(0) + ")", paths.get(0).contains("/* lucene:test-index(")); queryingCounter.set(0); query = "SELECT [jcr:path] from [" + TestUtil.NT_TEST + "] WHERE CONTAINS(*, 'bar2')"; executeQuery(query, SQL2); assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get()); queryingCounter.set(0); query = "EXPLAIN " + query; paths = executeQuery(query, SQL2, false); assertEquals("Query augmentor should get called for full text constraints", 1, queryingCounter.get()); assertTrue("property index should have made the index selected (" + paths.get(0) + ")", paths.get(0).contains("/* lucene:test-index(")); }
From source file:org.apache.hadoop.hbase.client.TestAsyncTable.java
@Test public void testCheckAndMutate() throws InterruptedException, ExecutionException { AsyncTableBase table = getTable.get(); int count = 10; CountDownLatch putLatch = new CountDownLatch(count + 1); table.put(new Put(row).addColumn(FAMILY, QUALIFIER, VALUE)).thenRun(() -> putLatch.countDown()); IntStream.range(0, count)/*from w w w .j a v a 2 s .co m*/ .forEach(i -> table.put(new Put(row).addColumn(FAMILY, concat(QUALIFIER, i), VALUE)) .thenRun(() -> putLatch.countDown())); putLatch.await(); AtomicInteger successCount = new AtomicInteger(0); AtomicInteger successIndex = new AtomicInteger(-1); CountDownLatch mutateLatch = new CountDownLatch(count); IntStream.range(0, count).forEach(i -> { RowMutations mutation = new RowMutations(row); try { mutation.add(new Delete(row).addColumn(FAMILY, QUALIFIER)); mutation.add(new Put(row).addColumn(FAMILY, concat(QUALIFIER, i), concat(VALUE, i))); } catch (IOException e) { throw new UncheckedIOException(e); } table.checkAndMutate(row, FAMILY, QUALIFIER, VALUE, mutation).thenAccept(x -> { if (x) { successCount.incrementAndGet(); successIndex.set(i); } mutateLatch.countDown(); }); }); mutateLatch.await(); assertEquals(1, successCount.get()); Result result = table.get(new Get(row)).get(); IntStream.range(0, count).forEach(i -> { if (i == successIndex.get()) { assertArrayEquals(concat(VALUE, i), result.getValue(FAMILY, concat(QUALIFIER, i))); } else { assertArrayEquals(VALUE, result.getValue(FAMILY, concat(QUALIFIER, i))); } }); }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexAugmentTest.java
@Test public void queryAugmentorMismatchedNodeType() throws Exception { //setup repo and index NodeTypeRegistry.register(root, IOUtils.toInputStream(TestUtil.TEST_NODE_TYPE), "test nodeType"); Tree props = createIndex(TestUtil.NT_TEST); TestUtil.enableForFullText(props, "foo1", false); root.commit();/*from www . ja v a 2s . co m*/ //setup augmentors final AtomicInteger indexingCounter1 = new AtomicInteger(0); final AtomicInteger indexingCounter2 = new AtomicInteger(0); factory.registerQueryTermsProvider(new FulltextQueryTermsProvider() { @Override public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) { indexingCounter1.set(1); return null; } @Nonnull @Override public Set<String> getSupportedTypes() { return Collections.singleton(JcrConstants.NT_BASE); } }); factory.registerQueryTermsProvider(new FulltextQueryTermsProvider() { @Override public Query getQueryTerm(String text, Analyzer analyzer, NodeState indexDefinition) { indexingCounter2.set(1); return null; } @Nonnull @Override public Set<String> getSupportedTypes() { return Collections.singleton(TestUtil.NT_TEST); } }); factory.useSuperBehavior = true; executeQuery("SELECT [jcr:path] FROM [" + TestUtil.NT_TEST + "] WHERE CONTAINS(*, 'test')", SQL2, false); assertEquals("Mismatching node type should not let index augmentor called", 0, indexingCounter1.get()); assertEquals("Matching node type should get augmentor called", 1, indexingCounter2.get()); }
From source file:com.netflix.curator.framework.recipes.barriers.TestDistributedDoubleBarrier.java
@Test public void testBasic() throws Exception { final Timing timing = new Timing(); final List<Closeable> closeables = Lists.newArrayList(); final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1)); try {//from w w w. j a v a2 s. c om closeables.add(client); client.start(); final CountDownLatch postEnterLatch = new CountDownLatch(QTY); final CountDownLatch postLeaveLatch = new CountDownLatch(QTY); final AtomicInteger count = new AtomicInteger(0); final AtomicInteger max = new AtomicInteger(0); List<Future<Void>> futures = Lists.newArrayList(); ExecutorService service = Executors.newCachedThreadPool(); for (int i = 0; i < QTY; ++i) { Future<Void> future = service.submit(new Callable<Void>() { @Override public Void call() throws Exception { DistributedDoubleBarrier barrier = new DistributedDoubleBarrier(client, "/barrier", QTY); Assert.assertTrue(barrier.enter(timing.seconds(), TimeUnit.SECONDS)); synchronized (TestDistributedDoubleBarrier.this) { int thisCount = count.incrementAndGet(); if (thisCount > max.get()) { max.set(thisCount); } } postEnterLatch.countDown(); Assert.assertTrue(timing.awaitLatch(postEnterLatch)); Assert.assertEquals(count.get(), QTY); Assert.assertTrue(barrier.leave(10, TimeUnit.SECONDS)); count.decrementAndGet(); postLeaveLatch.countDown(); Assert.assertTrue(timing.awaitLatch(postLeaveLatch)); return null; } }); futures.add(future); } for (Future<Void> f : futures) { f.get(); } Assert.assertEquals(count.get(), 0); Assert.assertEquals(max.get(), QTY); } finally { for (Closeable c : closeables) { IOUtils.closeQuietly(c); } } }
From source file:org.apache.hadoop.hbase.quotas.TestSpaceQuotasWithSnapshots.java
void waitForStableQuotaSize(Connection conn, TableName tn, String ns) throws Exception { // For some stability in the value before proceeding // Helps make sure that we got the actual last value, not some inbetween AtomicLong lastValue = new AtomicLong(-1); AtomicInteger counter = new AtomicInteger(0); TEST_UTIL.waitFor(15_000, 500, new SpaceQuotaSnapshotPredicate(conn, tn, ns) { @Override/*from w ww . j a v a2s .c om*/ boolean evaluate(SpaceQuotaSnapshot snapshot) throws Exception { LOG.debug("Last observed size=" + lastValue.get()); if (snapshot.getUsage() == lastValue.get()) { int numMatches = counter.incrementAndGet(); if (numMatches >= 5) { return true; } // Not yet.. return false; } counter.set(0); lastValue.set(snapshot.getUsage()); return false; } }); }
From source file:org.apache.hadoop.hbase.quotas.TestSpaceQuotasWithSnapshots.java
void waitForStableRegionSizeReport(Connection conn, TableName tn) throws Exception { // For some stability in the value before proceeding // Helps make sure that we got the actual last value, not some inbetween AtomicLong lastValue = new AtomicLong(-1); AtomicInteger counter = new AtomicInteger(0); TEST_UTIL.waitFor(15_000, 500, new Predicate<Exception>() { @Override/*from w ww. j a v a 2s .co m*/ public boolean evaluate() throws Exception { LOG.debug("Last observed size=" + lastValue.get()); long actual = getRegionSizeReportForTable(conn, tn); if (actual == lastValue.get()) { int numMatches = counter.incrementAndGet(); if (numMatches >= 5) { return true; } // Not yet.. return false; } counter.set(0); lastValue.set(actual); return false; } }); }