List of usage examples for java.util.concurrent.atomic AtomicBoolean set
public final void set(boolean newValue)
From source file:org.apache.phoenix.util.CoprocessorHConnectionTableFactoryTest.java
@Test public void testCachedConnections() throws Exception { final String tableName = generateUniqueName(); final String index1Name = generateUniqueName(); final Connection conn = DriverManager.getConnection(getUrl()); final HBaseAdmin admin = getUtility().getHBaseAdmin(); final MiniHBaseCluster cluster = getUtility().getHBaseCluster(); final HRegionServer regionServer = cluster.getRegionServer(0); Configuration conf = admin.getConfiguration(); final int noOfOrgs = 20; final AtomicBoolean flag = new AtomicBoolean(); flag.set(false); // create table and indices String createTableSql = "CREATE TABLE " + tableName + "(org_id VARCHAR NOT NULL PRIMARY KEY, v1 INTEGER, v2 INTEGER, v3 INTEGER) VERSIONS=1 SPLIT ON ('" + ORG_PREFIX + "-" + noOfOrgs / 2 + "')"; conn.createStatement().execute(createTableSql); conn.createStatement().execute("CREATE INDEX " + index1Name + " ON " + tableName + "(v1)"); List<HRegionInfo> regions = admin.getTableRegions(TableName.valueOf(tableName)); final HRegionInfo regionInfo = regions.get(0); writeToTable(tableName, conn, noOfOrgs); int beforeRegionCloseCount = getActiveConnections(regionServer, conf); int regionsCount = admin.getOnlineRegions(regionServer.getServerName()).size(); admin.unassign(regionInfo.getEncodedNameAsBytes(), true); while (!(admin.getOnlineRegions(regionServer.getServerName()).size() < regionsCount)) ;/*from ww w . ja v a2 s. c o m*/ int afterRegionCloseCount = getActiveConnections(regionServer, conf); assertTrue("Cached connections not closed when region closes: ", afterRegionCloseCount == beforeRegionCloseCount && afterRegionCloseCount > 0); }
From source file:com.jkoolcloud.tnt4j.streams.parsers.ActivityXmlParser.java
private static Object resolveValueOverXPath(Node xmlDoc, XPathExpression expr, AtomicBoolean formattingNeeded) throws XPathExpressionException { Object val = null; NodeList nodes = null;/*w w w.j a v a 2 s . com*/ try { nodes = (NodeList) expr.evaluate(xmlDoc, XPathConstants.NODESET); } catch (XPathException exc) { val = expr.evaluate(xmlDoc); } int length = nodes == null ? 0 : nodes.getLength(); if (length > 0) { List<Object> valuesList = new ArrayList<>(length); for (int i = 0; i < length; i++) { Node node = nodes.item(i); valuesList.add(node); } val = Utils.simplifyValue(valuesList); formattingNeeded.set(false); } return val; }
From source file:io.cloudslang.engine.queue.services.recovery.WorkerRecoveryServiceImpl.java
@Override @Transactional//from ww w .j a va2 s. c om public void doWorkerRecovery(String workerUuid) { //lock this worker to synchronize with drain action workerLockService.lock(workerUuid); logger.warn("Worker [" + workerUuid + "] is going to be recovered"); long time = System.currentTimeMillis(); // change status to in_recovery in separate transaction in order to make it as quickly as possible // so keep-alive wont be stuck and assigning won't take this worker as candidate workerNodeService.updateStatusInSeparateTransaction(workerUuid, WorkerStatus.IN_RECOVERY); final AtomicBoolean shouldContinue = new AtomicBoolean(true); while (shouldContinue.get()) { shouldContinue.set(messageRecoveryService.recoverMessagesBulk(workerUuid, DEFAULT_POLL_SIZE)); } String newWRV = UUID.randomUUID().toString(); workerNodeService.updateWRV(workerUuid, newWRV); workerNodeService.updateStatus(workerUuid, WorkerStatus.RECOVERED); logger.warn( "Worker [" + workerUuid + "] recovery is done in " + (System.currentTimeMillis() - time) + " ms"); }
From source file:com.ebay.cloud.cms.entmgr.entity.impl.EntityFieldTargetMerger.java
/** * Merge the delete references./*w w w .java 2 s . com*/ * * @param giveValues * @param foundValues * @param hasChange * @param output_DeleteValues * - this is OUTPUT parameters. The delete values would be add * into this list. * @return */ private List<?> mergeDeleteReference(List<IEntity> giveValues, List<IEntity> foundValues, AtomicBoolean hasChange) { if (foundValues.isEmpty()) { hasChange.set(true); return Collections.<IEntity>emptyList(); } Map<String, IEntity> oids = new HashMap<String, IEntity>(); for (IEntity entity : foundValues) { oids.put(entity.getId(), entity); } for (IEntity obj : giveValues) { if (oids.containsKey(obj.getId())) { hasChange.set(true); oids.remove(obj.getId()); } } return new ArrayList<IEntity>(oids.values()); }
From source file:com.acme.ModuleConfigurationTest.java
@Test public void test() { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); Properties properties = new Properties(); properties.put("prefix", "foo"); properties.put("suffix", "bar"); context.getEnvironment().getPropertySources().addLast(new PropertiesPropertySource("options", properties)); context.register(TestConfiguration.class); context.refresh();/* www .j av a 2s. c om*/ MessageChannel input = context.getBean("input", MessageChannel.class); SubscribableChannel output = context.getBean("output", SubscribableChannel.class); final AtomicBoolean handled = new AtomicBoolean(); output.subscribe(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { handled.set(true); assertEquals("foohellobar", message.getPayload()); } }); input.send(new GenericMessage<String>("hello")); assertTrue(handled.get()); }
From source file:fr.xebia.servlet.filter.SecuredRemoteAddressFilterTest.java
private void testRemoteAddr(String remoteAddr, boolean expected) throws ServletException, IOException { SecuredRemoteAddressFilter filter = new SecuredRemoteAddressFilter(); MockFilterConfig filterConfig = new MockFilterConfig(); filter.init(filterConfig);/* ww w. j a v a2s . c o m*/ final AtomicBoolean secured = new AtomicBoolean(); MockFilterChain filterChain = new MockFilterChain() { @Override public void doFilter(ServletRequest request, ServletResponse response) { secured.set(request.isSecure()); } }; MockHttpServletRequest request = new MockHttpServletRequest(); request.setRemoteAddr(remoteAddr); filter.doFilter(request, new MockHttpServletResponse(), filterChain); assertEquals(expected, secured.get()); }
From source file:com.adaptris.core.lms.StreamWrapperCase.java
@Test public void testOutputStream_Write() throws Exception { StreamWrapper wrapper = createWrapper(false); File file = TempFileUtils.createTrackedFile(wrapper); AtomicBoolean callback = new AtomicBoolean(false); OutputStream out = wrapper.openOutputStream(file, () -> { callback.set(true); });//from ww w .ja v a 2 s . co m try (OutputStream closeable = out) { out.write(BYTES_TEXT[0]); } tryQuietly(() -> { out.close(); }); assertTrue(callback.get()); }
From source file:com.netflix.spinnaker.fiat.shared.FiatPermissionEvaluator.java
public UserPermission.View getPermission(String username) { UserPermission.View view = null; if (StringUtils.isEmpty(username)) { return null; }//from w w w . j av a2 s .c o m try { AtomicBoolean cacheHit = new AtomicBoolean(true); view = permissionsCache.get(username, () -> { cacheHit.set(false); return AuthenticatedRequest.propagate(() -> fiatService.getUserPermission(username)).call(); }); log.debug("Fiat permission cache hit: " + cacheHit.get()); } catch (ExecutionException | UncheckedExecutionException ee) { String message = String.format("Cannot get whole user permission for user %s. Cause: %s", username, ee.getCause().getMessage()); if (log.isDebugEnabled()) { log.debug(message, ee.getCause()); } else { log.info(message); } } return view; }
From source file:io.vertx.config.git.GitConfigStoreWithGithubTest.java
@After public void tearDown() { AtomicBoolean done = new AtomicBoolean(); if (retriever != null) { retriever.close();/*from ww w.j av a 2s . c om*/ } if (git != null) { git.close(); } vertx.close(v -> done.set(true)); await().untilAtomic(done, is(true)); }
From source file:cc.gospy.example.google.GoogleScholarSpider.java
public Collection<String> getResultLinks(final String keyword, final int pageFrom, final int pageTo) { if (pageFrom < 1) throw new IllegalArgumentException(pageFrom + "<" + 1); if (pageFrom >= pageTo) throw new IllegalArgumentException(pageFrom + ">=" + pageTo); final AtomicInteger currentPage = new AtomicInteger(pageFrom); final AtomicBoolean returned = new AtomicBoolean(false); final Collection<String> links = new LinkedHashSet<>(); Gospy googleScholarSpider = Gospy.custom() .setScheduler(/*from ww w . j a v a2 s. c o m*/ Schedulers.VerifiableScheduler.custom().setExitCallback(() -> returned.set(true)).build()) .addFetcher(Fetchers.HttpFetcher.custom() .before(request -> request.setConfig( RequestConfig.custom().setProxy(new HttpHost("127.0.0.1", 8118)).build())) .build()) .addProcessor(Processors.XPathProcessor.custom().extract( "//*[@id='gs_ccl_results']/div/div/h3/a/@href", (task, resultList, returnedData) -> { links.addAll(resultList); currentPage.incrementAndGet(); if (pageFrom <= currentPage.get() && currentPage.get() < pageTo) { return Arrays.asList( new Task(String.format("https://scholar.google.com/scholar?start=%d&q=%s", (currentPage.get() - 1) * 10, keyword))); } else { return Arrays.asList(); } }).build()) .build() .addTask(String.format("https://scholar.google.com/scholar?start=%d&q=%s", pageFrom, keyword)); googleScholarSpider.start(); while (!returned.get()) ; // block until spider returned googleScholarSpider.stop(); return links; }