Search in sources :

Example 1 with CustomPOJO

use of com.azure.cosmos.examples.common.CustomPOJO in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SalesOrder method PerformanceTipsJavaSDKv4NeedsSchedulerAsync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
 * Performance tips - needs scheduler
 * Async only
 */
/**
 * Performance tips - needs scheduler
 */
public static void PerformanceTipsJavaSDKv4NeedsSchedulerAsync() {
    CosmosAsyncContainer asyncContainer = null;
    CustomPOJO item = null;
    // <PerformanceNeedsSchedulerAsync>
    Mono<CosmosItemResponse<CustomPOJO>> createItemPub = asyncContainer.createItem(item);
    createItemPub.subscribe(itemResponse -> {
        // this is executed on eventloop IO netty thread.
        // the eventloop thread is shared and is meant to return back quickly.
        // 
        // DON'T do this on eventloop IO netty thread.
        veryCpuIntensiveWork();
    });
// </PerformanceNeedsSchedulerAsync>
}
Also used : CosmosAsyncContainer(com.azure.cosmos.CosmosAsyncContainer) CosmosItemResponse(com.azure.cosmos.models.CosmosItemResponse) CustomPOJO(com.azure.cosmos.examples.common.CustomPOJO)

Example 2 with CustomPOJO

use of com.azure.cosmos.examples.common.CustomPOJO in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SalesOrder method PerformanceTipsJavaSDKv4AddSchedulerSync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
 * Performance tips - add scheduler
 * Async only
 */
/**
 * Performance tips - add scheduler
 */
public static void PerformanceTipsJavaSDKv4AddSchedulerSync() {
    CosmosAsyncContainer asyncContainer = null;
    CustomPOJO item = null;
    // <PerformanceAddSchedulerAsync>
    Mono<CosmosItemResponse<CustomPOJO>> createItemPub = asyncContainer.createItem(item);
    createItemPub.subscribeOn(Schedulers.elastic()).subscribe(itemResponse -> {
        // this is executed on eventloop IO netty thread.
        // the eventloop thread is shared and is meant to return back quickly.
        // 
        // DON'T do this on eventloop IO netty thread.
        veryCpuIntensiveWork();
    });
// </PerformanceAddSchedulerAsync>
}
Also used : CosmosAsyncContainer(com.azure.cosmos.CosmosAsyncContainer) CosmosItemResponse(com.azure.cosmos.models.CosmosItemResponse) CustomPOJO(com.azure.cosmos.examples.common.CustomPOJO)

Example 3 with CustomPOJO

use of com.azure.cosmos.examples.common.CustomPOJO in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SampleDocumentationSnippets method PerformanceTipsJavaSDKv4AddPKSpecSync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
 * Performance tips - add partition key in point-writes
 */
/**
 * Performance tips - add partition key in point-writes
 */
public static void PerformanceTipsJavaSDKv4AddPKSpecSync() {
    CosmosContainer syncContainer = null;
    CustomPOJO item = null;
    // <PerformanceAddPKSync>
    syncContainer.createItem(item);
// </PerformanceAddPKSync>
}
Also used : CosmosContainer(com.azure.cosmos.CosmosContainer) CustomPOJO(com.azure.cosmos.examples.common.CustomPOJO)

Example 4 with CustomPOJO

use of com.azure.cosmos.examples.common.CustomPOJO in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SalesOrder method TroubleshootingGuideJavaSDKv4CustomSchedulerAsync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/troubleshoot-java-sdk-v4-sql
 * Troubleshooting guide - custom scheduler
 * Async only
 */
/**
 * Troubleshooting guide - custom scheduler
 */
public static void TroubleshootingGuideJavaSDKv4CustomSchedulerAsync() {
    CosmosAsyncContainer container = null;
    CustomPOJO item = null;
    // <TroubleshootCustomSchedulerAsync>
    // Have a singleton instance of an executor and a scheduler.
    ExecutorService ex = Executors.newFixedThreadPool(30);
    Scheduler customScheduler = Schedulers.fromExecutor(ex);
// </TroubleshootCustomSchedulerAsync>
}
Also used : CosmosAsyncContainer(com.azure.cosmos.CosmosAsyncContainer) Scheduler(reactor.core.scheduler.Scheduler) ExecutorService(java.util.concurrent.ExecutorService) CustomPOJO(com.azure.cosmos.examples.common.CustomPOJO)

Example 5 with CustomPOJO

use of com.azure.cosmos.examples.common.CustomPOJO in project azure-cosmos-java-sql-api-samples by Azure-Samples.

the class SalesOrder method PerformanceTipsJavaSDKv4RequestChargeSpecAsync.

/**
 * https://docs.microsoft.com/en-us/azure/cosmos-db/performance-tips-java-sdk-v4-sql
 * Performance tips - get request charge
 */
/**
 * Performance tips - get request charge
 */
public static void PerformanceTipsJavaSDKv4RequestChargeSpecAsync() {
    CosmosAsyncContainer asyncContainer = null;
    CustomPOJO item = null;
    String pk = "pk_value";
    // <PerformanceRequestChargeAsync>
    CosmosItemResponse<CustomPOJO> response = asyncContainer.createItem(item).block();
    response.getRequestCharge();
// </PerformanceRequestChargeAsync>
}
Also used : CosmosAsyncContainer(com.azure.cosmos.CosmosAsyncContainer) CustomPOJO(com.azure.cosmos.examples.common.CustomPOJO)

Aggregations

CustomPOJO (com.azure.cosmos.examples.common.CustomPOJO)12 CosmosAsyncContainer (com.azure.cosmos.CosmosAsyncContainer)8 PartitionKey (com.azure.cosmos.models.PartitionKey)4 CosmosContainer (com.azure.cosmos.CosmosContainer)3 CosmosItemRequestOptions (com.azure.cosmos.models.CosmosItemRequestOptions)3 CosmosItemResponse (com.azure.cosmos.models.CosmosItemResponse)3 ChangeFeedProcessor (com.azure.cosmos.ChangeFeedProcessor)2 ChangeFeedProcessorBuilder (com.azure.cosmos.ChangeFeedProcessorBuilder)2 CosmosStoredProcedureRequestOptions (com.azure.cosmos.models.CosmosStoredProcedureRequestOptions)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayList (java.util.ArrayList)2 ExecutorService (java.util.concurrent.ExecutorService)2 Scheduler (reactor.core.scheduler.Scheduler)2 ProxyOptions (com.azure.core.http.ProxyOptions)1 ConsistencyLevel (com.azure.cosmos.ConsistencyLevel)1 CosmosAsyncClient (com.azure.cosmos.CosmosAsyncClient)1 CosmosAsyncDatabase (com.azure.cosmos.CosmosAsyncDatabase)1 CosmosClientBuilder (com.azure.cosmos.CosmosClientBuilder)1 DirectConnectionConfig (com.azure.cosmos.DirectConnectionConfig)1