use of org.jgroups.JChannel in project camel by apache.
the class JGroupsConsumerTest method doPreSetup.
// Fixture setup
@Override
protected void doPreSetup() throws Exception {
super.doPreSetup();
channel = new JChannel();
channel.connect(clusterName);
}
use of org.jgroups.JChannel in project camel by apache.
the class JGroupsProducerTest method doPreSetup.
// Fixture setup
@Override
protected void doPreSetup() throws Exception {
super.doPreSetup();
channel = new JChannel();
channel.setReceiver(new ReceiverAdapter() {
@Override
public void receive(Message msg) {
messageReceived = msg.getObject();
}
});
channel.connect(CLUSTER_NAME);
}
use of org.jgroups.JChannel 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;
}
use of org.jgroups.JChannel in project wildfly by wildfly.
the class ActiveMQServerService method start.
public synchronized void start(final StartContext context) throws StartException {
ClassLoader origTCCL = org.wildfly.security.manager.WildFlySecurityManager.getCurrentContextClassLoaderPrivileged();
// Validate whether the AIO native layer can be used
JournalType jtype = configuration.getJournalType();
if (jtype == JournalType.ASYNCIO) {
boolean supportsAIO = AIOSequentialFileFactory.isSupported();
if (supportsAIO == false) {
String osName = System.getProperty("os.name").toLowerCase(Locale.ENGLISH);
if (osName.contains("nux")) {
ROOT_LOGGER.aioInfoLinux();
} else {
ROOT_LOGGER.aioInfo();
}
configuration.setJournalType(JournalType.NIO);
}
}
// Setup paths
PathManager pathManager = this.pathManager.getValue();
configuration.setBindingsDirectory(pathConfig.resolveBindingsPath(pathManager));
configuration.setLargeMessagesDirectory(pathConfig.resolveLargeMessagePath(pathManager));
configuration.setJournalDirectory(pathConfig.resolveJournalPath(pathManager));
configuration.setPagingDirectory(pathConfig.resolvePagingPath(pathManager));
pathConfig.registerCallbacks(pathManager);
try {
// Update the acceptor/connector port/host values from the
// Map the socket bindings onto the connectors/acceptors
Collection<TransportConfiguration> acceptors = configuration.getAcceptorConfigurations();
Collection<TransportConfiguration> connectors = configuration.getConnectorConfigurations().values();
Collection<BroadcastGroupConfiguration> broadcastGroups = configuration.getBroadcastGroupConfigurations();
Map<String, DiscoveryGroupConfiguration> discoveryGroups = configuration.getDiscoveryGroupConfigurations();
if (connectors != null) {
for (TransportConfiguration tc : connectors) {
// If there is a socket binding set the HOST/PORT values
Object socketRef = tc.getParams().remove(SOCKET_REF);
if (socketRef != null) {
String name = socketRef.toString();
String host;
int port;
OutboundSocketBinding binding = outboundSocketBindings.get(name);
if (binding == null) {
final SocketBinding socketBinding = socketBindings.get(name);
if (socketBinding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
}
InetSocketAddress sa = socketBinding.getSocketAddress();
port = sa.getPort();
// resolve the host name of the address only if a loopback address has been set
if (sa.getAddress().isLoopbackAddress()) {
host = NetworkUtils.canonize(sa.getAddress().getHostName());
} else {
host = NetworkUtils.canonize(sa.getAddress().getHostAddress());
}
} else {
port = binding.getDestinationPort();
host = NetworkUtils.canonize(binding.getUnresolvedDestinationAddress());
if (binding.getSourceAddress() != null) {
tc.getParams().put(TransportConstants.LOCAL_ADDRESS_PROP_NAME, NetworkUtils.canonize(binding.getSourceAddress().getHostAddress()));
}
if (binding.getSourcePort() != null) {
// Use absolute port to account for source port offset/fixation
tc.getParams().put(TransportConstants.LOCAL_PORT_PROP_NAME, binding.getAbsoluteSourcePort());
}
}
tc.getParams().put(HOST, host);
tc.getParams().put(PORT, port);
}
}
}
if (acceptors != null) {
for (TransportConfiguration tc : acceptors) {
// If there is a socket binding set the HOST/PORT values
Object socketRef = tc.getParams().remove(SOCKET_REF);
if (socketRef != null) {
String name = socketRef.toString();
SocketBinding binding = socketBindings.get(name);
if (binding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindConnectorSocketBinding(tc.getName());
}
binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
InetSocketAddress socketAddress = binding.getSocketAddress();
tc.getParams().put(HOST, socketAddress.getAddress().getHostAddress());
tc.getParams().put(PORT, socketAddress.getPort());
}
}
}
if (broadcastGroups != null) {
final List<BroadcastGroupConfiguration> newConfigs = new ArrayList<BroadcastGroupConfiguration>();
for (final BroadcastGroupConfiguration config : broadcastGroups) {
final String name = config.getName();
final String key = "broadcast" + name;
if (jgroupFactories.containsKey(key)) {
ChannelFactory channelFactory = jgroupFactories.get(key);
String channelName = jgroupsChannels.get(key);
JChannel channel = (JChannel) channelFactory.createChannel(channelName);
channels.put(channelName, channel);
newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, channel, channelName));
} else {
final SocketBinding binding = groupBindings.get(key);
if (binding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindBroadcastSocketBinding(name);
}
binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
newConfigs.add(BroadcastGroupAdd.createBroadcastGroupConfiguration(name, config, binding));
}
}
configuration.getBroadcastGroupConfigurations().clear();
configuration.getBroadcastGroupConfigurations().addAll(newConfigs);
}
if (discoveryGroups != null) {
configuration.setDiscoveryGroupConfigurations(new HashMap<String, DiscoveryGroupConfiguration>());
for (final Map.Entry<String, DiscoveryGroupConfiguration> entry : discoveryGroups.entrySet()) {
final String name = entry.getKey();
final String key = "discovery" + name;
DiscoveryGroupConfiguration config = null;
if (jgroupFactories.containsKey(key)) {
ChannelFactory channelFactory = jgroupFactories.get(key);
String channelName = jgroupsChannels.get(key);
JChannel channel = channels.get(channelName);
if (channel == null) {
channel = (JChannel) channelFactory.createChannel(key);
channels.put(channelName, channel);
}
config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), channel, channelName);
} else {
final SocketBinding binding = groupBindings.get(key);
if (binding == null) {
throw MessagingLogger.ROOT_LOGGER.failedToFindDiscoverySocketBinding(name);
}
config = DiscoveryGroupAdd.createDiscoveryGroupConfiguration(name, entry.getValue(), binding);
binding.getSocketBindings().getNamedRegistry().registerBinding(ManagedBinding.Factory.createSimpleManagedBinding(binding));
}
configuration.getDiscoveryGroupConfigurations().put(name, config);
}
}
// security - if an Elytron domain has been defined we delegate security checks to the Elytron based security manager.
ActiveMQSecurityManager securityManager = null;
final SecurityDomain elytronDomain = this.elytronSecurityDomain.getOptionalValue();
if (elytronDomain != null) {
securityManager = new ElytronSecurityManager(elytronDomain);
} else {
securityManager = new WildFlySecurityManager(securityDomainContextValue.getValue());
}
// insert possible credential source hold passwords
setBridgePasswordsFromCredentialSource();
setClusterPasswordFromCredentialSource();
DataSource ds = dataSource.getOptionalValue();
if (ds != null) {
DatabaseStorageConfiguration dbConfiguration = (DatabaseStorageConfiguration) configuration.getStoreConfiguration();
dbConfiguration.setDataSource(ds);
// inject the datasource into the PropertySQLProviderFactory to be able to determine the
// type of database for the datasource metadata
PropertySQLProviderFactory sqlProviderFactory = (PropertySQLProviderFactory) dbConfiguration.getSqlProviderFactory();
sqlProviderFactory.investigateDialect(ds);
configuration.setStoreConfiguration(dbConfiguration);
ROOT_LOGGER.infof("use JDBC store for Artemis server, bindingsTable:%s", dbConfiguration.getBindingsTableName());
}
// Now start the server
server = new ActiveMQServerImpl(configuration, mbeanServer.getOptionalValue(), securityManager);
if (ActiveMQDefaultConfiguration.getDefaultClusterPassword().equals(server.getConfiguration().getClusterPassword())) {
server.getConfiguration().setClusterPassword(java.util.UUID.randomUUID().toString());
}
for (Interceptor incomingInterceptor : incomingInterceptors) {
server.getServiceRegistry().addIncomingInterceptor(incomingInterceptor);
}
for (Interceptor outgoingInterceptor : outgoingInterceptors) {
server.getServiceRegistry().addOutgoingInterceptor(outgoingInterceptor);
}
// the server is actually started by the JMSService.
} catch (Exception e) {
throw MessagingLogger.ROOT_LOGGER.failedToStartService(e);
} finally {
org.wildfly.security.manager.WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(origTCCL);
}
}
use of org.jgroups.JChannel in project wildfly by wildfly.
the class ChannelMetricExecutor method execute.
@Override
public ModelNode execute(OperationContext context, Metric<JChannel> metric) throws OperationFailedException {
String channelName = context.getCurrentAddressValue();
JChannel channel = ServiceContainerHelper.findValue(context.getServiceRegistry(false), JGroupsRequirement.CHANNEL.getServiceName(context, channelName));
return (channel != null) ? metric.execute(channel) : null;
}
Aggregations