use of org.apache.ignite.binary.BinaryNameMapper in project ignite by apache.
the class BinaryContext method configure.
/**
* @param globalIdMapper ID mapper.
* @param globalSerializer Serializer.
* @param typeCfgs Type configurations.
* @throws BinaryObjectException In case of error.
*/
private void configure(BinaryNameMapper globalNameMapper, BinaryIdMapper globalIdMapper, BinarySerializer globalSerializer, Collection<BinaryTypeConfiguration> typeCfgs) throws BinaryObjectException {
TypeDescriptors descs = new TypeDescriptors();
Map<String, String> affFields = new HashMap<>();
if (!F.isEmpty(igniteCfg.getCacheKeyConfiguration())) {
for (CacheKeyConfiguration keyCfg : igniteCfg.getCacheKeyConfiguration()) affFields.put(keyCfg.getTypeName(), keyCfg.getAffinityKeyFieldName());
}
if (typeCfgs != null) {
for (BinaryTypeConfiguration typeCfg : typeCfgs) {
String clsName = typeCfg.getTypeName();
if (clsName == null)
throw new BinaryObjectException("Class name is required for binary type configuration.");
// Resolve mapper.
BinaryIdMapper idMapper = U.firstNotNull(typeCfg.getIdMapper(), globalIdMapper);
BinaryNameMapper nameMapper = U.firstNotNull(typeCfg.getNameMapper(), globalNameMapper);
BinarySerializer serializer = U.firstNotNull(typeCfg.getSerializer(), globalSerializer);
BinaryIdentityResolver identity = BinaryArrayIdentityResolver.instance();
BinaryInternalMapper mapper = resolveMapper(nameMapper, idMapper);
if (clsName.endsWith(".*")) {
String pkgName = clsName.substring(0, clsName.length() - 2);
for (String clsName0 : classesInPackage(pkgName)) descs.add(clsName0, mapper, serializer, identity, affFields.get(clsName0), typeCfg.isEnum(), typeCfg.getEnumValues(), true);
} else
descs.add(clsName, mapper, serializer, identity, affFields.get(clsName), typeCfg.isEnum(), typeCfg.getEnumValues(), false);
}
}
for (TypeDescriptor desc : descs.descriptors()) registerUserType(desc.clsName, desc.mapper, desc.serializer, desc.identity, desc.affKeyFieldName, desc.isEnum, desc.enumMap);
BinaryInternalMapper globalMapper = resolveMapper(globalNameMapper, globalIdMapper);
// Put affinity field names for unconfigured types.
for (Map.Entry<String, String> entry : affFields.entrySet()) {
String typeName = entry.getKey();
int typeId = globalMapper.typeId(typeName);
affKeyFieldNames.putIfAbsent(typeId, entry.getValue());
}
addSystemClassAffinityKey(CollocatedSetItemKey.class);
addSystemClassAffinityKey(CollocatedQueueItemKey.class);
}
use of org.apache.ignite.binary.BinaryNameMapper in project ignite by apache.
the class BinaryContext method resolveMapper.
/**
* @param clsName Type name.
* @param cfg Binary configuration.
* @return Mapper according to configuration.
*/
private static BinaryInternalMapper resolveMapper(String clsName, BinaryConfiguration cfg) {
assert clsName != null;
if (cfg == null)
return DFLT_MAPPER;
BinaryIdMapper globalIdMapper = cfg.getIdMapper();
BinaryNameMapper globalNameMapper = cfg.getNameMapper();
Collection<BinaryTypeConfiguration> typeCfgs = cfg.getTypeConfigurations();
if (typeCfgs != null) {
for (BinaryTypeConfiguration typeCfg : typeCfgs) {
String typeCfgName = typeCfg.getTypeName();
// Pattern.
if (typeCfgName != null && typeCfgName.endsWith(".*")) {
String pkgName = typeCfgName.substring(0, typeCfgName.length() - 2);
int dotIndex = clsName.lastIndexOf('.');
if (dotIndex > 0) {
String typePkgName = clsName.substring(0, dotIndex);
if (pkgName.equals(typePkgName)) {
// Resolve mapper.
BinaryIdMapper idMapper = globalIdMapper;
if (typeCfg.getIdMapper() != null)
idMapper = typeCfg.getIdMapper();
BinaryNameMapper nameMapper = globalNameMapper;
if (typeCfg.getNameMapper() != null)
nameMapper = typeCfg.getNameMapper();
return resolveMapper(nameMapper, idMapper);
}
}
}
}
}
return resolveMapper(globalNameMapper, globalIdMapper);
}
use of org.apache.ignite.binary.BinaryNameMapper in project ignite by apache.
the class GridCacheBinaryObjectsAbstractSelfTest method testCircularReference.
/**
* @throws Exception If failed.
*/
@SuppressWarnings("unchecked")
public void testCircularReference() throws Exception {
IgniteCache c = keepBinaryCache();
TestReferenceObject obj1 = new TestReferenceObject();
obj1.obj = new TestReferenceObject(obj1);
c.put(1, obj1);
BinaryObject po = (BinaryObject) c.get(1);
String str = po.toString();
log.info("toString: " + str);
assertNotNull(str);
BinaryNameMapper nameMapper = BinaryContext.defaultNameMapper();
if (cfg.getBinaryConfiguration() != null && cfg.getBinaryConfiguration().getNameMapper() != null)
nameMapper = cfg.getBinaryConfiguration().getNameMapper();
String typeName = nameMapper.typeName(TestReferenceObject.class.getName());
assertTrue("Unexpected toString: " + str, S.INCLUDE_SENSITIVE ? str.startsWith(typeName) && str.contains("obj=" + typeName + " [") : str.startsWith("BinaryObject") && str.contains("idHash=") && str.contains("hash="));
TestReferenceObject obj1_r = po.deserialize();
assertNotNull(obj1_r);
TestReferenceObject obj2_r = obj1_r.obj;
assertNotNull(obj2_r);
assertSame(obj1_r, obj2_r.obj);
}
use of org.apache.ignite.binary.BinaryNameMapper in project ignite by apache.
the class PlatformCppConfigurationClosure method apply0.
/** {@inheritDoc} */
@SuppressWarnings("deprecation")
@Override
protected void apply0(IgniteConfiguration igniteCfg) {
// 3. Validate and copy Interop configuration setting environment pointer along the way.
PlatformConfiguration interopCfg = igniteCfg.getPlatformConfiguration();
if (interopCfg != null && !(interopCfg instanceof PlatformCppConfiguration))
throw new IgniteException("Illegal interop configuration (must be of type " + PlatformCppConfiguration.class.getName() + "): " + interopCfg.getClass().getName());
PlatformCppConfiguration cppCfg = interopCfg != null ? (PlatformCppConfiguration) interopCfg : null;
if (cppCfg == null)
cppCfg = new PlatformCppConfiguration();
PlatformMemoryManagerImpl memMgr = new PlatformMemoryManagerImpl(gate, 1024);
PlatformCppConfigurationEx cppCfg0 = new PlatformCppConfigurationEx(cppCfg, gate, memMgr);
igniteCfg.setPlatformConfiguration(cppCfg0);
// Check marshaller
Marshaller marsh = igniteCfg.getMarshaller();
if (marsh == null) {
igniteCfg.setMarshaller(new BinaryMarshaller());
cppCfg0.warnings(Collections.singleton("Marshaller is automatically set to " + BinaryMarshaller.class.getName() + " (other nodes must have the same marshaller type)."));
} else if (!(marsh instanceof BinaryMarshaller))
throw new IgniteException("Unsupported marshaller (only " + BinaryMarshaller.class.getName() + " can be used when running Apache Ignite C++): " + marsh.getClass().getName());
BinaryConfiguration bCfg = igniteCfg.getBinaryConfiguration();
if (bCfg == null) {
bCfg = new BinaryConfiguration();
bCfg.setCompactFooter(false);
bCfg.setNameMapper(new BinaryBasicNameMapper(true));
bCfg.setIdMapper(new BinaryBasicIdMapper(true));
igniteCfg.setBinaryConfiguration(bCfg);
cppCfg0.warnings(Collections.singleton("Binary configuration is automatically initiated, " + "note that binary name mapper is set to " + bCfg.getNameMapper() + " and binary ID mapper is set to " + bCfg.getIdMapper() + " (other nodes must have the same binary name and ID mapper types)."));
} else {
BinaryNameMapper nameMapper = bCfg.getNameMapper();
if (nameMapper == null) {
bCfg.setNameMapper(new BinaryBasicNameMapper(true));
cppCfg0.warnings(Collections.singleton("Binary name mapper is automatically set to " + bCfg.getNameMapper() + " (other nodes must have the same binary name mapper type)."));
}
BinaryIdMapper idMapper = bCfg.getIdMapper();
if (idMapper == null) {
bCfg.setIdMapper(new BinaryBasicIdMapper(true));
cppCfg0.warnings(Collections.singleton("Binary ID mapper is automatically set to " + bCfg.getIdMapper() + " (other nodes must have the same binary ID mapper type)."));
}
}
if (bCfg.isCompactFooter())
throw new IgniteException("Unsupported " + BinaryMarshaller.class.getName() + " \"compactFooter\" flag: must be false when running Apache Ignite C++.");
// Set Ignite home so that marshaller context works.
String ggHome = igniteCfg.getIgniteHome();
if (ggHome != null)
U.setIgniteHome(ggHome);
}
use of org.apache.ignite.binary.BinaryNameMapper in project ignite by apache.
the class BinaryObjectBuilderDefaultMappersSelfTest method expectedHashCode.
/**
* @return Expected hash code.
* @param fullName Full name of type.
*/
private int expectedHashCode(String fullName) {
BinaryIdMapper idMapper = cfg.getBinaryConfiguration().getIdMapper();
BinaryNameMapper nameMapper = cfg.getBinaryConfiguration().getNameMapper();
if (idMapper == null)
idMapper = BinaryContext.defaultIdMapper();
if (nameMapper == null)
nameMapper = BinaryContext.defaultNameMapper();
return idMapper.typeId(nameMapper.typeName(fullName));
}
Aggregations