Search in sources :

Example 6 with TcpDiscoveryIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder in project ignite by apache.

the class GridSpiAbstractTest method configure.

/**
     * @param spi SPI.
     * @throws Exception If failed.
     * @throws IllegalAccessException If failed.
     * @throws InvocationTargetException If failed.
     */
private void configure(IgniteSpi spi) throws Exception {
    // Inject Configuration.
    for (Method m : getClass().getMethods()) {
        GridSpiTestConfig cfg = m.getAnnotation(GridSpiTestConfig.class);
        if (cfg != null) {
            if (getTestData().isDiscoveryTest() || (cfg.type() != ConfigType.DISCOVERY && !(spi instanceof DiscoverySpi)) || (cfg.type() != ConfigType.SELF && spi instanceof DiscoverySpi)) {
                assert m.getName().startsWith("get") : "Test configuration must be a getter [method=" + m.getName() + ']';
                // Determine getter name.
                String name = cfg.setterName();
                if (name == null || name.isEmpty())
                    name = 's' + m.getName().substring(1);
                Method setter = getMethod(spi.getClass(), name);
                assert setter != null : "Spi does not have setter for configuration property [spi=" + spi.getClass().getName() + ", config-prop=" + name + ']';
                // Inject configuration parameter into spi.
                setter.invoke(spi, m.invoke(this));
            }
        }
    }
    // will find each other.
    if (spi instanceof TcpCommunicationSpi)
        ((TcpCommunicationSpi) spi).setLocalPort(GridTestUtils.getNextCommPort(getClass()));
    if (spi instanceof TcpDiscoverySpi) {
        TcpDiscoveryIpFinder ipFinder = ((TcpDiscoverySpi) spi).getIpFinder();
        if (ipFinder instanceof TcpDiscoveryMulticastIpFinder) {
            String mcastAddr = GridTestUtils.getNextMulticastGroup(getClass());
            if (mcastAddr != null && !mcastAddr.isEmpty()) {
                ((TcpDiscoveryMulticastIpFinder) ipFinder).setMulticastGroup(mcastAddr);
                ((TcpDiscoveryMulticastIpFinder) ipFinder).setMulticastPort(GridTestUtils.getNextMulticastPort(getClass()));
            }
        }
    }
}
Also used : TcpDiscoveryMulticastIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder) DiscoverySpi(org.apache.ignite.spi.discovery.DiscoverySpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) Method(java.lang.reflect.Method) IgniteProductVersion.fromString(org.apache.ignite.lang.IgniteProductVersion.fromString) TcpDiscoveryIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 7 with TcpDiscoveryIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder in project ignite by apache.

the class PlatformConfigurationUtils method writeDiscoveryConfiguration.

/**
     * Writes discovery configuration.
     *
     * @param w Writer.
     * @param spi Disco.
     */
private static void writeDiscoveryConfiguration(BinaryRawWriter w, DiscoverySpi spi) {
    assert w != null;
    assert spi != null;
    if (!(spi instanceof TcpDiscoverySpi)) {
        w.writeBoolean(false);
        return;
    }
    w.writeBoolean(true);
    TcpDiscoverySpi tcp = (TcpDiscoverySpi) spi;
    TcpDiscoveryIpFinder finder = tcp.getIpFinder();
    if (finder instanceof TcpDiscoveryVmIpFinder) {
        w.writeBoolean(true);
        boolean isMulticast = finder instanceof TcpDiscoveryMulticastIpFinder;
        w.writeByte((byte) (isMulticast ? 2 : 1));
        Collection<InetSocketAddress> addrs = finder.getRegisteredAddresses();
        w.writeInt(addrs.size());
        for (InetSocketAddress a : addrs) w.writeString(a.toString());
        if (isMulticast) {
            TcpDiscoveryMulticastIpFinder multiFinder = (TcpDiscoveryMulticastIpFinder) finder;
            w.writeString(multiFinder.getLocalAddress());
            w.writeString(multiFinder.getMulticastGroup());
            w.writeInt(multiFinder.getMulticastPort());
            w.writeInt(multiFinder.getAddressRequestAttempts());
            w.writeInt(multiFinder.getResponseWaitTime());
            int ttl = multiFinder.getTimeToLive();
            w.writeBoolean(ttl != -1);
            if (ttl != -1)
                w.writeInt(ttl);
        }
    } else
        w.writeBoolean(false);
    w.writeLong(tcp.getSocketTimeout());
    w.writeLong(tcp.getAckTimeout());
    w.writeLong(tcp.getMaxAckTimeout());
    w.writeLong(tcp.getNetworkTimeout());
    w.writeLong(tcp.getJoinTimeout());
    w.writeBoolean(tcp.isForceServerMode());
    w.writeBoolean(tcp.isClientReconnectDisabled());
    w.writeString(tcp.getLocalAddress());
    w.writeInt(tcp.getReconnectCount());
    w.writeInt(tcp.getLocalPort());
    w.writeInt(tcp.getLocalPortRange());
    w.writeLong(tcp.getStatisticsPrintFrequency());
    w.writeLong(tcp.getIpFinderCleanFrequency());
    w.writeInt(tcp.getThreadPriority());
    w.writeInt((int) tcp.getTopHistorySize());
}
Also used : TcpDiscoveryMulticastIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder) TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) InetSocketAddress(java.net.InetSocketAddress) TcpDiscoveryIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 8 with TcpDiscoveryIpFinder

use of org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder in project ignite by apache.

the class GridCacheNearReaderPreloadSelfTest method startUp.

/**
     * Startup routine.
     *
     * @throws Exception If failed.
     */
private void startUp() throws Exception {
    TcpDiscoveryIpFinder ipFinder = new TcpDiscoveryVmIpFinder(true);
    Ignite node1 = G.start(dataNode(ipFinder, "node1"));
    Ignite node2 = G.start(dataNode(ipFinder, "node2"));
    Ignite node3 = G.start(dataNode(ipFinder, "node3"));
    info("Node 1: " + node1.cluster().localNode().id());
    info("Node 2: " + node2.cluster().localNode().id());
    info("Node 3: " + node3.cluster().localNode().id());
    cache1 = node1.cache(CACHE_NAME);
    cache2 = node2.cache(CACHE_NAME);
    cache3 = node3.cache(CACHE_NAME);
}
Also used : TcpDiscoveryVmIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder) Ignite(org.apache.ignite.Ignite) TcpDiscoveryIpFinder(org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder)

Aggregations

TcpDiscoveryIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.TcpDiscoveryIpFinder)8 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)4 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)3 Ignite (org.apache.ignite.Ignite)2 TcpDiscoveryMulticastIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.multicast.TcpDiscoveryMulticastIpFinder)2 Method (java.lang.reflect.Method)1 InetSocketAddress (java.net.InetSocketAddress)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 IgniteClientReconnectAbstractTest (org.apache.ignite.internal.IgniteClientReconnectAbstractTest)1 IgniteProductVersion.fromString (org.apache.ignite.lang.IgniteProductVersion.fromString)1 NullLogger (org.apache.ignite.logger.NullLogger)1 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)1 DiscoverySpi (org.apache.ignite.spi.discovery.DiscoverySpi)1