Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,16 @@
package com.baeldung.cdi2observers.application;
import com.baeldung.cdi2observers.events.ExampleEvent;
import javax.enterprise.inject.se.SeContainer;
import javax.enterprise.inject.se.SeContainerInitializer;
public class BootstrappingApplication {
public static void main(String... args) {
SeContainerInitializer containerInitializer = SeContainerInitializer.newInstance();
try (SeContainer container = containerInitializer.initialize()) {
container.getBeanManager().fireEvent(new ExampleEvent("Welcome to Baeldung!"));
}
}
}
@@ -0,0 +1,14 @@
package com.baeldung.cdi2observers.events;
public class ExampleEvent {
private final String eventMessage;
public ExampleEvent(String eventMessage) {
this.eventMessage = eventMessage;
}
public String getEventMessage() {
return eventMessage;
}
}
@@ -0,0 +1,14 @@
package com.baeldung.cdi2observers.events;
import javax.enterprise.event.Event;
import javax.inject.Inject;
public class ExampleEventSource {
@Inject
Event<ExampleEvent> exampleEvent;
public void fireEvent() {
exampleEvent.fireAsync(new ExampleEvent("Welcome to Baeldung!"));
}
}
@@ -0,0 +1,13 @@
package com.baeldung.cdi2observers.observers;
import com.baeldung.cdi2observers.events.ExampleEvent;
import javax.annotation.Priority;
import javax.enterprise.event.Observes;
public class AnotherExampleEventObserver {
public String onEvent(@Observes @Priority(2) ExampleEvent event) {
return event.getEventMessage();
}
}
@@ -0,0 +1,13 @@
package com.baeldung.cdi2observers.observers;
import com.baeldung.cdi2observers.events.ExampleEvent;
import com.baeldung.cdi2observers.services.TextService;
import javax.annotation.Priority;
import javax.enterprise.event.Observes;
public class ExampleEventObserver {
public String onEvent(@Observes @Priority(1) ExampleEvent event, TextService textService) {
return textService.parseText(event.getEventMessage());
}
}
@@ -0,0 +1,8 @@
package com.baeldung.cdi2observers.services;
public class TextService {
public String parseText(String text) {
return text.toUpperCase();
}
}
@@ -0,0 +1,18 @@
package com.baeldung.dependencyinjection.application;
import com.baeldung.dependencyinjection.imageprocessors.ImageFileProcessor;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
public class FileApplication {
public static void main(String[] args) {
Weld weld = new Weld();
WeldContainer container = weld.initialize();
ImageFileProcessor imageFileProcessor = container.select(ImageFileProcessor.class).get();
System.out.println(imageFileProcessor.openFile("file1.png"));
System.out.println(imageFileProcessor.writeFile("file1.png"));
System.out.println(imageFileProcessor.saveFile("file1.png"));
container.shutdown();
}
}
@@ -0,0 +1,14 @@
package com.baeldung.dependencyinjection.factories;
import com.baeldung.dependencyinjection.loggers.TimeLogger;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import javax.enterprise.inject.Produces;
public class TimeLoggerFactory {
@Produces
public TimeLogger getTimeLogger() {
return new TimeLogger(new SimpleDateFormat("HH:mm"), Calendar.getInstance());
}
}
@@ -0,0 +1,27 @@
package com.baeldung.dependencyinjection.imagefileeditors;
import com.baeldung.dependencyinjection.qualifiers.GifFileEditorQualifier;
@GifFileEditorQualifier
public class GifFileEditor implements ImageFileEditor {
@Override
public String openFile(String fileName) {
return "Opening GIF file " + fileName;
}
@Override
public String editFile(String fileName) {
return "Editing GIF file " + fileName;
}
@Override
public String writeFile(String fileName) {
return "Writing GIF file " + fileName;
}
@Override
public String saveFile(String fileName) {
return "Saving GIF file " + fileName;
}
}
@@ -0,0 +1,12 @@
package com.baeldung.dependencyinjection.imagefileeditors;
public interface ImageFileEditor {
String openFile(String fileName);
String editFile(String fileName);
String writeFile(String fileName);
String saveFile(String fileName);
}
@@ -0,0 +1,27 @@
package com.baeldung.dependencyinjection.imagefileeditors;
import com.baeldung.dependencyinjection.qualifiers.JpgFileEditorQualifier;
@JpgFileEditorQualifier
public class JpgFileEditor implements ImageFileEditor {
@Override
public String openFile(String fileName) {
return "Opening JPG file " + fileName;
}
@Override
public String editFile(String fileName) {
return "Editing JPG file " + fileName;
}
@Override
public String writeFile(String fileName) {
return "Writing JPG file " + fileName;
}
@Override
public String saveFile(String fileName) {
return "Saving JPG file " + fileName;
}
}
@@ -0,0 +1,27 @@
package com.baeldung.dependencyinjection.imagefileeditors;
import com.baeldung.dependencyinjection.qualifiers.PngFileEditorQualifier;
@PngFileEditorQualifier
public class PngFileEditor implements ImageFileEditor {
@Override
public String openFile(String fileName) {
return "Opening PNG file " + fileName;
}
@Override
public String editFile(String fileName) {
return "Editing PNG file " + fileName;
}
@Override
public String writeFile(String fileName) {
return "Writing PNG file " + fileName;
}
@Override
public String saveFile(String fileName) {
return "Saving PNG file " + fileName;
}
}
@@ -0,0 +1,42 @@
package com.baeldung.dependencyinjection.imageprocessors;
import com.baeldung.dependencyinjection.loggers.TimeLogger;
import com.baeldung.dependencyinjection.qualifiers.PngFileEditorQualifier;
import javax.inject.Inject;
import com.baeldung.dependencyinjection.imagefileeditors.ImageFileEditor;
public class ImageFileProcessor {
private final ImageFileEditor imageFileEditor;
private final TimeLogger timeLogger;
@Inject
public ImageFileProcessor(@PngFileEditorQualifier ImageFileEditor imageFileEditor, TimeLogger timeLogger) {
this.imageFileEditor = imageFileEditor;
this.timeLogger = timeLogger;
}
public ImageFileEditor getImageFileditor() {
return imageFileEditor;
}
public TimeLogger getTimeLogger() {
return timeLogger;
}
public String openFile(String fileName) {
return imageFileEditor.openFile(fileName) + " at: " + timeLogger.getTime();
}
public String editFile(String fileName) {
return imageFileEditor.editFile(fileName) + " at: " + timeLogger.getTime();
}
public String writeFile(String fileName) {
return imageFileEditor.writeFile(fileName) + " at: " + timeLogger.getTime();
}
public String saveFile(String fileName) {
return imageFileEditor.saveFile(fileName)+ " at: " + timeLogger.getTime();
}
}
@@ -0,0 +1,19 @@
package com.baeldung.dependencyinjection.loggers;
import java.text.SimpleDateFormat;
import java.util.Calendar;
public class TimeLogger {
private final SimpleDateFormat dateFormat;
private final Calendar calendar;
public TimeLogger(SimpleDateFormat dateFormat, Calendar calendar) {
this.dateFormat = dateFormat;
this.calendar = calendar;
}
public String getTime() {
return dateFormat.format(calendar.getTime());
}
}
@@ -0,0 +1,12 @@
package com.baeldung.dependencyinjection.qualifiers;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER})
public @interface GifFileEditorQualifier {}
@@ -0,0 +1,12 @@
package com.baeldung.dependencyinjection.qualifiers;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER})
public @interface JpgFileEditorQualifier {}
@@ -0,0 +1,12 @@
package com.baeldung.dependencyinjection.qualifiers;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.inject.Qualifier;
@Qualifier
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.FIELD, ElementType.METHOD, ElementType.TYPE, ElementType.PARAMETER})
public @interface PngFileEditorQualifier {}
@@ -0,0 +1,14 @@
package com.baeldung.interceptor;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import javax.interceptor.InterceptorBinding;
@InterceptorBinding
@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface Audited {
}
@@ -0,0 +1,20 @@
package com.baeldung.interceptor;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
@Audited
@Interceptor
public class AuditedInterceptor {
public static boolean calledBefore = false;
public static boolean calledAfter = false;
@AroundInvoke
public Object auditMethod(InvocationContext ctx) throws Exception {
calledBefore = true;
Object result = ctx.proceed();
calledAfter = true;
return result;
}
}
@@ -0,0 +1,10 @@
package com.baeldung.service;
import com.baeldung.interceptor.Audited;
public class SuperService {
@Audited
public String deliverService(String uid) {
return uid;
}
}
@@ -0,0 +1,23 @@
package com.baeldung.spring.aspect;
import java.util.List;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
@Aspect
public class SpringTestAspect {
@Autowired
private List<String> accumulator;
@Around("execution(* com.baeldung.spring.service.SpringSuperService.*(..))")
public Object auditMethod(ProceedingJoinPoint jp) throws Throwable {
String methodName = jp.getSignature().getName();
accumulator.add("Call to " + methodName);
Object obj = jp.proceed();
accumulator.add("Method called successfully: " + methodName);
return obj;
}
}
@@ -0,0 +1,30 @@
package com.baeldung.spring.configuration;
import java.util.ArrayList;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import com.baeldung.spring.aspect.SpringTestAspect;
import com.baeldung.spring.service.SpringSuperService;
@Configuration
@EnableAspectJAutoProxy
public class AppConfig {
@Bean
public SpringSuperService springSuperService() {
return new SpringSuperService();
}
@Bean
public SpringTestAspect springTestAspect() {
return new SpringTestAspect();
}
@Bean
public List<String> getAccumulator() {
return new ArrayList<String>();
}
}
@@ -0,0 +1,7 @@
package com.baeldung.spring.service;
public class SpringSuperService {
public String getInfoFromService(String code) {
return code;
}
}