com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync Java Examples

The following examples show how to use com.amazonaws.services.dynamodbv2.AmazonDynamoDBAsync. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsTest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Test
public void testAsyncClient(final MockTracer tracer) throws Exception {
  final AmazonDynamoDBAsync dbClient = buildAsyncClient();
  final Future<CreateTableResult> createTableResultFuture = createTableAsync(dbClient, "asyncRequest");
  try {
    final CreateTableResult result = createTableResultFuture.get(10, TimeUnit.SECONDS);
    // The following assertion is only relevant when a local instance of dynamodb is present.
    // If a local instance of dynamodb is NOT present, an exception is thrown.
    assertEquals("asyncRequest", result.getTableDescription().getTableName());
  }
  catch (final Exception e) {
    logger.log(Level.WARNING, e.getMessage());
  }

  final List<MockSpan> spans = tracer.finishedSpans();
  assertEquals(1, spans.size());
  assertEquals("CreateTableRequest", spans.get(0).operationName());
}
 
Example #2
Source File: AwsTest.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
private static Future<CreateTableResult> createTableAsync(final AmazonDynamoDBAsync dbClient, final String tableName) {
  final String partitionKeyName = tableName + "Id";
  final CreateTableRequest createTableRequest = new CreateTableRequest()
    .withTableName(tableName).withKeySchema(new KeySchemaElement().withAttributeName(partitionKeyName).withKeyType(KeyType.HASH))
    .withAttributeDefinitions(new AttributeDefinition().withAttributeName(partitionKeyName).withAttributeType("S"))
    .withProvisionedThroughput(new ProvisionedThroughput().withReadCapacityUnits(10L).withWriteCapacityUnits(5L));

  return dbClient.createTableAsync(createTableRequest, new AsyncHandler<CreateTableRequest,CreateTableResult>() {
    @Override
    public void onError(final Exception exception) {
    }

    @Override
    public void onSuccess(final CreateTableRequest request, final CreateTableResult createTableResult) {
    }
  });
}
 
Example #3
Source File: KinesisBinderConfiguration.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
@ConditionalOnBean(AmazonDynamoDBAsync.class)
@ConditionalOnProperty(name = "spring.cloud.stream.kinesis.binder.kpl-kcl-enabled", havingValue = "false",
		matchIfMissing = true)
public LockRegistry dynamoDBLockRegistry(@Autowired(required = false) AmazonDynamoDBAsync dynamoDB) {
	if (dynamoDB != null) {
		KinesisBinderConfigurationProperties.Locks locks = this.configurationProperties.getLocks();
		DynamoDbLockRegistry dynamoDbLockRegistry = new DynamoDbLockRegistry(dynamoDB, locks.getTable());
		dynamoDbLockRegistry.setRefreshPeriod(locks.getRefreshPeriod());
		dynamoDbLockRegistry.setHeartbeatPeriod(locks.getHeartbeatPeriod());
		dynamoDbLockRegistry.setLeaseDuration(locks.getLeaseDuration());
		dynamoDbLockRegistry.setPartitionKey(locks.getPartitionKey());
		dynamoDbLockRegistry.setSortKeyName(locks.getSortKeyName());
		dynamoDbLockRegistry.setSortKey(locks.getSortKey());
		dynamoDbLockRegistry.setReadCapacity(locks.getReadCapacity());
		dynamoDbLockRegistry.setWriteCapacity(locks.getWriteCapacity());
		return dynamoDbLockRegistry;
	}
	else {
		return null;
	}
}
 
Example #4
Source File: DynamoDBClientPool.java    From geowave with Apache License 2.0 6 votes vote down vote up
public synchronized AmazonDynamoDBAsync getClient(final DynamoDBOptions options) {
  AmazonDynamoDBAsync client = clientCache.get(options);
  if (client == null) {

    if ((options.getRegion() == null)
        && ((options.getEndpoint() == null) || options.getEndpoint().isEmpty())) {
      throw new ParameterException("Compulsory to specify either the region or the endpoint");
    }

    final ClientConfiguration clientConfig = options.getClientConfig();
    final AmazonDynamoDBAsyncClientBuilder builder =
        AmazonDynamoDBAsyncClientBuilder.standard().withClientConfiguration(clientConfig);
    if ((options.getEndpoint() != null) && (options.getEndpoint().length() > 0)) {
      builder.withEndpointConfiguration(
          new EndpointConfiguration(
              options.getEndpoint(),
              options.getRegion() != null ? options.getRegion().getName() : "local"));
    } else {
      builder.withRegion(options.getRegion());
    }
    client = builder.build();
    clientCache.put(options, client);
  }
  return client;
}
 
Example #5
Source File: DynamoDBReplicationEmitter.java    From dynamodb-cross-region-library with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor with given parameters, used for when MultiRegionEmitter creates emitter dynamically.
 *
 * @param endpoint
 *            The endpoint of the emitter
 * @param region
 *            The region of the emitter
 * @param tableName
 *            The tableName the emitter should emit to
 * @param dynamoDBAsync
 *            The DynamoDB client used for this application
 * @param cloudwatch
 *            The cloudwatch client used for this application
 */
@SuppressWarnings("deprecation")
public DynamoDBReplicationEmitter(final String applicationName, final String endpoint, final String region, final String tableName,
                                  final AmazonDynamoDBAsync dynamoDBAsync, final AmazonCloudWatchAsync cloudwatch) {
    this.applicationName = applicationName;
    this.endpoint = endpoint;
    this.region = region;
    this.tableName = tableName;

    final boolean setDynamoDB = DYNAMODB.compareAndSet(null, dynamoDBAsync);
    if (setDynamoDB && dynamoDBAsync != null) {
        DYNAMODB.get().setEndpoint(endpoint);
    }
    final boolean setCloudWatch = CLOUDWATCH.compareAndSet(null, cloudwatch);
    if (setCloudWatch && cloudwatch != null) {
        CLOUDWATCH.get().setRegion(Regions.getCurrentRegion() == null ? Region.getRegion(Regions.US_EAST_1) : Regions.getCurrentRegion());
    }
    skipErrors = false; // TODO make configurable
}
 
Example #6
Source File: LazyPaginatedScan.java    From geowave with Apache License 2.0 5 votes vote down vote up
public LazyPaginatedScan(
    final ScanResult currentResult,
    final ScanRequest request,
    final AmazonDynamoDBAsync dynamoDBClient) {
  this.currentResult = currentResult;
  this.request = request;
  this.dynamoDBClient = dynamoDBClient;
}
 
Example #7
Source File: AmazonAsyncDockerClientsHolder.java    From spring-localstack with Apache License 2.0 5 votes vote down vote up
@Override
public AmazonDynamoDBAsync amazonDynamoDB() {
    return decorateWithConfigsAndBuild(
        AmazonDynamoDBAsyncClientBuilder.standard(),
        LocalstackDocker::getEndpointDynamoDB
    );
}
 
Example #8
Source File: AsyncPaginatedQuery.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * The async paginated query is a much more complicated but asynchronous version of the paginated
 * query
 *
 * <p> As soon a async paginated query is fired, multiple asynchronous query requests are fired in
 * tandem across different async paginated queries.
 *
 * <p> A max of "MAX_ASYNC_QUERY_RESULTS" can be in progress at any time
 */
public AsyncPaginatedQuery(final QueryRequest request, final AmazonDynamoDBAsync dynamoDBClient) {
  lastRequest = request;
  this.dynamoDBClient = dynamoDBClient;

  /**
   * Link list because we need to store null values Queues like ArrayDeque don't support null
   * value insertion
   */
  asyncQueryResults = new LinkedList<>();
  asyncRequestsInProgress = 0;

  checkAndAsyncQuery();
}
 
Example #9
Source File: AsyncPaginatedScan.java    From geowave with Apache License 2.0 5 votes vote down vote up
/**
 * The async paginated query is a much more complicated but asynchronous version of the paginated
 * query
 *
 * <p> As soon a async paginated query is fired, multiple asynchronous query requests are fired in
 * tandem across different async paginated queries.
 *
 * <p> A max of "MAX_ASYNC_SCAN_RESULTS" can be in progress at any time
 */
public AsyncPaginatedScan(final ScanRequest request, final AmazonDynamoDBAsync dynamoDBClient) {
  lastRequest = request;
  this.dynamoDBClient = dynamoDBClient;

  /**
   * Link list because we need to store null values Queues like ArrayDeque don't support null
   * value insertion
   */
  asyncScanResults = new LinkedList<>();
  asyncRequestsInProgress = 0;

  checkAndAsyncScan();
}
 
Example #10
Source File: LazyPaginatedQuery.java    From geowave with Apache License 2.0 5 votes vote down vote up
public LazyPaginatedQuery(
    final QueryResult currentResult,
    final QueryRequest request,
    final AmazonDynamoDBAsync dynamoDBClient) {
  this.currentResult = currentResult;
  this.request = request;
  this.dynamoDBClient = dynamoDBClient;
}
 
Example #11
Source File: DynamoDBWriter.java    From geowave with Apache License 2.0 5 votes vote down vote up
public DynamoDBWriter(
    final AmazonDynamoDBAsync client,
    final String tableName,
    final boolean isDataIndex) {
  this.isDataIndex = isDataIndex;
  this.client = client;
  this.tableName = tableName;
}
 
Example #12
Source File: ExtendedDockerTestUtils.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
public static AmazonDynamoDBAsync getClientDynamoDbAsync() {
	AmazonDynamoDBAsyncClientBuilder dynamoDBAsyncClientBuilder =
			AmazonDynamoDBAsyncClientBuilder.standard()
					.withEndpointConfiguration(
							createEndpointConfiguration(LocalstackDocker.INSTANCE::getEndpointDynamoDB));
	return applyConfigurationAndBuild(dynamoDBAsyncClientBuilder);
}
 
Example #13
Source File: KinesisTestBinder.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
TestKinesisMessageChannelBinder(AmazonKinesisAsync amazonKinesis,
		AmazonDynamoDBAsync dynamoDbClient,
		KinesisBinderConfigurationProperties kinesisBinderConfigurationProperties,
		KinesisStreamProvisioner provisioningProvider) {

	super(kinesisBinderConfigurationProperties, provisioningProvider, amazonKinesis,
			new AWSStaticCredentialsProvider(new BasicAWSCredentials("", "")), dynamoDbClient, null, null);
}
 
Example #14
Source File: KinesisBinderConfiguration.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 5 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public AmazonDynamoDBAsync dynamoDB() {
	if (this.hasInputs) {
		return AmazonDynamoDBAsyncClientBuilder.standard()
				.withCredentials(this.awsCredentialsProvider)
				.withRegion(this.region)
				.build();
	}
	else {
		return null;
	}
}
 
Example #15
Source File: AwsTest.java    From java-specialagent with Apache License 2.0 5 votes vote down vote up
private static AmazonDynamoDBAsync buildAsyncClient() {
  final EndpointConfiguration endpointConfiguration = new EndpointConfiguration("http://localhost:8000", "us-west-2");
  final BasicAWSCredentials awsCreds = new BasicAWSCredentials("access_key_id", "secret_key_id");
  return AmazonDynamoDBAsyncClientBuilder
    .standard()
    .withEndpointConfiguration(endpointConfiguration)
    .withRequestHandlers()
    .withCredentials(new AWSStaticCredentialsProvider(awsCreds))
    .withClientConfiguration(new ClientConfiguration().withConnectionTimeout(1))
    .build();
}
 
Example #16
Source File: CloudStreamKinesisToWebfluxApplicationTests.java    From spring-cloud-stream-samples with Apache License 2.0 4 votes vote down vote up
@Bean
public AmazonDynamoDBAsync dynamoDB() {
	return null;
}
 
Example #17
Source File: DynamoDBReplicationEmitter.java    From dynamodb-cross-region-library with Apache License 2.0 4 votes vote down vote up
/**
 * @return the dynamodb
 */
public AmazonDynamoDBAsync getDynamodb() {
    return DYNAMODB.get();
}
 
Example #18
Source File: KinesisBinderProcessorTests.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 4 votes vote down vote up
@Bean(destroyMethod = "")
public AmazonDynamoDBAsync dynamoDB() {
	return DYNAMO_DB;
}
 
Example #19
Source File: DynamoDBOperations.java    From geowave with Apache License 2.0 4 votes vote down vote up
public AmazonDynamoDBAsync getClient() {
  return client;
}
 
Example #20
Source File: KinesisTestBinder.java    From spring-cloud-stream-binder-aws-kinesis with Apache License 2.0 4 votes vote down vote up
public KinesisTestBinder(AmazonKinesisAsync amazonKinesis, AmazonDynamoDBAsync dynamoDbClient,
		KinesisBinderConfigurationProperties kinesisBinderConfigurationProperties) {

	this.applicationContext = new AnnotationConfigApplicationContext(Config.class);

	this.amazonKinesis = amazonKinesis;

	KinesisStreamProvisioner provisioningProvider = new KinesisStreamProvisioner(
			amazonKinesis, kinesisBinderConfigurationProperties);

	KinesisMessageChannelBinder binder = new TestKinesisMessageChannelBinder(
			amazonKinesis, dynamoDbClient, kinesisBinderConfigurationProperties,
			provisioningProvider);

	binder.setApplicationContext(this.applicationContext);

	setBinder(binder);
}
 
Example #21
Source File: DynamoDBReplicationEmitter.java    From dynamodb-cross-region-library with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor with given parameters and default CloudWatch client.
 * @param configuration
 *            The configuration for this emitter
 * @param dynamoDBAsync
 *            The DynamoDB client used for this application
 * @param cloudwatch
 *            The cloudwatch client used for this application
 */
public DynamoDBReplicationEmitter(final DynamoDBStreamsConnectorConfiguration configuration, final AmazonDynamoDBAsync dynamoDBAsync,
                                  final AmazonCloudWatchAsync cloudwatch) {
    this(configuration.APP_NAME, configuration.DYNAMODB_ENDPOINT, configuration.REGION_NAME, configuration.DYNAMODB_DATA_TABLE_NAME,
            dynamoDBAsync, cloudwatch);
}