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);
}
}
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;
}
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);
}
}
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);
}
}
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);
}
Aggregations