simonbence commented on a change in pull request #5696: URL: https://github.com/apache/nifi/pull/5696#discussion_r835080164
########## File path: nifi-nar-bundles/nifi-framework-bundle/nifi-framework-external-resource-utils/src/main/java/org/apache/nifi/flow/resource/BufferingExternalResourceProviderWorker.java ########## @@ -0,0 +1,90 @@ +/* + * 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.nifi.flow.resource; + +import org.apache.nifi.nar.NarCloseable; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.nio.file.Files; +import java.util.concurrent.CountDownLatch; + +/** + * It is important to note that this implementation prevents NiFi from catching up a file under writing. For example trying to load a NAR + * file which is not fully acquired for example could lead to issues. In order to avoid this, the worker first creates a temporary + * file and it will rename it to the expected name only after it has been successfully written to the disk. + */ +final class BufferingExternalResourceProviderWorker extends ConflictResolvingExternalResourceProviderWorker { + private static final Logger LOGGER = LoggerFactory.getLogger(BufferingExternalResourceProviderWorker.class); + + BufferingExternalResourceProviderWorker( + final String namePrefix, + final ClassLoader providerClassLoader, + final ExternalResourceProvider provider, + final ExternalResourceConflictResolutionStrategy resolutionStrategy, + final File targetDirectory, + final long pollTimeInMs, + final CountDownLatch restrainStartupLatch + ) { + super(namePrefix, providerClassLoader, provider, resolutionStrategy, targetDirectory, pollTimeInMs, restrainStartupLatch); + } + + protected void acquireResource(final ExternalResourceDescriptor availableResource) throws IOException { + final long startedAt = System.currentTimeMillis(); + final InputStream inputStream; + + final File targetFile = new File(getTargetDirectory(), availableResource.getLocation()); Review comment: Right now, the additional method looks to be a duplication. I think, location should be as it is (I deliberately left it more general than the location) and if needed, later we can add further methods. -- 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]
