Package org.apache.camel.support.cluster
Class RebalancingCamelClusterService
- java.lang.Object
-
- org.apache.camel.support.cluster.RebalancingCamelClusterService
-
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.CamelContextAware
,org.apache.camel.cluster.CamelClusterService
,org.apache.camel.cluster.CamelPreemptiveClusterService
,org.apache.camel.Ordered
,org.apache.camel.Service
,org.apache.camel.spi.HasId
,org.apache.camel.spi.IdAware
public class RebalancingCamelClusterService extends Object implements org.apache.camel.cluster.CamelPreemptiveClusterService
ARebalancingCamelClusterService
adds rebalancing capabilities to an underlyingCamelPreemptiveClusterService
. Each view is treated as a partition by this cluster service and it makes sure that all services belonging to the cluster own a balanced number of partitions (same number or difference at most 1 when not possible).
-
-
Field Summary
Fields Modifier and Type Field Description protected org.apache.camel.CamelContext
camelContext
protected org.apache.camel.cluster.CamelPreemptiveClusterService
delegate
protected long
periodMillis
protected ScheduledExecutorService
serializedExecutor
-
Constructor Summary
Constructors Constructor Description RebalancingCamelClusterService(org.apache.camel.CamelContext camelContext, org.apache.camel.cluster.CamelPreemptiveClusterService delegate, long periodMillis)
RebalancingCamelClusterService(org.apache.camel.cluster.CamelPreemptiveClusterService delegate, long periodMillis)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.camel.CamelContext
getCamelContext()
org.apache.camel.cluster.CamelPreemptiveClusterService
getDelegate()
String
getId()
Collection<String>
getNamespaces()
long
getPeriodMillis()
org.apache.camel.cluster.CamelPreemptiveClusterView
getView(String namespace)
boolean
isLeader(String namespace)
protected Integer
members()
protected List<String>
owned(List<String> partitions)
protected List<String>
partitionList()
protected void
rebalanceGroup(List<String> partitions, int quota)
protected void
reconcile()
void
releaseView(org.apache.camel.cluster.CamelClusterView view)
void
setCamelContext(org.apache.camel.CamelContext camelContext)
void
setDelegate(org.apache.camel.cluster.CamelPreemptiveClusterService delegate)
protected void
setDisabled(String partition, boolean disabled)
void
setId(String id)
void
start()
void
startView(String namespace)
void
stop()
void
stopView(String namespace)
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Field Detail
-
serializedExecutor
protected ScheduledExecutorService serializedExecutor
-
delegate
protected org.apache.camel.cluster.CamelPreemptiveClusterService delegate
-
camelContext
protected org.apache.camel.CamelContext camelContext
-
periodMillis
protected long periodMillis
-
-
Constructor Detail
-
RebalancingCamelClusterService
public RebalancingCamelClusterService(org.apache.camel.cluster.CamelPreemptiveClusterService delegate, long periodMillis)
-
RebalancingCamelClusterService
public RebalancingCamelClusterService(org.apache.camel.CamelContext camelContext, org.apache.camel.cluster.CamelPreemptiveClusterService delegate, long periodMillis)
-
-
Method Detail
-
start
public void start()
- Specified by:
start
in interfaceorg.apache.camel.Service
-
stop
public void stop()
- Specified by:
stop
in interfaceorg.apache.camel.Service
-
getDelegate
public org.apache.camel.cluster.CamelPreemptiveClusterService getDelegate()
-
getPeriodMillis
public long getPeriodMillis()
-
setDelegate
public void setDelegate(org.apache.camel.cluster.CamelPreemptiveClusterService delegate)
-
reconcile
protected void reconcile()
-
setDisabled
protected void setDisabled(String partition, boolean disabled)
-
members
protected Integer members()
-
getView
public org.apache.camel.cluster.CamelPreemptiveClusterView getView(String namespace) throws Exception
- Specified by:
getView
in interfaceorg.apache.camel.cluster.CamelClusterService
- Specified by:
getView
in interfaceorg.apache.camel.cluster.CamelPreemptiveClusterService
- Throws:
Exception
-
releaseView
public void releaseView(org.apache.camel.cluster.CamelClusterView view) throws Exception
- Specified by:
releaseView
in interfaceorg.apache.camel.cluster.CamelClusterService
- Throws:
Exception
-
getNamespaces
public Collection<String> getNamespaces()
- Specified by:
getNamespaces
in interfaceorg.apache.camel.cluster.CamelClusterService
-
startView
public void startView(String namespace) throws Exception
- Specified by:
startView
in interfaceorg.apache.camel.cluster.CamelClusterService
- Throws:
Exception
-
stopView
public void stopView(String namespace) throws Exception
- Specified by:
stopView
in interfaceorg.apache.camel.cluster.CamelClusterService
- Throws:
Exception
-
isLeader
public boolean isLeader(String namespace)
- Specified by:
isLeader
in interfaceorg.apache.camel.cluster.CamelClusterService
-
setCamelContext
public void setCamelContext(org.apache.camel.CamelContext camelContext)
- Specified by:
setCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContext
in interfaceorg.apache.camel.CamelContextAware
-
setId
public void setId(String id)
- Specified by:
setId
in interfaceorg.apache.camel.spi.IdAware
-
getId
public String getId()
- Specified by:
getId
in interfaceorg.apache.camel.spi.HasId
-
-