camel-cluster-service: add a way to unwrap the service/view to the concrete underlying implementation to access additional features
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3768550b Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3768550b Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3768550b Branch: refs/heads/master Commit: 3768550ba9c56e1b6a5115c76b86a0ab5c0ff1bb Parents: 733b1d4 Author: lburgazzoli <lburgazz...@gmail.com> Authored: Mon Jun 19 11:43:03 2017 +0200 Committer: lburgazzoli <lburgazz...@gmail.com> Committed: Mon Jun 19 11:43:03 2017 +0200 ---------------------------------------------------------------------- .../apache/camel/ha/CamelClusterService.java | 21 ++++++++++++++++++++ .../org/apache/camel/ha/CamelClusterView.java | 17 ++++++++++++++++ .../camel/impl/ha/AbstractCamelClusterView.java | 6 +++--- 3 files changed, 41 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/3768550b/camel-core/src/main/java/org/apache/camel/ha/CamelClusterService.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/ha/CamelClusterService.java b/camel-core/src/main/java/org/apache/camel/ha/CamelClusterService.java index 7dd12f3..bccad85 100644 --- a/camel-core/src/main/java/org/apache/camel/ha/CamelClusterService.java +++ b/camel-core/src/main/java/org/apache/camel/ha/CamelClusterService.java @@ -21,12 +21,33 @@ import org.apache.camel.Service; import org.apache.camel.spi.IdAware; public interface CamelClusterService extends Service, CamelContextAware, IdAware { + /** * Get a view of the cluster bound to a namespace creating it if needed. * + * Multiple calls to this method with the same namespace should return the + * same instance. + * * @param namespace the namespace the view refer to. * @return the view. * @throws Exception if the view can't be created. */ CamelClusterView getView(String namespace) throws Exception; + + /** + * Access the underlying concrete CamelClusterService implementation to + * provide access to further features. + * + * @param clazz the proprietary class or interface of the underlying concrete CamelClusterService. + * @return an instance of the underlying concrete CamelClusterService as the required type. + */ + default <T> T unwrap(Class<T> clazz) { + if (CamelClusterService.class.isAssignableFrom(clazz)) { + return clazz.cast(this); + } + + throw new IllegalArgumentException( + "Unable to unwrap this CamelClusterService type (" + getClass() + ") to the required type (" + clazz + ")" + ); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/3768550b/camel-core/src/main/java/org/apache/camel/ha/CamelClusterView.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/ha/CamelClusterView.java b/camel-core/src/main/java/org/apache/camel/ha/CamelClusterView.java index 893ba4c..7983fca 100644 --- a/camel-core/src/main/java/org/apache/camel/ha/CamelClusterView.java +++ b/camel-core/src/main/java/org/apache/camel/ha/CamelClusterView.java @@ -70,4 +70,21 @@ public interface CamelClusterView extends Service, CamelContextAware { * @param listener the event listener. */ void removeEventListener(CameClusterEventListener listener); + + /** + * Access the underlying concrete CamelClusterView implementation to + * provide access to further features. + * + * @param clazz the proprietary class or interface of the underlying concrete CamelClusterView. + * @return an instance of the underlying concrete CamelClusterView as the required type. + */ + default <T> T unwrap(Class<T> clazz) { + if (CamelClusterView.class.isAssignableFrom(clazz)) { + return clazz.cast(this); + } + + throw new IllegalArgumentException( + "Unable to unwrap this CamelClusterView type (" + getClass() + ") to the required type (" + clazz + ")" + ); + } } http://git-wip-us.apache.org/repos/asf/camel/blob/3768550b/camel-core/src/main/java/org/apache/camel/impl/ha/AbstractCamelClusterView.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/ha/AbstractCamelClusterView.java b/camel-core/src/main/java/org/apache/camel/impl/ha/AbstractCamelClusterView.java index b2cbe11..f5a2c8c 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/ha/AbstractCamelClusterView.java +++ b/camel-core/src/main/java/org/apache/camel/impl/ha/AbstractCamelClusterView.java @@ -30,14 +30,14 @@ import org.apache.camel.support.ServiceSupport; import org.apache.camel.util.concurrent.LockHelper; public abstract class AbstractCamelClusterView extends ServiceSupport implements CamelClusterView { - private final CamelClusterService cluster; + private final CamelClusterService clusterService; private final String namespace; private final List<CameClusterEventListener> listeners; private final StampedLock lock; private CamelContext camelContext; protected AbstractCamelClusterView(CamelClusterService cluster, String namespace) { - this.cluster = cluster; + this.clusterService = cluster; this.namespace = namespace; this.listeners = new ArrayList<>(); this.lock = new StampedLock(); @@ -55,7 +55,7 @@ public abstract class AbstractCamelClusterView extends ServiceSupport implements @Override public CamelClusterService getClusterService() { - return this.cluster; + return this.clusterService; } @Override