001/*
002 * Copyright 2019-2021 M. Sean Gilligan.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package app.supernaut;
017
018/**
019 * A background application that is started before the foreground app
020 * and can communicate with the foreground app. The background application
021 * is started before the UI toolkit is initialized and can make its first
022 * network requests simultaneously with loading the UI toolkit and
023 * the foreground UI application.
024 *
025 * In the JavaFX implementation this is an alternative to the PreLoader,
026 * which was essentially designed for applications that start synchronously. In
027 * an asynchronous/reactive JavaFX application the primaryStage should
028 * be displayed immediately and updated with data as data becomes available.
029 * The important thing is that network requests be sent as soon as possible
030 * after {@code main} is called.
031 *
032 */
033public interface BackgroundApp {
034    /**
035     * Override to do any (hopefully minimal and quick) initialization
036     * that you want to happen before the ForegroundApp is started
037     */
038    default void init() {};
039
040    /**
041     * Override this to create your own background threads and do any
042     * longer-duration initialization or start network I/O, etc.
043     */
044    void start();
045
046    /**
047     * Override to get called when the application is stopping.
048     */
049    default void stop() {}
050}