Skip to content

Commit

Permalink
fix(plc4j/spi): Made it simpler to detect configuration problems
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdutz committed Mar 31, 2022
1 parent 00a857a commit 551868f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,18 @@
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.plc4x.java.api.exceptions.PlcRuntimeException;
import org.apache.plc4x.java.spi.configuration.annotations.*;
import org.apache.plc4x.java.spi.configuration.annotations.defaults.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;
Expand All @@ -47,6 +49,8 @@
*/
public class ConfigurationFactory {

private static final Logger LOGGER = LoggerFactory.getLogger(ConfigurationFactory.class);

// TODO Respect Path Params
public <T extends Configuration> T createConfiguration(Class<T> pClazz, String configurationString) {
// Get a map of all configuration parameter fields.
Expand Down Expand Up @@ -130,7 +134,12 @@ public static <T> T configure(Configuration configuration, T obj) {
if (configType instanceof Class) {
Class<?> configClass = (Class<?>) configType;
if (configClass.isAssignableFrom(configuration.getClass())) {
((HasConfiguration) obj).setConfiguration(configuration);
try {
((HasConfiguration) obj).setConfiguration(configuration);
} catch(Throwable t) {
LOGGER.error("Error setting the configuration", t);
throw new PlcRuntimeException("Error setting the configuration", t);
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public Channel createChannel(ChannelHandler channelHandler) throws PlcConnection

final Channel channel = f.channel();

// Add to Event Loop Group
// Add to event-loop group
if (workerGroup != null) {
eventLoops.put(channel, workerGroup);
}
Expand All @@ -137,8 +137,8 @@ public Channel createChannel(ChannelHandler channelHandler) throws PlcConnection
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new PlcConnectionException("Error creating channel.", e);
} catch (Exception e) {
throw new PlcConnectionException("Error creating channel.", e);
} catch (Throwable t) {
throw new PlcConnectionException("Error creating channel.", t);
}
}

Expand Down

0 comments on commit 551868f

Please sign in to comment.