@Override public boolean isUnknownForkResponse(ByteBuffer response) { return this.parentFactory.isUnknownForkResponse(response); }
@Override public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ChannelFactory factory) throws OperationFailedException { // Create a temporary channel, but don't connect it try (JChannel channel = factory.createChannel(UUID.randomUUID().toString())) { // ProtocolStack.printProtocolSpecAsXML() is very hacky and only works on an uninitialized stack List<Protocol> protocols = channel.getProtocolStack().getProtocols(); Collections.reverse(protocols); ProtocolStack stack = new ProtocolStack(); stack.addProtocols(protocols); return new ModelNode(stack.printProtocolSpecAsXML()); } catch (Exception e) { throw new OperationFailedException(e); } } },
@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 JChannel createChannel(String id) throws Exception { JGroupsLogger.ROOT_LOGGER.debugf("Creating fork channel %s from channel %s", id, this.channel.getClusterName()); String stackName = this.protocols.isEmpty() ? this.channel.getClusterName() : id; Protocol[] protocols = new Protocol[this.protocols.size()]; for (int i = 0; i < protocols.length; ++i) { protocols[i] = this.protocols.get(i).createProtocol(this.parentFactory.getProtocolStackConfiguration()); } return new ForkChannel(this.channel, stackName, id, protocols); }
@Override public JChannel createChannel() throws Exception { JChannel channel = remoteSite.getChannelFactory().createChannel(siteName); // Don't use FORK in bridge stack channel.getProtocolStack().removeProtocol(FORK.class); return channel; } };
@Override public Object objectFromStream(DataInput stream) throws Exception { int size = IndexSerializer.VARIABLE.readInt(stream); byte[] buffer = new byte[size]; stream.readFully(buffer); if (this.factory.isUnknownForkResponse(ByteBuffer.wrap(buffer))) return NoSuchService.INSTANCE; try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(buffer))) { int version = this.versionSerializer.readInt(input); try (Unmarshaller unmarshaller = this.context.createUnmarshaller(version)) { unmarshaller.start(Marshalling.createByteInput(input)); return unmarshaller.readObject(); } } } }
@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 protected void initChannel() { try { this.channel = this.factory.createChannel(this.configuration.globalJmxStatistics().cacheManagerName()); this.channel.setDiscardOwnMessages(false); } catch (Exception e) { throw new CacheException(e); } } }
@Override public boolean isUnknownForkResponse(ByteBuffer response) { return this.parentFactory.isUnknownForkResponse(response); }
@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 JChannel get() { try { JChannel channel = this.factory.get().createChannel(this.name); if (JGroupsLogger.ROOT_LOGGER.isTraceEnabled()) { JGroupsLogger.ROOT_LOGGER.tracef("JGroups channel %s created with configuration:%n %s", this.name, channel.getProtocolStack().printProtocolSpec(true)); } channel.stats(this.statisticsEnabled); if (this.server != null) { try { JmxConfigurator.registerChannel(channel, this.server.get(), this.name); } catch (Exception e) { JGroupsLogger.ROOT_LOGGER.debug(e.getLocalizedMessage(), e); } } channel.connect(this.cluster.get()); return channel; } catch (Exception e) { throw new IllegalStateException(e); } }
@Override public Object objectFromStream(DataInput stream) throws Exception { int size = IndexSerializer.VARIABLE.readInt(stream); byte[] buffer = new byte[size]; stream.readFully(buffer); if (this.factory.isUnknownForkResponse(ByteBuffer.wrap(buffer))) return NoSuchService.INSTANCE; try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(buffer))) { int version = this.versionSerializer.readInt(input); try (Unmarshaller unmarshaller = this.context.createUnmarshaller(version)) { unmarshaller.start(Marshalling.createByteInput(input)); return unmarshaller.readObject(); } } } }
@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 ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ChannelFactory factory) throws OperationFailedException { // Create a temporary channel, but don't connect it try (JChannel channel = factory.createChannel(UUID.randomUUID().toString())) { // ProtocolStack.printProtocolSpecAsXML() is very hacky and only works on an uninitialized stack List<Protocol> protocols = channel.getProtocolStack().getProtocols(); Collections.reverse(protocols); ProtocolStack stack = new ProtocolStack(); stack.addProtocols(protocols); return new ModelNode(stack.printProtocolSpecAsXML()); } catch (Exception e) { throw new OperationFailedException(e); } } },
@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 JChannel createChannel() throws Exception { JChannel channel = remoteSite.getChannelFactory().createChannel(siteName); // Don't use FORK in bridge stack channel.getProtocolStack().removeProtocol(FORK.class); return channel; } };
@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 protected void initChannel() { try { this.channel = this.factory.createChannel(this.configuration.globalJmxStatistics().cacheManagerName()); this.channel.setDiscardOwnMessages(false); } catch (Exception e) { throw new CacheException(e); } } }
@Override public JChannel createChannel(String id) throws Exception { JGroupsLogger.ROOT_LOGGER.debugf("Creating fork channel %s from channel %s", id, this.channel.getClusterName()); String stackName = this.protocols.isEmpty() ? this.channel.getClusterName() : id; Protocol[] protocols = new Protocol[this.protocols.size()]; for (int i = 0; i < protocols.length; ++i) { protocols[i] = this.protocols.get(i).createProtocol(this.parentFactory.getProtocolStackConfiguration()); } return new ForkChannel(this.channel, stackName, id, protocols); }
@Override public JChannel get() { try { JChannel channel = this.factory.get().createChannel(this.name); if (JGroupsLogger.ROOT_LOGGER.isTraceEnabled()) { JGroupsLogger.ROOT_LOGGER.tracef("JGroups channel %s created with configuration:%n %s", this.name, channel.getProtocolStack().printProtocolSpec(true)); } channel.stats(this.statisticsEnabled); if (this.server != null) { try { JmxConfigurator.registerChannel(channel, this.server.get(), this.name); } catch (Exception e) { JGroupsLogger.ROOT_LOGGER.debug(e.getLocalizedMessage(), e); } } channel.connect(this.cluster.get()); return channel; } catch (Exception e) { throw new IllegalStateException(e); } }