Skip to content

Commit

Permalink
[aws-analytics-pinpoint] Minor formatting and style tweaks (aws-ampli…
Browse files Browse the repository at this point in the history
…fy#477)

Some basic formatting and style tweaks
  • Loading branch information
jamesonwilliams authored May 17, 2020
1 parent 275ae3c commit e3c634b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,10 @@
* Validates the functionality of the {@link AmazonPinpointAnalyticsPlugin}.
*/
public class AnalyticsPinpointInstrumentedTest {

/**
* Log tag for the test class.
*/
private static final Logger LOG = Amplify.Logging.forNamespace("amplify:aws-analytics");
private static final int EVENT_FLUSH_TIMEOUT = 60;
private static final int EVENT_FLUSH_WAIT = 2;

private static final int EVENT_FLUSH_TIMEOUT = 60 /* seconds */;
private static final int EVENT_FLUSH_WAIT = 2 /* seconds */;

private static AnalyticsClient analyticsClient;
private static TargetingClient targetingClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,42 +39,38 @@
* Factory class to vend out pinpoint analytics client.
*/
final class PinpointManagerFactory {

private static final Logger LOG = Amplify.Logging.forNamespace("amplify:aws-analytics");
private static final int INITIALIZATION_TIMEOUT_MS = 5000;
private static final long INITIALIZATION_TIMEOUT_MS = TimeUnit.SECONDS.toMillis(5);

private PinpointManagerFactory() {
}
private PinpointManagerFactory() {}

static PinpointManager create(Context context,
AmazonPinpointAnalyticsPluginConfiguration pinpointAnalyticsPluginConfiguration)
static PinpointManager create(
Context context,
AmazonPinpointAnalyticsPluginConfiguration pinpointAnalyticsPluginConfiguration)
throws AnalyticsException {
final PinpointManager pinpointManager;
final AWSConfiguration awsConfiguration = new AWSConfiguration(context);

CountDownLatch mobileClientLatch = new CountDownLatch(1);
// Initialize the AWSMobileClient
AWSMobileClient.getInstance().initialize(context, awsConfiguration,
new Callback<UserStateDetails>() {
@Override
public void onResult(UserStateDetails userStateDetails) {
LOG.info("Mobile client initialized");
mobileClientLatch.countDown();
}

@Override
public void onError(Exception exception) {
LOG.error("Error initializing AWS Mobile Client", exception);
}
});
AWSConfiguration awsConfiguration = new AWSConfiguration(context);
CountDownLatch mobileClientLatch = new CountDownLatch(1);
AWSMobileClient.getInstance().initialize(context, awsConfiguration, new Callback<UserStateDetails>() {
@Override
public void onResult(UserStateDetails userStateDetails) {
LOG.info("Mobile client initialized");
mobileClientLatch.countDown();
}

@Override
public void onError(Exception exception) {
LOG.error("Error initializing AWS Mobile Client", exception);
}
});
try {
if (!mobileClientLatch.await(INITIALIZATION_TIMEOUT_MS, TimeUnit.MILLISECONDS)) {
throw new AnalyticsException("Failed to initialize mobile client.",
"Please check your awsconfiguration json.");
throw new AnalyticsException(
"Failed to initialize mobile client.", "Please check your awsconfiguration json."
);
}
} catch (InterruptedException exception) {
throw new RuntimeException("Failed to initialize mobile client: " + exception.getLocalizedMessage());
throw new RuntimeException("Failed to initialize mobile client." + exception);
}

ClientConfiguration clientConfiguration = new ClientConfiguration();
Expand All @@ -89,7 +85,6 @@ public void onError(Exception exception) {
AWSMobileClient.getInstance()
).withClientConfiguration(clientConfiguration);

pinpointManager = new PinpointManager(pinpointConfiguration);
return pinpointManager;
return new PinpointManager(pinpointConfiguration);
}
}

0 comments on commit e3c634b

Please sign in to comment.