@Override public JChannel createChannel(String id) throws Exception { FORK fork = new FORK(); fork.enableStats(this.configuration.isStatisticsEnabled()); fork.setUnknownForkHandler(new UnknownForkHandler() { private final short id = ClassConfigurator.getProtocolId(RequestCorrelator.class); List<ProtocolConfiguration<? extends Protocol>> transports = Collections.singletonList(this.configuration.getTransport()); List<ProtocolConfiguration<? extends Protocol>> relays = this.configuration.getRelay().isPresent() ? Collections.singletonList(this.configuration.getRelay().get()) : Collections.emptyList(); List<Protocol> protocols = new ArrayList<>(transports.size() + this.configuration.getProtocols().size() + relays.size() + 1); for (List<ProtocolConfiguration<? extends Protocol>> protocolConfigs : Arrays.asList(transports, this.configuration.getProtocols(), relays)) { for (ProtocolConfiguration<? extends Protocol> protocolConfig : protocolConfigs) { protocols.add(protocolConfig.createProtocol(this.configuration)); protocols.get(0).setSocketFactory(new ManagedSocketFactory(this.configuration.getSocketBindingManager(), bindings)); channel.setName(this.configuration.getNodeName()); TransportConfiguration.Topology topology = this.configuration.getTransport().getTopology(); if (topology != null) { channel.addAddressGenerator(new TopologyAddressGenerator(topology));
@Override public Protocol findProtocol(OperationContext context) throws ClassNotFoundException, ModuleLoadException { PathAddress address = context.getCurrentAddress(); String channelName = address.getParent().getLastElement().getValue(); String protocolName = address.getLastElement().getValue(); ServiceRegistry registry = context.getServiceRegistry(true); JChannel channel = new PassiveServiceSupplier<JChannel>(registry, JGroupsRequirement.CHANNEL.getServiceName(context, channelName)).get(); if (channel != null) { ChannelFactory factory = new PassiveServiceSupplier<ChannelFactory>(registry, JGroupsRequirement.CHANNEL_SOURCE.getServiceName(context, channelName)).get(); if (factory != null) { ProtocolStackConfiguration configuration = factory.getProtocolStackConfiguration(); ProtocolConfiguration<? extends TP> transport = configuration.getTransport(); if (transport.getName().equals(protocolName)) { Class<? extends Protocol> protocolClass = transport.createProtocol(configuration).getClass(); return channel.getProtocolStack().findProtocol(protocolClass); } for (ProtocolConfiguration<? extends Protocol> protocol : configuration.getProtocols()) { if (protocol.getName().equals(protocolName)) { Class<? extends Protocol> protocolClass = protocol.createProtocol(configuration).getClass(); return channel.getProtocolStack().findProtocol(protocolClass); } } } } return null; }
@Override public Optional<RelayConfiguration> getRelay() { return this.parentStack.getRelay(); }
@Override public TransportConfiguration<? extends TP> getTransport() { return this.parentStack.getTransport(); }
@Override public boolean isStatisticsEnabled() { return this.parentStack.isStatisticsEnabled(); }
@Override public SocketBindingManager getSocketBindingManager() { return this.parentStack.getSocketBindingManager(); } }
@Override public ProtocolStackConfiguration getProtocolStackConfiguration() { ProtocolStackConfiguration parentStack = this.parentFactory.getProtocolStackConfiguration(); return new ForkProtocolStackConfiguration(this.channel.getClusterName(), parentStack, Stream.concat(parentStack.getProtocols().stream(), this.protocols.stream()).collect(Collectors.toList())); }
@Override public String getNodeName() { return this.parentStack.getNodeName(); }
@Override public Protocol findProtocol(OperationContext context) throws ClassNotFoundException, ModuleLoadException { PathAddress address = context.getCurrentAddress(); String channelName = address.getElement(address.size() - 3).getValue(); String forkName = address.getElement(address.size() - 2).getValue(); String protocolName = address.getElement(address.size() - 1).getValue(); ServiceRegistry registry = context.getServiceRegistry(true); JChannel channel = new PassiveServiceSupplier<JChannel>(registry, JGroupsRequirement.CHANNEL.getServiceName(context, channelName)).get(); if (channel != null) { FORK fork = (FORK) channel.getProtocolStack().findProtocol(FORK.class); if (fork != null) { ChannelFactory factory = new PassiveServiceSupplier<ChannelFactory>(registry, JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, channelName)).get(); if (factory != null) { ProtocolStackConfiguration configuration = factory.getProtocolStackConfiguration(); ProtocolConfiguration<? extends TP> transport = configuration.getTransport(); if (transport.getName().equals(protocolName)) { Class<? extends Protocol> protocolClass = transport.createProtocol(configuration).getClass(); return channel.getProtocolStack().findProtocol(protocolClass); } for (ProtocolConfiguration<? extends Protocol> protocol : configuration.getProtocols()) { if (protocol.getName().equals(protocolName)) { Class<? extends Protocol> protocolClass = protocol.createProtocol(configuration).getClass(); return fork.get(forkName).getProtocolStack().findProtocol(protocolClass); } } } } } return null; }
@Override public SiteConfiguration get() { SiteConfigurationBuilder builder = new GlobalConfigurationBuilder().site(); if (this.factory != null) { RelayConfiguration relay = this.factory.get().getProtocolStackConfiguration().getRelay().orElse(null); if (relay != null) { builder.localSite(relay.getSiteName()); } } return builder.create(); } }
@Override public TransportConfiguration get() { ChannelFactory factory = this.factory.get(); ProtocolStackConfiguration stack = factory.getProtocolStackConfiguration(); org.wildfly.clustering.jgroups.spi.TransportConfiguration.Topology topology = stack.getTransport().getTopology(); TransportConfigurationBuilder builder = new GlobalConfigurationBuilder().transport() .clusterName(this.cluster.get()) .distributedSyncTimeout(this.lockTimeout) .transport(new ChannelFactoryTransport(factory)) ; if (topology != null) { builder.siteId(topology.getSite()).rackId(topology.getRack()).machineId(topology.getMachine()); } return builder.create(); }
@Override public final P createProtocol(ProtocolStackConfiguration stackConfiguration) { // A "native" protocol is one that is not specified as a class name boolean nativeProtocol = this.moduleName.equals(AbstractProtocolResourceDefinition.Attribute.MODULE.getDefinition().getDefaultValue().asString()) && !this.name.startsWith(org.jgroups.conf.ProtocolConfiguration.protocol_prefix); String className = nativeProtocol ? String.join(".", org.jgroups.conf.ProtocolConfiguration.protocol_prefix, this.name) : this.name; try { Module module = this.loader.get().loadModule(this.moduleName); Class<? extends Protocol> protocolClass = module.getClassLoader().loadClass(className).asSubclass(Protocol.class); Map<String, String> properties = new HashMap<>(this.defaults.get().getProperties(protocolClass)); properties.putAll(this.properties); PrivilegedExceptionAction<Protocol> action = () -> { try { return protocolClass.newInstance().setProperties(properties); } catch (InstantiationException | IllegalAccessException e) { throw new IllegalStateException(e); } }; @SuppressWarnings("unchecked") P protocol = (P) WildFlySecurityManager.doUnchecked(action); this.accept(protocol); protocol.enableStats(this.statisticsEnabled != null ? this.statisticsEnabled : stackConfiguration.isStatisticsEnabled()); return protocol; } catch (Exception e) { throw new IllegalArgumentException(e); } } }
@Override public SocketBindingManager getSocketBindingManager() { return this.parentStack.getSocketBindingManager(); } }
@Override public ProtocolStackConfiguration getProtocolStackConfiguration() { ProtocolStackConfiguration parentStack = this.parentFactory.getProtocolStackConfiguration(); return new ForkProtocolStackConfiguration(this.channel.getClusterName(), parentStack, Stream.concat(parentStack.getProtocols().stream(), this.protocols.stream()).collect(Collectors.toList())); }
@Override public String getNodeName() { return this.parentStack.getNodeName(); }
@Override public JChannel createChannel(String id) throws Exception { FORK fork = new FORK(); fork.enableStats(this.configuration.isStatisticsEnabled()); fork.setUnknownForkHandler(new UnknownForkHandler() { private final short id = ClassConfigurator.getProtocolId(RequestCorrelator.class); List<ProtocolConfiguration<? extends Protocol>> transports = Collections.singletonList(this.configuration.getTransport()); List<ProtocolConfiguration<? extends Protocol>> relays = this.configuration.getRelay().isPresent() ? Collections.singletonList(this.configuration.getRelay().get()) : Collections.emptyList(); List<Protocol> protocols = new ArrayList<>(transports.size() + this.configuration.getProtocols().size() + relays.size() + 1); for (List<ProtocolConfiguration<? extends Protocol>> protocolConfigs : Arrays.asList(transports, this.configuration.getProtocols(), relays)) { for (ProtocolConfiguration<? extends Protocol> protocolConfig : protocolConfigs) { protocols.add(protocolConfig.createProtocol(this.configuration)); protocols.get(0).setSocketFactory(new ManagedSocketFactory(this.configuration.getSocketBindingManager(), bindings)); channel.setName(this.configuration.getNodeName()); TransportConfiguration.Topology topology = this.configuration.getTransport().getTopology(); if (topology != null) { channel.addAddressGenerator(new TopologyAddressGenerator(topology));
@Override public Protocol findProtocol(OperationContext context) throws ClassNotFoundException, ModuleLoadException { PathAddress address = context.getCurrentAddress(); String channelName = address.getParent().getLastElement().getValue(); String protocolName = address.getLastElement().getValue(); ServiceRegistry registry = context.getServiceRegistry(true); JChannel channel = new PassiveServiceSupplier<JChannel>(registry, JGroupsRequirement.CHANNEL.getServiceName(context, channelName)).get(); if (channel != null) { ChannelFactory factory = new PassiveServiceSupplier<ChannelFactory>(registry, JGroupsRequirement.CHANNEL_SOURCE.getServiceName(context, channelName)).get(); if (factory != null) { ProtocolStackConfiguration configuration = factory.getProtocolStackConfiguration(); ProtocolConfiguration<? extends TP> transport = configuration.getTransport(); if (transport.getName().equals(protocolName)) { Class<? extends Protocol> protocolClass = transport.createProtocol(configuration).getClass(); return channel.getProtocolStack().findProtocol(protocolClass); } for (ProtocolConfiguration<? extends Protocol> protocol : configuration.getProtocols()) { if (protocol.getName().equals(protocolName)) { Class<? extends Protocol> protocolClass = protocol.createProtocol(configuration).getClass(); return channel.getProtocolStack().findProtocol(protocolClass); } } } } return null; }
@Override public Optional<RelayConfiguration> getRelay() { return this.parentStack.getRelay(); }
@Override public TransportConfiguration<? extends TP> getTransport() { return this.parentStack.getTransport(); }
@Override public boolean isStatisticsEnabled() { return this.parentStack.isStatisticsEnabled(); }