Class DefaultServiceRegistry
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.service.ServiceRegistry
services.moleculer.service.DefaultServiceRegistry
- All Implemented Interfaces:
MetricConstants, MoleculerLifecycle
Default implementation of the Service Registry.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanInvoke all local services via Thread pool (true) or directly (false)protected FastBuildTreeprotected final AtomicReference<ScheduledFuture<?>> Cancelable timer for handling timeouts of action callsprotected booleanCheck protocol versionprotected MetricCounterprotected Eventbusprotected ExecutorServiceprotected MetricGaugeprotected MetricGaugeprotected Metricsprotected final LinkedHashSet<Middleware> protected Stringprotected final AtomicLongNext scheduled time to check timeoutsprotected final ConcurrentHashMap<String, PendingPromise> protected StringServiceBroker's protocol version.protected final ReentrantReadWriteLock.ReadLockprotected final ReentrantReadWriteLock.ReadLockprotected final HashMap<String, IncomingStream> protected final ReentrantReadWriteLock.WriteLockprotected final ReentrantReadWriteLock.ReadLockprotected final HashMap<String, IncomingStream> protected final ReentrantReadWriteLock.WriteLockprotected ScheduledExecutorServiceprotected ServiceInvokerprotected final LinkedList<ServiceListener> Promises of the "waitingForServices" callsprotected final LinkedHashMap<String, Service> protected ScheduledFuture<?> Cancelable timer for handling "wait for service" callsprotected final HashMap<String, Strategy<ActionEndpoint>> protected StrategyFactoryprotected longStream inactivity/read timeout in MILLISECONDS (0 = no timeout).protected AtomicLongTimestamp of the service descriptor of this Moleculer Node (~= "generated at" timestamp)protected Transporterprotected UidGeneratorprotected booleanWrite exceptions into the log fileprotected final ReentrantReadWriteLock.WriteLockprotected booleanWrite Service and Action registrations into the log fileFields inherited from class MoleculerComponent
broker, logger, nameFields inherited from interface MetricConstants
MOLECULER_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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddActions(String nodeID, io.datatree.Tree config) io.datatree.PromiseaddActions(String serviceName, Service service) protected voidaddOnlineActions(String serviceName, Service service) protected voidbroadcastServicesChanged(boolean local) protected voidprotected voidprotected voidprotected intcountOnlineServices(Collection<String> requiredServices) protected io.datatree.Treeprotected voidderegister(String id) io.datatree.TreegetService(String name) longlongbooleanbooleanprotected booleanisServicesOnline(Collection<String> requiredServices) booleanbooleanprotected voidlogUnableToInvokeAction(String action, Throwable cause) io.datatree.PromisevoidreceivePong(io.datatree.Tree message) voidreceiveRequest(io.datatree.Tree message) voidreceiveResponse(io.datatree.Tree message) protected voidregister(String id, io.datatree.Promise promise, long timeoutAt, String nodeID, String action, io.datatree.Tree req) voidremoveActions(String nodeID) protected voidreschedule(long minTimeoutAt) Recalculates the next timeout checking time.voidsetAsyncLocalInvocation(boolean asyncLocalInvocation) voidsetCheckVersion(boolean checkVersion) voidsetStreamTimeout(long streamTimeout) voidsetWriteErrorsToLog(boolean writeErrorsToLog) voidsetWriteRegistrations(boolean writeRegistrations) voidstarted(ServiceBroker broker) Initializes ServiceRegistry instance.protected voidvoidstopped()voiduse(Collection<Middleware> middlewares) io.datatree.PromisewaitForServices(long timeoutMillis, Collection<String> services) Methods inherited from class MoleculerComponent
getBroker, getLogger, getName
-
Field Details
-
middlewares
-
services
-
strategies
-
names
-
promises
-
requestStreams
-
responseStreams
-
readLock
-
writeLock
-
requestStreamReadLock
-
requestStreamWriteLock
-
responseStreamReadLock
-
responseStreamWriteLock
-
asyncLocalInvocation
protected boolean asyncLocalInvocationInvoke all local services via Thread pool (true) or directly (false) -
checkVersion
protected boolean checkVersionCheck protocol version -
protocolVersion
ServiceBroker's protocol version. Placeholder only: overwritten instarted(broker)frombroker.getProtocolVersion(). The authoritative default lives inServiceBrokerConfig.DEFAULT_PROTOCOL_VERSION("5"). -
writeErrorsToLog
protected boolean writeErrorsToLogWrite exceptions into the log file -
writeRegistrations
protected boolean writeRegistrationsWrite Service and Action registrations into the log file -
streamTimeout
protected long streamTimeoutStream inactivity/read timeout in MILLISECONDS (0 = no timeout). It may be useful if you want to remove the wrong packages from the memory. -
nodeID
-
executor
-
scheduler
-
strategyFactory
-
transporter
-
eventbus
-
uidGenerator
-
serviceInvoker
-
metrics
-
callTimeoutTimer
Cancelable timer for handling timeouts of action calls -
prevTimeoutAt
Next scheduled time to check timeouts -
servicesOnlineTimer
Cancelable timer for handling "wait for service" calls -
serviceListeners
Promises of the "waitingForServices" calls -
timestamp
Timestamp of the service descriptor of this Moleculer Node (~= "generated at" timestamp) -
cachedDescriptor
-
gaugeRequestsActive
-
gaugeStreamsReceiveActive
-
counterOrphanResponseTotal
-
-
Constructor Details
-
DefaultServiceRegistry
public DefaultServiceRegistry() -
DefaultServiceRegistry
public DefaultServiceRegistry(boolean asyncLocalInvocation)
-
-
Method Details
-
started
Initializes ServiceRegistry instance.- Specified by:
startedin interfaceMoleculerLifecycle- Overrides:
startedin classMoleculerComponent- Parameters:
broker- parent ServiceBroker- Throws:
Exception
-
stopped
public void stopped()- Specified by:
stoppedin interfaceMoleculerLifecycle- Overrides:
stoppedin classMoleculerComponent
-
checkTimeouts
protected void checkTimeouts() -
reschedule
protected void reschedule(long minTimeoutAt) Recalculates the next timeout checking time.- Parameters:
minTimeoutAt- next / closest timestamp
-
register
-
deregister
-
receiveRequest
public void receiveRequest(io.datatree.Tree message) - Specified by:
receiveRequestin classServiceRegistry
-
logUnableToInvokeAction
-
receivePong
public void receivePong(io.datatree.Tree message) - Specified by:
receivePongin classServiceRegistry
-
receiveResponse
public void receiveResponse(io.datatree.Tree message) - Specified by:
receiveResponsein classServiceRegistry
-
use
- Specified by:
usein classServiceRegistry
-
addActions
- Specified by:
addActionsin classServiceRegistry
-
addOnlineActions
-
broadcastServicesChanged
protected void broadcastServicesChanged(boolean local) -
addActions
- Specified by:
addActionsin classServiceRegistry
-
removeActions
- Specified by:
removeActionsin classServiceRegistry
-
stopAllLocalServices
protected void stopAllLocalServices() -
getService
- Specified by:
getServicein classServiceRegistry
-
getAction
- Specified by:
getActionin classServiceRegistry
-
waitForServices
- Specified by:
waitForServicesin classServiceRegistry
-
checkServicesOnline
protected void checkServicesOnline() -
isServicesOnline
-
countOnlineServices
-
ping
- Specified by:
pingin classServiceRegistry
-
getTimestamp
public long getTimestamp()- Specified by:
getTimestampin classServiceRegistry
-
getDescriptor
public io.datatree.Tree getDescriptor()- Specified by:
getDescriptorin classServiceRegistry
-
clearDescriptorCache
protected void clearDescriptorCache() -
currentDescriptor
protected io.datatree.Tree currentDescriptor() -
isCheckVersion
public boolean isCheckVersion() -
setCheckVersion
public void setCheckVersion(boolean checkVersion) -
isAsyncLocalInvocation
public boolean isAsyncLocalInvocation() -
setAsyncLocalInvocation
public void setAsyncLocalInvocation(boolean asyncLocalInvocation) -
isWriteErrorsToLog
public boolean isWriteErrorsToLog() -
setWriteErrorsToLog
public void setWriteErrorsToLog(boolean writeErrorsToLog) -
getStreamTimeout
public long getStreamTimeout() -
setStreamTimeout
public void setStreamTimeout(long streamTimeout) -
isWriteRegistrations
public boolean isWriteRegistrations() -
setWriteRegistrations
public void setWriteRegistrations(boolean writeRegistrations)
-