use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.
the class BinaryMarshallerSelfTest method testDuplicateNameFullNameMapper.
/**
* @throws Exception If failed.
*/
public void testDuplicateNameFullNameMapper() throws Exception {
BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false), null, null, null);
Test1.Job job1 = new Test1().new Job();
Test2.Job job2 = new Test2().new Job();
marsh.marshal(job1);
marsh.marshal(job2);
}
use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.
the class BinaryBasicNameMapperSelfTest method testSimpleName.
/**
* @throws Exception If failed.
*/
public void testSimpleName() throws Exception {
BinaryBasicNameMapper mapper = new BinaryBasicNameMapper(true);
assertEquals("GridBinaryTestClass1", mapper.typeName(GridBinaryTestClass1.class.getName()));
assertEquals("InnerClass", mapper.typeName(GridBinaryTestClass1.class.getName() + "$InnerClass"));
}
use of org.apache.ignite.binary.BinaryBasicNameMapper 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.BinaryBasicNameMapper in project ignite by apache.
the class BinaryMarshallerSelfTest method testTypeNamesCustomIdMapper.
/**
* @throws Exception If failed.
*/
public void testTypeNamesCustomIdMapper() throws Exception {
BinaryTypeConfiguration customType1 = new BinaryTypeConfiguration(Value.class.getName());
customType1.setIdMapper(new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
return 300;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryTypeConfiguration customType2 = new BinaryTypeConfiguration("org.gridgain.NonExistentClass1");
customType2.setIdMapper(new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
return 400;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryTypeConfiguration customType3 = new BinaryTypeConfiguration("NonExistentClass2");
customType3.setIdMapper(new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
return 500;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryTypeConfiguration customType4 = new BinaryTypeConfiguration("NonExistentClass0");
customType4.setIdMapper(new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
return 0;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
});
BinaryTypeConfiguration customType5 = new BinaryTypeConfiguration(DateClass1.class.getName());
customType5.setIdMapper(new BinaryBasicIdMapper(false));
BinaryTypeConfiguration customType6 = new BinaryTypeConfiguration(MyTestClass.class.getName());
customType6.setIdMapper(new BinaryBasicIdMapper(true));
customType6.setNameMapper(new BinaryBasicNameMapper(true));
BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(false), new BinaryIdMapper() {
@Override
public int typeId(String clsName) {
if ("org.blabla.NotConfiguredSpecialClass".equals(clsName))
return 0;
else if (Key.class.getName().equals(clsName))
return 991;
else if ("org.gridgain.NonExistentClass3".equals(clsName))
return 992;
else if ("NonExistentClass4".equals(clsName))
return 993;
return 999;
}
@Override
public int fieldId(int typeId, String fieldName) {
return 0;
}
}, Arrays.asList(new BinaryTypeConfiguration(Key.class.getName()), new BinaryTypeConfiguration("org.gridgain.NonExistentClass3"), new BinaryTypeConfiguration("NonExistentClass4"), customType1, customType2, customType3, customType4, customType5, customType6));
BinaryContext ctx = binaryContext(marsh);
assertEquals(999, ctx.typeId("NotConfiguredClass"));
assertEquals(999, ctx.typeId("org.blabla.NotConfiguredClass"));
// BinaryIdMapper.typeId() contract.
assertEquals("notconfiguredspecialclass".hashCode(), ctx.typeId("org.blabla.NotConfiguredSpecialClass"));
assertEquals(991, ctx.typeId(Key.class.getName()));
assertEquals(992, ctx.typeId("org.gridgain.NonExistentClass3"));
assertEquals(993, ctx.typeId("NonExistentClass4"));
// Custom types.
assertEquals(300, ctx.typeId(Value.class.getName()));
assertEquals(400, ctx.typeId("org.gridgain.NonExistentClass1"));
assertEquals(500, ctx.typeId("NonExistentClass2"));
// BinaryIdMapper.typeId() contract.
assertEquals("nonexistentclass0".hashCode(), ctx.typeId("NonExistentClass0"));
assertEquals(DateClass1.class.getName().hashCode(), ctx.typeId(DateClass1.class.getName()));
assertEquals("mytestclass".hashCode(), ctx.typeId(MyTestClass.class.getName()));
}
use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.
the class BinaryObjectBuilderSimpleNameLowerCaseMappersSelfTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
BinaryConfiguration bCfg = cfg.getBinaryConfiguration();
bCfg.setIdMapper(new BinaryBasicIdMapper(true));
bCfg.setNameMapper(new BinaryBasicNameMapper(true));
return cfg;
}
Aggregations