use of org.apache.ignite.binary.BinaryBasicIdMapper in project ignite by apache.
the class IgniteServiceProxyTimeoutInitializedTest method getConfiguration.
/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(final String igniteInstanceName) throws Exception {
final IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
final ServiceConfiguration scfg = new ServiceConfiguration();
if (igniteInstanceName.endsWith("0")) {
scfg.setName("testService");
scfg.setService(srvc);
scfg.setMaxPerNodeCount(1);
scfg.setTotalCount(1);
scfg.setNodeFilter(new NodeFilter());
final Map<String, String> attrs = new HashMap<>();
attrs.put("clusterGroup", "0");
cfg.setUserAttributes(attrs);
cfg.setServiceConfiguration(scfg);
}
cfg.setMarshaller(null);
final BinaryConfiguration binCfg = new BinaryConfiguration();
// Despite defaults explicitly set to lower case.
binCfg.setIdMapper(new BinaryBasicIdMapper(true));
cfg.setBinaryConfiguration(binCfg);
return cfg;
}
use of org.apache.ignite.binary.BinaryBasicIdMapper 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.BinaryBasicIdMapper 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.BinaryBasicIdMapper 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;
}
use of org.apache.ignite.binary.BinaryBasicIdMapper in project ignite by apache.
the class BinaryMarshallerSelfTest method testTypeNamesFullNameMappers.
/**
* @throws Exception If failed.
*/
public void testTypeNamesFullNameMappers() 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;
}
});
BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(false), new BinaryBasicIdMapper(false), Arrays.asList(new BinaryTypeConfiguration(Key.class.getName()), new BinaryTypeConfiguration("org.gridgain.NonExistentClass3"), new BinaryTypeConfiguration("NonExistentClass4"), customType1, customType2, customType3, customType4));
BinaryContext ctx = binaryContext(marsh);
// Full name hashCode.
assertEquals("NotConfiguredClass".hashCode(), ctx.typeId("NotConfiguredClass"));
assertEquals(Key.class.getName().hashCode(), ctx.typeId(Key.class.getName()));
assertEquals("org.gridgain.NonExistentClass3".hashCode(), ctx.typeId("org.gridgain.NonExistentClass3"));
assertEquals("NonExistentClass4".hashCode(), ctx.typeId("NonExistentClass4"));
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"));
}
Aggregations