Search in sources :

Example 1 with AddressResolver

use of org.apache.ignite.configuration.AddressResolver in project ignite by apache.

the class GridAddressResolverSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(final String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    TcpDiscoverySpi discoSpi = new TcpDiscoverySpi();
    discoSpi.setIpFinder(IP_FINDER);
    cfg.setDiscoverySpi(discoSpi);
    cfg.setAddressResolver(new AddressResolver() {

        @Override
        public Collection<InetSocketAddress> getExternalAddresses(InetSocketAddress addr) throws IgniteCheckedException {
            Set<InetSocketAddress> set = new HashSet<>();
            set.add(addr);
            set.add(igniteInstanceName.contains("0") ? addr0 : addr1);
            return set;
        }
    });
    return cfg;
}
Also used : AddressResolver(org.apache.ignite.configuration.AddressResolver) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) Set(java.util.Set) HashSet(java.util.HashSet) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) InetSocketAddress(java.net.InetSocketAddress) Collection(java.util.Collection) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 2 with AddressResolver

use of org.apache.ignite.configuration.AddressResolver in project ignite by apache.

the class TcpCommunicationSpiMultiJvmTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    TcpCommunicationSpi commSpi = new TestCommunicationSpi(replacingAttrSpi);
    commSpi.setLocalPort(45010);
    if (localAddrStr != null)
        commSpi.setLocalAddress(localAddrStr);
    if (externalAddr != null) {
        commSpi.setAddressResolver(new AddressResolver() {

            @Override
            public Collection<InetSocketAddress> getExternalAddresses(InetSocketAddress addr) throws IgniteCheckedException {
                return Collections.singletonList(externalAddr);
            }
        });
    } else
        commSpi.setLocalAddress(InetAddress.getLocalHost().getHostName());
    cfg.setCommunicationSpi(commSpi);
    return cfg;
}
Also used : AddressResolver(org.apache.ignite.configuration.AddressResolver) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) InetSocketAddress(java.net.InetSocketAddress) Collection(java.util.Collection)

Example 3 with AddressResolver

use of org.apache.ignite.configuration.AddressResolver in project ignite by apache.

the class GridTcpSpiForwardingSelfTest method testCustomResolver.

/**
 * @throws Exception If any error occurs.
 */
@Test
public void testCustomResolver() throws Exception {
    final Map<InetSocketAddress, Collection<InetSocketAddress>> map = new HashMap<>();
    map.put(new InetSocketAddress("127.0.0.1", locPort1), F.asList(new InetSocketAddress("127.0.0.1", extPort1)));
    map.put(new InetSocketAddress("127.0.0.1", commLocPort1), F.asList(new InetSocketAddress("127.0.0.1", commExtPort1)));
    map.put(new InetSocketAddress("127.0.0.1", locPort2), F.asList(new InetSocketAddress("127.0.0.1", extPort2)));
    map.put(new InetSocketAddress("127.0.0.1", commLocPort2), F.asList(new InetSocketAddress("127.0.0.1", commExtPort2)));
    rslvr = new AddressResolver() {

        @Override
        public Collection<InetSocketAddress> getExternalAddresses(InetSocketAddress addr) {
            return map.get(addr);
        }
    };
    doTestForward();
}
Also used : AddressResolver(org.apache.ignite.configuration.AddressResolver) BasicAddressResolver(org.apache.ignite.configuration.BasicAddressResolver) HashMap(java.util.HashMap) InetSocketAddress(java.net.InetSocketAddress) Collection(java.util.Collection) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)3 Collection (java.util.Collection)3 AddressResolver (org.apache.ignite.configuration.AddressResolver)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 BasicAddressResolver (org.apache.ignite.configuration.BasicAddressResolver)1 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1