@Test public void getClientPropFromProperties() throws Exception { Properties properties = new Properties(); properties.put(TransportConfigKey.GROUP_EVENT_TYPE.propName(), "io.netty.channel.nio.NioEventLoopGroup"); properties.put(TransportConfigKey.SOCKET_CHANNEL_TYPE.propName(), "io.netty.channel.socket.nio.NioSocketChannel"); properties.put(TransportConfigKey.WORKERS.propName(), 4); properties.put(TransportConfigKey.MAX_POOL_CONN.propName(), 30); properties.put(TransportConfigKey.CHANNEL_PIPELINES.propName(), "a, b, c"); NettyClientProperties clientProperties = PropertiesUtil.getClientPropFromProperties(properties); assertEquals(properties.get(TransportConfigKey.GROUP_EVENT_TYPE.propName()), clientProperties.getGroupEventType()); assertEquals(properties.get(TransportConfigKey.SOCKET_CHANNEL_TYPE.propName()), clientProperties.getSocketChannelType()); assertEquals(properties.get(TransportConfigKey.WORKERS.propName()), clientProperties.getWorkers()); assertEquals(properties.get(TransportConfigKey.MAX_POOL_CONN.propName()), clientProperties.getMaxPoolConn()); assertEquals(properties.getProperty(TransportConfigKey.CHANNEL_PIPELINES.propName()), String.join(", ", clientProperties.getChannelPipelines())); }
public static NettyClientProperties getClientPropFromProperties(Properties properties) { NettyClientProperties tcpClientProperties = new NettyClientProperties(); BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(NettyClientProperties.class); } catch (IntrospectionException e) { throw new RuntimeException(e); } for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { if (descriptor.getName().equals("class")) continue; TransportConfigKey key = TransportConfigKey.get(descriptor.getName()); Optional.ofNullable(key) .map(k -> { Object val = properties.get(k.propName()); return val != null ? k.convert(val) : null; }) .ifPresent(v -> { Method setter = descriptor.getWriteMethod(); try { setter.invoke(tcpClientProperties, v); } catch (IllegalAccessException | InvocationTargetException e) { log.debug(e); throw new IllegalArgumentException("illegal property value"); } }); } return tcpClientProperties; }
PropertiesUtil { public static NettyClientProperties getClientPropFromProperties(Properties properties) { NettyClientProperties tcpClientProperties = new NettyClientProperties(); BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(NettyClientProperties.class); } catch (IntrospectionException e) { throw new RuntimeException(e); } for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { if (descriptor.getName().equals("class")) continue; TransportConfigKey key = TransportConfigKey.get(descriptor.getName()); Optional.ofNullable(key) .map(k -> { Object val = properties.get(k.propName()); return val != null ? k.convert(val) : null; }) .ifPresent(v -> { Method setter = descriptor.getWriteMethod(); try { setter.invoke(tcpClientProperties, v); } catch (IllegalAccessException | InvocationTargetException e) { log.debug(e); throw new IllegalArgumentException("illegal property value"); } }); } return tcpClientProperties; } }
PropertiesUtil { public static NettyClientProperties getClientPropFromProperties(Properties properties) { NettyClientProperties tcpClientProperties = new NettyClientProperties(); BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(NettyClientProperties.class); } catch (IntrospectionException e) { throw new RuntimeException(e); } for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { if (descriptor.getName().equals("class")) continue; TransportConfigKey key = TransportConfigKey.get(descriptor.getName()); Optional.ofNullable(key) .map(k -> { Object val = properties.get(k.propName()); return val != null ? k.convert(val) : null; }) .ifPresent(v -> { Method setter = descriptor.getWriteMethod(); try { setter.invoke(tcpClientProperties, v); } catch (IllegalAccessException | InvocationTargetException e) { log.debug(e); throw new IllegalArgumentException("illegal property value"); } }); } return tcpClientProperties; }  }
PropertiesUtil { public static NettyClientProperties getClientPropFromProperties(Properties properties) { NettyClientProperties tcpClientProperties = new NettyClientProperties(); BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(NettyClientProperties.class); } catch (IntrospectionException e) { throw new RuntimeException(e); } for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { if (descriptor.getName().equals("class")) continue; TransportConfigKey key = TransportConfigKey.get(descriptor.getName()); Optional.ofNullable(key) .map(k -> { Object val = properties.get(k.propName()); return val != null ? k.convert(val) : null; }) .ifPresent(v -> { Method setter = descriptor.getWriteMethod(); try { setter.invoke(tcpClientProperties, v); } catch (IllegalAccessException | InvocationTargetException e) { log.debug(e); throw new IllegalArgumentException("illegal property value"); } }); } return tcpClientProperties; }  static NettyClientProperties getClientPropFromProperties(Properties properties); }
PropertiesUtil { public static NettyClientProperties getClientPropFromProperties(Properties properties) { NettyClientProperties tcpClientProperties = new NettyClientProperties(); BeanInfo beanInfo; try { beanInfo = Introspector.getBeanInfo(NettyClientProperties.class); } catch (IntrospectionException e) { throw new RuntimeException(e); } for (PropertyDescriptor descriptor : beanInfo.getPropertyDescriptors()) { if (descriptor.getName().equals("class")) continue; TransportConfigKey key = TransportConfigKey.get(descriptor.getName()); Optional.ofNullable(key) .map(k -> { Object val = properties.get(k.propName()); return val != null ? k.convert(val) : null; }) .ifPresent(v -> { Method setter = descriptor.getWriteMethod(); try { setter.invoke(tcpClientProperties, v); } catch (IllegalAccessException | InvocationTargetException e) { log.debug(e); throw new IllegalArgumentException("illegal property value"); } }); } return tcpClientProperties; }  static NettyClientProperties getClientPropFromProperties(Properties properties);  }