rx.Observable.toBlocking()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.9k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中rx.Observable.toBlocking()方法的一些代码示例,展示了Observable.toBlocking()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.toBlocking()方法的具体详情如下:
包路径:rx.Observable
类名称:Observable
方法名:toBlocking

Observable.toBlocking介绍

[英]Converts an Observable into a BlockingObservable (an Observable with blocking operators). Scheduler: toBlocking does not operate by default on a particular Scheduler.
[中]将可观测转换为BlockingObservable(带有阻塞运算符的可观测)。调度程序:默认情况下,toBlocking不会在特定调度程序上运行。

代码示例

代码示例来源:origin: apache/usergrid

  1. @Override
  2. public long performEntityCount() {
  3. //TODO, this really needs to be a task that writes this data somewhere since this will get
  4. //progressively slower as the system expands
  5. return (Long) getAllEntitiesObservable().countLong().toBlocking().last();
  6. }

代码示例来源:origin: Netflix/zuul

  1. @Test
  2. public void testWriteInboundRequestDebug()
  3. {
  4. ctx.setDebugRequest(true);
  5. ctx.setDebugRequestHeadersOnly(true);
  6. Debug.writeDebugRequest(ctx, request, true).toBlocking().single();
  7. List<String> debugLines = Debug.getRequestDebug(ctx);
  8. assertEquals(3, debugLines.size());
  9. assertEquals("REQUEST_INBOUND:: > LINE: POST /some/where?k1=v1 HTTP/1.1", debugLines.get(0));
  10. assertEquals("REQUEST_INBOUND:: > HDR: Content-Length:13", debugLines.get(1));
  11. assertEquals("REQUEST_INBOUND:: > HDR: lah:deda", debugLines.get(2));
  12. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void writeLoadDelete() {
  3. ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) );
  4. Entity newEntity = new Entity( new SimpleId( "test" ) );
  5. EntityCollectionManager manager = factory.createCollectionManager( context );
  6. Observable<Entity> observable = manager.write( newEntity, null );
  7. Entity createReturned = observable.toBlocking().lastOrDefault( null );
  8. assertNotNull( "Id was assigned", createReturned.getId() );
  9. Observable<Entity> loadObservable = manager.load( createReturned.getId() );
  10. Entity loadReturned = loadObservable.toBlocking().lastOrDefault( null );
  11. assertEquals( "Same value", createReturned, loadReturned );
  12. manager.mark( createReturned.getId(), null ).toBlocking().last();
  13. loadObservable = manager.load( createReturned.getId() );
  14. //load may return null, use last or default
  15. loadReturned = loadObservable.toBlocking().lastOrDefault( null );
  16. assertNull( "Entity was deleted", loadReturned );
  17. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

  1. /**
  2. * Deletes a policy set definition.
  3. *
  4. * @param policySetDefinitionName The name of the policy set definition to delete.
  5. * @throws IllegalArgumentException thrown if parameters fail the validation
  6. * @throws ErrorResponseException thrown if the request is rejected by server
  7. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
  8. */
  9. public void delete(String policySetDefinitionName) {
  10. deleteWithServiceResponseAsync(policySetDefinitionName).toBlocking().single().body();
  11. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

  1. /**
  2. * Deletes a resource group.
  3. * When you delete a resource group, all of its resources are also deleted. Deleting a resource group deletes all of its template deployments and currently stored operations.
  4. *
  5. * @param resourceGroupName The name of the resource group to delete. The name is case insensitive.
  6. * @throws IllegalArgumentException thrown if parameters fail the validation
  7. * @throws CloudException thrown if the request is rejected by server
  8. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
  9. */
  10. public void delete(String resourceGroupName) {
  11. deleteWithServiceResponseAsync(resourceGroupName).toBlocking().last().body();
  12. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testWriteReadEdgeTypeVersionTarget() throws TimeoutException, InterruptedException {
  3. GraphManager gm = emf.createEdgeManager( scope );
  4. final long earlyVersion = 10000l;
  5. Edge edge = createEdge( "source", "test", "target", earlyVersion );
  6. gm.writeEdge( edge ).toBlocking().last();
  7. //now test retrieving it
  8. SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getTimestamp(), null );
  9. Observable<MarkedEdge> edges = gm.loadEdgesToTarget( search );
  10. //implicitly blows up if more than 1 is returned from "single"
  11. Edge returned = edges.toBlocking().single();
  12. assertEquals( "Correct edge returned", edge, returned );
  13. //change edge type to be invalid, shouldn't get a result
  14. search = createSearchByEdge( edge.getTargetNode(), edge.getType(), earlyVersion - 1, null );
  15. edges = gm.loadEdgesToTarget( search );
  16. //implicitly blows up if more than 1 is returned from "single"
  17. returned = edges.toBlocking().singleOrDefault( null );
  18. assertNull( "Earlier version should not be returned", returned );
  19. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testWriteReadEdgeTypeSource() throws TimeoutException, InterruptedException {
  3. GraphManager gm = emf.createEdgeManager( scope );
  4. Edge edge = createEdge( "source", "test", "target" );
  5. gm.writeEdge( edge ).toBlocking().last();
  6. //now test retrieving it
  7. SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTimestamp(), null );
  8. Observable<MarkedEdge> edges = gm.loadEdgesFromSource( search );
  9. //implicitly blows up if more than 1 is returned from "single"
  10. Edge returned = edges.toBlocking().last();
  11. assertEquals( "Correct edge returned", edge, returned );
  12. //change edge type to be invalid, shouldn't get a result
  13. search = createSearchByEdge( edge.getSourceNode(), edge.getType() + "invalid", edge.getTimestamp(), null );
  14. edges = gm.loadEdgesFromSource( search );
  15. //implicitly blows up if more than 1 is returned from "single"
  16. returned = edges.toBlocking().singleOrDefault( null );
  17. assertNull( "Invalid type should not be returned", returned );
  18. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

  1. @Override
  2. public Page<PolicySetDefinitionInner> nextPage(String nextPageLink) {
  3. return listByManagementGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body();
  4. }
  5. };

代码示例来源:origin: Netflix/zuul

  1. @Test
  2. public void testWriteInboundResponseDebug()
  3. {
  4. ctx.setDebugRequest(true);
  5. ctx.setDebugRequestHeadersOnly(true);
  6. Debug.writeDebugResponse(ctx, response, true).toBlocking().single();
  7. List<String> debugLines = Debug.getRequestDebug(ctx);
  8. assertEquals(3, debugLines.size());
  9. assertEquals("RESPONSE_INBOUND:: < STATUS: 200", debugLines.get(0));
  10. assertEquals("RESPONSE_INBOUND:: < HDR: Content-Length:13", debugLines.get(1));
  11. assertEquals("RESPONSE_INBOUND:: < HDR: lah:deda", debugLines.get(2));
  12. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-network

  1. /**
  2. * Deletes a VirtualHub.
  3. *
  4. * @param resourceGroupName The resource group name of the VirtualHub.
  5. * @param virtualHubName The name of the VirtualHub.
  6. * @throws IllegalArgumentException thrown if parameters fail the validation
  7. * @throws ErrorException thrown if the request is rejected by server
  8. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
  9. */
  10. public void delete(String resourceGroupName, String virtualHubName) {
  11. deleteWithServiceResponseAsync(resourceGroupName, virtualHubName).toBlocking().last().body();
  12. }

代码示例来源:origin: apache/usergrid

  1. @Override
  2. public Set<String> getConnectionsAsTarget( final EntityRef entityRef ) {
  3. Preconditions.checkNotNull( entityRef, "entityRef cannot be null" );
  4. final GraphManager graphManager = graphManagerFactory.createEdgeManager( applicationScope );
  5. final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() );
  6. return graphManager.getEdgeTypesToTarget(searchByEdgeType).map(
  7. edgeName -> getConnectionNameFromEdgeName( edgeName ) )
  8. .collect( () -> new HashSet<String>( ), ( r, s ) -> r.add(s) ).toBlocking().last();
  9. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testWriteReadEdgeTypeTarget() throws TimeoutException, InterruptedException {
  3. GraphManager gm = emf.createEdgeManager( scope );
  4. Edge edge = createEdge( "source", "test", "target" );
  5. gm.writeEdge( edge ).toBlocking().last();
  6. //now test retrieving it
  7. SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getTimestamp(), null );
  8. Observable<MarkedEdge> edges = gm.loadEdgesToTarget( search );
  9. //implicitly blows up if more than 1 is returned from "single"
  10. Edge returned = edges.toBlocking().single();
  11. assertEquals( "Correct edge returned", edge, returned );
  12. //change edge type to be invalid, shouldn't get a result
  13. search = createSearchByEdge( edge.getTargetNode(), edge.getType() + "invalid", edge.getTimestamp(), null );
  14. edges = gm.loadEdgesToTarget( search );
  15. //implicitly blows up if more than 1 is returned from "single"
  16. returned = edges.toBlocking().singleOrDefault( null );
  17. assertNull( "Invalid type should not be returned", returned );
  18. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

  1. /**
  2. * Gets the specified resource provider.
  3. *
  4. * @param resourceProviderNamespace The namespace of the resource provider.
  5. * @throws IllegalArgumentException thrown if parameters fail the validation
  6. * @throws CloudException thrown if the request is rejected by server
  7. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
  8. * @return the ProviderInner object if successful.
  9. */
  10. public ProviderInner get(String resourceProviderNamespace) {
  11. return getWithServiceResponseAsync(resourceProviderNamespace).toBlocking().single().body();
  12. }

代码示例来源:origin: Netflix/zuul

  1. @Test
  2. public void testWriteOutboundRequestDebug()
  3. {
  4. ctx.setDebugRequest(true);
  5. ctx.setDebugRequestHeadersOnly(true);
  6. Debug.writeDebugRequest(ctx, request, false).toBlocking().single();
  7. List<String> debugLines = Debug.getRequestDebug(ctx);
  8. assertEquals(3, debugLines.size());
  9. assertEquals("REQUEST_OUTBOUND:: > LINE: POST /some/where?k1=v1 HTTP/1.1", debugLines.get(0));
  10. assertEquals("REQUEST_OUTBOUND:: > HDR: Content-Length:13", debugLines.get(1));
  11. assertEquals("REQUEST_OUTBOUND:: > HDR: lah:deda", debugLines.get(2));
  12. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-network

  1. /**
  2. * Deletes the specified local network gateway.
  3. *
  4. * @param resourceGroupName The name of the resource group.
  5. * @param localNetworkGatewayName The name of the local network gateway.
  6. * @throws IllegalArgumentException thrown if parameters fail the validation
  7. * @throws CloudException thrown if the request is rejected by server
  8. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
  9. */
  10. public void delete(String resourceGroupName, String localNetworkGatewayName) {
  11. deleteWithServiceResponseAsync(resourceGroupName, localNetworkGatewayName).toBlocking().last().body();
  12. }

代码示例来源:origin: apache/usergrid

  1. @Override
  2. public Set<String> getConnectionsAsSource( final EntityRef entityRef ) {
  3. Preconditions.checkNotNull(entityRef, "entityRef cannot be null");
  4. final GraphManager graphManager = graphManagerFactory.createEdgeManager( applicationScope );
  5. final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() );
  6. return graphManager.getEdgeTypesFromSource(
  7. searchByEdgeType ).map( edgeName -> getConnectionNameFromEdgeName( edgeName ) )
  8. .collect( () -> new HashSet<String>(), ( r, s ) -> r.add( s ) ).toBlocking().last();
  9. }

代码示例来源:origin: apache/usergrid

  1. @Test
  2. public void testWriteReadEdgeTypeVersionSource() throws TimeoutException, InterruptedException {
  3. GraphManager gm = emf.createEdgeManager( scope );
  4. final long earlyVersion = 1000l;
  5. Edge edge = createEdge( "source", "test", "target", earlyVersion );
  6. gm.writeEdge( edge ).toBlocking().last();
  7. //now test retrieving it
  8. SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTimestamp(), null );
  9. Observable<MarkedEdge> edges = gm.loadEdgesFromSource( search );
  10. //implicitly blows up if more than 1 is returned from "single"
  11. Edge returned = edges.toBlocking().single();
  12. assertEquals( "Correct edge returned", edge, returned );
  13. //now test with an earlier version, we shouldn't get the edge back
  14. search = createSearchByEdge( edge.getSourceNode(), edge.getType(), earlyVersion - 1, null );
  15. edges = gm.loadEdgesFromSource( search );
  16. //implicitly blows up if more than 1 is returned from "single"
  17. returned = edges.toBlocking().singleOrDefault( null );
  18. assertNull( "Earlier version should not be returned", returned );
  19. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources

  1. @Override
  2. public Page<DeploymentExtendedInner> nextPage(String nextPageLink) {
  3. return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body();
  4. }
  5. };

代码示例来源:origin: Netflix/zuul

  1. @Test
  2. public void testWriteOutboundResponseDebug()
  3. {
  4. ctx.setDebugRequest(true);
  5. ctx.setDebugRequestHeadersOnly(true);
  6. Debug.writeDebugResponse(ctx, response, false).toBlocking().single();
  7. List<String> debugLines = Debug.getRequestDebug(ctx);
  8. assertEquals(3, debugLines.size());
  9. assertEquals("RESPONSE_OUTBOUND:: < STATUS: 200", debugLines.get(0));
  10. assertEquals("RESPONSE_OUTBOUND:: < HDR: Content-Length:13", debugLines.get(1));
  11. assertEquals("RESPONSE_OUTBOUND:: < HDR: lah:deda", debugLines.get(2));
  12. }

代码示例来源:origin: com.microsoft.azure/azure-mgmt-network

  1. /**
  2. * Deletes the specified load balancer.
  3. *
  4. * @param resourceGroupName The name of the resource group.
  5. * @param loadBalancerName The name of the load balancer.
  6. * @throws IllegalArgumentException thrown if parameters fail the validation
  7. * @throws CloudException thrown if the request is rejected by server
  8. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
  9. */
  10. public void delete(String resourceGroupName, String loadBalancerName) {
  11. deleteWithServiceResponseAsync(resourceGroupName, loadBalancerName).toBlocking().last().body();
  12. }

相关文章

Observable类方法