use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl in project ignite by apache.
the class GridTcpCommunicationSpiConfigSelfTest method initializeSpi.
/**
* Initializes TcpCommunicationSpi with given context, node, logger and clientMode flag.
*/
private TcpCommunicationSpi initializeSpi(GridSpiTestContext ctx, GridTestNode node, IgniteLogger log, boolean clientMode) throws Exception {
TcpCommunicationSpi spi = new TcpCommunicationSpi();
spi.setLocalPort(GridTestUtils.getNextCommPort(getClass()));
spi.setIdleConnectionTimeout(2000);
IgniteConfiguration cfg = new IgniteConfiguration().setGridLogger(log).setClientMode(clientMode);
IgniteTestResources rsrcs = new IgniteTestResources(cfg);
resourcesToClean.add(rsrcs);
cfg.setMBeanServer(rsrcs.getMBeanServer());
node.setId(rsrcs.getNodeId());
MessageFactoryProvider testMsgFactory = factory -> factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.setLocalNode(node);
rsrcs.inject(spi);
spi.spiStart(getTestIgniteInstanceName() + node.order());
node.setAttributes(spi.getNodeAttributes());
node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
return spi;
}
use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl in project ignite by apache.
the class GridTcpCommunicationSpiRecoveryAckSelfTest method startSpis.
/**
* @param ackCnt Recovery acknowledgement count.
* @param idleTimeout Idle connection timeout.
* @param queueLimit Message queue limit.
* @throws Exception If failed.
*/
private void startSpis(int ackCnt, int idleTimeout, int queueLimit) throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
timeoutProcessor.start();
timeoutProcessor.onKernalStart(true);
for (int i = 0; i < SPI_CNT; i++) {
TcpCommunicationSpi spi = getSpi(ackCnt, idleTimeout, queueLimit);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
GridSpiTestContext ctx = initSpiContext();
MessageFactoryProvider testMsgFactory = new MessageFactoryProvider() {
@Override
public void registerAll(IgniteMessageFactory factory) {
factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
}
};
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.setLocalNode(node);
ctx.timeoutProcessor(timeoutProcessor);
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
spi.setListener(new TestListener());
node.order(i);
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
node.setAttributes(spi.getNodeAttributes());
spis.add(spi);
spi.onContextInitialized(ctx);
ctxs.put(node, ctx);
}
// For each context set remote nodes.
for (Map.Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
for (ClusterNode n : nodes) {
if (!n.equals(e.getKey()))
e.getValue().remoteNodes().add(n);
}
}
}
use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl in project ignite by apache.
the class GridAbstractCommunicationSelfTest method startSpis.
/**
* @throws Exception If failed.
*/
private void startSpis() throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
timeoutProcessor.start();
timeoutProcessor.onKernalStart(true);
for (int i = 0; i < getSpiCount(); i++) {
CommunicationSpi<Message> spi = getSpi(i);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
GridSpiTestContext ctx = initSpiContext();
MessageFactoryProvider testMsgFactory = new MessageFactoryProvider() {
@Override
public void registerAll(IgniteMessageFactory factory) {
factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
}
};
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.setLocalNode(node);
ctx.timeoutProcessor(timeoutProcessor);
info(">>> Initialized context: nodeId=" + ctx.localNode().id());
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
if (useSsl) {
IgniteMock ignite = GridTestUtils.getFieldValue(spi, IgniteSpiAdapter.class, "ignite");
IgniteConfiguration cfg = ignite.configuration().setSslContextFactory(GridTestUtils.sslFactory());
ignite.setStaticCfg(cfg);
}
spi.setListener(new MessageListener(rsrcs.getNodeId()));
node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
node.order(i + 1);
nodes.add(node);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
node.setAttributes(spi.getNodeAttributes());
spis.put(rsrcs.getNodeId(), spi);
spi.onContextInitialized(ctx);
ctxs.put(node, ctx);
}
// For each context set remote nodes.
for (Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
for (ClusterNode n : nodes) {
if (!n.equals(e.getKey()))
e.getValue().remoteNodes().add(n);
}
}
}
use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl in project ignite by apache.
the class GridTcpCommunicationSpiMultithreadedSelfTest method beforeTestsStarted.
/**
* {@inheritDoc}
*/
@Override
protected void beforeTestsStarted() throws Exception {
spis.clear();
nodes.clear();
spiRsrcs.clear();
lsnrs.clear();
Map<ClusterNode, GridSpiTestContext> ctxs = new HashMap<>();
timeoutProcessor = new GridTimeoutProcessor(new GridTestKernalContext(log));
timeoutProcessor.start();
timeoutProcessor.onKernalStart(true);
for (int i = 0; i < getSpiCount(); i++) {
CommunicationSpi<Message> spi = newCommunicationSpi();
GridTestUtils.setFieldValue(spi, IgniteSpiAdapter.class, "igniteInstanceName", "grid-" + i);
IgniteTestResources rsrcs = new IgniteTestResources();
GridTestNode node = new GridTestNode(rsrcs.getNodeId());
node.order(i);
GridSpiTestContext ctx = initSpiContext();
MessageFactoryProvider testMsgFactory = factory -> factory.register(GridTestMessage.DIRECT_TYPE, GridTestMessage::new);
ctx.messageFactory(new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory(), testMsgFactory }));
ctx.timeoutProcessor(timeoutProcessor);
ctx.setLocalNode(node);
info(">>> Initialized context: nodeId=" + ctx.localNode().id());
spiRsrcs.add(rsrcs);
rsrcs.inject(spi);
MessageListener lsnr = new MessageListener(rsrcs.getNodeId());
spi.setListener(lsnr);
lsnrs.put(rsrcs.getNodeId(), lsnr);
info("Lsnrs: " + lsnrs);
spi.spiStart(getTestIgniteInstanceName() + (i + 1));
nodes.add(node);
node.setAttributes(spi.getNodeAttributes());
node.setAttribute(ATTR_MACS, F.concat(U.allLocalMACs(), ", "));
spis.put(rsrcs.getNodeId(), spi);
spi.onContextInitialized(ctx);
ctxs.put(node, ctx);
}
// For each context set remote nodes.
for (Entry<ClusterNode, GridSpiTestContext> e : ctxs.entrySet()) {
for (ClusterNode n : nodes) {
if (!n.equals(e.getKey()))
e.getValue().remoteNodes().add(n);
}
}
}
use of org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl in project ignite by apache.
the class GridMessageCollectionTest method doTestMarshal.
/**
* @param m Message.
*/
private void doTestMarshal(Message m) {
ByteBuffer buf = ByteBuffer.allocate(8 * 1024);
m.writeTo(buf, writer(proto));
buf.flip();
byte b0 = buf.get();
byte b1 = buf.get();
short type = (short) ((b1 & 0xFF) << 8 | b0 & 0xFF);
assertEquals(m.directType(), type);
IgniteMessageFactory msgFactory = new IgniteMessageFactoryImpl(new MessageFactory[] { new GridIoMessageFactory() });
Message mx = msgFactory.create(type);
mx.readFrom(buf, reader(msgFactory, proto));
assertEquals(m, mx);
}
Aggregations