use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.
the class TcpClientDiscoverySpiMulticastTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
cfg.setLocalHost("127.0.0.1");
TcpDiscoverySpi spi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setAddressRequestAttempts(5);
spi.setIpFinder(ipFinder);
Boolean clientFlag = client.get();
client.set(null);
if (clientFlag != null && clientFlag) {
cfg.setClientMode(true);
spi.setForceServerMode(forceSrv);
} else {
Integer port = discoPort.get();
discoPort.set(null);
if (port != null)
spi.setLocalPort(port);
}
cfg.setDiscoverySpi(spi);
return cfg;
}
use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.
the class TcpDiscoveryConcurrentStartTest method getConfiguration.
/**
* {@inheritDoc}
*/
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
TcpDiscoveryMulticastIpFinder finder = new TcpDiscoveryMulticastIpFinder();
finder.setMulticastGroup(GridTestUtils.getNextMulticastGroup(getClass()));
finder.setMulticastPort(GridTestUtils.getNextMulticastPort(getClass()));
cfg.setDiscoverySpi(new TcpDiscoverySpi().setIpFinder(finder));
cfg.setCacheConfiguration();
return cfg;
}
use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.
the class ClientImpl method joinTopology.
/**
* @param recon {@code True} if reconnects.
* @param timeout Timeout.
* @return Opened socket or {@code null} if timeout.
* @throws InterruptedException If interrupted.
* @throws IgniteSpiException If failed.
* @see TcpDiscoverySpi#joinTimeout
*/
@SuppressWarnings("BusyWait")
@Nullable
private T2<SocketStream, Boolean> joinTopology(boolean recon, long timeout) throws IgniteSpiException, InterruptedException {
Collection<InetSocketAddress> addrs = null;
long startTime = U.currentTimeMillis();
while (true) {
if (Thread.currentThread().isInterrupted())
throw new InterruptedException();
while (addrs == null || addrs.isEmpty()) {
addrs = spi.resolvedAddresses();
if (!F.isEmpty(addrs)) {
if (log.isDebugEnabled())
log.debug("Resolved addresses from IP finder: " + addrs);
} else {
if (timeout > 0 && (U.currentTimeMillis() - startTime) > timeout)
return null;
LT.warn(log, "IP finder returned empty addresses list. " + "Please check IP finder configuration" + (spi.ipFinder instanceof TcpDiscoveryMulticastIpFinder ? " and make sure multicast works on your network. " : ". ") + "Will retry every 2 secs.", true);
Thread.sleep(2000);
}
}
Collection<InetSocketAddress> addrs0 = new ArrayList<>(addrs);
Iterator<InetSocketAddress> it = addrs.iterator();
boolean wait = false;
while (it.hasNext()) {
if (Thread.currentThread().isInterrupted())
throw new InterruptedException();
InetSocketAddress addr = it.next();
T3<SocketStream, Integer, Boolean> sockAndRes = sendJoinRequest(recon, addr);
if (sockAndRes == null) {
it.remove();
continue;
}
assert sockAndRes.get1() != null && sockAndRes.get2() != null : sockAndRes;
Socket sock = sockAndRes.get1().socket();
if (log.isDebugEnabled())
log.debug("Received response to join request [addr=" + addr + ", res=" + sockAndRes.get2() + ']');
switch(sockAndRes.get2()) {
case RES_OK:
return new T2<>(sockAndRes.get1(), sockAndRes.get3());
case RES_CONTINUE_JOIN:
case RES_WAIT:
wait = true;
U.closeQuiet(sock);
break;
default:
if (log.isDebugEnabled())
log.debug("Received unexpected response to join request: " + sockAndRes.get2());
U.closeQuiet(sock);
}
}
if (wait) {
if (timeout > 0 && (U.currentTimeMillis() - startTime) > timeout)
return null;
if (log.isDebugEnabled())
log.debug("Will wait before retry join.");
Thread.sleep(2000);
} else if (addrs.isEmpty()) {
if (timeout > 0 && (U.currentTimeMillis() - startTime) > timeout)
return null;
LT.warn(log, "Failed to connect to any address from IP finder (will retry to join topology " + "every 2 secs): " + toOrderedList(addrs0), true);
Thread.sleep(2000);
}
}
}
use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.
the class TcpIpDiscovery method multicastAndStaticDemo.
@Test
void multicastAndStaticDemo() {
// tag::multicastAndStatic[]
TcpDiscoverySpi spi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
// Set Multicast group.
ipFinder.setMulticastGroup("228.10.10.157");
// Set initial IP addresses.
// Note that you can optionally specify a port or a port range.
ipFinder.setAddresses(Arrays.asList("1.2.3.4", "1.2.3.5:47500..47509"));
spi.setIpFinder(ipFinder);
IgniteConfiguration cfg = new IgniteConfiguration();
// Override default discovery SPI.
cfg.setDiscoverySpi(spi);
// Start a node.
Ignite ignite = Ignition.start(cfg);
// end::multicastAndStatic[]
ignite.close();
}
use of org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder in project ignite by apache.
the class TcpIpDiscovery method multicastIpFinderDemo.
@Test
void multicastIpFinderDemo() {
// tag::multicast[]
TcpDiscoverySpi spi = new TcpDiscoverySpi();
TcpDiscoveryMulticastIpFinder ipFinder = new TcpDiscoveryMulticastIpFinder();
ipFinder.setMulticastGroup("228.10.10.157");
spi.setIpFinder(ipFinder);
IgniteConfiguration cfg = new IgniteConfiguration();
// Override default discovery SPI.
cfg.setDiscoverySpi(spi);
// Start the node.
Ignite ignite = Ignition.start(cfg);
// end::multicast[]
ignite.close();
}
Aggregations