public class NetworkLatencyStrategyFactory extends ArrayBasedStrategyFactory
Modifier and Type | Class and Description |
---|---|
protected static class |
NetworkLatencyStrategyFactory.Samples |
Modifier and Type | Field and Description |
---|---|
protected int |
collectCount
Number of samples used for average calculation.
|
protected java.lang.String |
nodeID |
protected int |
pingInterval
Ping period time, in SECONDS.
|
protected long |
pingTimeout
Ping timeout time, in MILLISECONDS.
|
protected java.util.concurrent.ScheduledFuture<?> |
pingTimer
Cancelable timer of ping loop
|
protected java.lang.String |
previousNodeID |
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,NetworkLatencyStrategyFactory.Samples> |
responseTimes |
protected int |
sampleCount
This strategy compares number of 'sampleCount' random node.
|
protected java.util.concurrent.ScheduledExecutorService |
scheduler |
protected Transporter |
transporter |
preferLocal
broker, logger, name
Constructor and Description |
---|
NetworkLatencyStrategyFactory()
Constructor that calls for service based primarily on its own
(latency-based) logic.
|
NetworkLatencyStrategyFactory(boolean preferLocal)
Constructor that can be configured to use local services if possible.
|
Modifier and Type | Method and Description |
---|---|
<T extends Endpoint> |
create() |
protected long |
getAverageResponseTime(java.lang.String nextNodeID) |
int |
getCollectCount() |
int |
getPingInterval() |
long |
getPingTimeout() |
int |
getSampleCount() |
protected void |
sendNextPing() |
protected void |
sendPing(java.lang.String nextNodeID) |
void |
setCollectCount(int collectCount) |
void |
setPingInterval(int pingInterval) |
void |
setPingTimeout(long pingTimeout) |
void |
setSampleCount(int sampleCount) |
void |
started(ServiceBroker broker)
Initializes strategy instance.
|
void |
stopped() |
isPreferLocal, setPreferLocal
getBroker, getLogger, getName
protected int sampleCount
protected int pingInterval
protected long pingTimeout
protected int collectCount
protected java.util.concurrent.ScheduledExecutorService scheduler
protected Transporter transporter
protected java.lang.String nodeID
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,NetworkLatencyStrategyFactory.Samples> responseTimes
protected volatile java.util.concurrent.ScheduledFuture<?> pingTimer
protected volatile java.lang.String previousNodeID
public NetworkLatencyStrategyFactory()
public NetworkLatencyStrategyFactory(boolean preferLocal)
preferLocal
- invoke local actions if possiblepublic void started(ServiceBroker broker) throws java.lang.Exception
started
in interface MoleculerLifecycle
started
in class MoleculerComponent
broker
- parent ServiceBrokerjava.lang.Exception
public void stopped()
stopped
in interface MoleculerLifecycle
stopped
in class MoleculerComponent
protected void sendNextPing()
protected void sendPing(java.lang.String nextNodeID)
protected long getAverageResponseTime(java.lang.String nextNodeID)
public <T extends Endpoint> Strategy<T> create()
create
in class StrategyFactory
public int getSampleCount()
public void setSampleCount(int sampleCount)
public int getPingInterval()
public void setPingInterval(int pingInterval)
public long getPingTimeout()
public void setPingTimeout(long pingTimeout)
public int getCollectCount()
public void setCollectCount(int collectCount)