本文整理汇总了Java中io.vertx.core.Verticle类的典型用法代码示例。如果您正苦于以下问题:Java Verticle类的具体用法?Java Verticle怎么用?Java Verticle使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Verticle类属于io.vertx.core包,在下文中一共展示了Verticle类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createVerticleFromBean
import io.vertx.core.Verticle; //导入依赖的package包/类
private Verticle createVerticleFromBean(String beanName) {
if (!beanFactory.containsBean(beanName)) {
throw new IllegalArgumentException("No such bean: " + beanName);
}
if (!beanFactory.isTypeMatch(beanName, Verticle.class)) {
throw new IllegalArgumentException("Bean \"" + beanName + "\" is not of type Verticle");
}
if (beanFactory.isSingleton(beanName)) {
throw new IllegalArgumentException("Verticle bean \"" + beanName + "\" is a singleton bean");
}
logger.debug("Creating verticle from bean \"{}\"", beanName);
return beanFactory.getBean(beanName, Verticle.class);
}
示例2: createVerticle
import io.vertx.core.Verticle; //导入依赖的package包/类
@Override
public Verticle createVerticle(String verticleName, ClassLoader classLoader) throws Exception {
verticleName = VerticleFactory.removePrefix(verticleName);
Class clazz;
if (verticleName.endsWith(".java")) {
CompilingClassLoader compilingLoader = new CompilingClassLoader(classLoader, verticleName);
String className = compilingLoader.resolveMainClassName();
clazz = compilingLoader.loadClass(className);
} else {
clazz = classLoader.loadClass(verticleName);
}
Verticle instance = (Verticle)clazz.newInstance();
ConfigurationInjection.getConfigurationInjector().configure(instance);
return instance;
}
示例3: addVerticle
import io.vertx.core.Verticle; //导入依赖的package包/类
@Reference(unbind = "removeVerticle", policy=ReferencePolicy.DYNAMIC, cardinality = ReferenceCardinality.MULTIPLE)
public void addVerticle(Verticle verticle) {
LOGGER.info("Deploying verticle " + verticle);
verticles.add(verticle);
if (verticle == null)
return;
if (vertxService != null)
vertxService.deployVerticle(verticle, deploy -> {
if (deploy.succeeded()) {
LOGGER.info("Deployment of verticle succeeded");
String id = deploy.result();
deployedVerticles.put(verticle, id);
} else {
LOGGER.log(Level.SEVERE, "Deployment of verticle failed", deploy.cause());
}
});
}
示例4: installExtendedBundle
import io.vertx.core.Verticle; //导入依赖的package包/类
@Test
public void installExtendedBundle() throws Exception {
logger.info("testing extender ... ");
String bundlePath = "mvn:de.nierbeck.example.vertx/Vertx-Extended-Verticles/0.1.0-SNAPSHOT";
logger.info("installing bundle with url: {}", bundlePath);
Bundle bundle = bc.installBundle(bundlePath);
bundle.start();
int count = 0;
while (bundle.getState() != Bundle.ACTIVE && count < 50) {
Thread.sleep(1000);
count = count++;
}
assertTrue (bundle.getState() == Bundle.ACTIVE);
logger.info("Bundle is active");
Thread.sleep(1000); //wait a second so the service is registered.
Collection<ServiceReference<Verticle>> serviceReferences = bc.getServiceReferences(Verticle.class, null);
logger.info("found {} services", serviceReferences.size());
List<ServiceReference<Verticle>> collect = serviceReferences.stream().filter(serviceReference -> serviceReference.getBundle() == bundle).collect(Collectors.toList());
assertTrue(collect.size() > 0);
}
示例5: main
import io.vertx.core.Verticle; //导入依赖的package包/类
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
Verticle todoVerticle = new TodoVerticle();
final int port = Integer.getInteger("http.port", 8082);
DeploymentOptions options = new DeploymentOptions()
.setConfig(new JsonObject().put("http.port", port)
);
vertx.deployVerticle(todoVerticle, options, res -> {
if (res.succeeded())
System.out.println("Todo service is running at " + port + " port...");
else
res.cause().printStackTrace();
});
}
示例6: BootstrapVerticle
import io.vertx.core.Verticle; //导入依赖的package包/类
@Inject
public BootstrapVerticle(@Nullable @Named("bootstrap.filter") final String filterString,
final Map<String, Verticle> verticleMap)
{
this.filter = filterFromString(filterString);
this.verticles = verticleMap.entrySet().stream()
.filter(e -> !NAME.equals(e.getKey()) && filter.test(e.getKey()))
.collect(Collectors.toMap(Entry::getKey, Entry::getValue));
if (verticles.isEmpty()) {
log.warn("No verticle participates in bootstrap? (are they discoverable, or filter '" + filter +
"' filtered out all of them?)");
}
else {
log.debug("Bootstrap verticle(filter='" + filterString + "', verticles=" + verticles.keySet() + ")");
}
}
示例7: start
import io.vertx.core.Verticle; //导入依赖的package包/类
@Override
public void start(final Future<Void> startFuture) throws Exception {
log.debug("Starting bootstrap verticle");
List<Future> futures = new ArrayList<>(verticles.size());
for (Verticle verticle : verticles.values()) {
Future<Void> f = Future.future();
verticle.start(f);
futures.add(f);
}
CompositeFuture.all(futures).setHandler(ar -> {
if (ar.succeeded()) {
startFuture.complete();
}
else {
startFuture.fail(ar.cause());
}
});
}
示例8: stop
import io.vertx.core.Verticle; //导入依赖的package包/类
@Override
public void stop(final Future<Void> stopFuture) throws Exception {
log.debug("Stopping bootstrap verticle");
List<Future> futures = new ArrayList<>(verticles.size());
for (Verticle verticle : verticles.values()) {
Future<Void> f = Future.future();
verticle.stop(f);
futures.add(f);
}
CompositeFuture.all(futures).setHandler(ar -> {
if (ar.succeeded()) {
stopFuture.complete();
}
else {
stopFuture.fail(ar.cause());
}
});
}
示例9: AMQPServiceImpl
import io.vertx.core.Verticle; //导入依赖的package包/类
public AMQPServiceImpl(Vertx vertx, AmqpServiceConfig config, Verticle parent) throws MessagingException {
_vertx = vertx;
_parent = parent;
_eb = _vertx.eventBus();
_config = config;
_msgTranslator = new MessageTranslator();
_msgBasedRouter = new MessageRouter(_config);
_linkBasedRouter = new LinkRouter();
_linkManager = new LinkManager(vertx, _config, this);
_replyToAddressPrefix = "amqp://" + _config.getInboundHost() + ":" + _config.getInboundPort();
_eb.consumer(config.getDefaultHandlerAddress(), this);
for (String handlerAddress : config.getHandlerAddressList()) {
_consumers.add(_eb.consumer(handlerAddress, this));
}
// TODO _config.print() // prints the current config at start time.
}
示例10: asJavaVerticle
import io.vertx.core.Verticle; //导入依赖的package包/类
/**
* @return the Java {@link Verticle} adapter for this Groovy Verticle
*/
public Verticle asJavaVerticle() {
return new AbstractVerticle() {
@Override
public void start(Future<Void> startFuture) throws Exception {
GroovyVerticle.this.vertx = super.vertx;
GroovyVerticle.this.context = super.context;
GroovyVerticle.this.start(startFuture);
}
@Override
public void stop(Future<Void> stopFuture) throws Exception {
GroovyVerticle.this.stop(stopFuture);
}
};
}
示例11: createSpringVerticle
import io.vertx.core.Verticle; //导入依赖的package包/类
private Verticle createSpringVerticle(final Class<?> currentVerticleClass, ClassLoader classLoader) {
final SpringVerticle annotation = currentVerticleClass.getAnnotation(SpringVerticle.class);
final Class<?> springConfigClass = annotation.springConfig();
// Create the parent context
final GenericApplicationContext genericApplicationContext = getGenericApplicationContext(
classLoader);
// 1. Create a new context for each verticle and use the specified spring configuration class if possible
AnnotationConfigApplicationContext annotationConfigApplicationContext = getAnnotationConfigApplicationContext(
springConfigClass, genericApplicationContext);
// 2. Register the Vertx instance as a singleton in spring context
annotationConfigApplicationContext.getBeanFactory().registerSingleton(vertx.getClass().getSimpleName(), vertx);
// 3. Register a bean definition for this verticle
annotationConfigApplicationContext.registerBeanDefinition(currentVerticleClass.getSimpleName(), new VerticleBeanDefinition(currentVerticleClass));
// 4. Add a bean factory post processor to avoid configuration issues
addPostprocessorAndUpdateContext(currentVerticleClass, annotationConfigApplicationContext);
// 5. Return the verticle by fetching the bean from the context
return (Verticle) annotationConfigApplicationContext.getBeanFactory().getBean(currentVerticleClass.getSimpleName());
}
示例12: testIsolatedContext
import io.vertx.core.Verticle; //导入依赖的package包/类
@Test
public void testIsolatedContext() throws Exception {
SpringVerticleFactory springVerticleFactory = createCleanSpringVerticleFactory();
Vertx vertx = mock(Vertx.class);
springVerticleFactory.init(vertx);
Verticle verticle1 = springVerticleFactory.createVerticle(SpringTestVerticle.class.getName(), Thread.currentThread().getContextClassLoader());
assertNotNull(verticle1);
Verticle verticle2 = springVerticleFactory.createVerticle(SpringTestVerticle.class.getName(), Thread.currentThread().getContextClassLoader());
assertNotNull(verticle2);
// SpringTestVerticle v1 = SpringTestVerticle.class.cast(verticle1);
// SpringTestVerticle v2 = SpringTestVerticle.class.cast(verticle2);
// assertFalse(v1.equals(v2));
// assertFalse(v1.getBean().equals(v2.getBean()));
// assertEquals(v1.getBean().getClass().getCanonicalName(),v2.getBean().getClass().getCanonicalName());
// assertFalse(v1.getSpringContext().equals(v2.getSpringContext()));
// assertEquals(v1.getSpringContext().getClass().getCanonicalName(),v2.getSpringContext().getClass().getCanonicalName());
}
示例13: main
import io.vertx.core.Verticle; //导入依赖的package包/类
public static void main(String[] args) {
VertxOptions options = new VertxOptions();
options.setMaxEventLoopExecuteTime(Long.MAX_VALUE);
final Vertx vertx = Vertx.factory.vertx(options);
ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfiguration.class);
Verticle serverVerticle = (Verticle) context.getBean("serverVerticle");
Verticle userDatabaseVerticle = (Verticle) context.getBean("userDatabaseVerticle");
Verticle blogServiceVerticle = (Verticle) context.getBean("blogServiceVerticle");
vertx.deployVerticle(serverVerticle);
vertx.deployVerticle(userDatabaseVerticle, new DeploymentOptions().setWorker(true));
vertx.deployVerticle(blogServiceVerticle, new DeploymentOptions().setWorker(true));
}
示例14: isVerticleBeanDefinition
import io.vertx.core.Verticle; //导入依赖的package包/类
private boolean isVerticleBeanDefinition(String beanName, BeanDefinition beanDefinition) {
Class<?> beanClass = getBeanClass(beanName, beanDefinition);
if (beanClass != null) {
if (Verticle.class.isAssignableFrom(beanClass)) {
return true;
}
if (FactoryBean.class.isAssignableFrom(beanClass) && beanDefinition instanceof AnnotatedBeanDefinition) {
MethodMetadata factoryMethodMetadata = ((AnnotatedBeanDefinition) beanDefinition).getFactoryMethodMetadata();
if (factoryMethodMetadata != null && factoryMethodMetadata.isAnnotated(VerticleDeployment.class.getName())) {
return true;
}
}
}
return false;
}
示例15: loadVerticleByClass
import io.vertx.core.Verticle; //导入依赖的package包/类
/**
* Loads a Verticle by instantiating the Java class first needed when
* objects need to be handed over
*
* @param bc
* the Base configuration
* @return a future that resolves after loading
*/
private Future<Void> loadVerticleByClass(final BaseConfig bc) {
final Future<Void> result = Future.future();
final String verticleId = bc.getVerticleName();
final DeploymentOptions options = this.getDeploymentOptions(bc);
try {
@SuppressWarnings("unchecked")
final Class<Verticle> vClass = (Class<Verticle>) Class.forName(verticleId);
final Verticle v = vClass.newInstance();
/*
* This is the magic: we hand over the router to the verticle to be
* used only sparingly
*/
if (v instanceof SFDCRouterExtension) {
((SFDCRouterExtension) v).addRoutes(this.router);
}
this.getVertx().deployVerticle(v, options, r -> {
if (r.succeeded()) {
final String vid = r.result();
this.logger.trace(verticleId + "started as " + vid);
this.loadedVerticles.add(vid);
result.complete();
} else {
this.logger.fatal(r.cause());
result.fail(r.cause());
}
});
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
this.logger.fatal(e.getMessage(), e);
result.fail(e);
}
return result;
}