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