diegosalvi commented on code in PR #3489:
URL: https://github.com/apache/bookkeeper/pull/3489#discussion_r1017763187


##########
bookkeeper-server/src/main/java/org/apache/bookkeeper/server/EmbeddedServer.java:
##########
@@ -0,0 +1,648 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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 org.apache.bookkeeper.server;
+
+import static com.google.common.base.Preconditions.checkNotNull;
+import static org.apache.bookkeeper.bookie.BookKeeperServerStats.BOOKIE_SCOPE;
+import static 
org.apache.bookkeeper.bookie.BookKeeperServerStats.LD_INDEX_SCOPE;
+import static 
org.apache.bookkeeper.bookie.BookKeeperServerStats.LD_LEDGER_SCOPE;
+import static org.apache.bookkeeper.client.BookKeeperClientStats.CLIENT_SCOPE;
+import static 
org.apache.bookkeeper.replication.ReplicationStats.REPLICATION_SCOPE;
+import static org.apache.bookkeeper.server.Main.storageDirectoriesFromConf;
+import static 
org.apache.bookkeeper.server.component.ServerLifecycleComponent.loadServerComponents;
+
+import com.google.common.base.Ticker;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.ByteBufAllocator;
+import io.netty.buffer.CompositeByteBuf;
+import io.reactivex.rxjava3.core.Scheduler;
+import io.reactivex.rxjava3.schedulers.Schedulers;
+import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.function.Consumer;
+import java.util.function.Supplier;
+import java.util.stream.Collectors;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.bookkeeper.bookie.Bookie;
+import org.apache.bookkeeper.bookie.BookieImpl;
+import org.apache.bookkeeper.bookie.BookieResources;
+import org.apache.bookkeeper.bookie.CookieValidation;
+import org.apache.bookkeeper.bookie.LedgerDirsManager;
+import org.apache.bookkeeper.bookie.LedgerStorage;
+import org.apache.bookkeeper.bookie.LegacyCookieValidation;
+import org.apache.bookkeeper.bookie.ReadOnlyBookie;
+import org.apache.bookkeeper.bookie.ScrubberStats;
+import org.apache.bookkeeper.bookie.UncleanShutdownDetection;
+import org.apache.bookkeeper.bookie.UncleanShutdownDetectionImpl;
+import org.apache.bookkeeper.bookie.datainteg.DataIntegrityCheck;
+import org.apache.bookkeeper.bookie.datainteg.DataIntegrityCheckImpl;
+import org.apache.bookkeeper.bookie.datainteg.DataIntegrityCookieValidation;
+import org.apache.bookkeeper.bookie.datainteg.DataIntegrityService;
+import org.apache.bookkeeper.bookie.datainteg.EntryCopier;
+import org.apache.bookkeeper.bookie.datainteg.EntryCopierImpl;
+import org.apache.bookkeeper.client.BookKeeper;
+import org.apache.bookkeeper.client.BookKeeperAdmin;
+import org.apache.bookkeeper.common.allocator.ByteBufAllocatorWithOomHandler;
+import org.apache.bookkeeper.common.component.AutoCloseableLifecycleComponent;
+import org.apache.bookkeeper.common.component.ComponentInfoPublisher;
+import org.apache.bookkeeper.common.component.LifecycleComponentStack;
+import org.apache.bookkeeper.common.component.RxSchedulerLifecycleComponent;
+import org.apache.bookkeeper.conf.ClientConfiguration;
+import org.apache.bookkeeper.discover.BookieServiceInfo;
+import org.apache.bookkeeper.discover.RegistrationManager;
+import org.apache.bookkeeper.meta.LedgerManager;
+import org.apache.bookkeeper.meta.LedgerManagerFactory;
+import org.apache.bookkeeper.meta.MetadataBookieDriver;
+import org.apache.bookkeeper.net.BookieId;
+import org.apache.bookkeeper.server.component.ServerLifecycleComponent;
+import org.apache.bookkeeper.server.conf.BookieConfiguration;
+import org.apache.bookkeeper.server.http.BKHttpServiceProvider;
+import org.apache.bookkeeper.server.service.AutoRecoveryService;
+import org.apache.bookkeeper.server.service.BookieService;
+import org.apache.bookkeeper.server.service.HttpService;
+import org.apache.bookkeeper.server.service.ScrubberService;
+import org.apache.bookkeeper.server.service.StatsProviderService;
+import org.apache.bookkeeper.stats.StatsLogger;
+import org.apache.bookkeeper.stats.StatsProvider;
+import org.apache.bookkeeper.util.DiskChecker;
+import org.apache.commons.lang3.StringUtils;
+
+/**
+ * An embedded server is a server that run bookie and serving rpc requests.
+ *
+ * <p>
+ * It is a rewritten server using {@link 
org.apache.bookkeeper.common.component.LifecycleComponent}, replacing the
+ * legacy server {@link org.apache.bookkeeper.proto.BookieServer}.
+ */
+public class EmbeddedServer {
+
+    private final LifecycleComponentStack lifecycleComponentStack;
+
+    private final StatsProvider statsProvider;
+
+    private final RegistrationManager registrationManager;
+
+    private final LedgerManagerFactory ledgerManagerFactory;
+
+    private final DiskChecker diskChecker;
+    private final LedgerDirsManager ledgerDirsManager;
+    private final LedgerDirsManager indexDirsManager;
+
+    private final BookieService bookieService;
+    private final AutoRecoveryService autoRecoveryService;
+    private final DataIntegrityService dataIntegrityService;
+    private final HttpService httpService;
+
+    private EmbeddedServer(LifecycleComponentStack lifecycleComponentStack, 
StatsProvider statsProvider,
+                           RegistrationManager registrationManager, 
LedgerManagerFactory ledgerManagerFactory,
+                           DiskChecker diskChecker, LedgerDirsManager 
ledgerDirsManager,
+                           LedgerDirsManager indexDirsManager, BookieService 
bookieService,
+                           AutoRecoveryService autoRecoveryService, 
DataIntegrityService dataIntegrityService,
+                           HttpService httpService) {
+        this.lifecycleComponentStack = lifecycleComponentStack;
+        this.statsProvider = statsProvider;
+        this.registrationManager = registrationManager;
+        this.ledgerManagerFactory = ledgerManagerFactory;
+        this.diskChecker = diskChecker;
+        this.ledgerDirsManager = ledgerDirsManager;
+        this.indexDirsManager = indexDirsManager;
+        this.bookieService = bookieService;
+        this.autoRecoveryService = autoRecoveryService;
+        this.dataIntegrityService = dataIntegrityService;
+        this.httpService = httpService;
+    }
+
+    public LifecycleComponentStack getLifecycleComponentStack() {
+        return lifecycleComponentStack;
+    }
+
+    public StatsProvider getStatsProvider() {
+        return statsProvider;
+    }
+
+    public RegistrationManager getRegistrationManager() {
+        return registrationManager;
+    }
+
+    public LedgerManagerFactory getLedgerManagerFactory() {
+        return ledgerManagerFactory;
+    }
+
+    public DiskChecker getDiskChecker() {
+        return diskChecker;
+    }
+
+    public LedgerDirsManager getLedgerDirsManager() {
+        return ledgerDirsManager;
+    }
+
+    public LedgerDirsManager getIndexDirsManager() {
+        return indexDirsManager;
+    }
+
+    public BookieService getBookieService() {
+        return bookieService;
+    }
+
+    public AutoRecoveryService getAutoRecoveryService() {
+        return autoRecoveryService;
+    }
+
+    public DataIntegrityService getDataIntegrityService() {
+        return dataIntegrityService;
+    }
+
+    public HttpService getHttpService() {
+        return httpService;
+    }
+
+    /**
+     * Create a new builder from given configuration. Actual services 
implementations can be provided to the builder and
+     * will override ones defined in the configuration.
+     * <p>
+     * Invoker is responsible to start and stop provided services 
implementations, components from
+     * {@link EmbeddedServer#getLifecycleComponentStack()} will reflect only 
those created from provided configuration.
+     *
+     * @param conf bookie configuration
+     * @return a new embedded server builder
+     */
+    public static final Builder builder(BookieConfiguration conf) {
+        return new Builder(conf);
+    }
+
+    @Slf4j
+    public static class Builder {
+
+        private BookieConfiguration conf;
+
+        boolean addExternalResourcesToLifecycle = true;

Review Comment:
   Sorry is a WIP fix but I had to see running it on CI.
   I think is useful to let BK to handle and close provided components but this 
behaviour should be off by default



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to