Package net.solarnetwork.common.s3
Class S3ResourceStorageService
- All Implemented Interfaces:
Comparable<String>,net.solarnetwork.domain.Identity<String>,net.solarnetwork.service.Identifiable,net.solarnetwork.service.LocalizedServiceInfoProvider,net.solarnetwork.service.ResourceStorageService,net.solarnetwork.settings.SettingsChangeObserver,net.solarnetwork.settings.SettingSpecifierProvider
public class S3ResourceStorageService
extends net.solarnetwork.settings.support.BaseSettingsSpecifierLocalizedServiceInfoProvider<String>
implements net.solarnetwork.service.ResourceStorageService, net.solarnetwork.settings.SettingSpecifierProvider, net.solarnetwork.settings.SettingsChangeObserver
AWS S3 based implementation of
ResourceStorageService using the
S3Client API.- Version:
- 2.0
- Author:
- matt
-
Field Summary
Fields inherited from class net.solarnetwork.service.support.BaseLocalizedServiceInfoProvider
logFields inherited from interface net.solarnetwork.service.Identifiable
GROUP_UID_PROPERTY, UID_PROPERTYFields inherited from interface net.solarnetwork.service.ResourceStorageService
EVENT_TOPIC_RESOURCE_SAVED, EVENT_TOPIC_RESOURCES_DELETED, RESOURCE_PATHS_PROPERTY, RESOURCE_URL_PROPERTY -
Constructor Summary
ConstructorsConstructorDescriptionS3ResourceStorageService(String id, Executor executor) Constructor.S3ResourceStorageService(Executor executor) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoidconfigurationChanged(Map<String, Object> properties) protected org.osgi.service.event.EventcreateResourceSavedEvent(org.springframework.core.io.Resource resource, String path) Create a newResourceStorageService.EVENT_TOPIC_RESOURCE_SAVEDEventobject out of a resource and path.protected org.osgi.service.event.EventCreate a newResourceStorageService.EVENT_TOPIC_RESOURCES_DELETEDEventobject out of a set of paths.deleteResources(Iterable<String> paths) net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> Get the optionalEventAdminservice.Get the executor that handles asynchronous operations.Deprecated.Get the S3 object key prefix.Get the S3 client.List<net.solarnetwork.settings.SettingSpecifier> getUid()getUID()Deprecated.since 2.0 usegetUid()booleanCompletableFuture<Iterable<org.springframework.core.io.Resource>> listResources(String pathPrefix) protected final voidpostEvent(org.osgi.service.event.Event event) Post anEvent.protected final voidpostResourceSavedEvent(org.springframework.core.io.Resource resource, String path) Post anEventfor theResourceStorageService.EVENT_TOPIC_RESOURCE_SAVEDtopic.protected final voidpostResourcesDeletedEvent(Iterable<String> paths) Post anEventfor theResourceStorageService.EVENT_TOPIC_RESOURCES_DELETEDtopic.resourceStorageUrl(String path) saveResource(String path, org.springframework.core.io.Resource resource, boolean replace, net.solarnetwork.service.ProgressListener<org.springframework.core.io.Resource> progressListener) voidsetEventAdmin(net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin) Set the optionalEventAdminservice.voidsetExecutor(Executor executor) Set the executor that handles asynchronous operations.voidsetGroupUid(String groupUid) Set the group UID.voidsetGroupUID(String groupUid) Deprecated.since 2.0 usesetGroupUid(String)voidsetObjectKeyPrefix(String objectKeyPrefix) Set a S3 object key prefix to use.voidsetS3Client(S3Client s3Client) Set the S3 client.voidSet the UID.voidDeprecated.since 2.0 usesetUid(String)voidstartup()Call after properties are configured.Methods inherited from class net.solarnetwork.settings.support.BaseSettingsSpecifierLocalizedServiceInfoProvider
getLocalizedServiceInfo, getSettingUid, populateInfoMessages, resolveInfoMessagesMethods inherited from class net.solarnetwork.service.support.BaseLocalizedServiceInfoProvider
getMessageSource, setMessageSourceMethods inherited from class net.solarnetwork.domain.BasicIdentity
clone, compareTo, equals, getId, hashCodeMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.solarnetwork.domain.Identity
hasIdMethods inherited from interface net.solarnetwork.settings.SettingSpecifierProvider
getMessageSource, getSettingUid, templateSettingSpecifiers
-
Constructor Details
-
S3ResourceStorageService
Constructor.- Parameters:
executor- the executor to use- Throws:
IllegalArgumentException- ifexecutoris null
-
S3ResourceStorageService
Constructor.- Parameters:
id- the settings UID to useexecutor- the executor to use- Throws:
IllegalArgumentException- ifexecutoris null
-
-
Method Details
-
startup
public void startup()Call after properties are configured. -
configurationChanged
- Specified by:
configurationChangedin interfacenet.solarnetwork.settings.SettingsChangeObserver
-
isConfigured
public boolean isConfigured()- Specified by:
isConfiguredin interfacenet.solarnetwork.service.ResourceStorageService
-
listResources
public CompletableFuture<Iterable<org.springframework.core.io.Resource>> listResources(String pathPrefix) - Specified by:
listResourcesin interfacenet.solarnetwork.service.ResourceStorageService
-
resourceStorageUrl
- Specified by:
resourceStorageUrlin interfacenet.solarnetwork.service.ResourceStorageService
-
saveResource
public CompletableFuture<Boolean> saveResource(String path, org.springframework.core.io.Resource resource, boolean replace, net.solarnetwork.service.ProgressListener<org.springframework.core.io.Resource> progressListener) - Specified by:
saveResourcein interfacenet.solarnetwork.service.ResourceStorageService
-
deleteResources
- Specified by:
deleteResourcesin interfacenet.solarnetwork.service.ResourceStorageService
-
postResourceSavedEvent
protected final void postResourceSavedEvent(org.springframework.core.io.Resource resource, String path) Post anEventfor theResourceStorageService.EVENT_TOPIC_RESOURCE_SAVEDtopic.- Parameters:
resource- the resource to create the event forpath- the resource path
-
createResourceSavedEvent
protected org.osgi.service.event.Event createResourceSavedEvent(org.springframework.core.io.Resource resource, String path) Create a newResourceStorageService.EVENT_TOPIC_RESOURCE_SAVEDEventobject out of a resource and path.- Parameters:
resource- the resource to create the event forpath- the resource path- Returns:
- the new Event instance, or null if
resourceis null or cannot be resolved to a URL
-
postResourcesDeletedEvent
Post anEventfor theResourceStorageService.EVENT_TOPIC_RESOURCES_DELETEDtopic.- Parameters:
paths- the paths that have been deleted
-
createResourcesDeletedEvent
Create a newResourceStorageService.EVENT_TOPIC_RESOURCES_DELETEDEventobject out of a set of paths.- Parameters:
paths- the paths that have been deleted- Returns:
- the new Event instance, or null if
pathsis null
-
postEvent
protected final void postEvent(org.osgi.service.event.Event event) Post anEvent.This method only works if a
EventAdminhas been configured viasetEventAdmin(OptionalService). Otherwise the event is silently ignored.- Parameters:
event- the event to post
-
getDisplayName
- Specified by:
getDisplayNamein interfacenet.solarnetwork.service.Identifiable- Specified by:
getDisplayNamein interfacenet.solarnetwork.settings.SettingSpecifierProvider
-
getSettingSpecifiers
- Specified by:
getSettingSpecifiersin interfacenet.solarnetwork.settings.SettingSpecifierProvider
-
getS3Client
Get the S3 client.- Returns:
- the client, never null
-
setS3Client
Set the S3 client.- Parameters:
s3Client- the client to set- Throws:
IllegalArgumentException- ifs3Clientis null
-
getExecutor
Get the executor that handles asynchronous operations.- Returns:
- the executor, never null
-
setExecutor
Set the executor that handles asynchronous operations.- Parameters:
executor- the executor to set- Throws:
IllegalArgumentException- ifExecutoris null
-
getObjectKeyPrefix
Get the S3 object key prefix.- Returns:
- the prefix to use, or null
-
setObjectKeyPrefix
Set a S3 object key prefix to use.This can essentially be a folder path to prefix all data with. All keys passed to all methods that do not already start with this prefix will have the prefix added before passing the operation to S3.
- Parameters:
objectKeyPrefix- the object key prefix to set, or null for no prefix
-
getUid
- Specified by:
getUidin interfacenet.solarnetwork.service.Identifiable
-
setUid
Set the UID.- Parameters:
uid- the UID to set
-
getGroupUid
- Specified by:
getGroupUidin interfacenet.solarnetwork.service.Identifiable
-
setGroupUid
Set the group UID.- Parameters:
groupUid- the group UID to set
-
getUID
Deprecated.since 2.0 usegetUid()Alias forgetUid().- Returns:
- the UID
-
setUID
Deprecated.since 2.0 usesetUid(String)Set the UID.This is an alias for
setUid(String).- Parameters:
uid- the UID to set
-
getGroupUID
Deprecated.usegetGroupUid()Alias forgetGroupUid().- Returns:
- the group UID
-
setGroupUID
Deprecated.since 2.0 usesetGroupUid(String)Set the group UID.This is an alias for
setGroupUid(String).- Parameters:
groupUid- the group UID to set
-
getEventAdmin
public net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> getEventAdmin()Get the optionalEventAdminservice.- Returns:
- the eventAdmin the service
-
setEventAdmin
public void setEventAdmin(net.solarnetwork.service.OptionalService<org.osgi.service.event.EventAdmin> eventAdmin) Set the optionalEventAdminservice.- Parameters:
eventAdmin- the service to set
-
getGroupUid()