protected void fixSocketBindings(SocketBindingGroup group) { ConfigKey key = ROOT.append(group.name()).append("socket-bindings"); List<SimpleKey> names = this.configView.simpleSubkeys(key); names.stream() .map(e -> e.name()) .map(name -> group.socketBindings() .stream() .filter(e -> e.name().equals(name)) .findFirst() .orElseGet(() -> { SocketBinding binding = new SocketBinding(name); group.socketBinding(binding); return binding; })) .forEach(e -> { applyConfiguration(key, e); }); }
protected void fixOutboundSocketBindings(SocketBindingGroup group) { ConfigKey key = ROOT.append(group.name()).append("outbound-socket-bindings"); List<SimpleKey> names = this.configView.simpleSubkeys(key); names.stream() .map(e -> e.name()) .map(name -> group.outboundSocketBindings() .stream() .filter(e -> e.name().equals(name)) .findFirst() .orElseGet(() -> { OutboundSocketBinding binding = new OutboundSocketBinding(name); group.outboundSocketBinding(binding); return binding; })) .forEach(e -> { applyConfiguration(key, e); }); }
@Produces @Singleton @Named(STANDARD_SOCKETS) public SocketBindingGroup standardSockets() { return new SocketBindingGroup( STANDARD_SOCKETS, "public", "0"); }
private void configureSocketBindings(PathAddress address, SocketBindingGroup group, List<ModelNode> list) { List<SocketBinding> socketBindings = group.socketBindings(); for (SocketBinding each : socketBindings) { configureSocketBinding(address, each, list); } List<OutboundSocketBinding> outboundSocketBindings = group.outboundSocketBindings(); for (OutboundSocketBinding each : outboundSocketBindings) { configureSocketBinding(address, each, list); } }
private void configureSocketBindingGroup(SocketBindingGroup group, List<ModelNode> list) { if ( hasSocketBindingGroup( list ) ) { return; } ModelNode node = new ModelNode(); PathAddress address = PathAddress.pathAddress("socket-binding-group", group.name()); node.get(OP).set(ADD); node.get(OP_ADDR).set(address.toModelNode()); node.get(DEFAULT_INTERFACE).set(group.defaultInterface()); node.get(PORT_OFFSET).set(new ValueExpression(group.portOffsetExpression())); list.add(node); configureSocketBindings(address, group, list); }
public void marshal(List<ModelNode> list) { for (SocketBindingGroup group : this.socketBindingGroups) { PathAddress address = PathAddress.pathAddress("socket-binding-group", group.name()); ModelNode node = new ModelNode(); node.get(OP).set(ADD); node.get(OP_ADDR).set(address.toModelNode()); node.get(DEFAULT_INTERFACE).set(group.defaultInterface()); node.get(PORT_OFFSET).set(new ValueExpression(group.portOffsetExpression())); LinkedList<ModelNode> subList = new LinkedList<>(); subList.add(node); for (SocketBinding binding : group.socketBindings()) { configureSocketBinding(address, binding, subList); } for (OutboundSocketBinding binding : group.outboundSocketBindings()) { configureSocketBinding(address, binding, subList); } if (!isAlreadyConfigured(subList, list)) { list.addAll(subList); } } }
public void customize() { this.group.socketBinding( new SocketBinding("http") .port(fraction.httpPort())); this.group.socketBinding( new SocketBinding("https") .port(fraction.httpsPort())); }
return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx); }) .filter(group -> group.name().equals(each.socketBindingGroup())) .findFirst() .ifPresent((group) -> group.socketBinding(each.socketBinding())); };
private void applySocketBindingGroupDefaults(Container config) { if (config.socketBindingGroups().isEmpty()) { config.socketBindingGroup( new SocketBindingGroup("default-sockets", "public", SwarmProperties.propertyVar(SwarmProperties.PORT_OFFSET, "0")) ); } Set<String> groupNames = config.socketBindings().keySet(); for (String each : groupNames) { List<SocketBinding> bindings = config.socketBindings().get(each); SocketBindingGroup group = config.getSocketBindingGroup(each); if (group == null) { throw new RuntimeException("No socket-binding-group for '" + each + "'"); } for (SocketBinding binding : bindings) { group.socketBinding(binding); } } groupNames = config.outboundSocketBindings().keySet(); for (String each : groupNames) { List<OutboundSocketBinding> bindings = config.outboundSocketBindings().get(each); SocketBindingGroup group = config.getSocketBindingGroup(each); if (group == null) { throw new RuntimeException("No socket-binding-group for '" + each + "'"); } for (OutboundSocketBinding binding : bindings) { group.outboundSocketBinding(binding); } } }
protected void fixGroup(SocketBindingGroup group) { ConfigKey key = ROOT.append(group.name()); int offset = this.configView.resolve(SWARM.append("port", "offset")).as(Integer.class).withDefault(0).getValue(); group.portOffset(offset); applyConfiguration(key.append("port-offset"), (portOffset) -> { group.portOffset(portOffset.toString()); }); applyConfiguration(key.append("default-interface"), (defaultInterface) -> { group.defaultInterface(defaultInterface.toString()); }); }
@SuppressWarnings("unused") void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception { try (AutoCloseable handle = Performance.time("OutboundSocketBindingExtension.afterBeanDiscovery")) { for (OutboundSocketBindingRequest each : this.bindings) { Supplier<Customizer> customizerSupplier = () -> (Customizer) () -> { Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, Any.Literal.INSTANCE); groups.stream() .map((Bean<?> e) -> { CreationalContext<?> ctx = beanManager.createCreationalContext(e); return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx); }) .filter(group -> group.name().equals(each.socketBindingGroup())) .findFirst() .ifPresent((group) -> group.outboundSocketBinding(each.outboundSocketBinding())); }; CommonBean<Customizer> customizerBean = CommonBeanBuilder.newBuilder(Customizer.class) .beanClass(OutboundSocketBindingExtension.class) .scope(Singleton.class) .addQualifier(Pre.Literal.INSTANCE) .addQualifier(Any.Literal.INSTANCE) .createSupplier(customizerSupplier) .addType(Customizer.class) .addType(Object.class).build(); abd.addBean(customizerBean); } } } }
.anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(groupName)))) { SocketBindingGroup group = new SocketBindingGroup(groupName.name(), null, "0"); .scope(ApplicationScoped.class) .addQualifier(Any.Literal.INSTANCE) .addQualifier(NamedLiteral.of(group.name())) .createSupplier(() -> group) .addType(SocketBindingGroup.class)
@Override protected void applyConfiguration(SocketBindingGroup instance) { ConfigKey key = ROOT.append(instance.name()); applyConfiguration(key.append("port-offset"), (offset) -> { instance.portOffset(offset.toString()); }); applyConfiguration(key.append("default-interface"), (offset) -> { instance.portOffset(offset.toString()); }); }
protected Object valueOf(SocketBindingGroup group, String name) throws Exception { String[] parts = name.split("\\."); String bindingName = null; String which = "port"; if (parts.length == 3) { bindingName = parts[1]; } else if (parts.length == 4) { bindingName = parts[1]; which = parts[2]; } int offset = Integer.parseInt(group.portOffsetExpression()); for (SocketBinding socketBinding : group.socketBindings()) { if (socketBinding.name().equals(bindingName)) { if (which.equals("port")) { int port = Integer.parseInt(socketBinding.portExpression()); return "" + (port + offset); } else if (which.equals("multicast-port")) { int port = Integer.parseInt(socketBinding.multicastPortExpression()); return "" + (port + offset); } else if (which.equals("multicast-address")) { String addr = socketBinding.multicastAddress(); return addr; } else if (which.equals("host")) { return valueOf("thorntail." + socketBinding.iface() + ".host"); } } } return null; }
@Override public void customize() { List<Server> servers = fraction.subresources().servers(); servers.stream() .filter(e -> e instanceof EnhancedServer) .forEach(server -> { ((EnhancedServer) server).remoteConnections() .forEach(connection -> { OutboundSocketBinding binding = new OutboundSocketBinding(connection.name()); binding.remoteHost(connection.host()) .remotePort(connection.port()); group.outboundSocketBinding(binding); }); }); } }
public SocketBindingGroup getSocketBindingGroup(String name) { for (SocketBindingGroup each : this.socketBindingGroups) { if (each.name().equals(name)) { return each; } } return null; }
@Override public void customize() { this.group.socketBinding(new SocketBinding("txn-recovery-environment") .port(this.fraction.port())); this.group.socketBinding(new SocketBinding("txn-status-manager") .port(this.fraction.statusPort())); } }
return (SocketBindingGroup) beanManager.getReference(e, SocketBindingGroup.class, ctx); }) .filter(group -> group.name().equals(each.socketBindingGroup())) .findFirst() .ifPresent((group) -> group.socketBinding(each.socketBinding())); };
public void marshal(List<ModelNode> list) { for (SocketBindingGroup group : this.socketBindingGroups) { PathAddress address = PathAddress.pathAddress("socket-binding-group", group.name()); ModelNode node = new ModelNode(); node.get(OP).set(ADD); node.get(OP_ADDR).set(address.toModelNode()); node.get(DEFAULT_INTERFACE).set(group.defaultInterface()); node.get(PORT_OFFSET).set(new ValueExpression(group.portOffsetExpression())); LinkedList<ModelNode> subList = new LinkedList<>(); subList.add(node); for (SocketBinding binding : group.socketBindings()) { configureSocketBinding(address, binding, subList); } for (OutboundSocketBinding binding : group.outboundSocketBindings()) { configureSocketBinding(address, binding, subList); } if (!isAlreadyConfigured(subList, list)) { list.addAll(subList); } } }
protected void fixGroup(SocketBindingGroup group) { ConfigKey key = ROOT.append(group.name()); int offset = this.configView.resolve(SWARM.append("port", "offset")).as(Integer.class).withDefault(0).getValue(); group.portOffset(offset); applyConfiguration(key.append("port-offset"), (portOffset) -> { group.portOffset(portOffset.toString()); }); applyConfiguration(key.append("default-interface"), (defaultInterface) -> { group.defaultInterface(defaultInterface.toString()); }); }