Search in sources :

Example 1 with MappedName

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

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

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

the class MarshallerContextImpl method onMappingProposed.

/**
 * @param item type mapping to propose
 * @return null if cache doesn't contain any mappings for given (platformId, typeId) pair,
 * previous {@link MappedName mapped name} otherwise.
 */
public MappedName onMappingProposed(MarshallerMappingItem item) {
    ConcurrentMap<Integer, MappedName> cache = getCacheFor(item.platformId());
    MappedName newName = new MappedName(item.className(), false);
    return cache.putIfAbsent(item.typeId(), newName);
}
Also used : MappedName(org.apache.ignite.internal.processors.marshaller.MappedName)

Example 4 with MappedName

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

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

the class MarshallerContextImpl method registerClassNameLocally.

/**
 * {@inheritDoc}
 */
@Override
public boolean registerClassNameLocally(byte platformId, int typeId, String clsName) throws IgniteCheckedException {
    ConcurrentMap<Integer, MappedName> cache = getCacheFor(platformId);
    fileStore.mergeAndWriteMapping(platformId, typeId, clsName);
    cache.put(typeId, new MappedName(clsName, true));
    return true;
}
Also used : MappedName(org.apache.ignite.internal.processors.marshaller.MappedName)

Aggregations

MappedName (org.apache.ignite.internal.processors.marshaller.MappedName)15 Map (java.util.Map)5 MarshallerMappingItem (org.apache.ignite.internal.processors.marshaller.MarshallerMappingItem)5 HashMap (java.util.HashMap)4 AbstractMap (java.util.AbstractMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentMap (java.util.concurrent.ConcurrentMap)3 GridDhtPartitionFullMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap)3 GridDhtPartitionMap (org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap)3 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)3 ArrayList (java.util.ArrayList)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 MappingExchangeResult (org.apache.ignite.internal.processors.marshaller.MappingExchangeResult)2 BufferedReader (java.io.BufferedReader)1 Closeable (java.io.Closeable)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStreamReader (java.io.InputStreamReader)1 ByteBuffer (java.nio.ByteBuffer)1