com.dinstone.vertx.starter.verticle.SpringVerticleFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of vertx-spring-boot-starter Show documentation
Show all versions of vertx-spring-boot-starter Show documentation
vertx starter project for spring boot
/*
* Copyright (C) 2016~2018 dinstone
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.dinstone.vertx.starter.verticle;
import org.springframework.context.ApplicationContext;
import io.vertx.core.Verticle;
import io.vertx.core.spi.VerticleFactory;
public class SpringVerticleFactory implements VerticleFactory {
private String prefix = "bean";
private ApplicationContext applicationContext;
@Override
public boolean blockingCreate() {
// Usually verticle instantiation is fast but since our verticles are Spring
// Beans,
// they might depend on other beans/resources which are slow to build/lookup.
return true;
}
@Override
public String prefix() {
return prefix;
}
@Override
public Verticle createVerticle(String verticleName, ClassLoader classLoader) throws Exception {
// Our convention in this example is to give the class name as verticle name
String clazz = VerticleFactory.removePrefix(verticleName);
return (Verticle) applicationContext.getBean(Class.forName(clazz));
}
public String verticleName(Class> verticleClass) {
return prefix() + ":" + verticleClass.getName();
}
public void setPrefix(String prefix) {
this.prefix = prefix;
}
public void setApplicationContext(ApplicationContext applicationContext) {
this.applicationContext = applicationContext;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy