Search in sources :

Example 1 with RelayConfiguration

use of org.wildfly.clustering.jgroups.spi.RelayConfiguration 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

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 FORK (org.jgroups.protocols.FORK)1 ProtocolStack (org.jgroups.stack.ProtocolStack)1 ProtocolConfiguration (org.wildfly.clustering.jgroups.spi.ProtocolConfiguration)1 RelayConfiguration (org.wildfly.clustering.jgroups.spi.RelayConfiguration)1 TransportConfiguration (org.wildfly.clustering.jgroups.spi.TransportConfiguration)1