Search in sources :

Example 1 with MarshallerMappingItem

use of org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem in project ignite by apache.

the class MarshallerContextImpl method registerClassName.

/**
 * {@inheritDoc}
 */
@Override
public boolean registerClassName(byte platformId, int typeId, String clsName) throws IgniteCheckedException {
    ConcurrentMap<Integer, MappedName> cache = getCacheFor(platformId);
    MappedName mappedName = cache.get(typeId);
    if (mappedName != null) {
        if (!mappedName.className().equals(clsName))
            throw new DuplicateTypeIdException(platformId, typeId, mappedName.className(), clsName);
        else {
            if (mappedName.accepted())
                return true;
            if (transport.stopping())
                return false;
            IgniteInternalFuture<MappingExchangeResult> fut = transport.awaitMappingAcceptance(new MarshallerMappingItem(platformId, typeId, clsName), cache);
            MappingExchangeResult res = fut.get();
            return convertXchRes(res);
        }
    } else {
        if (transport.stopping())
            return false;
        IgniteInternalFuture<MappingExchangeResult> fut = transport.proposeMapping(new MarshallerMappingItem(platformId, typeId, clsName), cache);
        MappingExchangeResult res = fut.get();
        return convertXchRes(res);
    }
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) MappingExchangeResult(org.apache.ignite.internal.processors.marshaller.MappingExchangeResult) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName)

Example 2 with MarshallerMappingItem

use of org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem in project ignite by apache.

the class MarshallerContextImpl method getClassName.

/**
 * {@inheritDoc}
 */
@Override
public String getClassName(byte platformId, int typeId) throws ClassNotFoundException, IgniteCheckedException {
    ConcurrentMap<Integer, MappedName> cache = getCacheFor(platformId);
    MappedName mappedName = cache.get(typeId);
    String clsName;
    if (mappedName != null)
        clsName = mappedName.className();
    else {
        clsName = fileStore.readMapping(platformId, typeId);
        if (clsName != null)
            cache.putIfAbsent(typeId, new MappedName(clsName, true));
        else if (clientNode) {
            mappedName = cache.get(typeId);
            if (mappedName == null) {
                GridFutureAdapter<MappingExchangeResult> fut = transport.requestMapping(new MarshallerMappingItem(platformId, typeId, null), cache);
                clsName = fut.get().className();
            } else
                clsName = mappedName.className();
            if (clsName == null)
                throw new ClassNotFoundException("Requesting mapping from grid failed for [platformId=" + platformId + ", typeId=" + typeId + "]");
            return clsName;
        } else
            throw new ClassNotFoundException("Unknown pair [platformId=" + platformId + ", typeId=" + typeId + "]");
    }
    return clsName;
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName)

Example 3 with MarshallerMappingItem

use of org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem in project ignite by apache.

the class MarshallerContextImpl method registerClassName.

/**
 * {@inheritDoc}
 */
@Override
public boolean registerClassName(byte platformId, int typeId, String clsName, boolean failIfUnregistered) throws IgniteCheckedException {
    ConcurrentMap<Integer, MappedName> cache = getCacheFor(platformId);
    MappedName mappedName = cache.get(typeId);
    if (mappedName != null) {
        if (!mappedName.className().equals(clsName))
            throw new DuplicateTypeIdException(platformId, typeId, mappedName.className(), clsName);
        else {
            if (mappedName.accepted())
                return true;
            if (transport.stopping())
                return false;
            MarshallerMappingItem item = new MarshallerMappingItem(platformId, typeId, clsName);
            GridFutureAdapter<MappingExchangeResult> fut = transport.awaitMappingAcceptance(item, cache);
            if (failIfUnregistered && !fut.isDone())
                throw new UnregisteredBinaryTypeException(typeId, fut);
            MappingExchangeResult res = fut.get();
            return convertXchRes(res);
        }
    } else {
        if (transport.stopping())
            return false;
        MarshallerMappingItem item = new MarshallerMappingItem(platformId, typeId, clsName);
        GridFutureAdapter<MappingExchangeResult> fut = transport.proposeMapping(item, cache);
        if (failIfUnregistered && !fut.isDone())
            throw new UnregisteredBinaryTypeException(typeId, fut);
        MappingExchangeResult res = fut.get();
        return convertXchRes(res);
    }
}
Also used : MarshallerMappingItem(org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem) MappingExchangeResult(org.apache.ignite.internal.processors.marshaller.MappingExchangeResult) MappedName(org.apache.ignite.internal.processors.marshaller.MappedName)

Example 4 with MarshallerMappingItem

use of org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem 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 5 with MarshallerMappingItem

use of org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem 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)

Aggregations

MarshallerMappingItem (org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem)10 MarshallerContextImpl (org.apache.ignite.internal.MarshallerContextImpl)6 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)6 Test (org.junit.Test)6 MappedName (org.apache.ignite.internal.processors.marshaller.MappedName)5 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Ignite (org.apache.ignite.Ignite)2 MappingExchangeResult (org.apache.ignite.internal.processors.marshaller.MappingExchangeResult)2 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)2 File (java.io.File)1 Map (java.util.Map)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1