com.vaadin.flow.server.
Class StreamResourceRegistry
- java.lang.Object
-
- com.vaadin.flow.server.StreamResourceRegistry
-
All Implemented Interfaces:
public class StreamResourceRegistry extends Object implements Serializable
Registry for
StreamResource
instances.Since:
1.0
Author:
Vaadin Ltd
See Also:
-
-
Constructor Summary
Constructors Constructor and Description StreamResourceRegistry(VaadinSession session)
Creates stream resource registry for provided
session
.
-
Method Summary
All Methods Modifier and Type Method and Description <T extends AbstractStreamResource>
Optional<T>getResource(Class<T> type, URI uri)
Get a registered resource of given type.
Optional<AbstractStreamResource>
getResource(URI uri)
Get a registered resource for given
URI
.URI
getTargetURI(AbstractStreamResource resource)
Returns the URI path to the given resource in the context of this registry (relevant in portlet context).
static URI
getURI(AbstractStreamResource resource)
Gets the URI for the given
resource
.StreamRegistration
registerResource(AbstractStreamResource resource)
Registers a stream resource in the session and returns registration handler.
void
unregisterResource(StreamReceiver resource)
Unregister a stream receiver resource.
-
-
-
Constructor Detail
-
StreamResourceRegistry
public StreamResourceRegistry(VaadinSession session)
Creates stream resource registry for provided
session
.Parameters:
session
- vaadin session
-
-
Method Detail
-
registerResource
public StreamRegistration registerResource(AbstractStreamResource resource)
Registers a stream resource in the session and returns registration handler.
You can get resource URI to use it in the application (e.g. set an attribute value or property value) via the registration handler. The registration handler should be used to unregister resource when it's not needed anymore. Note that it is the developer's responsibility to unregister resources. Otherwise resources won't be garbage collected until the session expires which causes memory leak.
Parameters:
resource
- stream resource to registerReturns:
registration handler
-
unregisterResource
public void unregisterResource(StreamReceiver resource)
Unregister a stream receiver resource.
Parameters:
resource
- stream receiver resource to unregister
-
getURI
public static URI getURI(AbstractStreamResource resource)
Gets the URI for the given
resource
.The URI won't be handled (and won't work) if
resource
is not registered in the session.Parameters:
resource
- stream resourceReturns:
resource URI
See Also:
-
getTargetURI
public URI getTargetURI(AbstractStreamResource resource)
Returns the URI path to the given resource in the context of this registry (relevant in portlet context).
Parameters:
resource
- stream resourceReturns:
resource URI
-
getResource
public Optional<AbstractStreamResource> getResource(URI uri)
Get a registered resource for given
URI
.Resource may be a StreamResource or a StreamReceiver
Parameters:
uri
- resource URIReturns:
an optional resource, or an empty optional if no resource has been registered with this URI
-
getResource
public <T extends AbstractStreamResource> Optional<T> getResource(Class<T> type, URI uri)
Get a registered resource of given type.
Type Parameters:
T
- resource extending AbstractStreamResourceParameters:
type
- resource class typeuri
- resource URIReturns:
an optional resource, or an empty optional if no resource has been registered with this URI
-
-