Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Adding missing javadocs #68

Merged
merged 2 commits into from
Mar 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions runtime/src/main/java/com/vaadin/quarkus/QuarkusInstantiator.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@
import com.vaadin.flow.server.VaadinServiceInitListener;
import com.vaadin.quarkus.annotation.VaadinServiceEnabled;

/**
* Instantiator implementation based on Quarkus DI feature.
*
* Quarkus DI solution (also called ArC) is based on the Contexts and Dependency
* Injection for Java 2.0 specification, but it is not a full CDI
* implementation. Only a subset of the CDI features is implemented.
*
* See <a href="https://quarkus.io/guides/cdi-reference">Quarkus CDI
* Reference</a> for further details.
*
* @see Instantiator
*/
@VaadinServiceEnabled
@Unremovable
@ApplicationScoped
Expand All @@ -47,10 +59,20 @@ public class QuarkusInstantiator implements Instantiator {
@Inject
BeanManager beanManager;

/**
* Gets the service class that this instantiator is supposed to work with.
*
* @return the service class this instantiator is supposed to work with.
*/
public Class<? extends VaadinService> getServiceClass() {
return QuarkusVaadinServletService.class;
}

/**
* Gets the {@link BeanManager} instance.
*
* @return the {@link BeanManager} instance.
*/
public BeanManager getBeanManager() {
return this.beanManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@

import com.vaadin.flow.di.ResourceProvider;

/**
* A {@link ResourceProvider} implementation that delegates resource loading to
* current thread context ClassLoader.
*/
public class QuarkusResourceProvider implements ResourceProvider {

private Map<String, CachedStreamData> cache = new ConcurrentHashMap<>();
Expand Down
10 changes: 10 additions & 0 deletions runtime/src/main/java/com/vaadin/quarkus/QuarkusVaadinServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
import com.vaadin.flow.server.VaadinServlet;
import com.vaadin.flow.server.VaadinServletService;

/**
* Servlet to create {@link QuarkusVaadinServletService}.
*
* An instance of this servlet is automatically registered if no other custom
* VaadinServlet class with Servlet 3.0 annotations is present on classpath. A
* subclass of this servlet can be to provide a customized
* {@link QuarkusVaadinServletService} implementation, in which case
* {@link #createServletService(DeploymentConfiguration)} must call
* {@code service.init()}.
*/
public class QuarkusVaadinServlet extends VaadinServlet {

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@
import com.vaadin.flow.server.VaadinServletService;
import com.vaadin.flow.server.VaadinSession;

/**
* An implementation of {@link com.vaadin.flow.server.VaadinService} for Quarkus
* environment.
*
* This class looks up for and therefore provides an {@link Instantiator} bean.
* It also forwards Vaadin events to CDI listeners.
*
* @author Vaadin Ltd
*/
public class QuarkusVaadinServletService extends VaadinServletService {

private BeanManager beanManager;
Expand Down Expand Up @@ -163,6 +172,20 @@ private void addUIListeners(UI ui) {
ui.addPollListener(uiEventListener);
}

/**
* Gets an instance of a {@code @VaadinServiceEnabled} annotated bean of the
* given {@code type}.
*
* @param type
* the required service type
* @param <T>
* the type of the service
* @return an {@link Optional} wrapping the service instance, or
* {@link Optional#empty()} if no bean definition exists for given
* type.
* @throws ServiceException
* if multiple beans exists for the given type.
*/
public <T> Optional<T> lookup(Class<T> type) throws ServiceException {
try {
T instance = new BeanLookup<>(getBeanManager(), type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public abstract class AbstractContext implements InjectableContext {
protected abstract ContextualStorage getContextualStorage(
Contextual<?> contextual, boolean createIfNotExist);

/**
* Gets all active contextual storages.
*
* @return a list of contextual storages.
*/
protected List<ContextualStorage> getActiveContextualStorages() {
List<ContextualStorage> result = new ArrayList<ContextualStorage>();
result.add(getContextualStorage(null, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,18 @@ protected AbstractContextualStorageManager(boolean concurrent) {
this.concurrent = concurrent;
}

/**
* Gets the {@link ContextualStorage} associated with the given context
* {@code key}, possibly creating a new instance, if requested and not
* already existing.
*
* @param key
* context key
* @param createIfNotExist
* whether a ContextualStorage shall get created if it doesn't
* yet exist.
* @return a {@link ContextualStorage} instance.
*/
protected ContextualStorage getContextualStorage(K key,
boolean createIfNotExist) {
if (createIfNotExist) {
Expand All @@ -55,17 +67,35 @@ protected ContextualStorage getContextualStorage(K key,
}
}

/**
* Changes the context key for a contextual storage.
*
* @param from
* the contextual storage context key
* @param to
* the new context for the contextual storage
*/
protected void relocate(K from, K to) {
ContextualStorage storage = storageMap.remove(from);
if (storage != null) {
storageMap.put(to, storage);
}
}

/**
* Creates a new {@link ContextualStorage} for the given context key.
*
* @param key
* the context key
* @return a new {@link ContextualStorage} instance.
*/
protected ContextualStorage newContextualStorage(K key) {
return new ContextualStorage(concurrent);
}

/**
* Destroys all existing contextual storages.
*/
@PreDestroy
protected void destroyAll() {
Collection<ContextualStorage> storages = storageMap.values();
Expand All @@ -75,13 +105,24 @@ protected void destroyAll() {
storageMap.clear();
}

/**
* Destroys the contextual storage associated with the given context key.
*
* @param key
* the context key
*/
protected void destroy(K key) {
ContextualStorage storage = storageMap.remove(key);
if (storage != null) {
AbstractContext.destroyAllActive(storage);
}
}

/**
* Gets context keys of all registered contextual storages.
*
* @return immutable set of context keys.
*/
protected Set<K> getKeySet() {
return Collections.unmodifiableSet(storageMap.keySet());
}
Expand Down