
com.github.thorbenkuck.netcom2.auto.GeneratedRepository Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of NetCom2-Auto Show documentation
Show all versions of NetCom2-Auto Show documentation
Annotation approach to reduce boilerplate code
The newest version!
package com.github.thorbenkuck.netcom2.auto;
import com.github.thorbenkuck.netcom2.network.client.ClientStart;
import com.github.thorbenkuck.netcom2.network.server.ServerStart;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
class GeneratedRepository {
private final List onReceiveWrapperCache = new ArrayList<>();
private final List clientConnectedWrappersCache = new ArrayList<>();
private final List clientDisconnectedWrappersCache = new ArrayList<>();
private final List serverPreConfigurationCache = new ArrayList<>();
private final List clientPreConfigurationCache = new ArrayList<>();
final synchronized void read() {
// We do not want to limit parallel
// work to much. This method is
// synchronized, because we do not
// want to have more than one thread
// actually trying to read the
// service files. The other
// method however is not synchronized.
// Therefor we have to synchronize
// for every cache we have.
ServiceLoader onReceiveWrappers = ServiceLoader.load(OnReceiveWrapper.class);
synchronized (onReceiveWrapperCache) {
onReceiveWrappers.forEach(onReceiveWrapperCache::add);
}
ServiceLoader clientConnectedWrappers = ServiceLoader.load(ClientConnectedWrapper.class);
synchronized (clientConnectedWrappersCache) {
clientConnectedWrappers.forEach(clientConnectedWrappersCache::add);
}
ServiceLoader clientDisconnectedWrappers = ServiceLoader.load(ClientDisconnectedWrapper.class);
synchronized (clientDisconnectedWrappersCache) {
clientDisconnectedWrappers.forEach(clientDisconnectedWrappersCache::add);
}
ServiceLoader serverPreConfigurationServiceLoader = ServiceLoader.load(ServerPreConfiguration.class);
synchronized (serverPreConfigurationCache) {
serverPreConfigurationServiceLoader.forEach(serverPreConfigurationCache::add);
}
ServiceLoader clientPreConfigurationServiceLoader = ServiceLoader.load(ClientPreConfiguration.class);
synchronized (clientPreConfigurationCache) {
clientPreConfigurationServiceLoader.forEach(clientPreConfigurationCache::add);
}
}
final void apply(ServerStart serverStart, ObjectRepository repository) {
synchronized (onReceiveWrapperCache) {
onReceiveWrapperCache.forEach(wrapper -> wrapper.apply(serverStart, repository));
}
synchronized (clientConnectedWrappersCache) {
clientConnectedWrappersCache.forEach(wrapper -> wrapper.apply(serverStart, repository));
}
synchronized (clientDisconnectedWrappersCache) {
clientDisconnectedWrappersCache.forEach(wrapper -> wrapper.apply(serverStart, repository));
}
synchronized (serverPreConfigurationCache) {
serverPreConfigurationCache.forEach(configuration -> configuration.accept(serverStart, repository));
}
}
final void apply(ClientStart clientStart, ObjectRepository repository) {
synchronized (onReceiveWrapperCache) {
onReceiveWrapperCache.forEach(wrapper -> wrapper.apply(clientStart, repository));
}
synchronized (clientDisconnectedWrappersCache) {
clientDisconnectedWrappersCache.forEach(wrapper -> wrapper.apply(clientStart, repository));
}
synchronized (clientPreConfigurationCache) {
clientPreConfigurationCache.forEach(configuration -> configuration.accept(clientStart, repository));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy