Search in sources :

Example 1 with MarshallerContextImpl

use of org.apache.ignite.internal.MarshallerContextImpl in project ignite by apache.

the class PlatformUtils method marshaller.

/**
 * Create binary marshaller.
 *
 * @return Marshaller.
 */
public static GridBinaryMarshaller marshaller() {
    BinaryContext ctx = new BinaryContext(BinaryNoopMetadataHandler.instance(), new IgniteConfiguration(), new NullLogger());
    BinaryMarshaller marsh = new BinaryMarshaller();
    marsh.setContext(new MarshallerContextImpl(null, null));
    ctx.configure(marsh);
    return new GridBinaryMarshaller(ctx);
}
Also used : MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryContext(org.apache.ignite.internal.binary.BinaryContext)

Example 2 with MarshallerContextImpl

use of org.apache.ignite.internal.MarshallerContextImpl in project ignite by apache.

the class MarshallerContextSelfTest method testClassName.

/**
 * @throws Exception If failed.
 */
@Test
public void testClassName() throws Exception {
    MarshallerContextImpl marshCtx = new MarshallerContextImpl(null, null);
    marshCtx.onMarshallerProcessorStarted(ctx, null);
    MarshallerMappingItem item = new MarshallerMappingItem(JAVA_ID, 1, String.class.getName());
    marshCtx.onMappingProposed(item);
    marshCtx.onMappingAccepted(item);
    try (Ignite g1 = startGrid(1)) {
        marshCtx = ((IgniteKernal) g1).context().marshallerContext();
        String clsName = marshCtx.getClassName(JAVA_ID, 1);
        assertEquals("java.lang.String", clsName);
    }
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) IgniteKernal(org.apache.ignite.internal.IgniteKernal) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 3 with MarshallerContextImpl

use of org.apache.ignite.internal.MarshallerContextImpl in project ignite by apache.

the class MarshallerContextSelfTest method testCacheStructure0.

/**
 * Tests that there is a null value inserted in allCaches list
 * if platform ids passed to marshaller cache were not sequential (like 0, 2).
 */
@Test
public void testCacheStructure0() throws Exception {
    MarshallerContextImpl ctx = new MarshallerContextImpl(null, null);
    ctx.onMarshallerProcessorStarted(this.ctx, null);
    MarshallerMappingItem item1 = new MarshallerMappingItem(JAVA_ID, 1, String.class.getName());
    ctx.onMappingAccepted(item1);
    MarshallerMappingItem item2 = new MarshallerMappingItem((byte) 2, 2, "Random.Class.Name");
    ctx.onMappingProposed(item2);
    List list = U.field(ctx, "allCaches");
    assertNotNull("Mapping cache is null for platformId: 0", list.get(0));
    assertNull("Mapping cache is not null for platformId: 1", list.get(1));
    assertNotNull("Mapping cache is null for platformId: 2", list.get(2));
    boolean excObserved = false;
    try {
        list.get(3);
    } catch (ArrayIndexOutOfBoundsException ignored) {
        excObserved = true;
    }
    assertTrue("ArrayIndexOutOfBoundsException had to be thrown", excObserved);
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) ArrayList(java.util.ArrayList) List(java.util.List) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 4 with MarshallerContextImpl

use of org.apache.ignite.internal.MarshallerContextImpl in project ignite by apache.

the class MarshallerContextSelfTest method testMultiplatformMappingsDistributing.

/**
 * Test for adding non-java mappings (with platformId > 0) to MarshallerContext and distributing them
 * to newly joining nodes.
 *
 * @throws Exception If failed.
 */
@Test
public void testMultiplatformMappingsDistributing() throws Exception {
    String nonJavaClassName = "random.platform.Mapping";
    Ignite grid0 = startGrid(0);
    MarshallerContextImpl marshCtx0 = ((IgniteKernal) grid0).context().marshallerContext();
    MarshallerMappingItem item = new MarshallerMappingItem((byte) 2, 101, nonJavaClassName);
    marshCtx0.onMappingProposed(item);
    marshCtx0.onMappingAccepted(item);
    Ignite grid1 = startGrid(1);
    MarshallerContextImpl marshCtx1 = ((IgniteKernal) grid1).context().marshallerContext();
    assertEquals(nonJavaClassName, marshCtx1.getClassName((byte) 2, 101));
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) Ignite(org.apache.ignite.Ignite) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 5 with MarshallerContextImpl

use of org.apache.ignite.internal.MarshallerContextImpl in project ignite by apache.

the class ClientListenerNioListener method onHandshake.

/**
 * Perform handshake.
 *
 * @param ses Session.
 * @param msg Message bytes.
 */
private void onHandshake(GridNioSession ses, ClientMessage msg) {
    BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration(), null);
    BinaryMarshaller marsh = new BinaryMarshaller();
    marsh.setContext(new MarshallerContextImpl(null, null));
    ctx.configure(marsh);
    BinaryReaderExImpl reader = new BinaryReaderExImpl(ctx, new BinaryHeapInputStream(msg.payload()), null, true);
    byte cmd = reader.readByte();
    if (cmd != ClientListenerRequest.HANDSHAKE) {
        U.warn(log, "Unexpected client request (will close session): " + ses.remoteAddress());
        ses.close();
        return;
    }
    short verMajor = reader.readShort();
    short verMinor = reader.readShort();
    short verMaintenance = reader.readShort();
    ClientListenerProtocolVersion ver = ClientListenerProtocolVersion.create(verMajor, verMinor, verMaintenance);
    BinaryWriterExImpl writer = new BinaryWriterExImpl(null, new BinaryHeapOutputStream(8), null, null);
    byte clientType = reader.readByte();
    ClientListenerConnectionContext connCtx = null;
    try {
        connCtx = prepareContext(clientType, ses);
        ensureClientPermissions(clientType);
        if (connCtx.isVersionSupported(ver)) {
            connCtx.initializeFromHandshake(ses, ver, reader);
            ses.addMeta(CONN_CTX_META_KEY, connCtx);
        } else
            throw new IgniteCheckedException("Unsupported version: " + ver.asString());
        cancelHandshakeTimeout(ses);
        connCtx.handler().writeHandshake(writer);
        metrics.onHandshakeAccept(clientType);
    } catch (IgniteAccessControlException authEx) {
        metrics.onFailedAuth();
        writer.writeBoolean(false);
        writer.writeShort((short) 0);
        writer.writeShort((short) 0);
        writer.writeShort((short) 0);
        writer.doWriteString(authEx.getMessage());
        if (ver.compareTo(ClientConnectionContext.VER_1_1_0) >= 0)
            writer.writeInt(ClientStatus.AUTH_FAILED);
    } catch (IgniteCheckedException e) {
        U.warn(log, "Error during handshake [rmtAddr=" + ses.remoteAddress() + ", msg=" + e.getMessage() + ']');
        metrics.onGeneralReject();
        ClientListenerProtocolVersion currVer;
        if (connCtx == null)
            currVer = ClientListenerProtocolVersion.create(0, 0, 0);
        else
            currVer = connCtx.defaultVersion();
        writer.writeBoolean(false);
        writer.writeShort(currVer.major());
        writer.writeShort(currVer.minor());
        writer.writeShort(currVer.maintenance());
        writer.doWriteString(e.getMessage());
        if (ver.compareTo(ClientConnectionContext.VER_1_1_0) >= 0)
            writer.writeInt(ClientStatus.FAILED);
    }
    ses.send(new ClientMessage(writer.array()));
}
Also used : MarshallerContextImpl(org.apache.ignite.internal.MarshallerContextImpl) BinaryReaderExImpl(org.apache.ignite.internal.binary.BinaryReaderExImpl) BinaryHeapOutputStream(org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) IgniteAccessControlException(org.apache.ignite.internal.processors.authentication.IgniteAccessControlException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryHeapInputStream(org.apache.ignite.internal.binary.streams.BinaryHeapInputStream) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) BinaryWriterExImpl(org.apache.ignite.internal.binary.BinaryWriterExImpl)

Aggregations

MarshallerContextImpl (org.apache.ignite.internal.MarshallerContextImpl)9 MarshallerMappingItem (org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)3 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)3 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 Ignite (org.apache.ignite.Ignite)2 BinaryReaderExImpl (org.apache.ignite.internal.binary.BinaryReaderExImpl)2 BinaryWriterExImpl (org.apache.ignite.internal.binary.BinaryWriterExImpl)2 BinaryHeapInputStream (org.apache.ignite.internal.binary.streams.BinaryHeapInputStream)2 BinaryHeapOutputStream (org.apache.ignite.internal.binary.streams.BinaryHeapOutputStream)2 File (java.io.File)1 SQLException (java.sql.SQLException)1 Factory (javax.cache.configuration.Factory)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1