List of usage examples for java.util.concurrent.atomic AtomicReference get
public final V get()
From source file:com.igormaznitsa.ideamindmap.utils.IdeaUtils.java
@Nullable public static VirtualFile findKnowledgeFolderForModule(@Nullable final Module module, final boolean createIfMissing) { final VirtualFile rootFolder = IdeaUtils.findPotentialRootFolderForModule(module); final AtomicReference<VirtualFile> result = new AtomicReference<VirtualFile>(); if (rootFolder != null) { result.set(rootFolder.findChild(PROJECT_KNOWLEDGE_FOLDER_NAME)); if (result.get() == null || !result.get().isDirectory()) { if (createIfMissing) { CommandProcessor.getInstance().executeCommand(module.getProject(), new Runnable() { @Override/*from ww w . j av a 2 s . c o m*/ public void run() { ApplicationManager.getApplication().runWriteAction(new Runnable() { @Override public void run() { try { result.set(VfsUtil.createDirectoryIfMissing(rootFolder, PROJECT_KNOWLEDGE_FOLDER_NAME)); LOGGER.info("Created knowledge folder for " + module); } catch (IOException ex) { LOGGER.error("Can't create knowledge folder for " + module, ex); } } }); } }, null, null); } else { result.set(null); } } } return result.get(); }
From source file:com.google.dart.engine.internal.index.AbstractDartTest.java
/** * @return {@link ASTNode} which has required offset and type. *///from w w w . j a v a 2s . com public static <E extends ASTNode> E findNode(ASTNode root, final int offset, final Class<E> clazz) { final AtomicReference<E> resultRef = new AtomicReference<E>(); root.accept(new GeneralizingASTVisitor<Void>() { @Override @SuppressWarnings("unchecked") public Void visitNode(ASTNode node) { if (node.getOffset() <= offset && offset < node.getEnd() && clazz.isInstance(node)) { resultRef.set((E) node); } return super.visitNode(node); } }); E result = resultRef.get(); assertNotNull(result); return result; }
From source file:com.microsoft.tfs.core.clients.versioncontrol.localworkspace.BaselineFolder.java
/** * Given the root baseline folder and a baseline file GUID, calculates the * path that this baseline file GUID would have in that root folder, without * the extension (.rw or .gz)./*from ww w . ja va 2s.co m*/ * * Example values for baselineFolderRootPath: "D:\workspace\$tf" -- from the * instance method GetPathFromGuid immediately above * "C:\ProgramData\TFS\Offline\<guid>\<workspace>" * * @param baselineFolderRootPath * Root folder of the baseline folder structure * @param baselineFileGuid * Baseline file GUID whose path should be computed * @param String * [out] A value equal to Path.GetDirectoryName(retval) * @return */ public static String getPathFromGUID(final String baselineFolderRootPath, final byte[] baselineFileGuid, final AtomicReference<String> individualBaselineFolder) { checkForValidBaselineFileGUID(baselineFileGuid); // i.e. @"D:\workspace\$tf\1" individualBaselineFolder.set(baselineFolderRootPath + File.separator + PARTITIONING_FOLDERS[((char) baselineFileGuid[0]) % PARTITIONING_FOLDER_COUNT]); // i.e. @"D:\workspace\$tf\1\408bed21-9023-47c3-8280-b1ec3ffacd94" return individualBaselineFolder.get() + File.separator + new GUID(baselineFileGuid).getGUIDString(); }
From source file:com.splout.db.common.TestUtils.java
/** * Returns a QNode instance if, after a maximum of X trials, we can find a port to bind it to. * The configuration passed by instance might have been modified accordingly. *//*from ww w.ja va 2 s . c om*/ public static QNode getTestQNode(final SploutConfiguration testConfig, final IQNodeHandler handler) throws Throwable { final AtomicReference<QNode> reference = new AtomicReference<QNode>(); CatchAndRetry qNodeInit = new CatchAndRetry(java.net.BindException.class, 50) { @Override public void businessLogic() throws Throwable { QNode qNode = new QNode(); qNode.start(testConfig, handler); reference.set(qNode); } @Override public void retryLogic() { testConfig.setProperty(QNodeProperties.PORT, testConfig.getInt(QNodeProperties.PORT) + 1); } }; qNodeInit.catchAndRetry(); return reference.get(); }
From source file:com.scvngr.levelup.core.test.TestThreadingUtils.java
/** * Validates that a fragment is either not managed by the fragment manager or is not visible to * the user.// ww w.j a v a 2 s .c o m * * @param <V> the type of Fragment. * @param instrumentation the test {@link Instrumentation}. * @param activity the activity for the test being run (null will fail validation). * @param fragmentManager the fragment manager the fragment was added to (null will fail * validation). * @param tag the tag to check for (null will fail validation). * @return the Fragment that is not visible to the user. */ @NonNull @SuppressWarnings("unchecked") public static <V extends Fragment> V validateFragmentIsNotVisible( @NonNull final Instrumentation instrumentation, final Activity activity, final FragmentManager fragmentManager, final String tag) { AndroidTestCase.assertNotNull(tag); AndroidTestCase.assertNotNull(activity); AndroidTestCase.assertNotNull(fragmentManager); final AtomicReference<Fragment> reference = new AtomicReference<Fragment>(); final LatchRunnable latchRunnable = new LatchRunnable() { @Override public void run() { final Fragment fragment = fragmentManager.findFragmentByTag(tag); if (null == fragment || !fragment.isVisible()) { reference.set(fragment); countDown(); } } }; AndroidTestCase.assertTrue(String.format(Locale.US, "%s is not visible", tag), waitForAction(instrumentation, activity, latchRunnable, true)); return (V) reference.get(); }
From source file:com.scvngr.levelup.core.test.TestThreadingUtils.java
/** * Validates that a fragment is visible to the user. * * @param <V> the type of Fragment. * @param instrumentation the test {@link Instrumentation}. * @param activity the activity for the test being run (null will fail validation). * @param fragmentManager the fragment manager the fragment was added to (null will fail * validation).// ww w . j a v a 2s .com * @param tag the tag to check for (null will fail validation). * @return the Fragment that is visible to the user. */ @NonNull @SuppressWarnings("unchecked") public static <V extends Fragment> V validateFragmentIsVisible(@NonNull final Instrumentation instrumentation, final Activity activity, final FragmentManager fragmentManager, final String tag) { AndroidTestCase.assertNotNull(tag); AndroidTestCase.assertNotNull(activity); AndroidTestCase.assertNotNull(fragmentManager); final AtomicReference<Fragment> reference = new AtomicReference<Fragment>(); final LatchRunnable latchRunnable = new LatchRunnable() { @Override public void run() { final Fragment fragment = fragmentManager.findFragmentByTag(tag); if (null != fragment) { if (fragment.isVisible()) { reference.set(fragment); countDown(); } } } }; AndroidTestCase.assertTrue(String.format(Locale.US, "%s is visible", tag), waitForAction(instrumentation, activity, latchRunnable, true)); return (V) reference.get(); }
From source file:objective.taskboard.it.BoardStepFragment.java
public void assertIssueList(String... expectedIssueKeyList) { AtomicReference<String> s = new AtomicReference<>(); try {/*from w ww. jav a 2 s .c o m*/ waitUntil((w) -> { s.set(join(issueList(), "\n")); return s.get().equals(join(expectedIssueKeyList, "\n")); }); } catch (TimeoutException e) { assertEquals(join(expectedIssueKeyList, "\n"), s.get()); } }
From source file:eu.eubrazilcc.lvl.storage.security.shiro.LinkedInRealm.java
@Override protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) throws AuthenticationException { // validate token if (token == null) { throw new CredentialsException("Uninitialized token"); }/* w w w . j a v a 2s.c o m*/ if (!(token instanceof AccessTokenToken)) { throw new UnsupportedTokenException("Unsuported token type: " + token.getClass().getCanonicalName()); } // get access token final AccessTokenToken accessToken = (AccessTokenToken) token; final String secret = trimToNull(accessToken.getToken()); if (isEmpty(secret)) { throw new AccountException("Empty tokens are not allowed in this realm"); } // find token in the LVL OAuth2 database String ownerid = null; final AtomicReference<String> ownerIdRef = new AtomicReference<String>(); if (TOKEN_DAO.isValid(secret, ownerIdRef)) { ownerid = ownerIdRef.get(); } if (isEmpty(ownerid)) { throw new IncorrectCredentialsException("Incorrect credentials found"); } // find resource owner in the LVL IdP database final ResourceOwner owner = RESOURCE_OWNER_DAO.useGravatar(false).find(ownerid); if (owner == null || owner.getUser() == null) { throw new UnknownAccountException("No account found for user [" + ownerid + "]"); } return new SimpleAuthenticationInfo(ownerid, secret, getName()); }
From source file:ro.contezi.websockets.main.SampleWebSocketsApplicationTest.java
@Test public void reverseEndpoint() throws Exception { ConfigurableApplicationContext context = new SpringApplicationBuilder(ClientConfiguration.class, PropertyPlaceholderAutoConfiguration.class) .properties("websocket.uri:ws://localhost:" + this.port + "/reverse") .run("--spring.main.web_environment=false"); long count = context.getBean(ClientConfiguration.class).getLatch().getCount(); AtomicReference<String> messagePayloadReference = context.getBean(ClientConfiguration.class) .getMessagePayload();//from www . jav a 2 s . co m context.close(); assertEquals(0, count); assertEquals("Reversed: !olleH", messagePayloadReference.get()); }
From source file:jp.realglobe.sugo.actor.android.call.MainActivity.java
/** * ??/*from ww w . j a v a 2s.c o m*/ * * @param interval ?????? * @param context * @param listener ???? * @param errorCallback ?? * @return ?? */ private static GoogleApiClient setupLocationClient(long interval, Context context, LocationListener listener, StringCallback errorCallback) { final AtomicReference<GoogleApiClient> client = new AtomicReference<>(); client.set((new GoogleApiClient.Builder(context)).addApi(LocationServices.API) .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() { @Override public void onConnected(@Nullable Bundle bundle) { if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { return; } LocationServices.FusedLocationApi.requestLocationUpdates(client.get(), LocationRequest .create().setInterval(interval).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY), location -> { Log.d(LOG_TAG, "Location changed to " + location); if (listener != null) { listener.onLocationChanged(location); } }); Log.d(LOG_TAG, "Location monitor started"); } @Override public void onConnectionSuspended(int i) { Log.d(LOG_TAG, "Location monitor suspended"); } }).addOnConnectionFailedListener(connectionResult -> { final String warning = "Location detector error: " + connectionResult; Log.w(LOG_TAG, warning); if (errorCallback != null) { errorCallback.call(connectionResult.getErrorMessage()); } }).build()); return client.get(); }