本文整理汇总了Java中com.amazonaws.handlers.AsyncHandler类的典型用法代码示例。如果您正苦于以下问题:Java AsyncHandler类的具体用法?Java AsyncHandler怎么用?Java AsyncHandler使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AsyncHandler类属于com.amazonaws.handlers包,在下文中一共展示了AsyncHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMetricData
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
private void sendMetricData(List<MetricDatum> metricData) {
PutMetricDataRequest putMetricDataRequest = new PutMetricDataRequest()
.withNamespace(config.namespace())
.withMetricData(metricData);
amazonCloudWatchAsync.putMetricDataAsync(putMetricDataRequest, new AsyncHandler<PutMetricDataRequest, PutMetricDataResult>() {
@Override
public void onError(Exception exception) {
logger.error("Error sending metric data.", exception);
}
@Override
public void onSuccess(PutMetricDataRequest request, PutMetricDataResult result) {
logger.debug("Published metric with namespace:{}", request.getNamespace());
}
});
}
示例2: process
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
@Override
public void process(AmazonEC2Async amazonEC2Async, Instance instance) {
amazonEC2Async.stopInstancesAsync(
new StopInstancesRequest().withInstanceIds(instance.getInstanceId()),
new AsyncHandler<StopInstancesRequest, StopInstancesResult>() {
@Override
public void onError(Exception exception) {
log.warn("something went wrong stopping the server {}",
exception.getLocalizedMessage());
}
@Override
public void onSuccess(StopInstancesRequest request, StopInstancesResult result) {
onSuccessStop(instance);
}
});
}
示例3: process
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
@Override
public void process(Instance instance) {
if (instance.getKeyName().contains("swordfish-")) {
ec2KeyPair.delete(instance);
}
ec2UserClient.amazonEC2Async().terminateInstancesAsync(
new TerminateInstancesRequest().withInstanceIds(instance.getInstanceId()),
new AsyncHandler<TerminateInstancesRequest, TerminateInstancesResult>() {
@Override
public void onError(Exception exception) {
log.warn("something went wrong terminating the server {}",
exception.getLocalizedMessage());
}
@Override
public void onSuccess(TerminateInstancesRequest request, TerminateInstancesResult result) {
ec2UserClient.amazonEC2Async().waiters()
.instanceRunning()
.runAsync(ec2Waiter.describeInstancesRequestWaiterParameters(instance.getInstanceId()), ec2Waiter.describeInstancesRequestWaiterHandler());
}
});
instanceRepository.delete(instance);
}
示例4: process
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
@Override
public void process(Instance instance) {
ec2UserClient.amazonEC2Async().rebootInstancesAsync(
new RebootInstancesRequest().withInstanceIds(instance.getInstanceId()),
new AsyncHandler<RebootInstancesRequest, RebootInstancesResult>() {
@Override
public void onError(Exception exception) {
log.warn("something went wrong starting the server {}",
exception.getLocalizedMessage());
}
@Override
public void onSuccess(RebootInstancesRequest request,
RebootInstancesResult result) {
ec2UserClient.amazonEC2Async().waiters()
.instanceRunning()
.runAsync(ec2Waiter.describeInstancesRequestWaiterParameters(instance.getInstanceId()), ec2Waiter.describeInstancesRequestWaiterHandler());
}
});
}
示例5: process
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
@Override
public void process(Instance instance) {
ec2UserClient.amazonEC2Async().startInstancesAsync(
new StartInstancesRequest().withInstanceIds(instance.getInstanceId()),
new AsyncHandler<StartInstancesRequest, StartInstancesResult>() {
@Override
public void onError(Exception exception) {
log.warn("something went wrong starting the server {}",
exception.getLocalizedMessage());
}
@Override
public void onSuccess(StartInstancesRequest request, StartInstancesResult result) {
onSuccessStart(instance);
}
});
}
示例6: runSearch
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
private void runSearch(T type) {
AmazonWebServiceRequest descRequest = buildRequest(type);
AsyncHandler describeHandler = buildHandler(type);
if (type instanceof Instance) {
this.amazonEC2Client.describeInstancesAsync(
(DescribeInstancesRequest) descRequest, describeHandler);
} else if (type instanceof NatGateway) {
this.amazonEC2Client.describeNatGatewaysAsync(
(DescribeNatGatewaysRequest) descRequest, describeHandler);
} else if (type instanceof Volume) {
this.amazonEC2Client.describeVolumesAsync(
(DescribeVolumesRequest) descRequest, describeHandler);
} else {
AWSTaskStatusChecker.this.taskManager.patchTaskToFailure(
new IllegalArgumentException("Invalid type " + type));
}
}
示例7: getRemoteInstances
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
/**
* Get the instances from AWS filtered by the instances Ids known to the local system.
*/
public void getRemoteInstances(EnumerationDeletionContext aws,
AWSEnumerationDeletionSubStage next) {
if (aws.localInstanceIds == null || aws.localInstanceIds.size() == 0) {
logFine(() -> "No local records found. No states need to be fetched from the AWS"
+ " endpoint.");
aws.subStage = next;
deleteResourcesInLocalSystem(aws);
return;
}
DescribeInstancesRequest request = new DescribeInstancesRequest();
Filter runningInstanceFilter = getAWSNonTerminatedInstancesFilter();
request.getFilters().add(runningInstanceFilter);
// Get only the instances from the remote system for which a compute state exists in the
// local system.
logFine(() -> String.format("Fetching instance details for %d instances on the AWS"
+ " endpoint.", aws.localInstanceIds.keySet().size()));
request.getInstanceIds().addAll(new ArrayList<>(aws.localInstanceIds.keySet()));
AsyncHandler<DescribeInstancesRequest, DescribeInstancesResult> resultHandler =
new AWSEnumerationAsyncHandler(this, aws, next);
aws.amazonEC2Client.describeInstancesAsync(request,
resultHandler);
}
示例8: write
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
@Override
public void write(byte[] bytes) throws IOException {
if (bytes == null || bytes.length == 0) {
return;
}
final String msg = new String(bytes);
if (bytes.length > maxMessageSizeInKB * 1024) {
addWarn(format("Logging event '%s' exceeds the maximum size of %dkB",
msg, maxMessageSizeInKB));
return;
}
sqs.sendMessageAsync(new SendMessageRequest(queueUrl, msg),
new AsyncHandler<SendMessageRequest, SendMessageResult>() {
public void onError(Exception exception) {
addWarn(format("Appender '%s' failed to send logging event '%s' to '%s'", getName(), msg, queueUrl), exception);
}
public void onSuccess(SendMessageRequest request, SendMessageResult result) {
/** noop **/
}
});
}
示例9: sendBatch
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
protected void sendBatch(Map<String, Collection<MetricDatum>> datums) {
for (final Map.Entry<String, Collection<MetricDatum>> e : datums.entrySet()) {
for (final List<MetricDatum> batch : Lists.partition(Lists.newLinkedList(e.getValue()), BATCH_SIZE)) {
cloudWatch.putMetricDataAsync(new PutMetricDataRequest().withNamespace(e.getKey())
.withMetricData(batch),
new AsyncHandler<PutMetricDataRequest, Void>() {
@Override
public void onError(Exception exception) {
LOG.error("PutMetricData failed", exception);
LOG.info("Requeueing metric data.");
queuedDatums.putAll(e.getKey(), batch);
}
@Override
public void onSuccess(PutMetricDataRequest request, Void result) {
LOG.info("Successfully put " + request.getMetricData().size() +
" datums for namespace " + request.getNamespace());
LOG.debug("Request", request);
}
});
}
}
}
示例10: sendUsingAsyncClient
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
private void sendUsingAsyncClient(final PutRecordRequest putRecordRequest, Message<JsonObject> event) {
if (retryCounter == 3) {
sendError(event, "Failed sending message to Kinesis");
}
final Context ctx = vertx.currentContext();
kinesisAsyncClient.putRecordAsync(putRecordRequest, new AsyncHandler<PutRecordRequest,PutRecordResult>() {
public void onSuccess(PutRecordRequest request, final PutRecordResult recordResult) {
ctx.runOnContext(v -> {
logger.debug("Sent message to Kinesis: " + recordResult.toString());
sendOK(event);
});
}
public void onError(final java.lang.Exception iexc) {
ctx.runOnContext(v -> {
retryCounter++;
kinesisAsyncClient = createClient();
logger.info("Failed sending message to Kinesis, retry: " + retryCounter + " ... ", iexc);
vertx.setTimer(500, timerID -> sendUsingAsyncClient(putRecordRequest, event));
});
}
});
}
示例11: process
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
@Override
public void process(Instance instance) {
String keyName = ec2KeyPair.setName(instance);
instance.setId(createUniqueId(keyName));
instance.setUserId(authenticationService.getCurrentUser().getId());
instance.setKeyName(keyName);
instance.setKeyBlob(ec2KeyPair.create(instance));
RunInstancesRequest runInstancesRequest = new RunInstancesRequest()
.withInstanceType(instance.getInstanceType())
.withImageId(instance.getImageId())
.withMinCount(1)
.withMaxCount(1)
.withSecurityGroupIds(instance.getSecurityGroupId())
.withKeyName(keyName)
.withSubnetId(instance.getSubnetId())
.withTagSpecifications(buildTags(instance));
instanceRepository.save(instance);
refreshClient(instance);
ec2UserClient.amazonEC2Async().runInstancesAsync(runInstancesRequest,
new AsyncHandler<RunInstancesRequest, RunInstancesResult>() {
@Override
public void onError(Exception exception) {
log.warn("something went wrong creating the server {}",
exception.getLocalizedMessage());
}
@Override
public void onSuccess(RunInstancesRequest request, RunInstancesResult result) {
onSuccessCreate(result, instance);
}
});
}
示例12: validateAWSCredentials
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
private void validateAWSCredentials(final AWSInstanceContext aws) {
if (aws.computeRequest.isMockRequest || AWSUtils.isAwsClientMock()) {
aws.operation.complete();
return;
}
// make a call to validate credentials
aws.amazonEC2Client
.describeAvailabilityZonesAsync(
new DescribeAvailabilityZonesRequest(),
new AsyncHandler<DescribeAvailabilityZonesRequest, DescribeAvailabilityZonesResult>() {
@Override
public void onError(Exception e) {
if (e instanceof AmazonServiceException) {
AmazonServiceException ase = (AmazonServiceException) e;
if (ase.getStatusCode() == STATUS_CODE_UNAUTHORIZED) {
ServiceErrorResponse r = Utils.toServiceErrorResponse(e);
r.statusCode = STATUS_CODE_UNAUTHORIZED;
aws.operation.fail(e, r);
return;
}
}
aws.operation.fail(e);
}
@Override
public void onSuccess(DescribeAvailabilityZonesRequest request,
DescribeAvailabilityZonesResult describeAvailabilityZonesResult) {
aws.operation.complete();
}
});
}
示例13: validateCredentials
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
public static void validateCredentials(AmazonEC2AsyncClient ec2Client,
AWSClientManager clientManager, AuthCredentialsServiceState credentials,
ComputeEnumerateAdapterRequest context, Operation op, StatelessService service,
Consumer<DescribeAvailabilityZonesResult> onSuccess, Consumer<Throwable> onFail) {
if (clientManager.isEc2ClientInvalid(credentials, context.regionId)) {
op.complete();
return;
}
ec2Client.describeAvailabilityZonesAsync(new DescribeAvailabilityZonesRequest(),
new AsyncHandler<DescribeAvailabilityZonesRequest, DescribeAvailabilityZonesResult>() {
@Override
public void onError(Exception e) {
if (e instanceof AmazonServiceException) {
AmazonServiceException ase = (AmazonServiceException) e;
if (ase.getStatusCode() == STATUS_CODE_UNAUTHORIZED) {
clientManager.markEc2ClientInvalid(service, credentials,
context.regionId);
op.complete();
return;
}
onFail.accept(e);
}
}
@Override
public void onSuccess(DescribeAvailabilityZonesRequest request,
DescribeAvailabilityZonesResult describeAvailabilityZonesResult) {
onSuccess.accept(describeAvailabilityZonesResult);
}
});
}
示例14: getOrCreateCloudWatchClient
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
/**
* Get or create a CloudWatch Client instance that will be used to get stats from AWS.
* @param credentials
* The auth credentials to be used for the client creation
* @param regionId
* The region of the AWS client
* @param service
* The stateless service for which the operation is being performed.
* @param isMock
* Indicates if this a mock request
* @return
*/
public AmazonCloudWatchAsyncClient getOrCreateCloudWatchClient(
AuthCredentialsServiceState credentials,
String regionId, StatelessService service, boolean isMock,
Consumer<Throwable> failConsumer) {
if (this.awsClientType != AwsClientType.CLOUD_WATCH) {
throw new UnsupportedOperationException(
"This client manager supports only AWS " + this.awsClientType + " clients.");
}
String cacheKey = createCredentialRegionCacheKey(credentials, regionId);
if (isCloudWatchClientInvalid(cacheKey)) {
failConsumer.accept(
new IllegalStateException("Invalid cloud watch client for key: " + cacheKey));
return null;
}
AmazonCloudWatchAsyncClient amazonCloudWatchClient = null;
try {
amazonCloudWatchClient = this.cloudWatchClientCache.computeIfAbsent(cacheKey, key -> {
AmazonCloudWatchAsyncClient client = AWSUtils.getStatsAsyncClient
(credentials, regionId, getExecutor(), isMock);
client.describeAlarmsAsync(
new AsyncHandler<DescribeAlarmsRequest, DescribeAlarmsResult>() {
@Override
public void onError(Exception exception) {
markCloudWatchClientInvalid(service, cacheKey);
}
@Override
public void onSuccess(DescribeAlarmsRequest request,
DescribeAlarmsResult result) {
//noop
}
});
return client;
});
} catch (Throwable e) {
service.logSevere(e);
failConsumer.accept(e);
}
return amazonCloudWatchClient;
}
示例15: createAWSRequestAndAsyncHandler
import com.amazonaws.handlers.AsyncHandler; //导入依赖的package包/类
/**
* Initializes and saves a reference to the request object that is sent to AWS to get a page of
* volumes. Also saves an instance to the async handler that will be used to handle the
* responses received from AWS. It sets the nextToken value in the request object sent to AWS
* for getting the next page of results from AWS.
*/
private void createAWSRequestAndAsyncHandler(EBSStorageEnumerationContext aws) {
DescribeVolumesRequest request = new DescribeVolumesRequest();
request.setMaxResults(getQueryPageSize());
request.setNextToken(aws.nextToken);
aws.describeVolumesRequest = request;
AsyncHandler<DescribeVolumesRequest, DescribeVolumesResult> resultHandler = new AWSStorageEnumerationAsyncHandler(
this, aws);
aws.resultHandler = resultHandler;
}