Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: impove events and build phase #339

Merged
merged 2 commits into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@
package org.apache.camel.quarkus.core.deployment;

import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.runtime.RuntimeValue;
import org.apache.camel.main.MainListener;
import org.apache.camel.quarkus.core.CamelMain;

/**
* A {@link MultiBuildItem} holding {@link MainListener}s to add to {@link CamelMain}.
*/
public final class CamelMainListenerBuildItem extends MultiBuildItem {
private final MainListener listener;
private final RuntimeValue<MainListener> listener;

public CamelMainListenerBuildItem(MainListener listener) {
public CamelMainListenerBuildItem(RuntimeValue<MainListener> listener) {
this.listener = listener;
}

public MainListener getListener() {
public RuntimeValue<MainListener> getListener() {
return listener;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,13 @@ public void setCamelContext(CamelContext camelContext) {
this.camelContext = camelContext;
}

@Override
protected void doInit() throws Exception {
postProcessCamelContext(getCamelContext());
}

@Override
protected void doStart() throws Exception {
for (MainListener listener : listeners) {
listener.beforeStart(this);
}

postProcessCamelContext(getCamelContext());
getCamelContext().start();

for (MainListener listener : listeners) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ public void addRouteBuilder(
}
}

public void addListener(RuntimeValue<CamelMain> main, MainListener listener) {
main.getValue().addMainListener(listener);
public void addListener(RuntimeValue<CamelMain> main, RuntimeValue<MainListener> listener) {
main.getValue().addMainListener(listener.getValue());
}

public void setReactiveExecutor(RuntimeValue<CamelMain> main, RuntimeValue<ReactiveExecutor> executor) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,16 @@
*/
package org.apache.camel.quarkus.core.runtime.support.deployment;

import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import org.apache.camel.quarkus.core.deployment.CamelMainListenerBuildItem;
import org.apache.camel.quarkus.core.runtime.support.SupportListener;
import org.apache.camel.quarkus.core.runtime.support.SupportRecorder;

public class SupportBuildStep {
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
void listener(BuildProducer<CamelMainListenerBuildItem> listener) {
listener.produce(new CamelMainListenerBuildItem(new SupportListener()));
CamelMainListenerBuildItem listener(SupportRecorder recorder) {
return new CamelMainListenerBuildItem(recorder.createSupportListener());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ public void configure(CamelContext context) {
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("timer:listener")
.id("listener")
.to("log:listener");
from("timer:configure")
.id("configure")
.to("log:configure");
}
});
} catch (Exception e) {
Expand All @@ -40,6 +40,7 @@ public void configure() throws Exception {

@Override
public void beforeStart(BaseMainSupport main) {
main.addRoutesBuilder(new MyBuilder());
}

@Override
Expand All @@ -53,4 +54,13 @@ public void beforeStop(BaseMainSupport main) {
@Override
public void afterStop(BaseMainSupport main) {
}

public static class MyBuilder extends RouteBuilder {
@Override
public void configure() throws Exception {
from("timer:beforeStart")
.id("beforeStart")
.to("log:beforeStart");
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.runtime.support;

import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import org.apache.camel.main.MainListener;

@Recorder
public class SupportRecorder {
public RuntimeValue<MainListener> createSupportListener() {
return new RuntimeValue<>(new SupportListener());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ public void testMainInstance() {
assertThat(p.getList("listeners", String.class))
.containsOnly(CamelMainEventDispatcher.class.getName(), SupportListener.class.getName());
assertThat(p.getList("routeBuilders", String.class))
.containsOnly(CamelRoute.class.getName());
.containsOnly(CamelRoute.class.getName(), SupportListener.MyBuilder.class.getName());
assertThat(p.getList("routes", String.class))
.containsOnly("keep-alive", "listener", "my-xml-route");
.containsOnly("keep-alive", "configure", "beforeStart", "my-xml-route");

assertThat(p.getBoolean("autoConfigurationLogSummary")).isFalse();

Expand Down