/** * @param globalIdMapper ID mapper. * @param globalSerializer Serializer. * @param typeCfgs Type configurations. * @throws BinaryObjectException In case of error. */ private void configure( 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."); BinaryIdMapper idMapper = globalIdMapper; if (typeCfg.getIdMapper() != null) idMapper = typeCfg.getIdMapper(); idMapper = BinaryInternalIdMapper.create(idMapper); BinarySerializer serializer = globalSerializer; if (typeCfg.getSerializer() != null) serializer = typeCfg.getSerializer(); if (clsName.endsWith(".*")) { String pkgName = clsName.substring(0, clsName.length() - 2); for (String clsName0 : classesInPackage(pkgName)) descs.add( clsName0, idMapper, serializer, affFields.get(clsName0), typeCfg.isEnum(), true); } else descs.add(clsName, idMapper, serializer, affFields.get(clsName), typeCfg.isEnum(), false); } } for (TypeDescriptor desc : descs.descriptors()) registerUserType( desc.clsName, desc.idMapper, desc.serializer, desc.affKeyFieldName, desc.isEnum); BinaryInternalIdMapper dfltMapper = BinaryInternalIdMapper.create(globalIdMapper); // Put affinity field names for unconfigured types. for (Map.Entry<String, String> entry : affFields.entrySet()) { String typeName = entry.getKey(); int typeId = dfltMapper.typeId(typeName); affKeyFieldNames.putIfAbsent(typeId, entry.getValue()); } addSystemClassAffinityKey(CollocatedSetItemKey.class); addSystemClassAffinityKey(CollocatedQueueItemKey.class); }
/** {@inheritDoc} */ @Override protected IgniteConfiguration getConfiguration(String gridName) throws Exception { IgniteConfiguration cfg = super.getConfiguration(gridName); BinaryTypeConfiguration customTypeCfg = new BinaryTypeConfiguration(); customTypeCfg.setTypeName(CustomIdMapper.class.getName()); customTypeCfg.setIdMapper( new BinaryIdMapper() { @Override public int typeId(String clsName) { return ~BinaryContext.defaultIdMapper().typeId(clsName); } @Override public int fieldId(int typeId, String fieldName) { return typeId + ~BinaryContext.defaultIdMapper().fieldId(typeId, fieldName); } }); BinaryConfiguration bCfg = new BinaryConfiguration(); bCfg.setCompactFooter(compactFooter()); bCfg.setTypeConfigurations( Arrays.asList( new BinaryTypeConfiguration(Key.class.getName()), new BinaryTypeConfiguration(Value.class.getName()), new BinaryTypeConfiguration("org.gridgain.grid.internal.util.binary.mutabletest.*"), customTypeCfg)); bCfg.setIdMapper(new BinaryBasicIdMapper(false)); bCfg.setNameMapper(new BinaryBasicNameMapper(false)); cfg.setBinaryConfiguration(bCfg); cfg.setMarshaller(new BinaryMarshaller()); this.cfg = cfg; return cfg; }