List of usage examples for java.lang.ref WeakReference WeakReference
public WeakReference(T referent)
From source file:de.hybris.platform.jdbcwrapper.DataSourceFactoryTest.java
@Test public void testPoolShutdownAfterError() { final Tenant t = Registry.getCurrentTenantNoFallback(); final Map<String, String> params = new HashMap<String, String>( t.getMasterDataSource().getConnectionParameters()); // make it fail on connect by messing up the user name params.put(SystemSpecificParams.DB_USERNAME, "FooDosntExist"); final DataSourceFactory dataSourceFactory = t.getMasterDataSource().getDataSourceFactory(); final AtomicReference<WeakReference<JDBCConnectionPool>> poolRef = new AtomicReference<WeakReference<JDBCConnectionPool>>(); final DataSourceFactory f = new DataSourceFactory() { @Override// w w w. j ava 2 s . com public HybrisDataSource createJNDIDataSource(final String id, final Tenant tenant, final String jndiName, final boolean readOnly) { throw new UnsupportedOperationException(); } @Override public HybrisDataSource createDataSource(final String id, final Tenant tenant, final Map<String, String> connectionParams, final boolean readOnly) { throw new UnsupportedOperationException(); } @Override public JDBCConnectionPool createConnectionPool(final HybrisDataSource dataSource, final Config poolConfig) { final JDBCConnectionPool ret = dataSourceFactory.createConnectionPool(dataSource, poolConfig); poolRef.set(new WeakReference<JDBCConnectionPool>(ret)); return ret; } @Override public Connection wrapConnection(final HybrisDataSource wrappedDataSource, final Connection rawConnection) { return dataSourceFactory.wrapConnection(wrappedDataSource, rawConnection); } @Override public Statement wrapStatement(final Connection wrappedConnection, final Statement rawStatement) { return dataSourceFactory.wrapStatement(wrappedConnection, rawStatement); } @Override public PreparedStatement wrapPreparedStatement(final Connection wrappedConnection, final PreparedStatement rawStatement, final String query) { return dataSourceFactory.wrapPreparedStatement(wrappedConnection, rawStatement, query); } @Override public ResultSet wrapResultSet(final Statement wrappedStatement, final ResultSet rawResultSet) { return dataSourceFactory.wrapResultSet(wrappedStatement, rawResultSet); } }; HybrisDataSource ds = null; try { TestUtils.disableFileAnalyzer("DataSource creation should throw exception"); ds = new DataSourceImpl(t, "DummyDS", params, false, f); } catch (final Exception e) { // fine so far - now check how the pool behaves assertPoolIsShutDown(poolRef.get(), 30); } finally { TestUtils.enableFileAnalyzer(); } if (ds != null) { // in case data source creation did not fail as expected we must clean up for sure ds.destroy(); fail("data source creation was supposed to fail but did not"); } }
From source file:com.vaadin.server.AbstractClientConnectorTest.java
private WeakReference<Class<?>> loadClass(String name) throws ClassNotFoundException { ClassLoader loader = new TestClassLoader(); Class<?> loaded = loader.loadClass(name); return new WeakReference<>(loaded); }
From source file:de.micromata.mgc.javafx.logging.LoggingLogViewAdapter.java
List<LogWriteEntry> getLogEntries(long lastPollTime) { synchronized (logWriteEntries) { if (curLogging.get() != LoggingServiceManager.get().getLogging()) { curLogging = new WeakReference<Logging>(LoggingServiceManager.get().getLogging()); initLogConfiguration();//from w w w . j av a 2 s .co m } List<LogWriteEntry> ret = new ArrayList<>(); for (LogWriteEntry le : logWriteEntries) { if (le.getTimestamp() <= lastPollTime) { continue; } ret.add(le); } return ret; } }
From source file:com.esminis.server.library.activity.main.MainViewImpl.java
MainViewImpl(AppCompatActivity activity, final MainPresenter presenter) { this.context = activity.getApplicationContext(); this.activity = new WeakReference<>(activity); this.presenter = presenter; viewServerInterfaces = (Spinner) activity.findViewById(R.id.server_interface); viewDocumentRoot = (TextView) activity.findViewById(R.id.server_root); viewLog = (TextView) activity.findViewById(R.id.error); viewPort = (TextView) activity.findViewById(R.id.server_port); viewInstalledPackage = (TextView) activity.findViewById(R.id.server_build); viewServerStatusLabel = (TextView) activity.findViewById(R.id.label); titleDefault = context.getString(R.string.title); viewContainer = activity.findViewById(R.id.container); drawerLayout = (DrawerLayout) activity.findViewById(R.id.drawer_layout); buttonStart = activity.findViewById(R.id.start); buttonStop = activity.findViewById(R.id.stop); setupToolbar(activity);/*from w ww . j ava 2s.c om*/ actionBar = activity.getSupportActionBar(); if (actionBar != null) { actionBar.setTitle(titleDefault); } drawerToggle = new ActionBarDrawerToggle(activity, drawerLayout, R.string.open, R.string.close) { private void invalidateOptionsMenu() { final Activity activity = MainViewImpl.this.activity.get(); if (activity != null) { activity.invalidateOptionsMenu(); } } public void onDrawerClosed(View view) { super.onDrawerClosed(view); if (actionBar != null && context.getApplicationInfo() != null) { actionBar.setTitle(titleDefault); } invalidateOptionsMenu(); } public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (actionBar != null) { actionBar.setTitle(R.string.settings); } invalidateOptionsMenu(); } }; setupDrawer(); setupListeners(activity); showButton(BUTTON_NONE); setStatusLabel(activity.getString(R.string.server_status_updating)); }
From source file:com.activiti.android.ui.fragments.AlfrescoFragment.java
protected void setRootView(View rootView) { this.vRoot = new WeakReference<View>(rootView); }
From source file:com.entertailion.android.slideshow.images.ImageManager.java
/** * Adds an observer to be notified when the set of items held by this * ImageManager changes./*from ww w . j ava2s . c o m*/ */ public void addObserver(DataSetObserver observer) { final WeakReference<DataSetObserver> obs = new WeakReference<DataSetObserver>(observer); dataSetObservers.add(obs); }
From source file:im.r_c.android.fusioncache.FusionCache.java
public FusionCache(Context context, long maxMemCacheSize, long maxDiskCacheSize, File diskCacheDir, boolean enableFusionMode) { // Do the real initialization if (maxMemCacheSize < 0 || maxDiskCacheSize < 0) { throw new IllegalArgumentException("Max cache size should be non-negative."); }// w ww .j av a2s . c o m mAppContextRef = new WeakReference<>(context.getApplicationContext()); mFusionModeEnabled = enableFusionMode; if (maxMemCacheSize > 0) { mMemCache = new MemCache(maxMemCacheSize); } if (maxDiskCacheSize > 0) { mDiskCache = new DiskCache2(diskCacheDir, maxDiskCacheSize); } }
From source file:com.appbase.androidquery.callback.BitmapAjaxCallback.java
/** * Set the target Image view.// w w w .j ava2 s . c o m * * @param view the view * @return self */ public BitmapAjaxCallback imageView(ImageView view) { v = new WeakReference<ImageView>(view); return this; }
From source file:br.com.anteros.social.instagram.AnterosInstagramSession.java
public AnterosInstagramSession(AnterosInstagramConfiguration configuration) { setActivity(configuration.getActivity()); this.onLoginListener = new WeakReference<OnLoginListener>(configuration.getOnLoginListener()); this.onLogoutListener = new WeakReference<OnLogoutListener>(configuration.getOnLogoutListener()); this.clientId = configuration.getClientId(); this.clientSecret = configuration.getClientSecret(); this.redirectURL = configuration.getRedirectURL(); this.activity = new WeakReference<Activity>(configuration.getActivity()); sharedPreferences = activity.get().getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); if (TextUtils.isEmpty(clientId) || TextUtils.isEmpty(clientSecret)) { throw new IllegalArgumentException("clientId and clientSecret are invalid"); }/*ww w . ja va 2 s . c o m*/ String scope = configuration.getScope(); if (scope == null) { scope = "basic"; } String INSTAGRAM_AUTHURL = "https://api.instagram.com/oauth/authorize/"; authURLString = INSTAGRAM_AUTHURL + "?client_id=" + clientId + "&redirect_uri=" + redirectURL + "&response_type=code&display=touch&scope=" + scope; tokenURLString = INSTAGRAM_TOKENURL + "?client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=" + redirectURL + "&grant_type=authorization_code"; }
From source file:com.ichi2.anki.Reviewer.java
@Override protected void onCollectionLoaded(Collection col) { super.onCollectionLoaded(col); // Load the first card and start reviewing. Uses the answer card // task to load a card, but since we send null // as the card to answer, no card will be answered. mPrefWhiteboard = MetaDB.getWhiteboardState(this, getParentDid()); if (mPrefWhiteboard) { setWhiteboardEnabledState(true); setWhiteboardVisibility(true);//from w w w.ja v a2s. c om } col.getSched().reset(); // Reset schedule incase card had previous been loaded DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ANSWER_CARD, mAnswerCardHandler, new DeckTask.TaskData(null, 0)); disableDrawerSwipeOnConflicts(); // Add a weak reference to current activity so that scheduler can talk to to Activity mSched.setContext(new WeakReference<Activity>(this)); // Set full screen/immersive mode if needed if (mPrefFullscreenReview) { CompatHelper.getCompat().setFullScreen(this); } }