Search in sources :

Example 6 with BinaryBasicNameMapper

use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method getConfiguration.

/** {@inheritDoc} */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    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;
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 7 with BinaryBasicNameMapper

use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.

the class GridCacheBinaryStoreAbstractSelfTest method getConfiguration.

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    BinaryConfiguration bCfg = new BinaryConfiguration();
    bCfg.setNameMapper(new BinaryBasicNameMapper(false));
    bCfg.setIdMapper(new BinaryBasicIdMapper(false));
    bCfg.setClassNames(Arrays.asList(Key.class.getName(), Value.class.getName()));
    cfg.setBinaryConfiguration(bCfg);
    cfg.setMarshaller(new BinaryMarshaller());
    CacheConfiguration cacheCfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
    cacheCfg.setCacheStoreFactory(singletonFactory(STORE));
    cacheCfg.setStoreKeepBinary(keepBinaryInStore());
    cacheCfg.setReadThrough(true);
    cacheCfg.setWriteThrough(true);
    cacheCfg.setLoadPreviousValue(true);
    cfg.setCacheConfiguration(cacheCfg);
    TcpDiscoverySpi disco = new TcpDiscoverySpi();
    disco.setIpFinder(IP_FINDER);
    cfg.setDiscoverySpi(disco);
    GridCacheBinaryStoreAbstractSelfTest.cfg = cfg;
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 8 with BinaryBasicNameMapper

use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.

the class GridAbstractTest method getConfiguration.

/**
     * This method should be overridden by subclasses to change configuration parameters.
     *
     * @param igniteInstanceName Ignite instance name.
     * @return Grid configuration used for starting of grid.
     * @throws Exception If failed.
     */
@SuppressWarnings("deprecation")
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = getConfiguration(igniteInstanceName, getTestResources());
    cfg.setNodeId(null);
    if (GridTestProperties.getProperty(GridTestProperties.BINARY_COMPACT_FOOTERS) != null) {
        if (!Boolean.valueOf(GridTestProperties.getProperty(GridTestProperties.BINARY_COMPACT_FOOTERS))) {
            BinaryConfiguration bCfg = cfg.getBinaryConfiguration();
            if (bCfg == null) {
                bCfg = new BinaryConfiguration();
                cfg.setBinaryConfiguration(bCfg);
            }
            bCfg.setCompactFooter(false);
        }
    }
    if (Boolean.valueOf(GridTestProperties.getProperty(BINARY_MARSHALLER_USE_SIMPLE_NAME_MAPPER))) {
        BinaryConfiguration bCfg = cfg.getBinaryConfiguration();
        if (bCfg == null) {
            bCfg = new BinaryConfiguration();
            cfg.setBinaryConfiguration(bCfg);
        }
        bCfg.setNameMapper(new BinaryBasicNameMapper(true));
    }
    if (igniteInstanceName != null && igniteInstanceName.matches(".*\\d")) {
        String idStr = UUID.randomUUID().toString();
        if (igniteInstanceName.startsWith(getTestIgniteInstanceName())) {
            String idxStr = String.valueOf(getTestIgniteInstanceIndex(igniteInstanceName));
            while (idxStr.length() < 5) idxStr = '0' + idxStr;
            char[] chars = idStr.toCharArray();
            for (int i = 0; i < idxStr.length(); i++) chars[chars.length - idxStr.length() + i] = idxStr.charAt(i);
            cfg.setNodeId(UUID.fromString(new String(chars)));
        } else {
            char[] chars = idStr.toCharArray();
            chars[0] = igniteInstanceName.charAt(igniteInstanceName.length() - 1);
            chars[1] = '0';
            chars[chars.length - 3] = '0';
            chars[chars.length - 2] = '0';
            chars[chars.length - 1] = igniteInstanceName.charAt(igniteInstanceName.length() - 1);
            cfg.setNodeId(UUID.fromString(new String(chars)));
        }
    }
    if (isMultiJvm())
        ((TcpDiscoverySpi) cfg.getDiscoverySpi()).setIpFinder(LOCAL_IP_FINDER);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper)

Example 9 with BinaryBasicNameMapper

use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.

the class BinaryMarshallerSelfTest method testTypeNamesSimpleNameMapper.

/**
     * @throws Exception If failed.
     */
public void testTypeNamesSimpleNameMapper() 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(true), new BinaryBasicIdMapper(true), 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".hashCode(), ctx.typeId(Key.class.getName()));
    assertEquals("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"));
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryIdMapper(org.apache.ignite.binary.BinaryIdMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration)

Example 10 with BinaryBasicNameMapper

use of org.apache.ignite.binary.BinaryBasicNameMapper in project ignite by apache.

the class BinaryMarshallerSelfTest method testDuplicateNameSimpleNameMapper.

/**
     * @throws Exception If failed.
     */
public void testDuplicateNameSimpleNameMapper() throws Exception {
    BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true), null, null, null);
    Test1.Job job1 = new Test1().new Job();
    Test2.Job job2 = new Test2().new Job();
    marsh.marshal(job1);
    try {
        marsh.marshal(job2);
    } catch (BinaryObjectException e) {
        assertEquals(true, e.getMessage().contains("Failed to register class"));
        return;
    }
    assert false;
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) BinaryBasicIdMapper(org.apache.ignite.binary.BinaryBasicIdMapper) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

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