Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (C) 2015 SoftIndex LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.datakernel.service;
import com.google.inject.*;
import com.google.inject.matcher.AbstractMatcher;
import com.google.inject.spi.Dependency;
import com.google.inject.spi.DependencyAndSource;
import com.google.inject.spi.HasDependencies;
import com.google.inject.spi.ProvisionListener;
import io.datakernel.eventloop.Eventloop;
import io.datakernel.eventloop.EventloopServer;
import io.datakernel.eventloop.EventloopService;
import io.datakernel.net.BlockingSocketServer;
import io.datakernel.util.Initializable;
import io.datakernel.util.Initializer;
import io.datakernel.util.guice.GuiceUtils;
import io.datakernel.util.guice.OptionalInitializer;
import io.datakernel.worker.Worker;
import io.datakernel.worker.WorkerPoolModule;
import io.datakernel.worker.WorkerPools;
import org.slf4j.Logger;
import javax.sql.DataSource;
import java.io.Closeable;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import static io.datakernel.service.ServiceAdapters.*;
import static io.datakernel.util.CollectionUtils.*;
import static io.datakernel.util.Preconditions.checkNotNull;
import static io.datakernel.util.Preconditions.checkState;
import static java.util.Collections.emptySet;
import static java.util.concurrent.CompletableFuture.completedFuture;
import static org.slf4j.LoggerFactory.getLogger;
/**
* Builds dependency graph of {@code Service} objects based on Guice's object
* graph. Service graph module is capable to start services concurrently.
*
* Consider some lifecycle details of this module:
*
*
* Put all objects from the graph which can be treated as
* {@link Service} instances.
*
*
* Starts services concurrently starting at leaf graph nodes (independent
* services) and ending with root nodes.
*
*
* Stop services starting from root and ending with independent services.
*
*
*
* An ability to use {@link ServiceAdapter} objects allows to create a service
* from any object by providing it's {@link ServiceAdapter} and registering
* it in {@code ServiceGraphModule}. Take a look at {@link ServiceAdapters},
* which has a lot of implemented adapters. Its necessarily to annotate your
* object provider with {@link Worker @Worker} or {@link Singleton @Singleton}
* annotation.
*
* An application terminates if a circular dependency found.
*/
public final class ServiceGraphModule extends AbstractModule implements Initializable {
private final Logger logger = getLogger(this.getClass());
private final Map, ServiceAdapter>> registeredServiceAdapters = new LinkedHashMap<>();
private final Set> excludedKeys = new LinkedHashSet<>();
private final Map, ServiceAdapter>> keys = new LinkedHashMap<>();
private final Map, Set>> addedDependencies = new HashMap<>();
private final Map, Set>> removedDependencies = new HashMap<>();
private final Set> singletonKeys = new HashSet<>();
private final Set> workerKeys = new HashSet<>();
private final Map, Set>> workerDependencies = new HashMap<>();
private final IdentityHashMap