本文整理了Java中org.jooby.Env.serviceKey()
方法的一些代码示例,展示了Env.serviceKey()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Env.serviceKey()
方法的具体详情如下:
包路径:org.jooby.Env
类名称:Env
方法名:serviceKey
暂无
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(@Nonnull final Env env, @Nonnull final Config conf, @Nonnull final Binder binder) {
ActorSystem sys = ActorSystem.create(name, conf);
env.serviceKey().generate(ActorSystem.class, name, syskey -> binder.bind(syskey).toInstance(sys));
}
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config config, final Binder binder) {
Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
DataSource ds = env.get(dskey)
.orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
Database db = Database.fromDataSource(ds);
env.serviceKey().generate(Database.class, name, k -> binder.bind(k).toInstance(db));
// close on shutdown
env.onStop(db::close);
}
}
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config config, final Binder binder) {
Config mail = config.getConfig(name).withFallback(config.getConfig("mail"));
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(SimpleEmail.class, name, k -> binder.bind(k).toProvider(new SimpleEmailProvider(mail)));
serviceKey.generate(HtmlEmail.class, name, k -> binder.bind(k).toProvider(new HtmlEmailProvider(mail)));
serviceKey.generate(MultiPartEmail.class, name, k -> binder.bind(k).toProvider(new MultiPartEmailProvider(mail)));
serviceKey.generate(ImageHtmlEmail.class, name, k -> binder.bind(k).toProvider(new ImageHtmlEmailProvider(mail)));
}
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
DataSource ds = env.get(dskey)
.orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
String dbtype = env.get(Key.get(String.class, Names.named(name + ".dbtype")))
.orElse("unknown");
SQLTemplates templates = this.templates.apply(dbtype);
Configuration querydslconf = new Configuration(templates);
if (callback != null) {
callback.accept(querydslconf, conf);
}
SQLQueryFactory sqfp = new SQLQueryFactory(querydslconf, ds);
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(SQLTemplates.class, name, k -> binder.bind(k).toInstance(templates));
serviceKey.generate(Configuration.class, name, k -> binder.bind(k).toInstance(querydslconf));
serviceKey.generate(SQLQueryFactory.class, name, k -> binder.bind(k).toInstance(sqfp));
}
代码示例来源:origin: jooby-project/jooby
@SuppressWarnings({"unchecked", "rawtypes" })
@Override
public void configure(final Env env, final Config conf, final Binder binder) throws Throwable {
String db = database(conf, this.db);
Properties props = props(neo4j(conf, this.db));
ServiceKey keys = env.serviceKey();
IDBAccess dbaccess = dbaccess(conf, this.db, db, props, keys, binder);
Arrays.asList(props.getProperty(SERVER_ROOT_URI), props.getProperty(DATABASE_DIR))
.stream()
.filter(Objects::nonNull)
.findFirst()
.ifPresent(it -> log.info("Starting neo4j: {}", it));
Class dbaccessType = dbaccess.getClass();
keys.generate(IDBAccess.class, this.db, k -> binder.bind(k).toInstance(dbaccess));
keys.generate(dbaccessType, this.db, k -> binder.bind(k).toInstance(dbaccess));
env.onStop(dbaccess::close);
}
代码示例来源:origin: jooby-project/jooby
protected void configure(final Env env, final Config config, final Binder binder,
final BiConsumer<MongoClientURI, MongoClient> callback) {
MongoClientOptions.Builder options = options(mongodb(config));
if (this.options != null) {
this.options.accept(options, config);
}
MongoClientURI uri = new MongoClientURI(config.getString(db), options);
String database = uri.getDatabase();
checkArgument(database != null, "Database not found: " + uri);
MongoClient client = new MongoClient(uri);
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(MongoClientURI.class, database, k -> binder.bind(k).toInstance(uri));
serviceKey.generate(MongoClient.class, database,
k -> binder.bind(k).toInstance(client));
MongoDatabase mongodb = client.getDatabase(database);
serviceKey.generate(MongoDatabase.class, database,
k -> binder.bind(k).toInstance(mongodb));
env.onStop(client::close);
callback.accept(uri, client);
}
代码示例来源: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
names.forEach(it -> env.serviceKey().generate(DataSource.class, it, k -> {
binder.bind(k).toInstance(ds);
env.set(k, ds);
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
Supplier<NoSuchElementException> noSuchElement = () -> new NoSuchElementException(
"DataSource missing: " + dskey);
HikariDataSource ds = (HikariDataSource) env.get(dskey).orElseThrow(noSuchElement);
Configuration jooqconf = new DefaultConfiguration();
ConnectionProvider dscp = new DataSourceConnectionProvider(ds);
jooqconf.set(JDBCUtils.dialect(env.get(Key.get(String.class, Names.named(name + ".url")))
.orElseThrow(noSuchElement)));
jooqconf.set(dscp);
jooqconf.set(new DefaultTransactionProvider(dscp));
if (callback != null) {
callback.accept(jooqconf, conf);
}
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(Configuration.class, name, k -> binder.bind(k).toInstance(jooqconf));
Provider<DSLContext> dsl = () -> DSL.using(jooqconf);
serviceKey.generate(DSLContext.class, name, k -> binder.bind(k).toProvider(dsl));
}
}
代码示例来源:origin: jooby-project/jooby
@Override
public void configure(final Env env, final Config conf, final Binder binder) {
Config $base = flyway(conf.getConfig("flyway"));
Config $flyway = Try.apply(() -> flyway(conf.getConfig(name)).withFallback($base))
.orElse($base);
Flyway flyway = new Flyway();
Properties props = props($flyway);
flyway.configure(props);
if (!props.containsKey("flyway.url")) {
Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
DataSource dataSource = env.get(dskey)
.orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
flyway.setDataSource(dataSource);
}
// bind
env.serviceKey()
.generate(Flyway.class, name, key -> binder.bind(key).toInstance(flyway));
// commands:
Iterable<Command> cmds = commands(conf);
// eager initialization
cmds.forEach(cmd -> cmd.run(flyway));
}
代码示例来源:origin: jooby-project/jooby
callback.accept(jdbi, conf);
env.serviceKey().generate(Jdbi.class, name, key -> binder.bind(key).toInstance(jdbi));
代码示例来源:origin: jooby-project/jooby
@SuppressWarnings({"unchecked", "rawtypes"})
@Override
public void configure(final Env env, final Config config, final Binder binder) {
Key<DataSource> dskey = Key.get(DataSource.class, Names.named(name));
DataSource ds = env.get(dskey)
.orElseThrow(() -> new NoSuchElementException("DataSource missing: " + dskey));
DBI dbi = new DBI2(ds);
dbi.setSQLLog(new SLF4JLog());
dbi.registerArgumentFactory(new OptionalArgumentFactory());
dbi.registerArgumentFactory(new IterableArgumentFactory());
dbi.registerContainerFactory(new OptionalContainerFactory());
dbi.setStatementRewriter(new ExpandedStmtRewriter());
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(DBI.class, name, k -> binder.bind(k).toInstance(dbi));
serviceKey.generate(Handle.class, name, k -> binder.bind(k).toProvider(() -> dbi.open()));
sqlObjects.forEach(sqlObject -> binder.bind(sqlObject)
.toProvider((Provider) () -> dbi.open(sqlObject)));
if (callback != null) {
callback.accept(dbi, config);
}
}
代码示例来源:origin: jooby-project/jooby
ServiceKey keys = env.serviceKey();
keys.generate(EbeanServer.class, name, provider);
代码示例来源:origin: jooby-project/jooby
Object newStore = store.apply(configuration);
ServiceKey keys = env.serviceKey();
Consumer bind = k -> binder.bind((Key) k).toInstance(newStore);
代码示例来源: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.serviceKey().generate(Consul.class, name, k -> binder.bind(k).toInstance(consul));
代码示例来源:origin: jooby-project/jooby
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(SessionFactory.class, name,
k -> binder.bind(k).toInstance(sessionFactory));
代码示例来源:origin: jooby-project/jooby
ServiceKey serviceKey = env.serviceKey();
Throwing.Function3<Class, String, Object, Void> bind = (type, name, value) -> {
serviceKey.generate(type, name, k -> binder.bind(k).toInstance(value));
代码示例来源:origin: jooby-project/jooby
.orElseGet(() -> ConnectionString.parse(conf.getString(db)));
ServiceKey serviceKey = env.serviceKey();
代码示例来源:origin: org.jooby/jooby-commons-email
@Override
public void configure(final Env env, final Config config, final Binder binder) {
Config mail = config.getConfig(name).withFallback(config.getConfig("mail"));
ServiceKey serviceKey = env.serviceKey();
serviceKey.generate(SimpleEmail.class, name, k -> binder.bind(k).toProvider(new SimpleEmailProvider(mail)));
serviceKey.generate(HtmlEmail.class, name, k -> binder.bind(k).toProvider(new HtmlEmailProvider(mail)));
serviceKey.generate(MultiPartEmail.class, name, k -> binder.bind(k).toProvider(new MultiPartEmailProvider(mail)));
serviceKey.generate(ImageHtmlEmail.class, name, k -> binder.bind(k).toProvider(new ImageHtmlEmailProvider(mail)));
}
内容来源于网络,如有侵权,请联系作者删除!