Class CpuUsageStrategyFactory
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.strategy.StrategyFactory
services.moleculer.strategy.ArrayBasedStrategyFactory
services.moleculer.strategy.CpuUsageStrategyFactory
- All Implemented Interfaces:
MoleculerLifecycle
Factory of lowest CPU usage strategy. This strategy comes from a random
strategy, but preferably communicates with the "least loaded" nodes (nodes
with the lowest CPU usage).
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intlowCpuUsage ~= zero CPU usageprotected intThis strategy compares number of 'sampleCount' random node.protected TransporterFields inherited from class ArrayBasedStrategyFactory
preferLocalFields inherited from class MoleculerComponent
broker, logger, name -
Constructor Summary
ConstructorsConstructorDescriptionConstructor that calls for service based primarily on its own (CPU-based) logic.CpuUsageStrategyFactory(boolean preferLocal) Constructor that can be configured to use local services if possible.CpuUsageStrategyFactory(boolean preferLocal, int sampleCount, int lowCpuUsage) -
Method Summary
Modifier and TypeMethodDescriptioncreate()intintvoidsetLowCpuUsage(int lowCpuUsage) voidsetSampleCount(int sampleCount) voidstarted(ServiceBroker broker) Initializes strategy instance.Methods inherited from class ArrayBasedStrategyFactory
isPreferLocal, setPreferLocalMethods inherited from class MoleculerComponent
getBroker, getLogger, getName, stopped
-
Field Details
-
sampleCount
protected int sampleCountThis strategy compares number of 'sampleCount' random node. -
lowCpuUsage
protected int lowCpuUsagelowCpuUsage ~= zero CPU usage -
transporter
-
-
Constructor Details
-
CpuUsageStrategyFactory
public CpuUsageStrategyFactory()Constructor that calls for service based primarily on its own (CPU-based) logic. Does not matter if the service is available locally. -
CpuUsageStrategyFactory
public CpuUsageStrategyFactory(boolean preferLocal) Constructor that can be configured to use local services if possible.- Parameters:
preferLocal- invoke local actions if possible
-
CpuUsageStrategyFactory
public CpuUsageStrategyFactory(boolean preferLocal, int sampleCount, int lowCpuUsage)
-
-
Method Details
-
started
Initializes strategy instance.- Specified by:
startedin interfaceMoleculerLifecycle- Overrides:
startedin classMoleculerComponent- Parameters:
broker- parent ServiceBroker- Throws:
Exception
-
create
- Specified by:
createin classStrategyFactory
-
getSampleCount
public int getSampleCount() -
setSampleCount
public void setSampleCount(int sampleCount) -
getLowCpuUsage
public int getLowCpuUsage() -
setLowCpuUsage
public void setLowCpuUsage(int lowCpuUsage)
-