Search in sources :

Example 1 with CustomMessageWrapper

use of org.apache.ignite.internal.managers.discovery.CustomMessageWrapper in project ignite by apache.

the class ClientImpl method sendCustomEvent.

/**
 * {@inheritDoc}
 */
@Override
public void sendCustomEvent(DiscoverySpiCustomMessage evt) {
    State state = this.state;
    if (state == DISCONNECTED)
        throw new IgniteClientDisconnectedException(null, "Failed to send custom message: client is disconnected.");
    if (state == STOPPED || state == SEGMENTED || state == STARTING)
        throw new IgniteException("Failed to send custom message: client is " + state.name().toLowerCase() + ".");
    try {
        TcpDiscoveryCustomEventMessage msg;
        if (((CustomMessageWrapper) evt).delegate() instanceof DiscoveryServerOnlyCustomMessage)
            msg = new TcpDiscoveryServerOnlyCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
        else
            msg = new TcpDiscoveryCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
        Span rootSpan = tracing.create(TraceableMessagesTable.traceName(msg.getClass())).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID), () -> getLocalNodeId().toString()).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.CONSISTENT_ID), () -> locNode.consistentId().toString()).addTag(SpanTags.MESSAGE_CLASS, () -> ((CustomMessageWrapper) evt).delegate().getClass().getSimpleName()).addLog(() -> "Created");
        // This root span will be parent both from local and remote nodes.
        msg.spanContainer().serializedSpanBytes(tracing.serialize(rootSpan));
        sockWriter.sendMessage(msg);
        rootSpan.addLog(() -> "Sent").end();
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to marshal custom event: " + evt, e);
    }
}
Also used : DiscoveryServerOnlyCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryServerOnlyCustomMessage) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Span(org.apache.ignite.internal.processors.tracing.Span) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage) TcpDiscoveryServerOnlyCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryServerOnlyCustomEventMessage)

Example 2 with CustomMessageWrapper

use of org.apache.ignite.internal.managers.discovery.CustomMessageWrapper in project ignite by apache.

the class ServerImpl method sendCustomEvent.

/**
 * {@inheritDoc}
 */
@Override
public void sendCustomEvent(DiscoverySpiCustomMessage evt) {
    try {
        TcpDiscoveryCustomEventMessage msg;
        if (((CustomMessageWrapper) evt).delegate() instanceof DiscoveryServerOnlyCustomMessage)
            msg = new TcpDiscoveryServerOnlyCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
        else
            msg = new TcpDiscoveryCustomEventMessage(getLocalNodeId(), evt, U.marshal(spi.marshaller(), evt));
        Span rootSpan = tracing.create(TraceableMessagesTable.traceName(msg.getClass())).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.ID), () -> getLocalNodeId().toString()).addTag(SpanTags.tag(SpanTags.EVENT_NODE, SpanTags.CONSISTENT_ID), () -> locNode.consistentId().toString()).addTag(SpanTags.MESSAGE_CLASS, () -> ((CustomMessageWrapper) evt).delegate().getClass().getSimpleName()).addLog(() -> "Created");
        // This root span will be parent both from local and remote nodes.
        msg.spanContainer().serializedSpanBytes(tracing.serialize(rootSpan));
        msgWorker.addMessage(msg);
        rootSpan.addLog(() -> "Sent").end();
    } catch (IgniteCheckedException e) {
        throw new IgniteSpiException("Failed to marshal custom event: " + evt, e);
    }
}
Also used : DiscoveryServerOnlyCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryServerOnlyCustomMessage) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) Span(org.apache.ignite.internal.processors.tracing.Span) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage) TcpDiscoveryServerOnlyCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryServerOnlyCustomEventMessage)

Example 3 with CustomMessageWrapper

use of org.apache.ignite.internal.managers.discovery.CustomMessageWrapper in project ignite by apache.

the class CacheRegisterMetadataLocallyTest method getConfiguration.

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

        @Override
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
            if (msg instanceof CustomMessageWrapper) {
                DiscoveryCustomMessage realMsg = ((CustomMessageWrapper) msg).delegate();
                if (realMsg instanceof MetadataUpdateProposedMessage || realMsg instanceof MetadataUpdateAcceptedMessage)
                    customMessages.add(realMsg);
            }
            super.sendCustomEvent(msg);
        }
    });
    cfg.setCommunicationSpi(new TcpCommunicationSpi() {

        @Override
        public void sendMessage(ClusterNode node, Message msg, IgniteInClosure<IgniteException> ackC) throws IgniteSpiException {
            if (msg instanceof GridIoMessage)
                communicationMessages.add(((GridIoMessage) msg).message());
            super.sendMessage(node, msg, ackC);
        }

        @Override
        public void sendMessage(ClusterNode node, Message msg) throws IgniteSpiException {
            if (msg instanceof GridIoMessage)
                communicationMessages.add(((GridIoMessage) msg).message());
            super.sendMessage(node, msg);
        }
    });
    ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(IP_FINDER);
    cfg.setCacheConfiguration(cacheConfiguration(STATIC_CACHE_NAME, StaticKey.class, StaticValue.class));
    return cfg;
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) MetadataUpdateAcceptedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) MetadataRequestMessage(org.apache.ignite.internal.processors.cache.binary.MetadataRequestMessage) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) MetadataUpdateProposedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage) MetadataUpdateAcceptedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateAcceptedMessage) GridIoMessage(org.apache.ignite.internal.managers.communication.GridIoMessage) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) MetadataResponseMessage(org.apache.ignite.internal.processors.cache.binary.MetadataResponseMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) MetadataUpdateProposedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage) IgniteException(org.apache.ignite.IgniteException) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 4 with CustomMessageWrapper

use of org.apache.ignite.internal.managers.discovery.CustomMessageWrapper in project ignite by apache.

the class BinaryTypeRegistrationTest method getConfiguration.

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

        @Override
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
            if (msg instanceof CustomMessageWrapper && ((CustomMessageWrapper) msg).delegate() instanceof MetadataUpdateProposedMessage)
                metadataUpdateProposedMessages.add(((CustomMessageWrapper) msg).delegate());
            super.sendCustomEvent(msg);
        }
    });
    return cfg;
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) MetadataUpdateProposedMessage(org.apache.ignite.internal.processors.cache.binary.MetadataUpdateProposedMessage) IgniteException(org.apache.ignite.IgniteException) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 5 with CustomMessageWrapper

use of org.apache.ignite.internal.managers.discovery.CustomMessageWrapper in project ignite by apache.

the class KillQueryTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    CacheConfiguration<?, ?> cache = GridAbstractTest.defaultCacheConfiguration();
    cache.setAffinity(new RendezvousAffinityFunction(false, PARTS_CNT));
    cache.setCacheMode(PARTITIONED);
    cache.setBackups(1);
    cache.setWriteSynchronizationMode(FULL_SYNC);
    cache.setSqlFunctionClasses(TestSQLFunctions.class);
    cache.setIndexedTypes(Integer.class, Integer.class, Long.class, Long.class, String.class, Person.class);
    cfg.setCacheConfiguration(cache);
    TestRecordingCommunicationSpi commSpi = new TestRecordingCommunicationSpi();
    cfg.setCommunicationSpi(commSpi);
    if (++cntr == NODES_COUNT)
        clientBlocker = commSpi;
    cfg.setDiscoverySpi(new TcpDiscoverySpi() {

        @Override
        public void sendCustomEvent(DiscoverySpiCustomMessage msg) throws IgniteException {
            if (msg instanceof CustomMessageWrapper) {
                DiscoveryCustomMessage delegate = ((CustomMessageWrapper) msg).delegate();
                if (delegate instanceof DynamicCacheChangeBatch) {
                    try {
                        awaitTimeout();
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                    }
                } else if (delegate instanceof SchemaProposeDiscoveryMessage) {
                    try {
                        awaitTimeout();
                    } catch (Exception e) {
                        log.error(e.getMessage(), e);
                    }
                }
            }
            super.sendCustomEvent(msg);
        }
    }.setIpFinder(IP_FINDER));
    return cfg;
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) CustomMessageWrapper(org.apache.ignite.internal.managers.discovery.CustomMessageWrapper) TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) DynamicCacheChangeBatch(org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch) SchemaProposeDiscoveryMessage(org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage) RendezvousAffinityFunction(org.apache.ignite.cache.affinity.rendezvous.RendezvousAffinityFunction) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) QueryCancelledException(org.apache.ignite.cache.query.QueryCancelledException) TimeoutException(java.util.concurrent.TimeoutException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) SQLException(java.sql.SQLException) CacheException(javax.cache.CacheException) BrokenBarrierException(java.util.concurrent.BrokenBarrierException) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Aggregations

CustomMessageWrapper (org.apache.ignite.internal.managers.discovery.CustomMessageWrapper)6 IgniteException (org.apache.ignite.IgniteException)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)4 DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)4 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)3 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)3 SQLException (java.sql.SQLException)2 BrokenBarrierException (java.util.concurrent.BrokenBarrierException)2 TimeoutException (java.util.concurrent.TimeoutException)2 ClusterNode (org.apache.ignite.cluster.ClusterNode)2 DiscoveryServerOnlyCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryServerOnlyCustomMessage)2 DynamicCacheChangeBatch (org.apache.ignite.internal.processors.cache.DynamicCacheChangeBatch)2 SchemaProposeDiscoveryMessage (org.apache.ignite.internal.processors.query.schema.message.SchemaProposeDiscoveryMessage)2 Span (org.apache.ignite.internal.processors.tracing.Span)2 TcpDiscoveryCustomEventMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage)2 TcpDiscoveryServerOnlyCustomEventMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryServerOnlyCustomEventMessage)2 Connection (java.sql.Connection)1 Statement (java.sql.Statement)1