Skip to content

Commit

Permalink
chore: Adding missing javadocs
Browse files Browse the repository at this point in the history
Part of #15
  • Loading branch information
mcollovati committed Mar 22, 2022
1 parent 6a3398b commit e400ad6
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 0 deletions.
21 changes: 21 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,17 @@
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 {@link https://quarkus.io/guides/cdi-reference} for details.
*
* @see Instantiator
*/
@VaadinServiceEnabled
@Unremovable
@ApplicationScoped
Expand All @@ -47,10 +58,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

0 comments on commit e400ad6

Please sign in to comment.