Skip to content

Instantly share code, notes, and snippets.

View ljnelson's full-sized avatar
🙃

Laird Nelson ljnelson

🙃
View GitHub Profile
@ljnelson
ljnelson / 02.pom.xml
Created December 22, 2018 00:33
Example of consumption of a specification
<dependencies>
<dependency>
<groupId>com.foobar</groupId>
<artifactId>cdi-specification-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
</dependencies>
@ljnelson
ljnelson / 01.pom.xml
Created December 22, 2018 00:19
Specification pom.xml Example
<groupId>com.foobar</groupId>
<artifactId>cdi-specification-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3</version>
@ljnelson
ljnelson / LogManagerConfigurator.java
Created June 26, 2018 18:38
A config class that allows you to specify logger levels using System properties.
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Properties;
@ljnelson
ljnelson / 00.pom.xml
Created May 4, 2018 17:13
CDI specification reified in Maven
<dependencies>
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
private final void stopControllers(@Observes @BeforeDestroyed(ApplicationScoped.class) @Priority(LIBRARY_BEFORE) final Object ignored) throws IOException {
Exception exception = null;
for (final Controller<?> controller : this.controllers) {
assert controller != null;
try {
controller.close();
} catch (final IOException | RuntimeException closeException) {
if (exception == null) {
exception = closeException;
@ljnelson
ljnelson / part11-10.java
Created February 14, 2018 22:15
CDIEventDistributor
private static final class CDIEventDistributor<T extends HasMetadata> implements Consumer<AbstractEvent<? extends T>> {
private static final Annotation[] EMPTY_ANNOTATION_ARRAY = new Annotation[0];
private final Annotation[] qualifiers;
private final NotificationOptions notificationOptions;
private final boolean syncNeeded;
private final <T extends HasMetadata, X extends Listable<? extends KubernetesResourceList> & VersionWatchable<? extends Closeable, Watcher<T>>> void startControllers(@Observes @Initialized(ApplicationScoped.class) @Priority(LIBRARY_AFTER) final Object ignored, final BeanManager beanManager) {
if (beanManager != null) {
for (final Bean<?> bean : this.beans) {
assert bean != null;
final Set<Annotation> qualifiers = bean.getQualifiers();
final Map<Object, T> knownObjects = new HashMap<>();
final EventDistributor<T> eventDistributor = new EventDistributor<>(knownObjects);
@ljnelson
ljnelson / part11-8.java
Created February 14, 2018 21:57
Matching producer method
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import io.fabric8.kubernetes.api.model.ConfigMap;
import io.fabric8.kubernetes.api.model.ConfigMapList;
import io.fabric8.kubernetes.api.model.DoneableConfigMap;
import io.fabric8.kubernetes.api.model.HasMetadata;
import io.fabric8.kubernetes.client.KubernetesClient;
import io.fabric8.kubernetes.client.dsl.Operation;
import io.fabric8.kubernetes.client.dsl.Resource;
@ljnelson
ljnelson / part11-7.java
Created February 14, 2018 21:56
Example observer method
import javax.enterprise.event.Observes;
import io.fabric8.kubernetes.api.model.HasMetadata;
import org.microbean.kubernetes.controller.Event;
private final void onConfigMapEvent(@Observes @AllConfigMapEvents final Event<? extends HasMetadata> event) {
}
@ljnelson
ljnelson / part11-6.java
Created February 14, 2018 21:55
Custom Qualifier
@Documented
@KubernetesEventSelector
@Qualifier
@Retention(value = RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD, ElementType.PARAMETER })
public @interface AllConfigMapEvents {
}