+ private void resolveSchemaContext(final SchemaContextFactory schemaContextFactory,
+ final SlaveSalFacade localSlaveSalManager, final ActorRef masterReference, final int tries) {
+ final ListenableFuture<SchemaContext> schemaContextFuture =
+ schemaContextFactory.createSchemaContext(sourceIdentifiers);
+ Futures.addCallback(schemaContextFuture, new FutureCallback<SchemaContext>() {
+ @Override
+ public void onSuccess(@Nonnull final SchemaContext result) {
+ executeInSelf(() -> {
+ // Make sure the slaveSalManager instance hasn't changed since we initiated the schema context
+ // resolution.
+ if (slaveSalManager == localSlaveSalManager) {
+ LOG.info("{}: Schema context resolved: {} - registering slave mount point",
+ id, result.getModules());
+ slaveSalManager.registerSlaveMountPoint(result, getDOMRpcService(masterReference),
+ masterReference);
+ }
+ });
+ }
+
+ @Override
+ public void onFailure(@Nonnull final Throwable throwable) {
+ executeInSelf(() -> {
+ if (slaveSalManager == localSlaveSalManager) {
+ final Throwable cause = Throwables.getRootCause(throwable);
+ if (cause instanceof AskTimeoutException) {
+ if (tries <= 5 || tries % 10 == 0) {
+ LOG.warn("{}: Failed to resolve schema context - retrying...", id, throwable);
+ }
+
+ resolveSchemaContext(schemaContextFactory, localSlaveSalManager,
+ masterReference, tries + 1);
+ } else {
+ LOG.error("{}: Failed to resolve schema context - unable to register slave mount point",
+ id, throwable);
+ closeSchemaSourceRegistrations();
+ }
+ }
+ });
+ }
+ }, MoreExecutors.directExecutor());