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
+9
View File
@@ -0,0 +1,9 @@
*.class
# Folders #
/gensrc
/target
# Packaged files #
*.jar
/bin/
+48
View File
@@ -0,0 +1,48 @@
## Libraries
This module contains articles about various Java libraries.
These are small libraries that are relatively easy to use and do not require any separate module of their own.
The code examples related to different libraries are each in their own module.
Remember, for advanced libraries like [Jackson](/jackson) and [JUnit](/testing-modules) we already have separate modules. Please make sure to have a look at the existing modules in such cases.
### Relevant articles
- [Introduction to Javatuples](https://www.baeldung.com/java-tuples)
- [Introduction to Javassist](https://www.baeldung.com/javassist)
- [Introduction to Apache Flink with Java](https://www.baeldung.com/apache-flink)
- [Intro to JaVers](https://www.baeldung.com/javers)
- [Merging Streams in Java](https://www.baeldung.com/java-merge-streams)
- [Introduction to Quartz](https://www.baeldung.com/quartz)
- [How to Warm Up the JVM](https://www.baeldung.com/java-jvm-warmup)
- [Software Transactional Memory in Java Using Multiverse](https://www.baeldung.com/java-multiverse-stm)
- [Locality-Sensitive Hashing in Java Using Java-LSH](https://www.baeldung.com/locality-sensitive-hashing)
- [Introduction to Neuroph](https://www.baeldung.com/neuroph)
- [Quick Guide to RSS with Rome](https://www.baeldung.com/rome-rss)
- [Introduction to PCollections](https://www.baeldung.com/java-pcollections)
- [Introduction to Eclipse Collections](https://www.baeldung.com/eclipse-collections)
- [DistinctBy in the Java Stream API](https://www.baeldung.com/java-streams-distinct-by)
- [Introduction to NoException](https://www.baeldung.com/no-exception)
- [Spring Yarg Integration](https://www.baeldung.com/spring-yarg)
- [Delete a Directory Recursively in Java](https://www.baeldung.com/java-delete-directory)
- [Guide to JDeferred](https://www.baeldung.com/jdeferred)
- [Introduction to MBassador](https://www.baeldung.com/mbassador)
- [Using Pairs in Java](https://www.baeldung.com/java-pairs)
- [Introduction to Caffeine](https://www.baeldung.com/java-caching-caffeine)
- [Introduction to StreamEx](https://www.baeldung.com/streamex)
- [A Docker Guide for Java](https://www.baeldung.com/docker-java-api)
- [Introduction to Akka Actors in Java](https://www.baeldung.com/akka-actors-java)
- [A Guide to Byte Buddy](https://www.baeldung.com/byte-buddy)
- [Introduction to jOOL](https://www.baeldung.com/jool)
- [Consumer Driven Contracts with Pact](https://www.baeldung.com/pact-junit-consumer-driven-contracts)
- [Introduction to Atlassian Fugue](https://www.baeldung.com/java-fugue)
- [Publish and Receive Messages with Nats Java Client](https://www.baeldung.com/nats-java-client)
- [Java Concurrency Utility with JCTools](https://www.baeldung.com/java-concurrency-jc-tools)
- [Introduction to JavaPoet](https://www.baeldung.com/java-poet)
- [Guide to Resilience4j](https://www.baeldung.com/resilience4j)
- [Exactly Once Processing in Kafka](https://www.baeldung.com/kafka-exactly-once)
- [Implementing a FTP-Client in Java](https://www.baeldung.com/java-ftp-client)
- [Introduction to Functional Java](https://www.baeldung.com/java-functional-library)
- [A Guide to the Reflections Library](https://www.baeldung.com/reflections-library)
- More articles [[next -->]](/libraries-2)
Binary file not shown.
+5
View File
@@ -0,0 +1,5 @@
log4j.rootLogger=INFO, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
+26
View File
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?><root>
</root>
+796
View File
File diff suppressed because it is too large Load Diff
+4
View File
@@ -0,0 +1,4 @@
jira.url=<jira-url>
jira.project=<jira-project>
jira.username=<jira-username>
jira.password=<jira-password>
@@ -0,0 +1,32 @@
package com.baeldung.akka;
import akka.actor.AbstractActor;
import akka.actor.Props;
import akka.event.Logging;
import akka.event.LoggingAdapter;
public class FirstActor extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
public static Props props() {
return Props.create(FirstActor.class);
}
@Override
public void preStart() {
log.info("Actor started");
}
@Override
public void postStop() {
log.info("Actor stopped");
}
// Messages will not be handled
@Override
public Receive createReceive() {
return receiveBuilder()
.build();
}
}
@@ -0,0 +1,24 @@
package com.baeldung.akka;
import akka.actor.AbstractActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
public class MyActor extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
@Override
public void postStop() {
log.info("Stopping actor {}", this);
}
public Receive createReceive() {
return receiveBuilder()
.matchEquals("printit", p -> {
System.out.println("The address of this actor is: " + getSelf());
getSender().tell("Got Message", getSelf());
})
.build();
}
}
@@ -0,0 +1,45 @@
package com.baeldung.akka;
import akka.actor.AbstractActor;
import akka.actor.Props;
import akka.event.Logging;
import akka.event.LoggingAdapter;
public class PrinterActor extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
public static Props props(String text) {
return Props.create(PrinterActor.class, text);
}
public static final class PrintFinalResult {
Integer totalNumberOfWords;
public PrintFinalResult(Integer totalNumberOfWords) {
this.totalNumberOfWords = totalNumberOfWords;
}
}
@Override
public void preStart() {
log.info("Starting PrinterActor {}", this);
}
@Override
public void postStop() {
log.info("Stopping PrinterActor {}", this);
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(PrinterActor.PrintFinalResult.class,
r -> {
log.info("Received PrintFinalResult message from " + getSender());
log.info("The text has a total number of {} words", r.totalNumberOfWords);
})
.build();
}
}
@@ -0,0 +1,73 @@
package com.baeldung.akka;
import akka.actor.AbstractActor;
import akka.actor.ActorRef;
import akka.actor.Props;
import akka.event.Logging;
import akka.event.LoggingAdapter;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import static akka.pattern.PatternsCS.ask;
public class ReadingActor extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
private String text;
public ReadingActor(String text) {
this.text = text;
}
public static Props props(String text) {
return Props.create(ReadingActor.class, text);
}
public static final class ReadLines {
}
@Override
public void preStart() {
log.info("Starting ReadingActor {}", this);
}
@Override
public void postStop() {
log.info("Stopping ReadingActor {}", this);
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(ReadLines.class, r -> {
log.info("Received ReadLines message from " + getSender());
String[] lines = text.split("\n");
List<CompletableFuture> futures = new ArrayList<>();
for (int i = 0; i < lines.length; i++) {
String line = lines[i];
ActorRef wordCounterActorRef = getContext().actorOf(Props.create(WordCounterActor.class), "word-counter-" + i);
CompletableFuture<Object> future =
ask(wordCounterActorRef, new WordCounterActor.CountWords(line), 1000).toCompletableFuture();
futures.add(future);
}
Integer totalNumberOfWords = futures.stream()
.map(CompletableFuture::join)
.mapToInt(n -> (Integer) n)
.sum();
ActorRef printerActorRef = getContext().actorOf(Props.create(PrinterActor.class), "Printer-Actor");
printerActorRef.forward(new PrinterActor.PrintFinalResult(totalNumberOfWords), getContext());
// printerActorRef.tell(new PrinterActor.PrintFinalResult(totalNumberOfWords), getSelf());
})
.build();
}
}
@@ -0,0 +1,55 @@
package com.baeldung.akka;
import akka.actor.AbstractActor;
import akka.event.Logging;
import akka.event.LoggingAdapter;
public class WordCounterActor extends AbstractActor {
private final LoggingAdapter log = Logging.getLogger(getContext().getSystem(), this);
public static final class CountWords {
String line;
public CountWords(String line) {
this.line = line;
}
}
@Override
public void preStart() {
log.info("Starting WordCounterActor {}", this);
}
@Override
public Receive createReceive() {
return receiveBuilder()
.match(CountWords.class, r -> {
try {
log.info("Received CountWords message from " + getSender());
int numberOfWords = countWordsFromLine(r.line);
getSender().tell(numberOfWords, getSelf());
} catch (Exception ex) {
getSender().tell(new akka.actor.Status.Failure(ex), getSelf());
throw ex;
}
})
.build();
}
private int countWordsFromLine(String line) throws Exception {
if (line == null) {
throw new IllegalArgumentException("The text to process can't be null!");
}
int numberOfWords = 0;
String[] words = line.split(" ");
for (String possibleWord : words) {
if (possibleWord.trim().length() > 0) {
numberOfWords++;
}
}
return numberOfWords;
}
}
@@ -0,0 +1,21 @@
package com.baeldung.bytebuddy;
import net.bytebuddy.implementation.bind.annotation.BindingPriority;
public class Bar {
@BindingPriority(3)
public static String sayHelloBar() {
return "Holla in Bar!";
}
@BindingPriority(2)
public static String sayBar() {
return "bar";
}
public String bar() {
return Bar.class.getSimpleName() + " - Bar";
}
}
@@ -0,0 +1,9 @@
package com.baeldung.bytebuddy;
public class Foo {
public String sayHelloFoo() {
return "Hello in Foo!";
}
}
@@ -0,0 +1,30 @@
package com.baeldung.caffeine;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
final class DataObject {
private final String data;
private static int objectCounter = 0;
private static final Logger log = LoggerFactory.getLogger(DataObject.class);
private DataObject(String data) {
this.data = data;
}
public String getData() {
return data;
}
@Override
public String toString() {
return "DataObject{" + "data='" + data + '\'' + '}';
}
public static DataObject get(String data) {
objectCounter++;
log.info("Init DataObject#{} with '{}'", objectCounter, data);
return new DataObject(data);
}
}
@@ -0,0 +1,8 @@
package com.baeldung.cglib.mixin;
public class Class1 implements Interface1 {
@Override
public String first() {
return "first behaviour";
}
}
@@ -0,0 +1,8 @@
package com.baeldung.cglib.mixin;
public class Class2 implements Interface2 {
@Override
public String second() {
return "second behaviour";
}
}
@@ -0,0 +1,5 @@
package com.baeldung.cglib.mixin;
public interface Interface1 {
String first();
}
@@ -0,0 +1,5 @@
package com.baeldung.cglib.mixin;
public interface Interface2 {
String second();
}
@@ -0,0 +1,4 @@
package com.baeldung.cglib.mixin;
public interface MixinInterface extends Interface1, Interface2 {
}
@@ -0,0 +1,11 @@
package com.baeldung.cglib.proxy;
public class PersonService {
public String sayHello(String name) {
return "Hello " + name;
}
public Integer lengthOfName(String name) {
return name.length();
}
}
@@ -0,0 +1,21 @@
package com.baeldung.chronicle.queue;
import java.io.IOException;
import net.openhft.chronicle.Chronicle;
import net.openhft.chronicle.ExcerptAppender;
public class ChronicleQueue {
static void writeToQueue(Chronicle chronicle, String stringValue, int intValue, long longValue, double doubleValue) throws IOException {
ExcerptAppender appender = chronicle.createAppender();
appender.startExcerpt();
appender.writeUTF(stringValue);
appender.writeInt(intValue);
appender.writeLong(longValue);
appender.writeDouble(doubleValue);
appender.finish();
appender.close();
}
}
@@ -0,0 +1,15 @@
package com.baeldung.distinct;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Predicate;
public class DistinctWithJavaFunction {
public static <T> Predicate<T> distinctByKey(Function<? super T, ?> keyExtractor) {
Map<Object, Boolean> seen = new ConcurrentHashMap<>();
return t -> seen.putIfAbsent(keyExtractor.apply(t), Boolean.TRUE) == null;
}
}
@@ -0,0 +1,65 @@
package com.baeldung.distinct;
public class Person {
int age;
String name;
String email;
public Person(int age, String name, String email) {
super();
this.age = age;
this.name = name;
this.email = email;
}
public int getAge() {
return age;
}
public String getName() {
return name;
}
public String getEmail() {
return email;
}
@Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("Person [age=");
builder.append(age);
builder.append(", name=");
builder.append(name);
builder.append(", email=");
builder.append(email);
builder.append("]");
return builder.toString();
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((email == null) ? 0 : email.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Person other = (Person) obj;
if (email == null) {
if (other.email != null)
return false;
} else if (!email.equals(other.email))
return false;
return true;
}
}
@@ -0,0 +1,19 @@
package com.baeldung.eclipsecollections;
import java.util.List;
import org.eclipse.collections.impl.set.mutable.UnifiedSet;
public class ConvertContainerToAnother {
@SuppressWarnings("rawtypes")
public static List convertToList() {
UnifiedSet<String> cars = new UnifiedSet<>();
cars.add("Toyota");
cars.add("Mercedes");
cars.add("Volkswagen");
return cars.toList();
}
}
@@ -0,0 +1,46 @@
package com.baeldung.eclipsecollections;
import java.util.List;
public class Student {
private String firstName;
private String lastName;
private List<String> addresses;
public Student(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
public Student(String firstName, String lastName, List<String> addresses) {
super();
this.firstName = firstName;
this.lastName = lastName;
this.addresses = addresses;
}
public String getFirstName() {
return this.firstName;
}
public String getLastName() {
return this.lastName;
}
public List<String> getAddresses() {
return addresses;
}
public void setAddresses(List<String> addresses) {
this.addresses = addresses;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
}
@@ -0,0 +1,43 @@
package com.baeldung.fj;
import fj.F;
import fj.F1Functions;
import fj.Unit;
import fj.data.IO;
import fj.data.IOFunctions;
public class FunctionalJavaIOMain {
public static IO<Unit> printLetters(final String s) {
return () -> {
for (int i = 0; i < s.length(); i++) {
System.out.println(s.charAt(i));
}
return Unit.unit();
};
}
public static void main(String[] args) {
F<String, IO<Unit>> printLetters = i -> printLetters(i);
IO<Unit> lowerCase = IOFunctions.stdoutPrintln("What's your first Name ?");
IO<Unit> input = IOFunctions.stdoutPrint("First Name: ");
IO<Unit> userInput = IOFunctions.append(lowerCase, input);
IO<String> readInput = IOFunctions.stdinReadLine();
F<String, String> toUpperCase = i -> i.toUpperCase();
F<String, IO<Unit>> transformInput = F1Functions.<String, IO<Unit>, String> o(printLetters).f(toUpperCase);
IO<Unit> readAndPrintResult = IOFunctions.bind(readInput, transformInput);
IO<Unit> program = IOFunctions.bind(userInput, nothing -> readAndPrintResult);
IOFunctions.toSafe(program).run();
}
}
@@ -0,0 +1,48 @@
package com.baeldung.fj;
import fj.F;
import fj.Show;
import fj.data.Array;
import fj.data.List;
import fj.data.Option;
import fj.function.Characters;
import fj.function.Integers;
public class FunctionalJavaMain {
public static final F<Integer, Boolean> isEven = i -> i % 2 == 0;
public static void main(String[] args) {
List<Integer> fList = List.list(3, 4, 5, 6);
List<Boolean> evenList = fList.map(isEven);
Show.listShow(Show.booleanShow).println(evenList);
fList = fList.map(i -> i + 1);
Show.listShow(Show.intShow).println(fList);
Array<Integer> a = Array.array(17, 44, 67, 2, 22, 80, 1, 27);
Array<Integer> b = a.filter(Integers.even);
Show.arrayShow(Show.intShow).println(b);
Array<String> array = Array.array("Welcome", "To", "baeldung");
Boolean isExist = array.exists(s -> List.fromString(s).forall(Characters.isLowerCase));
System.out.println(isExist);
Array<Integer> intArray = Array.array(17, 44, 67, 2, 22, 80, 1, 27);
int sum = intArray.foldLeft(Integers.add, 0);
System.out.println(sum);
Option<Integer> n1 = Option.some(1);
Option<Integer> n2 = Option.some(2);
F<Integer, Option<Integer>> f1 = i -> i % 2 == 0 ? Option.some(i + 100) : Option.none();
Option<Integer> result1 = n1.bind(f1);
Option<Integer> result2 = n2.bind(f1);
Show.optionShow(Show.intShow).println(result1);
Show.optionShow(Show.intShow).println(result2);
}
}
@@ -0,0 +1,4 @@
package com.baeldung.flips;
public class TestFlipsBean {
}
@@ -0,0 +1,64 @@
package com.baeldung.ftp;
import org.apache.commons.net.PrintCommandListener;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
import java.io.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Collectors;
class FtpClient {
private final String server;
private final int port;
private final String user;
private final String password;
private FTPClient ftp;
FtpClient(String server, int port, String user, String password) {
this.server = server;
this.port = port;
this.user = user;
this.password = password;
}
void open() throws IOException {
ftp = new FTPClient();
ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));
ftp.connect(server, port);
int reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
throw new IOException("Exception in connecting to FTP Server");
}
ftp.login(user, password);
}
void close() throws IOException {
ftp.disconnect();
}
Collection<String> listFiles(String path) throws IOException {
FTPFile[] files = ftp.listFiles(path);
return Arrays.stream(files)
.map(FTPFile::getName)
.collect(Collectors.toList());
}
void putFileToPath(File file, String path) throws IOException {
ftp.storeFile(path, new FileInputStream(file));
}
void downloadFile(String source, String destination) throws IOException {
FileOutputStream out = new FileOutputStream(destination);
ftp.retrieveFile(source, out);
out.close();
}
}

Some files were not shown because too many files have changed in this diff Show More