本文整理了Java中rx.Observable.toBlocking()
方法的一些代码示例,展示了Observable.toBlocking()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Observable.toBlocking()
方法的具体详情如下:
包路径:rx.Observable
类名称: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
@Override
public long performEntityCount() {
//TODO, this really needs to be a task that writes this data somewhere since this will get
//progressively slower as the system expands
return (Long) getAllEntitiesObservable().countLong().toBlocking().last();
}
代码示例来源:origin: Netflix/zuul
@Test
public void testWriteInboundRequestDebug()
{
ctx.setDebugRequest(true);
ctx.setDebugRequestHeadersOnly(true);
Debug.writeDebugRequest(ctx, request, true).toBlocking().single();
List<String> debugLines = Debug.getRequestDebug(ctx);
assertEquals(3, debugLines.size());
assertEquals("REQUEST_INBOUND:: > LINE: POST /some/where?k1=v1 HTTP/1.1", debugLines.get(0));
assertEquals("REQUEST_INBOUND:: > HDR: Content-Length:13", debugLines.get(1));
assertEquals("REQUEST_INBOUND:: > HDR: lah:deda", debugLines.get(2));
}
代码示例来源:origin: apache/usergrid
@Test
public void writeLoadDelete() {
ApplicationScope context = new ApplicationScopeImpl( new SimpleId( "organization" ) );
Entity newEntity = new Entity( new SimpleId( "test" ) );
EntityCollectionManager manager = factory.createCollectionManager( context );
Observable<Entity> observable = manager.write( newEntity, null );
Entity createReturned = observable.toBlocking().lastOrDefault( null );
assertNotNull( "Id was assigned", createReturned.getId() );
Observable<Entity> loadObservable = manager.load( createReturned.getId() );
Entity loadReturned = loadObservable.toBlocking().lastOrDefault( null );
assertEquals( "Same value", createReturned, loadReturned );
manager.mark( createReturned.getId(), null ).toBlocking().last();
loadObservable = manager.load( createReturned.getId() );
//load may return null, use last or default
loadReturned = loadObservable.toBlocking().lastOrDefault( null );
assertNull( "Entity was deleted", loadReturned );
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
/**
* Deletes a policy set definition.
*
* @param policySetDefinitionName The name of the policy set definition to delete.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws ErrorResponseException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
*/
public void delete(String policySetDefinitionName) {
deleteWithServiceResponseAsync(policySetDefinitionName).toBlocking().single().body();
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
/**
* Deletes a resource group.
* 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.
*
* @param resourceGroupName The name of the resource group to delete. The name is case insensitive.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws CloudException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
*/
public void delete(String resourceGroupName) {
deleteWithServiceResponseAsync(resourceGroupName).toBlocking().last().body();
}
代码示例来源:origin: apache/usergrid
@Test
public void testWriteReadEdgeTypeVersionTarget() throws TimeoutException, InterruptedException {
GraphManager gm = emf.createEdgeManager( scope );
final long earlyVersion = 10000l;
Edge edge = createEdge( "source", "test", "target", earlyVersion );
gm.writeEdge( edge ).toBlocking().last();
//now test retrieving it
SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getTimestamp(), null );
Observable<MarkedEdge> edges = gm.loadEdgesToTarget( search );
//implicitly blows up if more than 1 is returned from "single"
Edge returned = edges.toBlocking().single();
assertEquals( "Correct edge returned", edge, returned );
//change edge type to be invalid, shouldn't get a result
search = createSearchByEdge( edge.getTargetNode(), edge.getType(), earlyVersion - 1, null );
edges = gm.loadEdgesToTarget( search );
//implicitly blows up if more than 1 is returned from "single"
returned = edges.toBlocking().singleOrDefault( null );
assertNull( "Earlier version should not be returned", returned );
}
代码示例来源:origin: apache/usergrid
@Test
public void testWriteReadEdgeTypeSource() throws TimeoutException, InterruptedException {
GraphManager gm = emf.createEdgeManager( scope );
Edge edge = createEdge( "source", "test", "target" );
gm.writeEdge( edge ).toBlocking().last();
//now test retrieving it
SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTimestamp(), null );
Observable<MarkedEdge> edges = gm.loadEdgesFromSource( search );
//implicitly blows up if more than 1 is returned from "single"
Edge returned = edges.toBlocking().last();
assertEquals( "Correct edge returned", edge, returned );
//change edge type to be invalid, shouldn't get a result
search = createSearchByEdge( edge.getSourceNode(), edge.getType() + "invalid", edge.getTimestamp(), null );
edges = gm.loadEdgesFromSource( search );
//implicitly blows up if more than 1 is returned from "single"
returned = edges.toBlocking().singleOrDefault( null );
assertNull( "Invalid type should not be returned", returned );
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Page<PolicySetDefinitionInner> nextPage(String nextPageLink) {
return listByManagementGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body();
}
};
代码示例来源:origin: Netflix/zuul
@Test
public void testWriteInboundResponseDebug()
{
ctx.setDebugRequest(true);
ctx.setDebugRequestHeadersOnly(true);
Debug.writeDebugResponse(ctx, response, true).toBlocking().single();
List<String> debugLines = Debug.getRequestDebug(ctx);
assertEquals(3, debugLines.size());
assertEquals("RESPONSE_INBOUND:: < STATUS: 200", debugLines.get(0));
assertEquals("RESPONSE_INBOUND:: < HDR: Content-Length:13", debugLines.get(1));
assertEquals("RESPONSE_INBOUND:: < HDR: lah:deda", debugLines.get(2));
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-network
/**
* Deletes a VirtualHub.
*
* @param resourceGroupName The resource group name of the VirtualHub.
* @param virtualHubName The name of the VirtualHub.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws ErrorException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
*/
public void delete(String resourceGroupName, String virtualHubName) {
deleteWithServiceResponseAsync(resourceGroupName, virtualHubName).toBlocking().last().body();
}
代码示例来源:origin: apache/usergrid
@Override
public Set<String> getConnectionsAsTarget( final EntityRef entityRef ) {
Preconditions.checkNotNull( entityRef, "entityRef cannot be null" );
final GraphManager graphManager = graphManagerFactory.createEdgeManager( applicationScope );
final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() );
return graphManager.getEdgeTypesToTarget(searchByEdgeType).map(
edgeName -> getConnectionNameFromEdgeName( edgeName ) )
.collect( () -> new HashSet<String>( ), ( r, s ) -> r.add(s) ).toBlocking().last();
}
代码示例来源:origin: apache/usergrid
@Test
public void testWriteReadEdgeTypeTarget() throws TimeoutException, InterruptedException {
GraphManager gm = emf.createEdgeManager( scope );
Edge edge = createEdge( "source", "test", "target" );
gm.writeEdge( edge ).toBlocking().last();
//now test retrieving it
SearchByEdgeType search = createSearchByEdge( edge.getTargetNode(), edge.getType(), edge.getTimestamp(), null );
Observable<MarkedEdge> edges = gm.loadEdgesToTarget( search );
//implicitly blows up if more than 1 is returned from "single"
Edge returned = edges.toBlocking().single();
assertEquals( "Correct edge returned", edge, returned );
//change edge type to be invalid, shouldn't get a result
search = createSearchByEdge( edge.getTargetNode(), edge.getType() + "invalid", edge.getTimestamp(), null );
edges = gm.loadEdgesToTarget( search );
//implicitly blows up if more than 1 is returned from "single"
returned = edges.toBlocking().singleOrDefault( null );
assertNull( "Invalid type should not be returned", returned );
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
/**
* Gets the specified resource provider.
*
* @param resourceProviderNamespace The namespace of the resource provider.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws CloudException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
* @return the ProviderInner object if successful.
*/
public ProviderInner get(String resourceProviderNamespace) {
return getWithServiceResponseAsync(resourceProviderNamespace).toBlocking().single().body();
}
代码示例来源:origin: Netflix/zuul
@Test
public void testWriteOutboundRequestDebug()
{
ctx.setDebugRequest(true);
ctx.setDebugRequestHeadersOnly(true);
Debug.writeDebugRequest(ctx, request, false).toBlocking().single();
List<String> debugLines = Debug.getRequestDebug(ctx);
assertEquals(3, debugLines.size());
assertEquals("REQUEST_OUTBOUND:: > LINE: POST /some/where?k1=v1 HTTP/1.1", debugLines.get(0));
assertEquals("REQUEST_OUTBOUND:: > HDR: Content-Length:13", debugLines.get(1));
assertEquals("REQUEST_OUTBOUND:: > HDR: lah:deda", debugLines.get(2));
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-network
/**
* Deletes the specified local network gateway.
*
* @param resourceGroupName The name of the resource group.
* @param localNetworkGatewayName The name of the local network gateway.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws CloudException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
*/
public void delete(String resourceGroupName, String localNetworkGatewayName) {
deleteWithServiceResponseAsync(resourceGroupName, localNetworkGatewayName).toBlocking().last().body();
}
代码示例来源:origin: apache/usergrid
@Override
public Set<String> getConnectionsAsSource( final EntityRef entityRef ) {
Preconditions.checkNotNull(entityRef, "entityRef cannot be null");
final GraphManager graphManager = graphManagerFactory.createEdgeManager( applicationScope );
final SearchEdgeType searchByEdgeType = createConnectionTypeSearch( entityRef.asId() );
return graphManager.getEdgeTypesFromSource(
searchByEdgeType ).map( edgeName -> getConnectionNameFromEdgeName( edgeName ) )
.collect( () -> new HashSet<String>(), ( r, s ) -> r.add( s ) ).toBlocking().last();
}
代码示例来源:origin: apache/usergrid
@Test
public void testWriteReadEdgeTypeVersionSource() throws TimeoutException, InterruptedException {
GraphManager gm = emf.createEdgeManager( scope );
final long earlyVersion = 1000l;
Edge edge = createEdge( "source", "test", "target", earlyVersion );
gm.writeEdge( edge ).toBlocking().last();
//now test retrieving it
SearchByEdgeType search = createSearchByEdge( edge.getSourceNode(), edge.getType(), edge.getTimestamp(), null );
Observable<MarkedEdge> edges = gm.loadEdgesFromSource( search );
//implicitly blows up if more than 1 is returned from "single"
Edge returned = edges.toBlocking().single();
assertEquals( "Correct edge returned", edge, returned );
//now test with an earlier version, we shouldn't get the edge back
search = createSearchByEdge( edge.getSourceNode(), edge.getType(), earlyVersion - 1, null );
edges = gm.loadEdgesFromSource( search );
//implicitly blows up if more than 1 is returned from "single"
returned = edges.toBlocking().singleOrDefault( null );
assertNull( "Earlier version should not be returned", returned );
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-resources
@Override
public Page<DeploymentExtendedInner> nextPage(String nextPageLink) {
return listByResourceGroupNextSinglePageAsync(nextPageLink).toBlocking().single().body();
}
};
代码示例来源:origin: Netflix/zuul
@Test
public void testWriteOutboundResponseDebug()
{
ctx.setDebugRequest(true);
ctx.setDebugRequestHeadersOnly(true);
Debug.writeDebugResponse(ctx, response, false).toBlocking().single();
List<String> debugLines = Debug.getRequestDebug(ctx);
assertEquals(3, debugLines.size());
assertEquals("RESPONSE_OUTBOUND:: < STATUS: 200", debugLines.get(0));
assertEquals("RESPONSE_OUTBOUND:: < HDR: Content-Length:13", debugLines.get(1));
assertEquals("RESPONSE_OUTBOUND:: < HDR: lah:deda", debugLines.get(2));
}
代码示例来源:origin: com.microsoft.azure/azure-mgmt-network
/**
* Deletes the specified load balancer.
*
* @param resourceGroupName The name of the resource group.
* @param loadBalancerName The name of the load balancer.
* @throws IllegalArgumentException thrown if parameters fail the validation
* @throws CloudException thrown if the request is rejected by server
* @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent
*/
public void delete(String resourceGroupName, String loadBalancerName) {
deleteWithServiceResponseAsync(resourceGroupName, loadBalancerName).toBlocking().last().body();
}
内容来源于网络,如有侵权,请联系作者删除!