Skip to content

Instantly share code, notes, and snippets.

public class DefaultEventBroadcastingTest
{
@Inject
private AsynchronousEvent<MyEvent> myAsyncEvent;
public void fireAsyncEvent()
{
this.myAsyncEvent.fire(new MyEvent(/*...*/));
}
}
@SessionScoped
@JsfPhaseListener
public class WindowQuotaHandler implements PhaseListener
{
@Inject
private WindowContext windowContext;
private Stack<String> windowIdStack = new Stack<String>();
@Override
@os890
os890 / TypeSafeConfig.java
Last active October 3, 2015 12:39
@TypeSafeConfig - Implementation
@PartialBeanBinding
@Retention(RUNTIME)
@Target(TYPE)
public @interface TypeSafeConfig {
}
@os890
os890 / AppConfig.java
Last active October 3, 2015 12:41
@TypeSafeConfig - Usage
//example #1 for a custom type-safe config
@TypeSafeConfig
public interface AppConfig {
String name();
ApplicationVersion version();
}
@os890
os890 / AppConfig2.java
Created October 26, 2015 16:30
type-safe config with producer
@TypeSafeConfig
public interface AppConfig2 {
String name();
@Produces //since ds v1.5.1
ApplicationVersion version();
}
@os890
os890 / AppConfig.java
Created October 26, 2015 16:36
type-safe config without producer
@TypeSafeConfig
public interface AppConfig {
String name();
ApplicationVersion version();
}
@os890
os890 / CustomKeyFormatAwareConfigSource.java
Last active March 12, 2016 17:57
Support a custom/additional key-format
//add the fully qualified class name to META-INF/services/org.apache.deltaspike.core.spi.config.ConfigSource
public class CustomKeyFormatAwareConfigSource implements ConfigSource {
private final static int ordinal = 1000;
@Override
public int getOrdinal() {
return ordinal;
}
@Override
public class MultiProfileExtension implements Extension {
private Set<String> activeProfileNames = new HashSet<>();
protected void determineActiveProfiles(@Observes BeforeBeanDiscovery beforeBeanDiscovery) {
String activeProfileString =
ConfigResolver.getPropertyValue("active-profiles", "Production");
Collections.addAll(activeProfileNames, activeProfileString.split(","));
}
protected void matchActiveProfiles(@Observes ProcessAnnotatedType pat, BeanManager bm) {
@Profile("X")
//further cdi annotation/s
public class BeanProfileX {
}
@ProfileA
//further cdi-annotation/s
public class BeanProfileA {
}