Search in sources :

Example 1 with Startable

use of org.webpieces.router.api.extensions.Startable in project webpieces by deanhiller.

the class AbstractRouterService method runStartupHooks.

protected void runStartupHooks(Injector injector) {
    log.info("Running startup hooks for server");
    Key<Set<Startable>> key = Key.get(new TypeLiteral<Set<Startable>>() {
    });
    Set<Startable> startupHooks = injector.getInstance(key);
    for (Startable s : startupHooks) {
        runStartupHook(s);
    }
    log.info("Ran all startup hooks");
}
Also used : Startable(org.webpieces.router.api.extensions.Startable) Set(java.util.Set)

Example 2 with Startable

use of org.webpieces.router.api.extensions.Startable in project webpieces by deanhiller.

the class PropertiesModule method configure.

@Override
public void configure(Binder binder) {
    Multibinder<BackendGuiDescriptor> backendBinder = Multibinder.newSetBinder(binder, BackendGuiDescriptor.class);
    backendBinder.addBinding().to(PropertiesGuiDescriptor.class);
    binder.bind(PropertiesConfig.class).toInstance(config);
    Multibinder<Startable> startableBinder = Multibinder.newSetBinder(binder, Startable.class);
    // Unfortunately, DURING guice heirarchy construction, we need to record into BeanMetaData
    // later, after Guice construction is complete and the Startable.class implementations are being
    // called, BeanMetaData can officially use the ObjectTranslator at that point to know if it
    // can install methods or not into the GUI
    // 
    // This is a bit complex but
    // 1. while guice is creating things, it records in BeanMetaData(which is not injected into anything except the guice listeners at this point)
    // 2. guice is done creating the full tree, webpieces invokes all Startable.class including BeanMetaData
    // 3. BeanMetaData's start() method now loads all methods and such
    // 4. BeanMetaData now loads all properties from DB and applies them from the DB if they exist
    // 5. BeanMetaData now kicks off a recurring task to load DB properties (in case props are edited on another server)
    Provider<ObjectTranslator> translatorProvider = binder.getProvider(ObjectTranslator.class);
    Provider<SimpleStorage> storageProvider = binder.getProvider(SimpleStorage.class);
    Provider<ManagedBeanMeta> webpiecesBeanProvider = binder.getProvider(ManagedBeanMeta.class);
    Provider<ScheduledExecutorService> schedulerProvider = binder.getProvider(ScheduledExecutorService.class);
    BeanMetaData proxy = new BeanMetaData(config, translatorProvider, storageProvider, webpiecesBeanProvider, schedulerProvider);
    // this binding is for the controller....
    binder.bind(BeanMetaData.class).toInstance(proxy);
    // this binding is to plugin to webpieces so the start() method is called
    startableBinder.addBinding().toInstance(proxy);
    binder.bindListener(Matchers.any(), new GuiceTypeListener(proxy, config));
}
Also used : BackendGuiDescriptor(org.webpieces.plugin.backend.spi.BackendGuiDescriptor) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) BeanMetaData(org.webpieces.plugin.secure.properties.beans.BeanMetaData) ManagedBeanMeta(org.webpieces.router.impl.mgmt.ManagedBeanMeta) Startable(org.webpieces.router.api.extensions.Startable) ObjectTranslator(org.webpieces.router.impl.params.ObjectTranslator) GuiceTypeListener(org.webpieces.plugin.secure.properties.beans.GuiceTypeListener) SimpleStorage(org.webpieces.router.api.extensions.SimpleStorage)

Example 3 with Startable

use of org.webpieces.router.api.extensions.Startable in project webpieces by deanhiller.

the class GuiceModule method configure.

// This is where you would put the guice bindings you need though generally if done
// right, you won't have much in this file.
// If you need more Guice Modules as you want to scale, just modify ServerMeta which returns
// the list of all the Guice Modules in your application
@SuppressWarnings("rawtypes")
@Override
public void configure(Binder binder) {
    log.info("running module");
    // all modules have access to adding their own Startable objects to be run on server startup
    Multibinder<Startable> uriBinder = Multibinder.newSetBinder(binder, Startable.class);
    uriBinder.addBinding().to(PopulateDatabase.class);
    Multibinder<ObjectStringConverter> conversionBinder = Multibinder.newSetBinder(binder, ObjectStringConverter.class);
    conversionBinder.addBinding().to(EducationEnum.WebConverter.class);
    conversionBinder.addBinding().to(RoleEnum.WebConverter.class);
    Multibinder<HtmlTagCreator> htmlTagCreators = Multibinder.newSetBinder(binder, HtmlTagCreator.class);
    htmlTagCreators.addBinding().to(MyHtmlTagCreator.class);
    binder.bind(SomeLibrary.class).to(SomeLibraryImpl.class);
    // Must bind a SimpleStorage for plugins to read/save data and render their html pages
    binder.bind(SimpleStorage.class).to(SimpleStorageImpl.class).asEagerSingleton();
    // Must bind a BackendLogin for the backend plugin(or remove the backend plugin)
    binder.bind(BackendLogin.class).to(BackendLoginImpl.class).asEagerSingleton();
    // since GlobalAppContext is a singleton, ApplicationContext will be to and will be the same
    binder.bind(ApplicationContext.class).to(GlobalAppContext.class).asEagerSingleton();
    binder.bind(HttpsConfig.class).toInstance(new HttpsConfig(true));
    binder.bind(ClientAssertions.class).to(ClientAssertionsImpl.class).asEagerSingleton();
}
Also used : SimpleStorageImpl(webpiecesxxxxxpackage.service.SimpleStorageImpl) BackendLoginImpl(webpiecesxxxxxpackage.web.login.BackendLoginImpl) Startable(org.webpieces.router.api.extensions.Startable) EducationEnum(webpiecesxxxxxpackage.db.EducationEnum) RoleEnum(webpiecesxxxxxpackage.db.RoleEnum) HtmlTagCreator(org.webpieces.ctx.api.extension.HtmlTagCreator) MyHtmlTagCreator(webpiecesxxxxxpackage.web.tags.MyHtmlTagCreator) HttpsConfig(org.webpieces.microsvc.client.api.HttpsConfig) ObjectStringConverter(org.webpieces.router.api.extensions.ObjectStringConverter) SomeLibrary(webpiecesxxxxxpackage.service.SomeLibrary)

Aggregations

Startable (org.webpieces.router.api.extensions.Startable)3 Set (java.util.Set)1 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)1 HtmlTagCreator (org.webpieces.ctx.api.extension.HtmlTagCreator)1 HttpsConfig (org.webpieces.microsvc.client.api.HttpsConfig)1 BackendGuiDescriptor (org.webpieces.plugin.backend.spi.BackendGuiDescriptor)1 BeanMetaData (org.webpieces.plugin.secure.properties.beans.BeanMetaData)1 GuiceTypeListener (org.webpieces.plugin.secure.properties.beans.GuiceTypeListener)1 ObjectStringConverter (org.webpieces.router.api.extensions.ObjectStringConverter)1 SimpleStorage (org.webpieces.router.api.extensions.SimpleStorage)1 ManagedBeanMeta (org.webpieces.router.impl.mgmt.ManagedBeanMeta)1 ObjectTranslator (org.webpieces.router.impl.params.ObjectTranslator)1 EducationEnum (webpiecesxxxxxpackage.db.EducationEnum)1 RoleEnum (webpiecesxxxxxpackage.db.RoleEnum)1 SimpleStorageImpl (webpiecesxxxxxpackage.service.SimpleStorageImpl)1 SomeLibrary (webpiecesxxxxxpackage.service.SomeLibrary)1 BackendLoginImpl (webpiecesxxxxxpackage.web.login.BackendLoginImpl)1 MyHtmlTagCreator (webpiecesxxxxxpackage.web.tags.MyHtmlTagCreator)1