Search in sources :

Example 11 with BinaryBasicNameMapper

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);
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper)

Example 12 with BinaryBasicNameMapper

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"));
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) GridBinaryTestClass1(org.apache.ignite.internal.binary.test.GridBinaryTestClass1)

Example 13 with BinaryBasicNameMapper

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);
}
Also used : PlatformConfiguration(org.apache.ignite.configuration.PlatformConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) Marshaller(org.apache.ignite.marshaller.Marshaller) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) PlatformCppConfiguration(org.apache.ignite.platform.cpp.PlatformCppConfiguration) IgniteException(org.apache.ignite.IgniteException) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryNameMapper(org.apache.ignite.binary.BinaryNameMapper) PlatformMemoryManagerImpl(org.apache.ignite.internal.processors.platform.memory.PlatformMemoryManagerImpl)

Example 14 with BinaryBasicNameMapper

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()));
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 15 with BinaryBasicNameMapper

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;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper)

Aggregations

BinaryBasicNameMapper (org.apache.ignite.binary.BinaryBasicNameMapper)24 BinaryBasicIdMapper (org.apache.ignite.binary.BinaryBasicIdMapper)14 BinaryIdMapper (org.apache.ignite.binary.BinaryIdMapper)12 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)11 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)10 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)7 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 AtomicConfiguration (org.apache.ignite.configuration.AtomicConfiguration)2 TransactionConfiguration (org.apache.ignite.configuration.TransactionConfiguration)2 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)2 GridBinaryTestClass1 (org.apache.ignite.internal.binary.test.GridBinaryTestClass1)2 PlatformDotNetBinaryConfiguration (org.apache.ignite.platform.dotnet.PlatformDotNetBinaryConfiguration)2 TcpCommunicationSpi (org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi)2 NoopEventStorageSpi (org.apache.ignite.spi.eventstorage.NoopEventStorageSpi)2 MemoryEventStorageSpi (org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi)2 Map (java.util.Map)1 IgniteException (org.apache.ignite.IgniteException)1 BinaryNameMapper (org.apache.ignite.binary.BinaryNameMapper)1