DockerCluster(DiscoveryStorageImpl storage, DockerClusterConfig config) { super(config, storage, Collections.singleton(Feature.SWARM_MODE)); long cacheTimeAfterWrite = config.getConfig().getCacheTimeAfterWrite(); nodesMap = SingleValueCache.builder(this::loadNodesMap) .timeAfterWrite(cacheTimeAfterWrite) .nullStrategy(SingleValueCache.NullStrategy.DIRTY) .build(); this.scheduledExecutor = Executors.newSingleThreadScheduledExecutor(new ThreadFactoryBuilder() .setDaemon(true) .setNameFormat(getClass().getSimpleName() + "-" + getName() + "-%d") .build()); this.rereadNodesTask = RescheduledTask.builder() .runnable(this::rereadNodes) .service(this.scheduledExecutor) .maxDelay(10L, TimeUnit.SECONDS) .build(); }
@SuppressWarnings("unchecked") public DockerServiceImpl(Builder b) { this.node = b.getNode(); this.cluster = b.getCluster(); // != below is not an error because we check that them both is not null Assert.isTrue((this.node == null || this.cluster == null) && this.node != this.cluster, "Invalid config of service: cluster=" + this.cluster + " node=" + node + " service must has only one non null value."); this.id = DockerService.super.getId();//cache id this.clusterConfig = ClusterConfigImpl.of(b.config).validate(); this.restTemplate = b.restTemplate; Assert.notNull(this.restTemplate, "restTemplate is null"); this.nodeInfoProvider = b.nodeInfoProvider; Assert.notNull(this.nodeInfoProvider, "nodeInfoProvider is null"); this.eventConsumer = b.eventConsumer; Assert.notNull(this.eventConsumer, "eventConsumer is null"); this.infoInterceptor = b.infoInterceptor; this.objectMapper = b.objectMapper; Assert.notNull(this.objectMapper, "objectMapper is null"); this.uri = createUri(); this.maxTimeout = Math.max(TimeUnit.SECONDS.toMillis(clusterConfig.getDockerTimeout()), FAST_TIMEOUT * 10); this.infoCache = SingleValueCache.builder(this::getInfoForCache) .timeAfterWrite(TimeUnit.SECONDS, this.clusterConfig.getCacheTimeAfterWrite()) .build(); }
public SearchIndex(RegistryService service, Config config) { this.service = service; this.registryName = this.service.getConfig().getName(); this.ses = config.getScheduledExecutorService(); this.timeout = TimeUnit.MINUTES.toMillis(config.cacheMinutes); this.cache = SingleValueCache.builder(this::load).timeAfterWrite(TimeUnit.MILLISECONDS, getTimeout()).build(); }
public NetworkManager(AbstractNodesGroup<?> group) { this.group = group; this.networksCache = SingleValueCache.builder(this::loadNetworks) .timeAfterWrite(TimeUnit.MINUTES, 5L) .build(); }
DockerClusterContainers(DockerCluster dc, ContainerStorage containerStorage, ContainerCreator containerCreator) { this.dc = dc; this.containerStorage = containerStorage; this.containerCreator = containerCreator; this.svcmap = SingleValueCache.builder(this::loadServices) .timeAfterWrite(TimeUnit.SECONDS, dc.getConfig().getConfig().getCacheTimeAfterWrite()) .build(); this.tasksmap = SingleValueCache.builder(this::loadTasks) .timeAfterWrite(TimeUnit.SECONDS, dc.getConfig().getConfig().getCacheTimeAfterWrite()) .build(); }