Search in sources :

Example 1 with ClientInitializationException

use of com.canoo.platform.remoting.client.ClientInitializationException in project dolphin-platform by canoo.

the class ClientContextImpl method connect.

@Override
public CompletableFuture<Void> connect() {
    final CompletableFuture<Void> result = new CompletableFuture<>();
    clientConnector.connect();
    clientConfiguration.getBackgroundExecutor().execute(() -> {
        dolphinCommandHandler.invokeDolphinCommand(new CreateContextCommand()).handle((Void aVoid, Throwable throwable) -> {
            if (throwable != null) {
                result.completeExceptionally(new ClientInitializationException("Can't call init action!", throwable));
            } else {
            }
            result.complete(null);
            return null;
        });
    });
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) CreateContextCommand(com.canoo.dp.impl.remoting.commands.CreateContextCommand)

Example 2 with ClientInitializationException

use of com.canoo.platform.remoting.client.ClientInitializationException in project dolphin-platform by canoo.

the class DolphinPlatformApplication method reconnect.

protected final CompletableFuture<Void> reconnect(final Stage primaryStage) {
    Assert.requireNonNull(primaryStage, "primaryStage");
    final CompletableFuture<Void> result = new CompletableFuture<>();
    PlatformClient.getClientConfiguration().getBackgroundExecutor().execute(() -> {
        try {
            disconnect().get(1_000, TimeUnit.MILLISECONDS);
        } catch (Exception e) {
            LOG.warn("Can not disconnect. Trying to reconnect anyway.");
        }
        try {
            if (clientContext == null) {
                clientContext = createClientContext();
            }
            Assert.requireNonNull(clientContext, "clientContext");
            connectInProgress.set(true);
            clientContext.connect().get(3_000, TimeUnit.MILLISECONDS);
            Platform.runLater(() -> {
                try {
                    start(primaryStage, clientContext);
                } catch (Exception e) {
                    handleInitializationError(primaryStage, new ClientInitializationException("Error in application reconnect", e));
                }
            });
        } catch (Exception e) {
            Platform.runLater(() -> handleInitializationError(primaryStage, new ClientInitializationException("Error in application reconnect", e)));
        } finally {
            connectInProgress.set(false);
        }
        result.complete(null);
    });
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) MalformedURLException(java.net.MalformedURLException) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException)

Example 3 with ClientInitializationException

use of com.canoo.platform.remoting.client.ClientInitializationException in project dolphin-platform by canoo.

the class DolphinPlatformApplication method start.

/**
 * This methods defines parts of the Dolphin Platform lifecyycle and is therefore defined as final.
 * Use the {@link DolphinPlatformApplication#start(Stage, ClientContext)} method instead.
 *
 * @param primaryStage the primary stage
 * @throws Exception in case of an error
 */
@Override
public final void start(final Stage primaryStage) throws Exception {
    Assert.requireNonNull(primaryStage, "primaryStage");
    this.primaryStage = primaryStage;
    if (initializationException == null) {
        if (clientContext != null) {
            try {
                start(primaryStage, clientContext);
            } catch (Exception e) {
                handleInitializationError(primaryStage, new ClientInitializationException("Error in application start!", e));
            }
        } else {
            handleInitializationError(primaryStage, new ClientInitializationException("No clientContext was created!"));
        }
    } else {
        handleInitializationError(primaryStage, initializationException);
    }
}
Also used : ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) MalformedURLException(java.net.MalformedURLException) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException)

Example 4 with ClientInitializationException

use of com.canoo.platform.remoting.client.ClientInitializationException in project dolphin-platform by canoo.

the class ClientContextFactoryImpl method create.

/**
 * Create a {@link ClientContext} based on the given configuration. This method doesn't block and returns a
 * {@link CompletableFuture} to receive its result. If the {@link ClientContext} can't be created the
 * {@link CompletableFuture#get()} will throw a {@link ClientInitializationException}.
 *
 * @param clientConfiguration the configuration
 * @return the future
 */
public ClientContext create(final ClientConfiguration clientConfiguration, final URI endpoint) {
    Assert.requireNonNull(clientConfiguration, "clientConfiguration");
    final HttpClient httpClient = PlatformClient.getService(HttpClient.class);
    final HttpURLConnectionHandler clientSessionCheckResponseHandler = new StrictClientSessionResponseHandler(endpoint);
    httpClient.addResponseHandler(clientSessionCheckResponseHandler);
    final Function<ClientModelStore, AbstractClientConnector> connectionProvider = s -> {
        return new DolphinPlatformHttpClientConnector(endpoint, clientConfiguration, s, OptimizedJsonCodec.getInstance(), e -> {
        }, httpClient);
    };
    return new ClientContextImpl(clientConfiguration, endpoint, connectionProvider, PlatformClient.getService(ClientSessionStore.class));
}
Also used : ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) Assert(com.canoo.dp.impl.platform.core.Assert) ClientContextFactory(com.canoo.platform.remoting.client.ClientContextFactory) HttpClient(com.canoo.platform.core.http.HttpClient) AbstractClientConnector(com.canoo.dp.impl.client.legacy.communication.AbstractClientConnector) CompletableFuture(java.util.concurrent.CompletableFuture) API(org.apiguardian.api.API) ClientContext(com.canoo.platform.remoting.client.ClientContext) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) Function(java.util.function.Function) INTERNAL(org.apiguardian.api.API.Status.INTERNAL) PlatformClient(com.canoo.platform.client.PlatformClient) HttpURLConnectionHandler(com.canoo.platform.core.http.HttpURLConnectionHandler) StrictClientSessionResponseHandler(com.canoo.dp.impl.platform.client.session.StrictClientSessionResponseHandler) URI(java.net.URI) ClientSessionStore(com.canoo.platform.client.session.ClientSessionStore) OptimizedJsonCodec(com.canoo.dp.impl.remoting.codec.OptimizedJsonCodec) ClientConfiguration(com.canoo.platform.client.ClientConfiguration) StrictClientSessionResponseHandler(com.canoo.dp.impl.platform.client.session.StrictClientSessionResponseHandler) ClientSessionStore(com.canoo.platform.client.session.ClientSessionStore) HttpClient(com.canoo.platform.core.http.HttpClient) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) HttpURLConnectionHandler(com.canoo.platform.core.http.HttpURLConnectionHandler) AbstractClientConnector(com.canoo.dp.impl.client.legacy.communication.AbstractClientConnector)

Example 5 with ClientInitializationException

use of com.canoo.platform.remoting.client.ClientInitializationException in project dolphin-platform by canoo.

the class DolphinPlatformApplication method init.

/**
 * Creates the connection to the Dolphin Platform server. If this method will be overridden always call the super method.
 *
 * @throws Exception a exception if the connection can't be created
 */
@Override
public final void init() throws Exception {
    FxToolkit.init();
    applicationInit();
    PlatformClient.getClientConfiguration().setUncaughtExceptionHandler((Thread thread, Throwable exception) -> {
        PlatformClient.getClientConfiguration().getUiExecutor().execute(() -> {
            Assert.requireNonNull(thread, "thread");
            Assert.requireNonNull(exception, "exception");
            if (connectInProgress.get()) {
                runtimeExceptionsAtInitialization.add(new DolphinRuntimeException(thread, "Unhandled error in Dolphin Platform background thread", exception));
            } else {
                onRuntimeError(primaryStage, new DolphinRuntimeException(thread, "Unhandled error in Dolphin Platform background thread", exception));
            }
        });
    });
    try {
        clientContext = createClientContext();
        Assert.requireNonNull(clientContext, "clientContext");
        connectInProgress.set(true);
        clientContext.connect().get(30_000, TimeUnit.MILLISECONDS);
    } catch (ClientInitializationException e) {
        initializationException = e;
    } catch (Exception e) {
        initializationException = new ClientInitializationException("Can not initialize Dolphin Platform Context", e);
    } finally {
        connectInProgress.set(false);
    }
}
Also used : DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) MalformedURLException(java.net.MalformedURLException) ClientInitializationException(com.canoo.platform.remoting.client.ClientInitializationException) DolphinRuntimeException(com.canoo.platform.core.DolphinRuntimeException)

Aggregations

ClientInitializationException (com.canoo.platform.remoting.client.ClientInitializationException)5 DolphinRuntimeException (com.canoo.platform.core.DolphinRuntimeException)3 MalformedURLException (java.net.MalformedURLException)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)1 AbstractClientConnector (com.canoo.dp.impl.client.legacy.communication.AbstractClientConnector)1 StrictClientSessionResponseHandler (com.canoo.dp.impl.platform.client.session.StrictClientSessionResponseHandler)1 Assert (com.canoo.dp.impl.platform.core.Assert)1 OptimizedJsonCodec (com.canoo.dp.impl.remoting.codec.OptimizedJsonCodec)1 CreateContextCommand (com.canoo.dp.impl.remoting.commands.CreateContextCommand)1 ClientConfiguration (com.canoo.platform.client.ClientConfiguration)1 PlatformClient (com.canoo.platform.client.PlatformClient)1 ClientSessionStore (com.canoo.platform.client.session.ClientSessionStore)1 HttpClient (com.canoo.platform.core.http.HttpClient)1 HttpURLConnectionHandler (com.canoo.platform.core.http.HttpURLConnectionHandler)1 ClientContext (com.canoo.platform.remoting.client.ClientContext)1 ClientContextFactory (com.canoo.platform.remoting.client.ClientContextFactory)1 URI (java.net.URI)1 Function (java.util.function.Function)1 API (org.apiguardian.api.API)1