List of usage examples for com.amazonaws.services.sns AmazonSNS shutdown
void shutdown();
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public String createTopic(INotificationEndpoint notificationEndpoint) { Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null"); Preconditions.checkArgument((notificationEndpoint.getTopicArn() == null), "Notification already has a notification URL defined"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1);/*from w ww .jav a2 s .c o m*/ String topicArn = null; try { String topicName = stripUrnUuidPrefix(notificationEndpoint.getAccount()); LOG.info("Topic Name Assigned: " + topicName); CreateTopicRequest request = new CreateTopicRequest(topicName); CreateTopicResult result = sns.createTopic(request); topicArn = result.getTopicArn(); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), result.getTopicArn()); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationEnroll, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } return topicArn; }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public String subscribe(INotificationEndpoint notificationEndpoint) { String subscriptionArn;//from w ww.ja va 2 s . co m Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null"); Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null), "Notification Topic ARN must not be null"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1); try { SubscribeRequest request = new SubscribeRequest(notificationEndpoint.getTopicArn(), "https", notificationEndpoint.getNotificationEndpointUrl()); SubscribeResult result = sns.subscribe(request); subscriptionArn = result.getSubscriptionArn(); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), result.getSubscriptionArn()); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationSubscribe, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } return subscriptionArn; }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public void deleteTopic(INotificationEndpoint notificationEndpoint) { Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null"); Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null), "Notification Topic ARN must not be null"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1);/* ww w. j av a2 s . c o m*/ try { DeleteTopicRequest request = new DeleteTopicRequest(notificationEndpoint.getTopicArn()); sns.deleteTopic(request); } finally { sns.shutdown(); } // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), ""); IEventService eventService = context.getServiceFactory().getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationWithdrawn, notificationEndpoint.getAccount(), null, nro); }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public void publish(INotificationEndpoint notificationEndpoint, String json) { Preconditions.checkArgument((notificationEndpoint != null), "Endpoint must not be null"); Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null), "Endpoint is missing a notification URL definition"); Preconditions.checkArgument((!notificationEndpoint.isPendingConfirmation()), "Endpoint has not yet been confirmed"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1);/*from w w w. java 2s . c o m*/ try { String subject = "SMART COSMOS Objects Event Notification"; JSONObject jsonObject = null; try { jsonObject = new JSONObject(json); if (jsonObject.has(EVENT_TYPE)) { String eventType = jsonObject.getString(EVENT_TYPE); subject = "Objects Event: " + eventType; } } catch (JSONException e) { e.printStackTrace(); } PublishRequest request = new PublishRequest(notificationEndpoint.getTopicArn(), json, subject); PublishResult result = sns.publish(request); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), result.getMessageId()); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationBroadcast, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public void unsubscribe(INotificationEndpoint notificationEndpoint) { Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1);// ww w . j a va2 s. com try { UnsubscribeRequest request = new UnsubscribeRequest(notificationEndpoint.getSubscriptionArn()); sns.unsubscribe(request); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), ""); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationUnsubscribe, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } }
From source file:net.smartcosmos.plugin.service.aws.notification.AwsNotificationService.java
License:Apache License
@Override public void confirmSubscription(INotificationEndpoint notificationEndpoint, String token) { Preconditions.checkArgument((notificationEndpoint != null), "Notification endpoint must not be null"); Preconditions.checkArgument((notificationEndpoint.getTopicArn() != null), "Notification Topic ARN must not be null"); AmazonSNS sns = new AmazonSNSClient(credentials); Region usEast1 = Region.getRegion(Regions.US_EAST_1); sns.setRegion(usEast1);// w w w.j a va 2s .co m try { ConfirmSubscriptionRequest request = new ConfirmSubscriptionRequest(notificationEndpoint.getTopicArn(), token); ConfirmSubscriptionResult result = sns.confirmSubscription(request); // // Event // INotificationResultObject<IAccount> nro = new NotificationResultObject<>(EntityReferenceType.Account, notificationEndpoint.getAccount(), result.getSubscriptionArn()); IEventService eventService = context.getServiceFactory() .getEventService(notificationEndpoint.getAccount()); eventService.recordEvent(EventType.NotificationSubscriptionConfirmed, notificationEndpoint.getAccount(), null, nro); } finally { sns.shutdown(); } }