Search in sources :

Example 16 with BinaryBasicNameMapper

use of org.apache.ignite.binary.BinaryBasicNameMapper 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"));
}
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 17 with BinaryBasicNameMapper

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

the class BinaryMarshallerSelfTest method testTypeNamesSimpleNameMappers.

/**
     * @throws Exception If failed.
     */
public void testTypeNamesSimpleNameMappers() 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.setNameMapper(new BinaryBasicNameMapper(false));
    customType5.setIdMapper(new BinaryBasicIdMapper(false));
    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, customType5));
    BinaryContext ctx = binaryContext(marsh);
    assertEquals("notconfiguredclass".hashCode(), ctx.typeId("NotConfiguredClass"));
    assertEquals("notconfiguredclass".hashCode(), ctx.typeId("org.blabla.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"));
    assertEquals(DateClass1.class.getName().hashCode(), ctx.typeId(DateClass1.class.getName()));
    // 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 18 with BinaryBasicNameMapper

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

the class BinaryBasicNameMapperSelfTest method testFullName.

/**
     * @throws Exception If failed.
     */
public void testFullName() throws Exception {
    BinaryBasicNameMapper mapper = new BinaryBasicNameMapper(false);
    assertEquals(GridBinaryTestClass1.class.getName(), mapper.typeName(GridBinaryTestClass1.class.getName()));
    assertEquals(GridBinaryTestClass1.class.getName() + "$InnerClass", mapper.typeName(GridBinaryTestClass1.class.getName() + "$InnerClass"));
}
Also used : BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) GridBinaryTestClass1(org.apache.ignite.internal.binary.test.GridBinaryTestClass1)

Example 19 with BinaryBasicNameMapper

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

the class BinaryMarshallerSelfTest method testSimpleNameLowerCaseMappers.

/**
     * @throws Exception If failed.
     */
public void testSimpleNameLowerCaseMappers() throws Exception {
    BinaryTypeConfiguration innerClassType = new BinaryTypeConfiguration(InnerMappedObject.class.getName());
    BinaryTypeConfiguration publicClassType = new BinaryTypeConfiguration(TestMappedObject.class.getName());
    BinaryTypeConfiguration typeWithCustomMapper = new BinaryTypeConfiguration(CustomMappedObject2.class.getName());
    typeWithCustomMapper.setIdMapper(new BinaryIdMapper() {

        @Override
        public int typeId(String clsName) {
            return 44444;
        }

        @Override
        public int fieldId(int typeId, String fieldName) {
            assert typeId == 44444;
            if ("val1".equals(fieldName))
                return 55555;
            else if ("val2".equals(fieldName))
                return 66666;
            assert false : "Unknown field: " + fieldName;
            return 0;
        }
    });
    BinaryMarshaller marsh = binaryMarshaller(new BinaryBasicNameMapper(true), new BinaryBasicIdMapper(true), Arrays.asList(innerClassType, publicClassType, typeWithCustomMapper));
    InnerMappedObject innerObj = new InnerMappedObject(10, "str1");
    BinaryObjectExImpl innerBo = marshal(innerObj, marsh);
    assertEquals("InnerMappedObject".toLowerCase().hashCode(), innerBo.type().typeId());
    assertEquals(10, innerBo.<CustomMappedObject1>deserialize().val1);
    assertEquals("str1", innerBo.<CustomMappedObject1>deserialize().val2);
    TestMappedObject publicObj = new TestMappedObject();
    BinaryObjectExImpl publicBo = marshal(publicObj, marsh);
    assertEquals("TestMappedObject".toLowerCase().hashCode(), publicBo.type().typeId());
    CustomMappedObject2 obj2 = new CustomMappedObject2(20, "str2");
    BinaryObjectExImpl po2 = marshal(obj2, marsh);
    assertEquals(44444, po2.type().typeId());
    assertEquals((Integer) 20, po2.field(55555));
    assertEquals("str2", po2.field(66666));
    assertEquals(20, po2.<CustomMappedObject2>deserialize().val1);
    assertEquals("str2", po2.<CustomMappedObject2>deserialize().val2);
}
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 20 with BinaryBasicNameMapper

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

the class PlatformConfigurationUtils method readIgniteConfiguration.

/**
     * Reads Ignite configuration.
     * @param in Reader.
     * @param cfg Configuration.
     */
public static void readIgniteConfiguration(BinaryRawReaderEx in, IgniteConfiguration cfg) {
    if (in.readBoolean())
        cfg.setClientMode(in.readBoolean());
    int[] eventTypes = in.readIntArray();
    if (eventTypes != null)
        cfg.setIncludeEventTypes(eventTypes);
    if (in.readBoolean())
        cfg.setMetricsExpireTime(in.readLong());
    if (in.readBoolean())
        cfg.setMetricsHistorySize(in.readInt());
    if (in.readBoolean())
        cfg.setMetricsLogFrequency(in.readLong());
    if (in.readBoolean())
        cfg.setMetricsUpdateFrequency(in.readLong());
    if (in.readBoolean())
        cfg.setNetworkSendRetryCount(in.readInt());
    if (in.readBoolean())
        cfg.setNetworkSendRetryDelay(in.readLong());
    if (in.readBoolean())
        cfg.setNetworkTimeout(in.readLong());
    String workDir = in.readString();
    if (workDir != null)
        cfg.setWorkDirectory(workDir);
    String localHost = in.readString();
    if (localHost != null)
        cfg.setLocalHost(localHost);
    if (in.readBoolean())
        cfg.setDaemon(in.readBoolean());
    if (in.readBoolean())
        cfg.setLateAffinityAssignment(in.readBoolean());
    if (in.readBoolean())
        cfg.setFailureDetectionTimeout(in.readLong());
    if (in.readBoolean())
        cfg.setClientFailureDetectionTimeout(in.readLong());
    readCacheConfigurations(in, cfg);
    readDiscoveryConfiguration(in, cfg);
    if (in.readBoolean()) {
        TcpCommunicationSpi comm = new TcpCommunicationSpi();
        comm.setAckSendThreshold(in.readInt());
        comm.setConnectTimeout(in.readLong());
        comm.setDirectBuffer(in.readBoolean());
        comm.setDirectSendBuffer(in.readBoolean());
        comm.setIdleConnectionTimeout(in.readLong());
        comm.setLocalAddress(in.readString());
        comm.setLocalPort(in.readInt());
        comm.setLocalPortRange(in.readInt());
        comm.setMaxConnectTimeout(in.readLong());
        comm.setMessageQueueLimit(in.readInt());
        comm.setReconnectCount(in.readInt());
        comm.setSelectorsCount(in.readInt());
        comm.setSlowClientQueueLimit(in.readInt());
        comm.setSocketReceiveBuffer(in.readInt());
        comm.setSocketSendBuffer(in.readInt());
        comm.setTcpNoDelay(in.readBoolean());
        comm.setUnacknowledgedMessagesBufferSize(in.readInt());
        cfg.setCommunicationSpi(comm);
    }
    if (in.readBoolean()) {
        // binary config is present
        if (cfg.getBinaryConfiguration() == null)
            cfg.setBinaryConfiguration(new BinaryConfiguration());
        if (// compact footer is set
        in.readBoolean())
            cfg.getBinaryConfiguration().setCompactFooter(in.readBoolean());
        if (in.readBoolean()) {
            // Simple name mapper.
            cfg.getBinaryConfiguration().setNameMapper(new BinaryBasicNameMapper(true));
        }
    }
    int attrCnt = in.readInt();
    if (attrCnt > 0) {
        Map<String, Object> attrs = new HashMap<>(attrCnt);
        for (int i = 0; i < attrCnt; i++) attrs.put(in.readString(), in.readObject());
        cfg.setUserAttributes(attrs);
    }
    if (in.readBoolean()) {
        AtomicConfiguration atomic = new AtomicConfiguration();
        atomic.setAtomicSequenceReserveSize(in.readInt());
        atomic.setBackups(in.readInt());
        atomic.setCacheMode(CacheMode.fromOrdinal(in.readInt()));
        cfg.setAtomicConfiguration(atomic);
    }
    if (in.readBoolean()) {
        TransactionConfiguration tx = new TransactionConfiguration();
        tx.setPessimisticTxLogSize(in.readInt());
        tx.setDefaultTxConcurrency(TransactionConcurrency.fromOrdinal(in.readInt()));
        tx.setDefaultTxIsolation(TransactionIsolation.fromOrdinal(in.readInt()));
        tx.setDefaultTxTimeout(in.readLong());
        tx.setPessimisticTxLogLinger(in.readInt());
        cfg.setTransactionConfiguration(tx);
    }
    switch(in.readByte()) {
        case 1:
            cfg.setEventStorageSpi(new NoopEventStorageSpi());
            break;
        case 2:
            cfg.setEventStorageSpi(new MemoryEventStorageSpi().setExpireCount(in.readLong()).setExpireAgeMs(in.readLong()));
            break;
    }
    if (in.readBoolean())
        cfg.setMemoryConfiguration(readMemoryConfiguration(in));
    readPluginConfiguration(cfg, in);
}
Also used : TransactionConfiguration(org.apache.ignite.configuration.TransactionConfiguration) BinaryBasicNameMapper(org.apache.ignite.binary.BinaryBasicNameMapper) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MemoryEventStorageSpi(org.apache.ignite.spi.eventstorage.memory.MemoryEventStorageSpi) NoopEventStorageSpi(org.apache.ignite.spi.eventstorage.NoopEventStorageSpi) TcpCommunicationSpi(org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) PlatformDotNetBinaryConfiguration(org.apache.ignite.platform.dotnet.PlatformDotNetBinaryConfiguration) AtomicConfiguration(org.apache.ignite.configuration.AtomicConfiguration)

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