Skip to content

Commit

Permalink
Add support for quarkus provided event loop #131
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Oct 7, 2019
1 parent 027d923 commit c8bffa2
Show file tree
Hide file tree
Showing 19 changed files with 471 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
* `camel-quarkus-netty-http`
* `camel-quarkus-paho`
* `camel-quarkus-platform-http`
* `camel-quarkus-reactive-executor`
* `camel-quarkus-rest`
* `camel-quarkus-salesforce`
* `camel-quarkus-servlet`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,22 @@ CamelRegistryBuildItem registry(

RuntimeValue<Registry> registry = recorder.createRegistry();

CamelSupport.services(applicationArchives).forEach(si -> {
CamelSupport.services(applicationArchives)
.filter(si -> {
//
// by default all the service found in META-INF/service/org/apache/camel are
// bound to the registry but some of the services are then replaced or set
// to the camel context directly by extension so it does not make sense to
// instantiate them in this phase.
//
boolean blacklisted = si.path.endsWith("reactive-executor") || si.path.endsWith("platform-http");
if (blacklisted) {
LOGGER.debug("Ignore service: {}", si);
}

return !blacklisted;
})
.forEach(si -> {
LOGGER.debug("Binding bean with name: {}, type {}", si.name, si.type);

recorder.bind(
Expand Down Expand Up @@ -174,13 +189,21 @@ void start(
CamelMainRecorder recorder,
CamelMainBuildItem main,
// TODO: keep this as placeholder to ensure the registry is fully configured
// befire startuing the camel context
// before starting the camel context
CamelRuntimeRegistryBuildItem registry,
// TODO: replace with @Overridable
List<CamelReactiveExecutorBuildItem> reactiveExecutors,
ShutdownContextBuildItem shutdown,
// TODO: keep this list as placeholder to ensure the ArC container is fully
// started before starting main
List<ServiceStartBuildItem> startList) {

if (reactiveExecutors.size() > 1) {
throw new IllegalArgumentException("Detected multiple reactive executors");
} else if (reactiveExecutors.size() == 1) {
recorder.setReactiveExecutor(main.getInstance(), reactiveExecutors.get(0).getInstance());
}

recorder.start(shutdown, main.getInstance());
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.quarkus.core.deployment;


import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.runtime.RuntimeValue;
import org.apache.camel.quarkus.core.CamelMain;
import org.apache.camel.spi.ReactiveExecutor;

/**
* Holds the {@link CamelMain} {@link RuntimeValue}.
*
* TODO: should extend SimpleBuildItem when moving to quarkus snapshots or 0.24
* as we can then use the @Overridable annotation which allow to provide
* alternative implementation of a build item.
*/
public final class CamelReactiveExecutorBuildItem extends MultiBuildItem {
private final RuntimeValue<ReactiveExecutor> instance;

public CamelReactiveExecutorBuildItem(RuntimeValue<ReactiveExecutor> instance) {
this.instance = instance;
}

public RuntimeValue<ReactiveExecutor> getInstance() {
return instance;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ private static List<ServiceInfo> services(Path p) {
for (Map.Entry<Object, Object> entry : props.entrySet()) {
String k = entry.getKey().toString();
if (k.equals("class")) {
answer.add(new ServiceInfo(name, entry.getValue().toString()));
answer.add(new ServiceInfo(p, name, entry.getValue().toString()));
}
}
} catch (Exception e) {
Expand All @@ -117,18 +117,21 @@ private static List<ServiceInfo> services(Path p) {
* services from resources belonging to META-INF/services/org/apache/camel.
*/
public static class ServiceInfo {
public final Path path;
public final String name;
public final String type;

public ServiceInfo(String name, String type) {
public ServiceInfo(Path path, String name, String type) {
this.path = path;
this.name = name;
this.type = type;
}

@Override
public String toString() {
return "ServiceInfo{"
+ "name='" + name + '\''
+ "path='" + path.toString() + '\''
+ ", name=" + name
+ ", type=" + type
+ '}';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@
import io.quarkus.runtime.annotations.Recorder;
import org.apache.camel.CamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.impl.engine.DefaultReactiveExecutor;
import org.apache.camel.main.MainListener;
import org.apache.camel.model.Model;
import org.apache.camel.spi.ReactiveExecutor;
import org.apache.camel.support.ResourceHelper;
import org.apache.camel.util.ObjectHelper;

@Recorder
public class CamelMainRecorder {
public RuntimeValue<ReactiveExecutor> createReactiveExecutor() {
return new RuntimeValue<>(new DefaultReactiveExecutor());
}

public RuntimeValue<CamelMain> createCamelMain(
RuntimeValue<CamelContext> runtime,
BeanContainer container) {
Expand Down Expand Up @@ -87,6 +93,9 @@ public void addListener(RuntimeValue<CamelMain> main, MainListener listener) {
main.getValue().addMainListener(listener);
}

public void setReactiveExecutor(RuntimeValue<CamelMain> main, RuntimeValue<ReactiveExecutor> executor) {
main.getValue().getCamelContext().setReactiveExecutor(executor.getValue());
}
public void start(ShutdownContext shutdown, RuntimeValue<CamelMain> main) {
shutdown.addShutdownTask(new Runnable() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import org.apache.camel.impl.engine.DefaultNodeIdFactory;
import org.apache.camel.impl.engine.DefaultPackageScanClassResolver;
import org.apache.camel.impl.engine.DefaultProcessorFactory;
import org.apache.camel.impl.engine.DefaultReactiveExecutor;
import org.apache.camel.impl.engine.DefaultRouteController;
import org.apache.camel.impl.engine.DefaultStreamCachingStrategy;
import org.apache.camel.impl.engine.DefaultTracer;
Expand All @@ -58,7 +59,6 @@
import org.apache.camel.impl.engine.DefaultValidatorRegistry;
import org.apache.camel.impl.engine.EndpointKey;
import org.apache.camel.impl.engine.HeadersMapFactoryResolver;
import org.apache.camel.impl.engine.ReactiveExecutorResolver;
import org.apache.camel.impl.engine.RestRegistryFactoryResolver;
import org.apache.camel.impl.engine.ServicePool;
import org.apache.camel.impl.health.DefaultHealthCheckRegistry;
Expand Down Expand Up @@ -380,7 +380,7 @@ protected ValidatorRegistry<ValidatorKey> createValidatorRegistry() throws Excep

@Override
protected ReactiveExecutor createReactiveExecutor() {
return new ReactiveExecutorResolver().resolve(this);
return new DefaultReactiveExecutor();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
*/
package org.apache.camel.quarkus.core;

import java.util.LinkedHashSet;
import java.util.Set;

import io.quarkus.runtime.RuntimeValue;
import org.apache.camel.spi.BeanRepository;
import org.apache.camel.support.DefaultRegistry;

public class RuntimeRegistry extends DefaultRegistry {
Expand All @@ -30,4 +34,36 @@ public Object unwrap(Object value) {
? ((RuntimeValue)value).getValue()
: value;
}

//
// DefaultRegistry does not merge results from the repositories
// and fallback registry so in case beans are bound to the local
// registry only but any of the configured repositories returns
// a non null answer, then the local values are not taken into
// account for the final answer.
//
// TODO: fix upstream and remove this method
//
@Override
public <T> Set<T> findByType(Class<T> type) {
final Set<T> answer = new LinkedHashSet<>();

if (repositories != null) {
for (BeanRepository r : repositories) {
Set<T> instances = r.findByType(type);
if (instances != null && !instances.isEmpty()) {
answer.addAll(instances);
}
}
}

Set<T> instances = fallbackRegistry.findByType(type);
if (instances != null && !instances.isEmpty()) {
for (T instance: instances) {
answer.add((T)unwrap(instance));
}
}

return answer;
}
}
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
<module>core</module>
<module>core-cloud</module>
<module>http-common</module>
<module>reactive-executor</module>

<!-- components -->
<module>netty-http</module>
Expand Down
77 changes: 77 additions & 0 deletions extensions/reactive-executor/deployment/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-reactive-executor-parent</artifactId>
<version>0.2.1-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-reactive-executor-deployment</artifactId>
<name>Camel Quarkus :: Core :: Reactive Executor :: Deployment</name>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-reactive-executor</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx-deployment</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${quarkus.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.quarkus.reactive.executor.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.vertx.deployment.VertxBuildItem;
import org.apache.camel.quarkus.core.Flags;
import org.apache.camel.quarkus.core.deployment.CamelReactiveExecutorBuildItem;
import org.apache.camel.quarkus.reactive.executor.ReactiveExecutorRecorder;

public class BuildProcessor {
@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep(onlyIfNot = Flags.MainDisabled.class)
CamelReactiveExecutorBuildItem reactiveExecutor(ReactiveExecutorRecorder recorder, VertxBuildItem vertx) {
return new CamelReactiveExecutorBuildItem(recorder.createReactiveExecutor(vertx.getVertx()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.quarkus.reactive.executor.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.FeatureBuildItem;

public class Feature {
private static final String FEATURE = "camel-reactive-executor";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}
}

0 comments on commit c8bffa2

Please sign in to comment.