rishabhdaim commented on code in PR #2810: URL: https://github.com/apache/jackrabbit-oak/pull/2810#discussion_r3008330436
########## oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/AbstractBackend.java: ########## @@ -0,0 +1,191 @@ +/* + * 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.jackrabbit.oak.spi.blob.data; + +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; + +import org.apache.jackrabbit.oak.spi.blob.data.util.NamedThreadFactory; + +/** + * Abstract Backend which has a reference to the underlying {@link CachingDataStore} and is + * maintaining the lifecycle of the internal asynchronous write executor. + */ +public abstract class AbstractBackend implements Backend { + + /** + * {@link CachingDataStore} instance using this backend. + */ + private CachingDataStore dataStore; + + /** + * path of repository home dir. + */ + private String homeDir; + + /** + * path of config property file. + */ + private String config; + + /** + * The pool size of asynchronous write pooling executor. + */ + private int asyncWritePoolSize = 10; + + /** + * Asynchronous write pooling executor. + */ + private volatile Executor asyncWriteExecutor; + + /** + * Returns the pool size of the asynchronous write pool executor. + * @return the pool size of the asynchronous write pool executor + */ + public int getAsyncWritePoolSize() { + return asyncWritePoolSize; + } + + /** + * Sets the pool size of the asynchronous write pool executor. + * @param asyncWritePoolSize pool size of the async write pool executor + */ + public void setAsyncWritePoolSize(int asyncWritePoolSize) { + this.asyncWritePoolSize = asyncWritePoolSize; + } + + /** + * {@inheritDoc} + */ + @Override + public void init(CachingDataStore dataStore, String homeDir, String config) throws DataStoreException { + this.dataStore = dataStore; + this.homeDir = homeDir; + this.config = config; + } + + /** + * {@inheritDoc} + */ + @Override + public void close() throws DataStoreException { Review Comment: We could use `ExecutorCloser` to handle it in sync with other oak modules. ########## oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/AbstractBackend.java: ########## @@ -0,0 +1,191 @@ +/* + * 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.jackrabbit.oak.spi.blob.data; + +import java.util.concurrent.Executor; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ThreadPoolExecutor; + +import org.apache.jackrabbit.oak.spi.blob.data.util.NamedThreadFactory; + +/** + * Abstract Backend which has a reference to the underlying {@link CachingDataStore} and is + * maintaining the lifecycle of the internal asynchronous write executor. + */ +public abstract class AbstractBackend implements Backend { + + /** + * {@link CachingDataStore} instance using this backend. + */ + private CachingDataStore dataStore; + + /** + * path of repository home dir. + */ + private String homeDir; + + /** + * path of config property file. + */ + private String config; + + /** + * The pool size of asynchronous write pooling executor. + */ + private int asyncWritePoolSize = 10; + + /** + * Asynchronous write pooling executor. + */ + private volatile Executor asyncWriteExecutor; + + /** + * Returns the pool size of the asynchronous write pool executor. + * @return the pool size of the asynchronous write pool executor + */ + public int getAsyncWritePoolSize() { + return asyncWritePoolSize; + } + + /** + * Sets the pool size of the asynchronous write pool executor. + * @param asyncWritePoolSize pool size of the async write pool executor + */ + public void setAsyncWritePoolSize(int asyncWritePoolSize) { + this.asyncWritePoolSize = asyncWritePoolSize; + } + + /** + * {@inheritDoc} + */ + @Override + public void init(CachingDataStore dataStore, String homeDir, String config) throws DataStoreException { + this.dataStore = dataStore; + this.homeDir = homeDir; + this.config = config; + } + + /** + * {@inheritDoc} + */ + @Override + public void close() throws DataStoreException { + Executor asyncExecutor = getAsyncWriteExecutor(); + + if (asyncExecutor != null && asyncExecutor instanceof ExecutorService) { Review Comment: Also, a `null` check here is not required. ########## oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/util/NamedThreadFactory.java: ########## @@ -0,0 +1,44 @@ +/* + * 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.jackrabbit.oak.spi.blob.data.util; + +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.atomic.AtomicInteger; + +/** + * This class extends {@link ThreadFactory} to creates named threads. + */ +public class NamedThreadFactory implements ThreadFactory { Review Comment: We already have a similar class in `oak-lucene` module named `NamedThreadFactory` ########## oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/AsyncTouchCallback.java: ########## @@ -0,0 +1,41 @@ +/* + * 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.jackrabbit.oak.spi.blob.data; +/** + * This interface defines callback methods to reflect the status of asynchronous + * touch. + */ +public interface AsyncTouchCallback { + + + /** + * Callback method for successful asynchronous touch. + */ + public void onSuccess(AsyncTouchResult result); Review Comment: Just a nit-pick: no need for `public` in interface. ########## oak-blob/src/main/java/org/apache/jackrabbit/oak/spi/blob/data/AsyncUploadCallback.java: ########## @@ -0,0 +1,40 @@ +/* + * 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.jackrabbit.oak.spi.blob.data; + +/** + * This interface defines callback methods to reflect the status of asynchronous + * upload. + */ +public interface AsyncUploadCallback { + + /** + * Callback method for successful asynchronous upload. + */ + public void onSuccess(AsyncUploadResult result); Review Comment: same as above nit-pick, no need for `public` -- 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]
