Search in sources :

Example 36 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class GridDiscoveryManagerAttributesSelfTest method getConfiguration.

/**
 * {@inheritDoc}
 */
@Override
protected IgniteConfiguration getConfiguration(String igniteInstanceName) throws Exception {
    IgniteConfiguration cfg = super.getConfiguration(igniteInstanceName);
    if (igniteInstanceName.equals(getTestIgniteInstanceName(1)))
        cfg.setClientMode(true);
    if (binaryMarshallerEnabled)
        cfg.setMarshaller(new BinaryMarshaller());
    cfg.setIncludeProperties(PREFER_IPV4);
    cfg.setDeploymentMode(mode);
    cfg.setPeerClassLoadingEnabled(p2pEnabled);
    TcpDiscoverySpi discoverySpi = new TcpDiscoverySpi();
    discoverySpi.setIpFinder(IP_FINDER);
    cfg.setDiscoverySpi(discoverySpi);
    return cfg;
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) TcpDiscoverySpi(org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)

Example 37 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class CacheObjectBinaryProcessorImpl method start.

/** {@inheritDoc} */
@Override
public void start(boolean activeOnStart) throws IgniteCheckedException {
    if (marsh instanceof BinaryMarshaller) {
        if (ctx.clientNode())
            ctx.event().addLocalEventListener(clientDisconLsnr, EVT_CLIENT_NODE_DISCONNECTED);
        transport = new BinaryMetadataTransport(metadataLocCache, ctx, log);
        BinaryMetadataHandler metaHnd = new BinaryMetadataHandler() {

            @Override
            public void addMeta(int typeId, BinaryType newMeta) throws BinaryObjectException {
                assert newMeta != null;
                assert newMeta instanceof BinaryTypeImpl;
                if (!discoveryStarted) {
                    BinaryMetadataHolder holder = metadataLocCache.get(typeId);
                    BinaryMetadata oldMeta = holder != null ? holder.metadata() : null;
                    BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, ((BinaryTypeImpl) newMeta).metadata());
                    if (oldMeta != mergedMeta)
                        metadataLocCache.putIfAbsent(typeId, new BinaryMetadataHolder(mergedMeta, 0, 0));
                    return;
                }
                BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
                CacheObjectBinaryProcessorImpl.this.addMeta(typeId, newMeta0.wrap(binaryCtx));
            }

            @Override
            public BinaryType metadata(int typeId) throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata(typeId);
            }

            @Override
            public BinaryMetadata metadata0(int typeId) throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata0(typeId);
            }

            @Override
            public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectException {
                return CacheObjectBinaryProcessorImpl.this.metadata(typeId, schemaId);
            }
        };
        BinaryMarshaller bMarsh0 = (BinaryMarshaller) marsh;
        binaryCtx = new BinaryContext(metaHnd, ctx.config(), ctx.log(BinaryContext.class));
        IgniteUtils.invoke(BinaryMarshaller.class, bMarsh0, "setBinaryContext", binaryCtx, ctx.config());
        binaryMarsh = new GridBinaryMarshaller(binaryCtx);
        binaries = new IgniteBinaryImpl(ctx, this);
        if (!getBoolean(IGNITE_SKIP_CONFIGURATION_CONSISTENCY_CHECK)) {
            BinaryConfiguration bCfg = ctx.config().getBinaryConfiguration();
            if (bCfg != null) {
                Map<String, Object> map = new HashMap<>();
                map.put("globIdMapper", bCfg.getIdMapper() != null ? bCfg.getIdMapper().getClass().getName() : null);
                map.put("globSerializer", bCfg.getSerializer() != null ? bCfg.getSerializer().getClass() : null);
                map.put("compactFooter", bCfg.isCompactFooter());
                if (bCfg.getTypeConfigurations() != null) {
                    Map<Object, Object> typeCfgsMap = new HashMap<>();
                    for (BinaryTypeConfiguration c : bCfg.getTypeConfigurations()) {
                        typeCfgsMap.put(c.getTypeName() != null, Arrays.asList(c.getIdMapper() != null ? c.getIdMapper().getClass() : null, c.getSerializer() != null ? c.getSerializer().getClass() : null, c.isEnum()));
                        if (c.isEnum())
                            BinaryUtils.validateEnumValues(c.getTypeName(), c.getEnumValues());
                    }
                    map.put("typeCfgs", typeCfgsMap);
                }
                ctx.addNodeAttribute(IgniteNodeAttributes.ATTR_BINARY_CONFIGURATION, map);
            }
        }
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) BinaryType(org.apache.ignite.binary.BinaryType) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) BinaryMetadataHandler(org.apache.ignite.internal.binary.BinaryMetadataHandler) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryTypeConfiguration(org.apache.ignite.binary.BinaryTypeConfiguration) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) BinaryObject(org.apache.ignite.binary.BinaryObject) CacheObject(org.apache.ignite.internal.processors.cache.CacheObject) KeyCacheObject(org.apache.ignite.internal.processors.cache.KeyCacheObject)

Example 38 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class SharedFsCheckpointSpi method spiStart.

/**
 * {@inheritDoc}
 */
@Override
public void spiStart(String igniteInstanceName) throws IgniteSpiException {
    // Start SPI start stopwatch.
    startStopwatch();
    assertParameter(!F.isEmpty(dirPaths), "!F.isEmpty(dirPaths)");
    this.igniteInstanceName = igniteInstanceName;
    if (ignite.configuration().getMarshaller() instanceof BinaryMarshaller)
        marsh = MarshallerUtils.jdkMarshaller(ignite.name());
    else
        marsh = ignite.configuration().getMarshaller();
    folder = getNextSharedPath();
    if (folder == null)
        throw new IgniteSpiException("Failed to create checkpoint directory.");
    if (!folder.isDirectory())
        throw new IgniteSpiException("Checkpoint directory path is not a valid directory: " + curDirPath);
    registerMBean(igniteInstanceName, new SharedFsCheckpointSpiMBeanImpl(this), SharedFsCheckpointSpiMBean.class);
    // Ack parameters.
    if (log.isDebugEnabled()) {
        log.debug(configInfo("folder", folder));
        log.debug(configInfo("dirPaths", dirPaths));
    }
    try {
        host = U.getLocalHost().getHostName();
    } catch (IOException e) {
        throw new IgniteSpiException("Failed to get localhost address.", e);
    }
    // Ack ok start.
    if (log.isDebugEnabled())
        log.debug(startInfo());
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) IgniteSpiException(org.apache.ignite.spi.IgniteSpiException) IOException(java.io.IOException)

Example 39 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class CacheJdbcPojoStoreAbstractSelfTest method checkPutRemove.

/**
 * Check put in cache and store it in db.
 *
 * @throws Exception If failed.
 */
private void checkPutRemove() throws Exception {
    boolean binaryMarshaller = marshaller() instanceof BinaryMarshaller || marshaller() == null;
    IgniteCache<Object, Person> c1 = grid().cache(CACHE_NAME);
    Connection conn = getConnection();
    try {
        PreparedStatement stmt = conn.prepareStatement("SELECT ID, ORG_ID, BIRTHDAY, NAME, GENDER FROM PERSON WHERE ID = ?");
        stmt.setInt(1, -1);
        ResultSet rs = stmt.executeQuery();
        assertFalse("Unexpected non empty result set", rs.next());
        U.closeQuiet(rs);
        Date testDate = Date.valueOf("2001-05-05");
        Gender testGender = Gender.random();
        Person val = new Person(-1, -2, testDate, "Person-to-test-put-insert", 999, testGender);
        Object key = builtinKeys ? Integer.valueOf(-1) : new PersonKey(-1);
        // Test put-insert.
        c1.put(key, val);
        rs = stmt.executeQuery();
        assertTrue("Unexpected empty result set", rs.next());
        assertEquals(-1, rs.getInt(1));
        assertEquals(-2, rs.getInt(2));
        assertEquals(testDate, rs.getDate(3));
        assertEquals("Person-to-test-put-insert", rs.getString(4));
        assertEquals(testGender.toString(), binaryMarshaller ? Gender.values()[rs.getInt(5)].toString() : rs.getString(5));
        assertFalse("Unexpected more data in result set", rs.next());
        U.closeQuiet(rs);
        // Test put-update.
        testDate = Date.valueOf("2016-04-04");
        c1.put(key, new Person(-1, -3, testDate, "Person-to-test-put-update", 999, testGender));
        rs = stmt.executeQuery();
        assertTrue("Unexpected empty result set", rs.next());
        assertEquals(-1, rs.getInt(1));
        assertEquals(-3, rs.getInt(2));
        assertEquals(testDate, rs.getDate(3));
        assertEquals("Person-to-test-put-update", rs.getString(4));
        assertEquals(testGender.toString(), binaryMarshaller ? Gender.values()[rs.getInt(5)].toString() : rs.getString(5));
        assertFalse("Unexpected more data in result set", rs.next());
        // Test remove.
        c1.remove(key);
        rs = stmt.executeQuery();
        assertFalse("Unexpected non-empty result set", rs.next());
        U.closeQuiet(rs);
    } finally {
        U.closeQuiet(conn);
    }
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) PersonKey(org.apache.ignite.cache.store.jdbc.model.PersonKey) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) Gender(org.apache.ignite.cache.store.jdbc.model.Gender) Person(org.apache.ignite.cache.store.jdbc.model.Person) Date(java.sql.Date)

Example 40 with BinaryMarshaller

use of org.apache.ignite.internal.binary.BinaryMarshaller in project ignite by apache.

the class CacheJdbcPojoStoreTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    Connection conn = store.openConnection(false);
    Statement stmt = conn.createStatement();
    try {
        stmt.executeUpdate("delete from String_Entries");
    } catch (SQLException ignore) {
    // No-op.
    }
    try {
        stmt.executeUpdate("delete from UUID_Entries");
    } catch (SQLException ignore) {
    // No-op.
    }
    try {
        stmt.executeUpdate("delete from Organization");
    } catch (SQLException ignore) {
    // No-op.
    }
    try {
        stmt.executeUpdate("delete from Person");
    } catch (SQLException ignore) {
    // No-op.
    }
    try {
        stmt.executeUpdate("delete from Timestamp_Entries");
    } catch (SQLException ignore) {
    // No-op.
    }
    try {
        stmt.executeUpdate("delete from Binary_Entries");
    } catch (SQLException ignore) {
    // No-op.
    }
    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + "String_Entries (key varchar(100) not null, val varchar(100), PRIMARY KEY(key))");
    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + "UUID_Entries (key binary(16) not null, val binary(16), PRIMARY KEY(key))");
    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + "Binary_Entries (key binary(16) not null, val binary(16), PRIMARY KEY(key))");
    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + "Timestamp_Entries (key timestamp not null, val integer, PRIMARY KEY(key))");
    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + "Organization (id integer not null, name varchar(50), city varchar(50), PRIMARY KEY(id))");
    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + "Person (id integer not null, org_id integer, name varchar(50), PRIMARY KEY(id))");
    stmt.executeUpdate("CREATE TABLE IF NOT EXISTS " + "Person_Complex (id integer not null, org_id integer not null, city_id integer not null, " + "name varchar(50), salary integer, PRIMARY KEY(id, org_id, city_id))");
    conn.commit();
    U.closeQuiet(stmt);
    U.closeQuiet(conn);
    super.beforeTest();
    Ignite ig = U.field(store, "ignite");
    this.ig = ig;
    binaryEnable = ig.configuration().getMarshaller() instanceof BinaryMarshaller;
}
Also used : SQLException(java.sql.SQLException) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) Ignite(org.apache.ignite.Ignite)

Aggregations

BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)93 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)61 TcpDiscoverySpi (org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi)34 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)22 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)14 Ignite (org.apache.ignite.Ignite)9 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)9 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)9 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)8 ArrayList (java.util.ArrayList)7 BinaryObject (org.apache.ignite.binary.BinaryObject)7 Marshaller (org.apache.ignite.marshaller.Marshaller)7 IgniteException (org.apache.ignite.IgniteException)6 NullLogger (org.apache.ignite.logger.NullLogger)6 TcpDiscoveryVmIpFinder (org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder)6 HashMap (java.util.HashMap)5 CacheKeyConfiguration (org.apache.ignite.cache.CacheKeyConfiguration)5 MarshallerContextTestImpl (org.apache.ignite.marshaller.MarshallerContextTestImpl)5 NearCacheConfiguration (org.apache.ignite.configuration.NearCacheConfiguration)4 JdkMarshaller (org.apache.ignite.marshaller.jdk.JdkMarshaller)4