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;
}
Aggregations