Search in sources :

Example 1 with FORK

use of org.jgroups.protocols.FORK in project wildfly by wildfly.

the class ForkProtocolResourceRegistrationHandler method findProtocol.

@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(false);
    ServiceController<?> controller = registry.getService(JGroupsRequirement.CHANNEL.getServiceName(context, channelName));
    if (controller != null) {
        Channel channel = (Channel) controller.getValue();
        if (channel != null) {
            FORK fork = (FORK) channel.getProtocolStack().findProtocol(FORK.class);
            if (fork != null) {
                controller = registry.getService(JGroupsRequirement.CHANNEL_FACTORY.getServiceName(context, channelName));
                if (controller != null) {
                    ChannelFactory factory = (ChannelFactory) controller.getValue();
                    if (factory != null) {
                        ProtocolStackConfiguration configuration = factory.getProtocolStackConfiguration();
                        ProtocolConfiguration<? extends TP> transport = configuration.getTransport();
                        if (transport.getName().equals(protocolName)) {
                            Class<? extends Protocol> protocolClass = transport.createProtocol().getClass();
                            return channel.getProtocolStack().findProtocol(protocolClass);
                        }
                        for (ProtocolConfiguration<? extends Protocol> protocol : configuration.getProtocols()) {
                            if (protocol.getName().equals(protocolName)) {
                                Class<? extends Protocol> protocolClass = protocol.createProtocol().getClass();
                                return fork.get(forkName).getProtocolStack().findProtocol(protocolClass);
                            }
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : FORK(org.jgroups.protocols.FORK) PathAddress(org.jboss.as.controller.PathAddress) Channel(org.jgroups.Channel) ProtocolStackConfiguration(org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration) ServiceRegistry(org.jboss.msc.service.ServiceRegistry) ChannelFactory(org.wildfly.clustering.jgroups.spi.ChannelFactory)

Example 2 with FORK

use of org.jgroups.protocols.FORK in project wildfly by wildfly.

the class JChannelFactory method createChannel.

@Override
public Channel createChannel(String id) throws Exception {
    JChannel channel = new JChannel(false);
    ProtocolStack stack = new ProtocolStack();
    channel.setProtocolStack(stack);
    stack.addProtocol(this.configuration.getTransport().createProtocol());
    stack.addProtocols(this.configuration.getProtocols().stream().map(ProtocolConfiguration::createProtocol).collect(Collectors.toList()));
    RelayConfiguration relay = this.configuration.getRelay();
    if (relay != null) {
        stack.addProtocol(relay.createProtocol());
    }
    // Add implicit FORK to the top of the stack
    FORK fork = new FORK();
    fork.setUnknownForkHandler(new UnknownForkHandler() {

        private final short id = ClassConfigurator.getProtocolId(RequestCorrelator.class);

        @Override
        public Object handleUnknownForkStack(Message message, String forkStackId) {
            return this.handle(message);
        }

        @Override
        public Object handleUnknownForkChannel(Message message, String forkChannelId) {
            return this.handle(message);
        }

        private Object handle(Message message) {
            Header header = (Header) message.getHeader(this.id);
            // If this is a request expecting a response, don't leave the requester hanging - send an identifiable response on which it can filter
            if ((header != null) && (header.type == Header.REQ) && header.rspExpected()) {
                Message response = message.makeReply().setFlag(message.getFlags()).clearFlag(Message.Flag.RSVP, Message.Flag.SCOPED);
                response.putHeader(FORK.ID, message.getHeader(FORK.ID));
                response.putHeader(this.id, new Header(Header.RSP, header.req_id, header.corrId));
                response.setBuffer(UNKNOWN_FORK_RESPONSE.array());
                channel.down(new Event(Event.MSG, response));
            }
            return null;
        }
    });
    stack.addProtocol(fork);
    stack.init();
    channel.setName(this.configuration.getNodeName());
    TransportConfiguration.Topology topology = this.configuration.getTransport().getTopology();
    if (topology != null) {
        channel.addAddressGenerator(new TopologyAddressGenerator(topology));
    }
    return channel;
}
Also used : JChannel(org.jgroups.JChannel) FORK(org.jgroups.protocols.FORK) Message(org.jgroups.Message) TransportConfiguration(org.wildfly.clustering.jgroups.spi.TransportConfiguration) UnknownForkHandler(org.jgroups.fork.UnknownForkHandler) ProtocolConfiguration(org.wildfly.clustering.jgroups.spi.ProtocolConfiguration) Header(org.jgroups.blocks.RequestCorrelator.Header) ProtocolStack(org.jgroups.stack.ProtocolStack) RelayConfiguration(org.wildfly.clustering.jgroups.spi.RelayConfiguration) Event(org.jgroups.Event)

Aggregations

FORK (org.jgroups.protocols.FORK)2 PathAddress (org.jboss.as.controller.PathAddress)1 ServiceRegistry (org.jboss.msc.service.ServiceRegistry)1 Channel (org.jgroups.Channel)1 Event (org.jgroups.Event)1 JChannel (org.jgroups.JChannel)1 Message (org.jgroups.Message)1 Header (org.jgroups.blocks.RequestCorrelator.Header)1 UnknownForkHandler (org.jgroups.fork.UnknownForkHandler)1 ProtocolStack (org.jgroups.stack.ProtocolStack)1 ChannelFactory (org.wildfly.clustering.jgroups.spi.ChannelFactory)1 ProtocolConfiguration (org.wildfly.clustering.jgroups.spi.ProtocolConfiguration)1 ProtocolStackConfiguration (org.wildfly.clustering.jgroups.spi.ProtocolStackConfiguration)1 RelayConfiguration (org.wildfly.clustering.jgroups.spi.RelayConfiguration)1 TransportConfiguration (org.wildfly.clustering.jgroups.spi.TransportConfiguration)1