當前位置: 首頁>>代碼示例>>Java>>正文


Java ConditionVariable.block方法代碼示例

本文整理匯總了Java中android.os.ConditionVariable.block方法的典型用法代碼示例。如果您正苦於以下問題:Java ConditionVariable.block方法的具體用法?Java ConditionVariable.block怎麽用?Java ConditionVariable.block使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.os.ConditionVariable的用法示例。


在下文中一共展示了ConditionVariable.block方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SimpleCache

import android.os.ConditionVariable; //導入方法依賴的package包/類
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 */
public SimpleCache(File cacheDir, CacheEvictor evictor) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.cachedSpans = new HashMap<>();
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
      }
    }
  }.start();
  conditionVariable.block();
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:26,代碼來源:SimpleCache.java

示例2: SimpleCache

import android.os.ConditionVariable; //導入方法依賴的package包/類
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 * @param evictor The evictor to be used.
 * @param secretKey If not null, cache keys will be stored encrypted on filesystem using AES/CBC.
 *     The key must be 16 bytes long.
 */
public SimpleCache(File cacheDir, CacheEvictor evictor, byte[] secretKey) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.index = new CachedContentIndex(cacheDir, secretKey);
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        try {
          initialize();
        } catch (CacheException e) {
          initializationException = e;
        }
        SimpleCache.this.evictor.onCacheInitialized();
      }
    }
  }.start();
  conditionVariable.block();
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:34,代碼來源:SimpleCache.java

示例3: testInvokeCallbackWithErrorShouldSucceed

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testInvokeCallbackWithErrorShouldSucceed () throws Exception {
	WebViewApp.setCurrentApp(null);
	final ConditionVariable cv = new ConditionVariable();
	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			WebViewApp.setCurrentApp(new WebViewApp());
			WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
			WebViewApp.getCurrentApp().setWebAppLoaded(true);
			WebViewApp.getCurrentApp().setWebAppInitialized(true);
			cv.open();
		}
	});

	boolean cvsuccess = cv.block(10000);
	assertTrue("ConditionVariable was not opened successfully", cvsuccess);
	Invocation invocation = new Invocation();
	invocation.setInvocationResponse(CallbackStatus.OK, MockError.TEST_ERROR_1, "Test", 12345, true);
	boolean success = WebViewApp.getCurrentApp().invokeCallback(invocation);
	assertTrue("invokeCallback -method should've returned true", success);
	assertTrue("WebView invokeJavascript should've been invoked but was not", ((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_INVOKED);
	assertNotNull("The invoked JavaScript string should not be null", ((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:26,代碼來源:WebViewAppTest.java

示例4: testInvokeMethodShouldSucceedMethodNull

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testInvokeMethodShouldSucceedMethodNull () throws Exception {
	WebViewApp.setCurrentApp(null);
	final ConditionVariable cv = new ConditionVariable();
	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			WebViewApp.setCurrentApp(new WebViewApp());
			WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
			WebViewApp.getCurrentApp().setWebAppLoaded(true);
			WebViewApp.getCurrentApp().setWebAppInitialized(true);
			cv.open();
		}
	});

	boolean cvsuccess = cv.block(10000);
	assertTrue("ConditionVariable was not opened successfully", cvsuccess);
	Method m = null;
	boolean success = WebViewApp.getCurrentApp().invokeMethod("TestClass", "testMethod", m);
	assertTrue("invokeMethod -method should've returned true", success);
	assertTrue("WebView invokeJavascript should've succeeded but didn't", ((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_INVOKED);
	assertNotNull("The invoked JavaScript string should not be null.", ((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:25,代碼來源:WebViewAppTest.java

示例5: testConstruct

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
@RequiresDevice
public void testConstruct () throws Exception {
	final ConditionVariable cv = new ConditionVariable();
	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			VideoPlayerView vp = new VideoPlayerView(getInstrumentation().getTargetContext());
			assertNotNull("VideoPlayerView should not be null after constructing", vp);
			cv.open();
		}
	});

	boolean success = cv.block(30000);
	assertTrue("Condition variable was not opened properly: VideoPlayer was not created", success);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:18,代碼來源:VideoViewTest.java

示例6: testSetActivity

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testSetActivity () throws InterruptedException {
	final ConditionVariable cv = new ConditionVariable();

	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			MockActivity act = new MockActivity();
			ClientProperties.setActivity(act);
			cv.open();
		}
	});

	boolean success = cv.block(10000);
	assertTrue("ConditionVariable was not opened!", success);
	assertNotNull("Activity should not be null after setting it", ClientProperties.getActivity());
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:19,代碼來源:ClientPropertiesTest.java

示例7: testSetConfiguration

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testSetConfiguration () throws Exception {
	WebViewApp.setCurrentApp(null);
	final ConditionVariable cv = new ConditionVariable();

	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			WebViewApp.setCurrentApp(new WebViewApp());
			WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
			WebViewApp.getCurrentApp().setWebAppLoaded(true);
			WebViewApp.getCurrentApp().setWebAppInitialized(true);
			cv.open();
		}
	});

	boolean success = cv.block(10000);
	assertTrue("ConditionVariable was not opened successfully", success);

	final Configuration conf = new Configuration(TestUtilities.getTestServerAddress());
	WebViewApp.getCurrentApp().setConfiguration(conf);

	assertNotNull("Current WebApp configuration should not be null", WebViewApp.getCurrentApp().getConfiguration());
	assertEquals("Local configuration and current WebApp configuration should be the same object", conf, WebViewApp.getCurrentApp().getConfiguration());
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:27,代碼來源:WebViewAppTest.java

示例8: testSendEventShouldFail

import android.os.ConditionVariable; //導入方法依賴的package包/類
@Test
public void testSendEventShouldFail () throws Exception {
	WebViewApp.setCurrentApp(null);
	final ConditionVariable cv = new ConditionVariable();

	Handler handler = new Handler(Looper.getMainLooper());
	handler.post(new Runnable() {
		@Override
		public void run() {
			WebViewApp.setCurrentApp(new WebViewApp());
			WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
			WebViewApp.getCurrentApp().setWebAppInitialized(true);
			cv.open();
		}
	});

	boolean cvsuccess = cv.block(10000);
	assertTrue("ConditionVariable was not opened successfully", cvsuccess);
	boolean success = WebViewApp.getCurrentApp().sendEvent(MockEventCategory.TEST_CATEGORY_1, MockEvent.TEST_EVENT_1);
	assertFalse("sendEvent -method should've returned false", success);
	assertFalse("WebView invokeJavascript should've not been invoked but was (webviewapp is not loaded so no call should have occured)", ((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_INVOKED);
	assertNull("The invoked JavaScript string should be null (webviewapp is not loaded so no call should have occured)", ((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
 
開發者ID:Unity-Technologies,項目名稱:unity-ads-android,代碼行數:24,代碼來源:WebViewAppTest.java

示例9: testExecutorShutdown

import android.os.ConditionVariable; //導入方法依賴的package包/類
@SmallTest
@Feature({"Cronet"})
@OnlyRunNativeCronet // No destroyed callback for tests
public void testExecutorShutdown() {
    TestUrlRequestCallback callback = new TestUrlRequestCallback();

    callback.setAutoAdvance(false);
    UrlRequest.Builder builder = new UrlRequest.Builder(NativeTestServer.getEchoBodyURL(),
            callback, callback.getExecutor(), mTestFramework.mCronetEngine);
    CronetUrlRequest urlRequest = (CronetUrlRequest) builder.build();
    urlRequest.start();
    callback.waitForNextStep();
    assertFalse(callback.isDone());
    assertFalse(urlRequest.isDone());

    final ConditionVariable requestDestroyed = new ConditionVariable(false);
    urlRequest.setOnDestroyedCallbackForTesting(new Runnable() {
        @Override
        public void run() {
            requestDestroyed.open();
        }
    });

    // Shutdown the executor, so posting the task will throw an exception.
    callback.shutdownExecutor();
    ByteBuffer readBuffer = ByteBuffer.allocateDirect(5);
    urlRequest.read(readBuffer);
    // Callback will never be called again because executor is shutdown,
    // but request will be destroyed from network thread.
    requestDestroyed.block();

    assertFalse(callback.isDone());
    assertTrue(urlRequest.isDone());
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:35,代碼來源:CronetUrlRequestTest.java

示例10: testDestroyUploadDataStreamAdapterOnSucceededCallback

import android.os.ConditionVariable; //導入方法依賴的package包/類
@SmallTest
@Feature({"Cronet"})
@OnlyRunNativeCronet // No adapter to destroy in pure java
// Regression test for crbug.com/564946.
public void testDestroyUploadDataStreamAdapterOnSucceededCallback() throws Exception {
    TestUrlRequestCallback callback = new QuitOnSuccessCallback();
    UrlRequest.Builder builder = new UrlRequest.Builder(NativeTestServer.getEchoBodyURL(),
            callback, callback.getExecutor(), mTestFramework.mCronetEngine);

    TestUploadDataProvider dataProvider = new TestUploadDataProvider(
            TestUploadDataProvider.SuccessCallbackMode.SYNC, callback.getExecutor());
    builder.setUploadDataProvider(dataProvider, callback.getExecutor());
    builder.addHeader("Content-Type", "useless/string");
    CronetUrlRequest request = (CronetUrlRequest) builder.build();
    final ConditionVariable uploadDataStreamAdapterDestroyed = new ConditionVariable();
    request.setOnDestroyedUploadCallbackForTesting(new Runnable() {
        @Override
        public void run() {
            uploadDataStreamAdapterDestroyed.open();
        }
    });

    request.start();
    uploadDataStreamAdapterDestroyed.block();

    assertEquals(200, callback.mResponseInfo.getHttpStatusCode());
    assertEquals("", callback.mResponseAsString);
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:29,代碼來源:CronetUrlRequestTest.java

示例11: testInitAndShutdownOnMainThread

import android.os.ConditionVariable; //導入方法依賴的package包/類
@SmallTest
@Feature({"Cronet"})
public void testInitAndShutdownOnMainThread() throws Exception {
    final CronetTestFramework testFramework = startCronetTestFrameworkAndSkipLibraryInit();
    final ConditionVariable block = new ConditionVariable(false);

    // Post a task to main thread to init and shutdown on the main thread.
    Runnable blockingTask = new Runnable() {
        @Override
        public void run() {
            // Create new request context, loading the library.
            final CronetEngine cronetEngine = testFramework.initCronetEngine();
            // Shutdown right after init.
            cronetEngine.shutdown();
            // Verify that context is shutdown.
            try {
                cronetEngine.stopNetLog();
                fail("Should throw an exception.");
            } catch (Exception e) {
                assertEquals("Engine is shut down.", e.getMessage());
            }
            block.open();
        }
    };
    new Handler(Looper.getMainLooper()).post(blockingTask);
    // Wait for shutdown to complete on main thread.
    block.block();
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:29,代碼來源:CronetUrlRequestContextTest.java

示例12: testExecutorShutdownBeforeStreamIsDone

import android.os.ConditionVariable; //導入方法依賴的package包/類
@SmallTest
@Feature({"Cronet"})
@OnlyRunNativeCronet
public void testExecutorShutdownBeforeStreamIsDone() {
    // Test that stream is destroyed even if executor is shut down and rejects posting tasks.
    TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCallback();
    callback.setAutoAdvance(false);
    BidirectionalStream.Builder builder =
            new BidirectionalStream.Builder(Http2TestServer.getEchoMethodUrl(), callback,
                    callback.getExecutor(), mTestFramework.mCronetEngine);
    CronetBidirectionalStream stream =
            (CronetBidirectionalStream) builder.setHttpMethod("GET").build();
    stream.start();
    callback.waitForNextReadStep();
    assertFalse(callback.isDone());
    assertFalse(stream.isDone());

    final ConditionVariable streamDestroyed = new ConditionVariable(false);
    stream.setOnDestroyedCallbackForTesting(new Runnable() {
        @Override
        public void run() {
            streamDestroyed.open();
        }
    });

    // Shut down the executor, so posting the task will throw an exception.
    callback.shutdownExecutor();
    ByteBuffer readBuffer = ByteBuffer.allocateDirect(5);
    stream.read(readBuffer);
    // Callback will never be called again because executor is shut down,
    // but stream will be destroyed from network thread.
    streamDestroyed.block();

    assertFalse(callback.isDone());
    assertTrue(stream.isDone());
}
 
開發者ID:lizhangqu,項目名稱:chromium-net-for-android,代碼行數:37,代碼來源:BidirectionalStreamTest.java

示例13: fakeBusy

import android.os.ConditionVariable; //導入方法依賴的package包/類
public static void fakeBusy(ThreadPool.JobContext jc, int timeout) {
    final ConditionVariable cv = new ConditionVariable();
    jc.setCancelListener(new ThreadPool.CancelListener() {
        @Override
        public void onCancel() {
            cv.open();
        }
    });
    cv.block(timeout);
    jc.setCancelListener(null);
}
 
開發者ID:mayurkaul,項目名稱:medialibrary,代碼行數:12,代碼來源:GalleryUtils.java

示例14: bindApplication

import android.os.ConditionVariable; //導入方法依賴的package包/類
public void bindApplication(final String packageName, final String processName) {
    if (Looper.getMainLooper() == Looper.myLooper()) {
        bindApplicationNoCheck(packageName, processName, new ConditionVariable());
    } else {
        final ConditionVariable lock = new ConditionVariable();
        VirtualRuntime.getUIHandler().post(new Runnable() {
            @Override
            public void run() {
                bindApplicationNoCheck(packageName, processName, lock);
                lock.open();
            }
        });
        lock.block();
    }
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:16,代碼來源:VClientImpl.java

示例15: initProcess

import android.os.ConditionVariable; //導入方法依賴的package包/類
private Bundle initProcess(Bundle extras) {
	ConditionVariable lock = VirtualCore.get().getInitLock();
	if (lock != null) {
		lock.block();
	}
	IBinder token = BundleCompat.getBinder(extras,"_VA_|_binder_");
	int vuid = extras.getInt("_VA_|_vuid_");
	VClientImpl client = VClientImpl.get();
	client.initProcess(token, vuid);
	Bundle res = new Bundle();
	BundleCompat.putBinder(res, "_VA_|_client_", client.asBinder());
	res.putInt("_VA_|_pid_", Process.myPid());
	return res;
}
 
開發者ID:7763sea,項目名稱:VirtualHook,代碼行數:15,代碼來源:StubContentProvider.java


注:本文中的android.os.ConditionVariable.block方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。