arp.repository.ViewCacheUpdateMessageConsumer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ARP Show documentation
Show all versions of ARP Show documentation
a java development framework with aggregation, repository and process
The newest version!
package arp.repository;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.LockSupport;
import arp.process.publish.Message;
import arp.process.publish.ProcessMessageReceiver;
public class ViewCacheUpdateMessageConsumer {
private ProcessMessageReceiver receiver;
private ExecutorService executorService;
private Map> repositories = new ConcurrentHashMap<>();
public ViewCacheUpdateMessageConsumer(ProcessMessageReceiver receiver) {
this.receiver = receiver;
executorService = Executors.newCachedThreadPool();
}
public void registerRepository(ViewCachedRepository, ?> repository,
Class> entityType) {
repositories.put(entityType.getName(), repository);
}
public void start() {
new Thread(
() -> {
boolean park = false;
long parkNanos = 100 * 1000L;
while (true) {
if (park) {
LockSupport.parkNanos(parkNanos);
}
List msgList = null;
try {
msgList = receiver.receive();
} catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
if (msgList == null || msgList.isEmpty()) {
park = true;
continue;
}
park = true;
for (Message msg : msgList) {
List