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;
}
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;
}
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);
}
}
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));
}
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);
}
}
Aggregations