Search in sources :

Example 1 with TcpDiscoveryCustomEventMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage 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 2 with TcpDiscoveryCustomEventMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage 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 3 with TcpDiscoveryCustomEventMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage in project ignite by apache.

the class BlockTcpDiscoverySpi method apply.

/**
 * @param addr Address.
 * @param msg Message.
 */
private synchronized void apply(ClusterNode addr, TcpDiscoveryAbstractMessage msg) {
    if (!(msg instanceof TcpDiscoveryCustomEventMessage))
        return;
    TcpDiscoveryCustomEventMessage cm = (TcpDiscoveryCustomEventMessage) msg;
    DiscoveryCustomMessage delegate;
    try {
        DiscoverySpiCustomMessage custMsg = cm.message(marshaller(), U.resolveClassLoader(ignite().configuration()));
        assertNotNull(custMsg);
        delegate = ((CustomMessageWrapper) custMsg).delegate();
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
    if (clo != null)
        clo.apply(addr, delegate);
}
Also used : DiscoverySpiCustomMessage(org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage) DiscoveryCustomMessage(org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage)

Example 4 with TcpDiscoveryCustomEventMessage

use of org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage in project ignite by apache.

the class CacheClientsConcurrentStartTest method getConfiguration.

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

        @Override
        protected void writeToSocket(Socket sock, OutputStream out, TcpDiscoveryAbstractMessage msg, long timeout) throws IOException, IgniteCheckedException {
            if (msg instanceof TcpDiscoveryCustomEventMessage && msg.verified()) {
                try {
                    System.out.println(Thread.currentThread().getName() + " delay custom message");
                    U.sleep(ThreadLocalRandom.current().nextLong(500) + 100);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            super.writeToSocket(sock, out, msg, timeout);
        }
    };
    cfg.setMarshaller(null);
    cfg.setCommunicationSpi(new TestRecordingCommunicationSpi());
    if (getTestIgniteInstanceIndex(gridName) < SRV_CNT) {
        CacheConfiguration[] ccfgs = new CacheConfiguration[CACHES / 2];
        for (int i = 0; i < ccfgs.length; i++) ccfgs[i] = cacheConfiguration("cache-" + i);
        cfg.setCacheConfiguration(ccfgs);
    }
    return cfg;
}
Also used : TestRecordingCommunicationSpi(org.apache.ignite.internal.TestRecordingCommunicationSpi) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) TcpDiscoveryAbstractMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage) OutputStream(java.io.OutputStream) Socket(java.net.Socket) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi) TcpDiscoveryCustomEventMessage(org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage)

Aggregations

TcpDiscoveryCustomEventMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryCustomEventMessage)4 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)3 CustomMessageWrapper (org.apache.ignite.internal.managers.discovery.CustomMessageWrapper)2 DiscoveryServerOnlyCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryServerOnlyCustomMessage)2 Span (org.apache.ignite.internal.processors.tracing.Span)2 IgniteSpiException (org.apache.ignite.spi.IgniteSpiException)2 TcpDiscoveryServerOnlyCustomEventMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryServerOnlyCustomEventMessage)2 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 Socket (java.net.Socket)1 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)1 IgniteException (org.apache.ignite.IgniteException)1 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)1 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)1 TestRecordingCommunicationSpi (org.apache.ignite.internal.TestRecordingCommunicationSpi)1 DiscoveryCustomMessage (org.apache.ignite.internal.managers.discovery.DiscoveryCustomMessage)1 DiscoverySpiCustomMessage (org.apache.ignite.spi.discovery.DiscoverySpiCustomMessage)1 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)1 TcpDiscoveryAbstractMessage (org.apache.ignite.spi.discovery.tcp.messages.TcpDiscoveryAbstractMessage)1