forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Observe Camel's Lifecycle events apache#1399
- Loading branch information
1 parent
6f08473
commit 39b4e8f
Showing
9 changed files
with
280 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
...e/core/runtime/src/main/java/org/apache/camel/quarkus/core/CamelLifecycleEventBridge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* 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; | ||
|
||
import javax.enterprise.inject.spi.BeanManager; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.arc.ArcContainer; | ||
import org.apache.camel.Component; | ||
import org.apache.camel.Endpoint; | ||
import org.apache.camel.quarkus.core.events.ComponentAddEvent; | ||
import org.apache.camel.quarkus.core.events.ComponentRemoveEvent; | ||
import org.apache.camel.quarkus.core.events.EndpointAddEvent; | ||
import org.apache.camel.quarkus.core.events.EndpointRemoveEvent; | ||
import org.apache.camel.spi.CamelEvent; | ||
import org.apache.camel.support.LifecycleStrategySupport; | ||
|
||
public class CamelLifecycleEventBridge extends LifecycleStrategySupport { | ||
@Override | ||
public void onComponentAdd(String name, Component component) { | ||
|
||
fireEvent(new ComponentAddEvent(component)); | ||
} | ||
|
||
@Override | ||
public void onComponentRemove(String name, Component component) { | ||
fireEvent(new ComponentRemoveEvent(component)); | ||
} | ||
|
||
@Override | ||
public void onEndpointAdd(Endpoint endpoint) { | ||
fireEvent(new EndpointAddEvent(endpoint)); | ||
} | ||
|
||
@Override | ||
public void onEndpointRemove(Endpoint endpoint) { | ||
fireEvent(new EndpointRemoveEvent(endpoint)); | ||
} | ||
|
||
private static <T extends CamelEvent> void fireEvent(T event) { | ||
fireEvent(CamelEvent.class, event); | ||
} | ||
|
||
private static <T> void fireEvent(Class<T> clazz, T event) { | ||
ArcContainer container = Arc.container(); | ||
if (container != null) { | ||
BeanManager beanManager = container.beanManager(); | ||
if (beanManager != null) { | ||
beanManager.getEvent().select(clazz).fire(event); | ||
} | ||
} | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...re/core/runtime/src/main/java/org/apache/camel/quarkus/core/events/ComponentAddEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.events; | ||
|
||
import org.apache.camel.Component; | ||
|
||
public class ComponentAddEvent extends ComponentEvent { | ||
public ComponentAddEvent(Component component) { | ||
super(component); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/events/ComponentEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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.events; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.Component; | ||
import org.apache.camel.spi.CamelEvent; | ||
|
||
public class ComponentEvent implements CamelEvent.CamelContextEvent { | ||
private final Component component; | ||
|
||
public ComponentEvent(Component component) { | ||
this.component = component; | ||
} | ||
|
||
@Override | ||
public CamelContext getContext() { | ||
return this.component.getCamelContext(); | ||
} | ||
|
||
public Component getComponent() { | ||
return this.component; | ||
} | ||
|
||
public <T extends Component> T getComponent(Class<T> type) { | ||
return type.cast(this.component); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.Custom; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...core/runtime/src/main/java/org/apache/camel/quarkus/core/events/ComponentRemoveEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.events; | ||
|
||
import org.apache.camel.Component; | ||
|
||
public class ComponentRemoveEvent extends ComponentEvent { | ||
public ComponentRemoveEvent(Component component) { | ||
super(component); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ore/core/runtime/src/main/java/org/apache/camel/quarkus/core/events/EndpointAddEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.events; | ||
|
||
import org.apache.camel.Endpoint; | ||
|
||
public class EndpointAddEvent extends EndpointEvent { | ||
public EndpointAddEvent(Endpoint endpoint) { | ||
super(endpoint); | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
...s-core/core/runtime/src/main/java/org/apache/camel/quarkus/core/events/EndpointEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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.events; | ||
|
||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.Endpoint; | ||
import org.apache.camel.spi.CamelEvent; | ||
|
||
public class EndpointEvent implements CamelEvent.CamelContextEvent { | ||
private final Endpoint endpoint; | ||
|
||
public EndpointEvent(Endpoint endpoint) { | ||
this.endpoint = endpoint; | ||
} | ||
|
||
@Override | ||
public CamelContext getContext() { | ||
return this.endpoint.getCamelContext(); | ||
} | ||
|
||
public Endpoint getEndpoint() { | ||
return this.endpoint; | ||
} | ||
|
||
public <T extends Endpoint> T getEndpoint(Class<T> type) { | ||
return type.cast(this.endpoint); | ||
} | ||
|
||
@Override | ||
public Type getType() { | ||
return Type.Custom; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../core/runtime/src/main/java/org/apache/camel/quarkus/core/events/EndpointRemoveEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* 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.events; | ||
|
||
import org.apache.camel.Endpoint; | ||
|
||
public class EndpointRemoveEvent extends EndpointEvent { | ||
public EndpointRemoveEvent(Endpoint endpoint) { | ||
super(endpoint); | ||
} | ||
} |