Class TransactionalResourceService
java.lang.Object
dev.getelements.elements.rt.transact.TransactionalResourceService
- All Implemented Interfaces:
ResourceService
-
Nested Class Summary
Nested classes/interfaces inherited from interface dev.getelements.elements.rt.ResourceService
ResourceService.Listing, ResourceService.ResourceAcquisition, ResourceService.ResourceTransaction, ResourceService.Unlink
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionacquire
(ResourceId resourceId) Acquires aResource
guaranteeing it will remain in-memory until the resource is released.Acquires aResource
guaranteeing it will remain in-memory until the resource is released.acquireWithTransaction
(ResourceId resourceId) Opens aResourceService.ResourceTransaction
.acquireWithTransaction
(Path path) Opens aResourceService.ResourceTransaction
.addAndAcquireResource
(Path path, Resource resource) Adds an acquires thisResource
.void
addAndReleaseResource
(Path path, Resource resource) Adds aResource
to this resource service.boolean
exists
(ResourceId resourceId) Without affecting acquisition or releases, this performs a simple check to see if theResource
with the suppliedResourceId
exists in thisResourceService
.long
void
link
(ResourceId sourceResourceId, Path destination) Given the providedResourceId
, this will create an additional alias for the provided destinationPath
.void
listStream
(Path path) Returns aStream<ResourceId>
matching the providedPath
.Removes all resources from.removeResource
(ResourceId resourceId) Removes aResource
instance from this resource service.removeResources
(Path path, int max, Consumer<Resource> removed) void
void
setPersistence
(TransactionalResourceServicePersistence persistence) void
setResourceLoader
(ResourceLoader resourceLoader) void
start()
Called on start-up to ensure that theResourceService
has created and started any internal processes that it may need to perform its work.void
stop()
Releases all memory associated with thisResourceService
.unlinkMultiple
(Path path, int max, Consumer<Resource> removed) Unlinks multipleResource
s.unlinkPath
(Path path, Consumer<Resource> removed) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface dev.getelements.elements.rt.ResourceService
destroy, destroy, destroyResources, removeAndCloseAllResources, removeResource, removeResources, unlinkMultiple, unlinkPath
-
Constructor Details
-
TransactionalResourceService
public TransactionalResourceService()
-
-
Method Details
-
start
public void start()Description copied from interface:ResourceService
Called on start-up to ensure that theResourceService
has created and started any internal processes that it may need to perform its work.- Specified by:
start
in interfaceResourceService
-
stop
public void stop()Description copied from interface:ResourceService
Releases all memory associated with thisResourceService
. The actual action that happens here is dependent on the specific implementation. For in-memory implementations, this will simply close all resources and exit. For persistence-backed implementations this should flush all resources to disk before closing all. Once closed this instance may only be used after it has been restarted.- Specified by:
stop
in interfaceResourceService
-
exists
Description copied from interface:ResourceService
Without affecting acquisition or releases, this performs a simple check to see if theResource
with the suppliedResourceId
exists in thisResourceService
.- Specified by:
exists
in interfaceResourceService
- Parameters:
resourceId
- theResourceId
- Returns:
- true if exists, false otherwise.
-
acquire
Description copied from interface:ResourceService
Acquires aResource
guaranteeing it will remain in-memory until the resource is released.- Specified by:
acquire
in interfaceResourceService
- Returns:
- the
ResourceService.ResourceAcquisition
-
acquire
Description copied from interface:ResourceService
Acquires aResource
guaranteeing it will remain in-memory until the resource is released.- Specified by:
acquire
in interfaceResourceService
- Returns:
- the
ResourceService.ResourceAcquisition
-
acquireWithTransaction
Description copied from interface:ResourceService
Opens aResourceService.ResourceTransaction
.- Specified by:
acquireWithTransaction
in interfaceResourceService
- Returns:
- the
ResourceService.ResourceTransaction
-
acquireWithTransaction
Description copied from interface:ResourceService
Opens aResourceService.ResourceTransaction
.- Specified by:
acquireWithTransaction
in interfaceResourceService
- Returns:
- the
ResourceService.ResourceTransaction
-
addAndAcquireResource
Description copied from interface:ResourceService
Adds an acquires thisResource
. This is used for the initial insert into theResourceService
. If linking to an additionalPath
is necessary, then the methodsResourceService.linkPath(Path, Path)
orResourceService.link(ResourceId, Path)
must be used to perform additional aliasing operations. It is strongly recommended that newly insertedResource
instances be given a globally unique path initially, which can be thought of as the primary path, and then subsequent aliases or links be maintained, even if those particularPath
s may collide. This is only safe to use with freshly createdResource
instances whoseResourceId
has never before been seen by the system.- Specified by:
addAndAcquireResource
in interfaceResourceService
- Parameters:
path
-resource
-- Returns:
- the managed version of the supplied
Resource
-
addAndReleaseResource
Description copied from interface:ResourceService
Adds aResource
to this resource service. This is used for the initial insert into theResourceService
. If linking to an additionalPath
is necessary, then the methodsResourceService.linkPath(Path, Path)
orResourceService.link(ResourceId, Path)
must be used to perform additional aliasing operations. It is strongly recommended that newly insertedResource
instances be given a globally unique path initially, which can be thought of as the primary path, and then subsequent aliases or links be maintained, even if those particularPath
s may collide. Once aResource
is passed ot this method, thisResourceService
will take ownership of it. This means the theResource
may be closed after this call. Therefore, subsequent operations may require theResource
be fetched from serialization later for subsequent operations.- Specified by:
addAndReleaseResource
in interfaceResourceService
- Parameters:
path
- the initial path for theResource
resource
- the resource to insert
-
listStream
Description copied from interface:ResourceService
Returns aStream<ResourceId>
matching the providedPath
.- Specified by:
listStream
in interfaceResourceService
- Parameters:
path
- thePath
to match- Returns:
- a
Stream<ResourceId>
-
link
Description copied from interface:ResourceService
Given the providedResourceId
, this will create an additional alias for the provided destinationPath
.- Specified by:
link
in interfaceResourceService
- Parameters:
sourceResourceId
-destination
-
-
linkPath
Description copied from interface:ResourceService
- Specified by:
linkPath
in interfaceResourceService
- Parameters:
source
- the sourcePath
destination
- the destinationPath
-
unlinkPath
Description copied from interface:ResourceService
Unlinks theResource
for the providedPath
. If the unlinkedPath
is the final path, then this will remove thePath
from theResourceService
. If thisPath
is the last alias for the associatedResource
, then the removedResourceId
will be passed to the suppliedConsumer
. The suppliedConsumer
will not be called if there still exist aliases for the associatedResource
. Only oneResource
may be unlinked at a time. Therefore, the supplied,Path
most not be a wildcard path.- Specified by:
unlinkPath
in interfaceResourceService
- Parameters:
path
- aPath
to unlinkremoved
- a Consumer which will receive the removedResource
- Returns:
- true if the
Resource
associated with thePath
was removed, false otherwise
-
unlinkMultiple
Description copied from interface:ResourceService
- Specified by:
unlinkMultiple
in interfaceResourceService
- Parameters:
path
- the path to removemax
- the maximum count to removeremoved
- aConsumer<Resource>
to process each removal- Returns:
- the final
ResourceService.Unlink
operations
-
removeResource
Description copied from interface:ResourceService
Removes aResource
instance from this resource service.- Specified by:
removeResource
in interfaceResourceService
- Parameters:
resourceId
- the resourceId to the resource
-
removeResources
Description copied from interface:ResourceService
- Specified by:
removeResources
in interfaceResourceService
- Parameters:
path
- the thePath
for the resource.max
-removed
- aConsumer<Resource>
which accepts the removed resource
-
removeAllResources
Description copied from interface:ResourceService
Removes all resources from. The returnedStream<Resource>
returns anyResource
s that are still occupying memory and must be closed. The returned stream may be empty if all have been persisted. This operation may lock the wholeResourceService
to accomplish its task.- Specified by:
removeAllResources
in interfaceResourceService
-
getInMemoryResourceCount
public long getInMemoryResourceCount()- Specified by:
getInMemoryResourceCount
in interfaceResourceService
-
getNodeId
-
setNodeId
-
getResourceLoader
-
setResourceLoader
-
getPersistence
-
setPersistence
-