@Internal public class ResourceManager extends Object implements Closeable
Modifier and Type | Field and Description |
---|---|
protected Path |
localResourceDir |
protected Map<ResourceUri,URL> |
resourceInfos |
protected MutableURLClassLoader |
userClassLoader |
Constructor and Description |
---|
ResourceManager(ReadableConfig config,
MutableURLClassLoader userClassLoader) |
Modifier and Type | Method and Description |
---|---|
void |
addJarConfiguration(TableConfig tableConfig)
Adds the local jar resources to the given
TableConfig . |
protected void |
checkPath(Path path,
ResourceType expectedType) |
void |
close() |
ResourceManager |
copy() |
static ResourceManager |
createResourceManager(URL[] urls,
ClassLoader parent,
ReadableConfig config) |
URLClassLoader |
createUserClassLoader(List<ResourceUri> resourceUris) |
void |
declareFunctionResources(Set<ResourceUri> resourceUris)
Declare a resource for function and add it to the function resource infos.
|
boolean |
exists(Path filePath)
Check whether the
Path exists. |
Set<URL> |
getLocalJarResources()
Get the local jars' URL.
|
Map<ResourceUri,URL> |
getResources() |
protected URL |
getURLFromPath(Path path) |
URLClassLoader |
getUserClassLoader() |
String |
registerFileResource(ResourceUri resourceUri)
Register a file resource into
ResourceManager and return the absolute local file path
without the scheme. |
void |
registerJarResources(List<ResourceUri> resourceUris)
Due to anyone of the resource in list maybe fail during register, so we should stage it
before actual register to guarantee transaction process.
|
void |
registerPythonResources() |
void |
syncFileResource(ResourceUri resourceUri,
Consumer<String> resourceGenerator)
Generate a local file resource by the given resource generator and then synchronize to the
path identified by the given
ResourceUri . |
void |
unregisterFunctionResources(List<ResourceUri> resourceUris)
Unregister the resource uri in function resources, when the reference count of the resource
is 0, the resource will be removed from the function resources.
|
protected final Path localResourceDir
protected final Map<ResourceUri,URL> resourceInfos
protected final MutableURLClassLoader userClassLoader
public ResourceManager(ReadableConfig config, MutableURLClassLoader userClassLoader)
public static ResourceManager createResourceManager(URL[] urls, ClassLoader parent, ReadableConfig config)
public void registerJarResources(List<ResourceUri> resourceUris) throws IOException
ResourceManager
.IOException
public String registerFileResource(ResourceUri resourceUri) throws IOException
ResourceManager
and return the absolute local file path
without the scheme.
If the file is remote, it will be copied to a local file, with file name suffixed with a UUID.
resourceUri
- resource with type as ResourceType.FILE
, the resource uri might or
might not contain the uri scheme, or it could be a relative path.IOException
public void declareFunctionResources(Set<ResourceUri> resourceUris) throws IOException
resourceUris
- the resource uri for function.IOException
public void unregisterFunctionResources(List<ResourceUri> resourceUris)
resourceUris
- the uris to unregister in function resources.public void registerPythonResources()
public URLClassLoader getUserClassLoader()
public URLClassLoader createUserClassLoader(List<ResourceUri> resourceUris)
public Map<ResourceUri,URL> getResources()
public Set<URL> getLocalJarResources()
public void addJarConfiguration(TableConfig tableConfig)
TableConfig
. It implicitly considers the
TableConfig.getRootConfiguration()
and stores the merged result into TableConfig.getConfiguration()
.public ResourceManager copy()
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
public boolean exists(Path filePath) throws IOException
Path
exists.IOException
public void syncFileResource(ResourceUri resourceUri, Consumer<String> resourceGenerator) throws IOException
ResourceUri
. The path passed to resource generator
should be a local path retrieved from the given ResourceUri
.
NOTE: if the given ResourceUri
represents a remote file path like
"hdfs://path/to/file.json", then the retrieved local path will be
"/localResourceDir/file-${uuid}.json"
resourceUri
- the file resource uri to synchronize toresourceGenerator
- a consumer that generates a local copy of the file resourceIOException
protected void checkPath(Path path, ResourceType expectedType) throws IOException
IOException
@VisibleForTesting protected URL getURLFromPath(Path path) throws IOException
IOException
Copyright © 2014–2024 The Apache Software Foundation. All rights reserved.