public class DefaultServiceRegistry extends ServiceRegistry
| Modifier and Type | Field and Description |
|---|---|
protected boolean |
asyncLocalInvocation
Invoke all local services via Thread pool (true) or directly (false)
|
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 Eventbus |
eventbus |
protected java.util.concurrent.ExecutorService |
executor |
protected java.util.concurrent.locks.StampedLock |
lock |
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.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 Transporter |
transporter |
protected UidGenerator |
uidGenerator |
protected boolean |
writeErrorsToLog
Write exceptions into the log file
|
broker, logger, name| Constructor and Description |
|---|
DefaultServiceRegistry() |
DefaultServiceRegistry(boolean asyncLocalInvocation) |
| Modifier and Type | Method and Description |
|---|---|
void |
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() |
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 |
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 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 boolean writeErrorsToLog
protected long streamTimeout
protected final java.util.concurrent.locks.StampedLock lock
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 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
public DefaultServiceRegistry()
public DefaultServiceRegistry(boolean asyncLocalInvocation)
public void started(ServiceBroker broker) throws java.lang.Exception
started in class MoleculerComponentbroker - parent ServiceBrokerjava.lang.Exceptionpublic void stopped()
stopped 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 ServiceRegistrypublic 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 void 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)