public class DefaultServiceRegistry extends ServiceRegistry implements MetricConstants
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
asyncLocalInvocation
Invoke all local services via Thread pool (true) or directly (false)
|
protected FastBuildTree |
cachedDescriptor |
protected java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledFuture<?>> |
callTimeoutTimer
Cancelable timer for handling timeouts of action calls
|
protected boolean |
checkVersion
Check protocol version
|
protected MetricCounter |
counterOrphanResponseTotal |
protected Eventbus |
eventbus |
protected java.util.concurrent.ExecutorService |
executor |
protected MetricGauge |
gaugeRequestsActive |
protected MetricGauge |
gaugeStreamsReceiveActive |
protected Metrics |
metrics |
protected java.util.LinkedHashSet<Middleware> |
middlewares |
protected java.util.HashSet<java.lang.String> |
names |
protected java.lang.String |
nodeID |
protected java.util.concurrent.atomic.AtomicLong |
prevTimeoutAt
Next scheduled time to check timeouts
|
protected java.util.concurrent.ConcurrentHashMap<java.lang.String,PendingPromise> |
promises |
protected java.lang.String |
protocolVersion
ServiceBroker's protocol version
|
protected java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock |
readLock |
protected java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock |
requestStreamReadLock |
protected java.util.HashMap<java.lang.String,IncomingStream> |
requestStreams |
protected java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
requestStreamWriteLock |
protected java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock |
responseStreamReadLock |
protected java.util.HashMap<java.lang.String,IncomingStream> |
responseStreams |
protected java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
responseStreamWriteLock |
protected java.util.concurrent.ScheduledExecutorService |
scheduler |
protected ServiceInvoker |
serviceInvoker |
protected java.util.LinkedList<ServiceListener> |
serviceListeners
Promises of the "waitingForServices" calls
|
protected java.util.LinkedHashMap<java.lang.String,Service> |
services |
protected java.util.concurrent.ScheduledFuture<?> |
servicesOnlineTimer
Cancelable timer for handling "wait for service" calls
|
protected java.util.HashMap<java.lang.String,Strategy<ActionEndpoint>> |
strategies |
protected StrategyFactory |
strategyFactory |
protected long |
streamTimeout
Stream inactivity/read timeout in MILLISECONDS (0 = no timeout).
|
protected java.util.concurrent.atomic.AtomicLong |
timestamp
Timestamp of the service descriptor of this Moleculer Node (~=
"generated at" timestamp)
|
protected Transporter |
transporter |
protected UidGenerator |
uidGenerator |
protected boolean |
writeErrorsToLog
Write exceptions into the log file
|
protected java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock |
writeLock |
protected boolean |
writeRegistrations
Write Service and Action registrations into the log file
|
broker, logger, nameMOLECULER_CACHER_CLEAN_TIME, MOLECULER_CACHER_CLEAN_TIME_DESC, MOLECULER_CACHER_CLEAN_TOTAL, MOLECULER_CACHER_CLEAN_TOTAL_DESC, MOLECULER_CACHER_DEL_TIME, MOLECULER_CACHER_DEL_TIME_DESC, MOLECULER_CACHER_DEL_TOTAL, MOLECULER_CACHER_DEL_TOTAL_DESC, MOLECULER_CACHER_EXPIRED_TOTAL, MOLECULER_CACHER_EXPIRED_TOTAL_DESC, MOLECULER_CACHER_FOUND_TOTAL, MOLECULER_CACHER_FOUND_TOTAL_DESC, MOLECULER_CACHER_GET_TIME, MOLECULER_CACHER_GET_TIME_DESC, MOLECULER_CACHER_GET_TOTAL, MOLECULER_CACHER_GET_TOTAL_DESC, MOLECULER_CACHER_SET_TIME, MOLECULER_CACHER_SET_TIME_DESC, MOLECULER_CACHER_SET_TOTAL, MOLECULER_CACHER_SET_TOTAL_DESC, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_HALF_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE, MOLECULER_CIRCUIT_BREAKER_OPENED_ACTIVE_DESC, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL, MOLECULER_CIRCUIT_BREAKER_OPENED_TOTAL_DESC, MOLECULER_EVENT_BROADCAST_TOTAL, MOLECULER_EVENT_BROADCAST_TOTAL_DESC, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL, MOLECULER_EVENT_BROADCASTLOCAL_TOTAL_DESC, MOLECULER_EVENT_EMIT_TOTAL, MOLECULER_EVENT_EMIT_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_ACTIVE, MOLECULER_EVENT_RECEIVED_ACTIVE_DESC, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL, MOLECULER_EVENT_RECEIVED_ERROR_TOTAL_DESC, MOLECULER_EVENT_RECEIVED_TIME, MOLECULER_EVENT_RECEIVED_TIME_DESC, MOLECULER_EVENT_RECEIVED_TOTAL, MOLECULER_EVENT_RECEIVED_TOTAL_DESC, MOLECULER_EXECUTOR, MOLECULER_REQUEST_ACTIVE, MOLECULER_REQUEST_ACTIVE_DESC, MOLECULER_REQUEST_ERROR_TOTAL, MOLECULER_REQUEST_ERROR_TOTAL_DESC, MOLECULER_REQUEST_LEVELS, MOLECULER_REQUEST_LEVELS_DESC, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL, MOLECULER_REQUEST_RETRY_ATTEMPTS_TOTAL_DESC, MOLECULER_REQUEST_TIME, MOLECULER_REQUEST_TIME_DESC, MOLECULER_REQUEST_TIMEOUT_TOTAL, MOLECULER_REQUEST_TIMEOUT_TOTAL_DESC, MOLECULER_REQUEST_TOTAL, MOLECULER_REQUEST_TOTAL_DESC, MOLECULER_SCHEDULER, MOLECULER_TRANSIT_CONNECTED, MOLECULER_TRANSIT_CONNECTED_DESC, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL, MOLECULER_TRANSIT_ORPHAN_RESPONSE_TOTAL_DESC, MOLECULER_TRANSIT_REQUESTS_ACTIVE, MOLECULER_TRANSIT_REQUESTS_ACTIVE_DESC, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE, MOLECULER_TRANSIT_STREAMS_RECEIVE_ACTIVE_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL, MOLECULER_TRANSPORTER_PACKETS_RECEIVED_TOTAL_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES, MOLECULER_TRANSPORTER_PACKETS_SENT_BYTES_DESC, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL, MOLECULER_TRANSPORTER_PACKETS_SENT_TOTAL_DESC| Constructor and Description |
|---|
DefaultServiceRegistry() |
DefaultServiceRegistry(boolean asyncLocalInvocation) |
| Modifier and Type | Method and Description |
|---|---|
io.datatree.Promise |
addActions(java.lang.String serviceName,
Service service) |
void |
addActions(java.lang.String nodeID,
io.datatree.Tree config) |
protected void |
addOnlineActions(java.lang.String serviceName,
Service service) |
protected void |
broadcastServicesChanged(boolean local) |
protected void |
checkServicesOnline() |
protected void |
checkTimeouts() |
protected void |
clearDescriptorCache() |
protected int |
countOnlineServices(java.util.Collection<java.lang.String> requiredServices) |
protected io.datatree.Tree |
currentDescriptor() |
protected void |
deregister(java.lang.String id) |
Action |
getAction(java.lang.String name,
java.lang.String nodeID) |
io.datatree.Tree |
getDescriptor() |
Service |
getService(java.lang.String name) |
long |
getStreamTimeout() |
long |
getTimestamp() |
boolean |
isAsyncLocalInvocation() |
boolean |
isCheckVersion() |
protected boolean |
isServicesOnline(java.util.Collection<java.lang.String> requiredServices) |
boolean |
isWriteErrorsToLog() |
boolean |
isWriteRegistrations() |
protected void |
logUnableToInvokeAction(java.lang.String action,
java.lang.Throwable cause) |
io.datatree.Promise |
ping(long timeoutMillis,
java.lang.String nodeID) |
void |
receivePong(io.datatree.Tree message) |
void |
receiveRequest(io.datatree.Tree message) |
void |
receiveResponse(io.datatree.Tree message) |
protected void |
register(java.lang.String id,
io.datatree.Promise promise,
long timeoutAt,
java.lang.String nodeID,
java.lang.String action,
io.datatree.Tree req) |
void |
removeActions(java.lang.String nodeID) |
protected void |
reschedule(long minTimeoutAt)
Recalculates the next timeout checking time.
|
void |
setAsyncLocalInvocation(boolean asyncLocalInvocation) |
void |
setCheckVersion(boolean checkVersion) |
void |
setStreamTimeout(long streamTimeout) |
void |
setWriteErrorsToLog(boolean writeErrorsToLog) |
void |
setWriteRegistrations(boolean writeRegistrations) |
void |
started(ServiceBroker broker)
Initializes ServiceRegistry instance.
|
protected void |
stopAllLocalServices() |
void |
stopped() |
void |
use(java.util.Collection<Middleware> middlewares) |
io.datatree.Promise |
waitForServices(long timeoutMillis,
java.util.Collection<java.lang.String> services) |
getBroker, getLogger, getNameprotected final java.util.LinkedHashSet<Middleware> middlewares
protected final java.util.LinkedHashMap<java.lang.String,Service> services
protected final java.util.HashMap<java.lang.String,Strategy<ActionEndpoint>> strategies
protected final java.util.HashSet<java.lang.String> names
protected final java.util.concurrent.ConcurrentHashMap<java.lang.String,PendingPromise> promises
protected final java.util.HashMap<java.lang.String,IncomingStream> requestStreams
protected final java.util.HashMap<java.lang.String,IncomingStream> responseStreams
protected final java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock readLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock writeLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock requestStreamReadLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock requestStreamWriteLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock responseStreamReadLock
protected final java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock responseStreamWriteLock
protected boolean asyncLocalInvocation
protected boolean checkVersion
protected java.lang.String protocolVersion
protected boolean writeErrorsToLog
protected boolean writeRegistrations
protected long streamTimeout
protected java.lang.String nodeID
protected java.util.concurrent.ExecutorService executor
protected java.util.concurrent.ScheduledExecutorService scheduler
protected StrategyFactory strategyFactory
protected Transporter transporter
protected Eventbus eventbus
protected UidGenerator uidGenerator
protected ServiceInvoker serviceInvoker
protected Metrics metrics
protected final java.util.concurrent.atomic.AtomicReference<java.util.concurrent.ScheduledFuture<?>> callTimeoutTimer
protected final java.util.concurrent.atomic.AtomicLong prevTimeoutAt
protected java.util.concurrent.ScheduledFuture<?> servicesOnlineTimer
protected final java.util.LinkedList<ServiceListener> serviceListeners
protected java.util.concurrent.atomic.AtomicLong timestamp
protected volatile FastBuildTree cachedDescriptor
protected MetricGauge gaugeRequestsActive
protected MetricGauge gaugeStreamsReceiveActive
protected MetricCounter counterOrphanResponseTotal
public DefaultServiceRegistry()
public DefaultServiceRegistry(boolean asyncLocalInvocation)
public void started(ServiceBroker broker) throws java.lang.Exception
started in interface MoleculerLifecyclestarted in class MoleculerComponentbroker - parent ServiceBrokerjava.lang.Exceptionpublic void stopped()
stopped in interface MoleculerLifecyclestopped in class MoleculerComponentprotected void checkTimeouts()
protected void reschedule(long minTimeoutAt)
minTimeoutAt - next / closest timestampprotected void register(java.lang.String id,
io.datatree.Promise promise,
long timeoutAt,
java.lang.String nodeID,
java.lang.String action,
io.datatree.Tree req)
protected void deregister(java.lang.String id)
public void receiveRequest(io.datatree.Tree message)
receiveRequest in class ServiceRegistryprotected void logUnableToInvokeAction(java.lang.String action,
java.lang.Throwable cause)
public void receivePong(io.datatree.Tree message)
receivePong in class ServiceRegistrypublic void receiveResponse(io.datatree.Tree message)
receiveResponse in class ServiceRegistrypublic void use(java.util.Collection<Middleware> middlewares)
use in class ServiceRegistrypublic io.datatree.Promise addActions(java.lang.String serviceName,
Service service)
addActions in class ServiceRegistryprotected void addOnlineActions(java.lang.String serviceName,
Service service)
protected void broadcastServicesChanged(boolean local)
public void addActions(java.lang.String nodeID,
io.datatree.Tree config)
addActions in class ServiceRegistrypublic void removeActions(java.lang.String nodeID)
removeActions in class ServiceRegistryprotected void stopAllLocalServices()
public Service getService(java.lang.String name)
getService in class ServiceRegistrypublic Action getAction(java.lang.String name, java.lang.String nodeID)
getAction in class ServiceRegistrypublic io.datatree.Promise waitForServices(long timeoutMillis,
java.util.Collection<java.lang.String> services)
waitForServices in class ServiceRegistryprotected void checkServicesOnline()
protected boolean isServicesOnline(java.util.Collection<java.lang.String> requiredServices)
protected int countOnlineServices(java.util.Collection<java.lang.String> requiredServices)
public io.datatree.Promise ping(long timeoutMillis,
java.lang.String nodeID)
ping in class ServiceRegistrypublic long getTimestamp()
getTimestamp in class ServiceRegistrypublic io.datatree.Tree getDescriptor()
getDescriptor in class ServiceRegistryprotected void clearDescriptorCache()
protected io.datatree.Tree currentDescriptor()
public boolean isCheckVersion()
public void setCheckVersion(boolean checkVersion)
public boolean isAsyncLocalInvocation()
public void setAsyncLocalInvocation(boolean asyncLocalInvocation)
public boolean isWriteErrorsToLog()
public void setWriteErrorsToLog(boolean writeErrorsToLog)
public long getStreamTimeout()
public void setStreamTimeout(long streamTimeout)
public boolean isWriteRegistrations()
public void setWriteRegistrations(boolean writeRegistrations)