Search in sources :

Example 6 with IgniteMessageFactory

use of org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory 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);
        }
    }
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) GridSpiTestContext(org.apache.ignite.testframework.GridSpiTestContext) GridTimeoutProcessor(org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor) Message(org.apache.ignite.plugin.extensions.communication.Message) MessageFactory(org.apache.ignite.plugin.extensions.communication.MessageFactory) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) HashMap(java.util.HashMap) GridTestKernalContext(org.apache.ignite.testframework.junits.GridTestKernalContext) GridTestNode(org.apache.ignite.testframework.GridTestNode) IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) IgniteTestResources(org.apache.ignite.testframework.junits.IgniteTestResources) MessageFactoryProvider(org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) IgniteMock(org.apache.ignite.testframework.junits.IgniteMock)

Example 7 with IgniteMessageFactory

use of org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory 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);
}
Also used : IgniteMessageFactory(org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory) IgniteMessageFactoryImpl(org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl) UUIDCollectionMessage(org.apache.ignite.internal.util.UUIDCollectionMessage) Message(org.apache.ignite.plugin.extensions.communication.Message) GridIoMessageFactory(org.apache.ignite.internal.managers.communication.GridIoMessageFactory) ByteBuffer(java.nio.ByteBuffer)

Aggregations

IgniteMessageFactory (org.apache.ignite.plugin.extensions.communication.IgniteMessageFactory)7 MessageFactory (org.apache.ignite.plugin.extensions.communication.MessageFactory)6 GridIoMessageFactory (org.apache.ignite.internal.managers.communication.GridIoMessageFactory)5 IgniteMessageFactoryImpl (org.apache.ignite.internal.managers.communication.IgniteMessageFactoryImpl)5 HashMap (java.util.HashMap)4 ClusterNode (org.apache.ignite.cluster.ClusterNode)4 GridTimeoutProcessor (org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor)4 MessageFactoryProvider (org.apache.ignite.plugin.extensions.communication.MessageFactoryProvider)4 GridSpiTestContext (org.apache.ignite.testframework.GridSpiTestContext)4 GridTestNode (org.apache.ignite.testframework.GridTestNode)4 GridTestKernalContext (org.apache.ignite.testframework.junits.GridTestKernalContext)4 IgniteTestResources (org.apache.ignite.testframework.junits.IgniteTestResources)4 Map (java.util.Map)3 Message (org.apache.ignite.plugin.extensions.communication.Message)3 GridTestMessage (org.apache.ignite.spi.communication.GridTestMessage)3 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)2 IgniteMock (org.apache.ignite.testframework.junits.IgniteMock)2 Test (org.junit.Test)2 ByteBuffer (java.nio.ByteBuffer)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1