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);
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations