本文整理了Java中org.jooby.Env.onStart()
方法的一些代码示例,展示了Env.onStart()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Env.onStart()
方法的具体详情如下:
包路径:org.jooby.Env
类名称:Env
方法名:onStart
暂无
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
String name = conf.getString("application.name");
Logger log = LoggerFactory.getLogger(name);
String v = conf.getString("application.version");
String text = this.text.orElse(name);
Provider<String> ascii = () -> Try
.apply(() -> CharMatcher.whitespace()
.trimTrailingFrom(convertOneLine(String.format(FONT, font), text)))
.orElse(text);
binder.bind(Key.get(String.class, Names.named("application.banner"))).toProvider(ascii);
env.onStart(() -> {
log.info("\n{} v{}\n", ascii.get(), v);
});
}
代码示例来源:origin: jooby-project/jooby
@Override public void configure(final Env env, final Config conf, final Binder binder)
throws Throwable {
Path userdir = Paths.get(System.getProperty("user.dir"));
Path workDirectory = Optional.ofNullable(this.workDirectory)
.orElse(userdir);
Path installDirectory = Optional.ofNullable(this.installDirectory).orElse(workDirectory);
ProxyConfig proxy = new ProxyConfig(proxies(conf));
CacheResolver cache = Files.exists(userdir.resolve("pom.xml"))
? new MavenCacheResolver()
: null;
FrontendPluginFactory factory = new FrontendPluginFactory(workDirectory.toFile(),
installDirectory.toFile(), cache);
installNode(conf, nodeVersion, proxy, factory);
Map<String, String> environment = environment(conf);
NodeTask task = newTask(factory, conf, proxy, environment, nodeVersion);
onSyncPackageJson(conf, workDirectory, task::executeSync);
if (onStart == null && onStarted == null) {
onStart = cmd -> cmd.execute("run", "build");
}
if (onStart != null) {
env.onStart(() -> onStart.accept(task));
}
if (onStarted != null) {
env.onStarted(() -> onStarted.accept(task));
}
}
代码示例来源:origin: jooby-project/jooby
@Override public void configure(Env env, Config conf, Binder binder) {
EventBus eventbus = factory.apply(conf);
binder.bind(EventBus.class).toInstance(eventbus);
List<Object> subscribers = new ArrayList<>(initialSubscribers.size());
/** Register subscribers: */
env.onStart(registry -> {
initialSubscribers.forEach(candidate -> {
Object subscriber = candidate;
if (subscriber instanceof Class) {
subscriber = registry.require((Class) subscriber);
}
subscribers.add(subscriber);
eventbus.register(subscriber);
}
);
// free initial subscribers
initialSubscribers.clear();
});
/** Unregister subscribers: */
env.onStop(() -> subscribers.forEach(eventbus::unregister));
}
}
代码示例来源:origin: jooby-project/jooby
@SuppressWarnings({"unchecked", "rawtypes"})
private static void guavaServices(final Env env, final Binder binder,
final Set<Class<Service>> serviceTypes) {
Consumer<Class> guavaService = klass -> {
binder.bind(klass).asEagerSingleton();
serviceTypes.add(klass);
};
serviceTypes.forEach(guavaService);
// lazy service manager
AtomicReference<ServiceManager> sm = new AtomicReference<>();
Provider<ServiceManager> smProvider = sm::get;
binder.bind(ServiceManager.class).toProvider(smProvider);
// ask Guice for services, create ServiceManager and start services
env.onStart(r -> {
List<Service> services = serviceTypes.stream()
.map(r::require)
.collect(Collectors.toList());
sm.set(new ServiceManager(services));
sm.get().startAsync().awaitHealthy();
});
// stop services
env.onStop(() -> sm.get().stopAsync().awaitStopped());
}
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config config, final Binder binder) {
/**
* Pool
*/
GenericObjectPoolConfig poolConfig = poolConfig(config, name);
int timeout = (int) config.getDuration("jedis.timeout", TimeUnit.MILLISECONDS);
URI uri = URI.create(config.getString(name));
JedisPool pool = new JedisPool(poolConfig, uri, timeout);
RedisProvider provider = new RedisProvider(pool, uri, poolConfig);
env.onStart(provider::start);
env.onStop(provider::stop);
Provider<Jedis> jedis = (Provider<Jedis>) () -> pool.getResource();
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(JedisPool.class, name, k -> binder.bind(k).toInstance(pool));
serviceKey.generate(Jedis.class, name,
k -> binder.bind(k).toProvider(jedis));
}
代码示例来源:origin: jooby-project/jooby
binder.bind(PluginContext.class).toProvider(throwingSupplier(ctx::get)::get);
env.onStart(r -> {
Set<Route.Definition> routes = r.require(Route.KEY);
Set<WebSocket.Definition> sockets = r.require(WebSocket.KEY);
代码示例来源:origin: jooby-project/jooby
.in(RequestScoped.class);
AtomicReference<Registry> registry = new AtomicReference<>();
env.onStart(registry::set);
代码示例来源:origin: jooby-project/jooby
env.onStart(ebean::start);
env.onStop(ebean::stop);
env.onStart(runEnhancer());
代码示例来源:origin: jooby-project/jooby
keys.generate(storeType, model.getName(), bind);
env.onStart(registry -> {
schema(conf, schema, schema -> new SchemaModifier(dataSource, model).createTables(schema));
states
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
configure(env, conf, binder, (uri, client) -> {
String db = uri.getDatabase();
Mapper mapper = new Mapper();
Morphia morphia = new Morphia(mapper);
if (this.morphiaCbck != null) {
this.morphiaCbck.accept(morphia, conf);
}
Datastore datastore = morphia.createDatastore(client, mapper, db);
if (gen != null) {
mapper.addInterceptor(new AutoIncID(datastore, gen));
}
if (callback != null) {
callback.accept(datastore);
}
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(Morphia.class, db,
k -> binder.bind(k).toInstance(morphia));
serviceKey.generate(Datastore.class, db,
k -> binder.bind(k).toInstance(datastore));
env.onStart(registry -> new GuiceObjectFactory(registry, morphia));
});
}
代码示例来源:origin: jooby-project/jooby
env.onStart(registry -> {
registryRef.set(registry);
pac4j.getAuthorizers().values().stream()
代码示例来源:origin: jooby-project/jooby
env.onStart(r -> {
registry.complete(r);
listeners.forEach(it -> it.accept((SessionFactoryImplementor) sessionFactory, r));
代码示例来源:origin: org.jooby/jooby-banner
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
String name = conf.getString("application.name");
Logger log = LoggerFactory.getLogger(name);
String v = conf.getString("application.version");
String text = this.text.orElse(name);
Provider<String> ascii = () -> Try
.apply(() -> CharMatcher.whitespace()
.trimTrailingFrom(convertOneLine(String.format(FONT, font), text)))
.orElse(text);
binder.bind(Key.get(String.class, Names.named("application.banner"))).toProvider(ascii);
env.onStart(() -> {
log.info("\n{} v{}\n", ascii.get(), v);
});
}
代码示例来源:origin: org.jooby/jooby-scanner
@SuppressWarnings({"unchecked", "rawtypes"})
private static void guavaServices(final Env env, final Binder binder,
final Set<Class<Service>> serviceTypes) {
Consumer<Class> guavaService = klass -> {
binder.bind(klass).asEagerSingleton();
serviceTypes.add(klass);
};
serviceTypes.forEach(guavaService);
// lazy service manager
AtomicReference<ServiceManager> sm = new AtomicReference<>();
Provider<ServiceManager> smProvider = sm::get;
binder.bind(ServiceManager.class).toProvider(smProvider);
// ask Guice for services, create ServiceManager and start services
env.onStart(r -> {
List<Service> services = serviceTypes.stream()
.map(r::require)
.collect(Collectors.toList());
sm.set(new ServiceManager(services));
sm.get().startAsync().awaitHealthy();
});
// stop services
env.onStop(() -> sm.get().stopAsync().awaitStopped());
}
代码示例来源:origin: org.jooby/jooby-jedis
@Override
public void configure(final Env env, final Config config, final Binder binder) {
/**
* Pool
*/
GenericObjectPoolConfig poolConfig = poolConfig(config, name);
int timeout = (int) config.getDuration("jedis.timeout", TimeUnit.MILLISECONDS);
URI uri = URI.create(config.getString(name));
JedisPool pool = new JedisPool(poolConfig, uri, timeout);
RedisProvider provider = new RedisProvider(pool, uri, poolConfig);
env.onStart(provider::start);
env.onStop(provider::stop);
Provider<Jedis> jedis = (Provider<Jedis>) () -> pool.getResource();
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(JedisPool.class, name, k -> binder.bind(k).toInstance(pool));
serviceKey.generate(Jedis.class, name,
k -> binder.bind(k).toProvider(jedis));
}
代码示例来源:origin: org.jooby/jooby-ebean
env.onStart(ebean::start);
env.onStop(ebean::stop);
env.onStart(runEnhancer());
代码示例来源:origin: org.jooby/jooby-requery
keys.generate(storeType, model.getName(), bind);
env.onStart(registry -> {
schema(conf, schema, schema -> new SchemaModifier(dataSource, model).createTables(schema));
states
代码示例来源:origin: org.jooby/jooby-morphia
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
configure(env, conf, binder, (uri, client) -> {
String db = uri.getDatabase();
Mapper mapper = new Mapper();
Morphia morphia = new Morphia(mapper);
if (this.morphiaCbck != null) {
this.morphiaCbck.accept(morphia, conf);
}
Datastore datastore = morphia.createDatastore(client, mapper, db);
if (gen != null) {
mapper.addInterceptor(new AutoIncID(datastore, gen));
}
if (callback != null) {
callback.accept(datastore);
}
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(Morphia.class, db,
k -> binder.bind(k).toInstance(morphia));
serviceKey.generate(Datastore.class, db,
k -> binder.bind(k).toInstance(datastore));
env.onStart(registry -> new GuiceObjectFactory(registry, morphia));
});
}
代码示例来源:origin: org.jooby/jooby-hbm
env.onStart(r -> {
registry.complete(r);
listeners.forEach(it -> it.accept((SessionFactoryImplementor) sessionFactory, r));
内容来源于网络,如有侵权,请联系作者删除!