Search in sources :

Example 6 with CacheObjectBinaryProcessorImpl

use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testOffheapBinary.

/**
 * @throws Exception If failed.
 */
public void testOffheapBinary() throws Exception {
    BinaryObjectBuilder builder = builder("Class");
    builder.setField("i", 111);
    builder.setField("f", 111.111f);
    builder.setField("iArr", new int[] { 1, 2, 3 });
    builder.setField("obj", new Key(1));
    builder.setField("col", Arrays.asList(new Value(1), new Value(2)), Collection.class);
    BinaryObject po = builder.build();
    byte[] arr = ((CacheObjectBinaryProcessorImpl) (grid(0)).context().cacheObjects()).marshal(po);
    long ptr = GridUnsafe.allocateMemory(arr.length + 5);
    try {
        long ptr0 = ptr;
        GridUnsafe.putBoolean(null, ptr0++, false);
        int len = arr.length;
        if (BIG_ENDIAN)
            GridUnsafe.putIntLE(ptr0, len);
        else
            GridUnsafe.putInt(ptr0, len);
        GridUnsafe.copyHeapOffheap(arr, GridUnsafe.BYTE_ARR_OFF, ptr0 + 4, arr.length);
        BinaryObject offheapObj = (BinaryObject) ((CacheObjectBinaryProcessorImpl) (grid(0)).context().cacheObjects()).unmarshal(ptr, false);
        assertEquals(BinaryObjectOffheapImpl.class, offheapObj.getClass());
        assertEquals(expectedHashCode("Class"), offheapObj.type().typeId());
        assertEquals(BinaryArrayIdentityResolver.instance().hashCode(po), offheapObj.hashCode());
        assertEquals(111, offheapObj.<Integer>field("i").intValue());
        assertEquals(111.111f, offheapObj.<Float>field("f").floatValue(), 0);
        assertTrue(Arrays.equals(new int[] { 1, 2, 3 }, offheapObj.<int[]>field("iArr")));
        assertEquals(1, offheapObj.<BinaryObject>field("obj").<Key>deserialize().i);
        List<BinaryObject> list = offheapObj.field("col");
        assertEquals(2, list.size());
        assertEquals(1, list.get(0).<Value>deserialize().i);
        assertEquals(2, list.get(1).<Value>deserialize().i);
        assertEquals(po, offheapObj);
        assertEquals(offheapObj, po);
    } finally {
        GridUnsafe.freeMemory(ptr);
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder)

Example 7 with CacheObjectBinaryProcessorImpl

use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.

the class BinaryObjectBuilderDefaultMappersSelfTest method testSetBinaryObject.

/**
 */
public void testSetBinaryObject() {
    // Prepare marshaller context.
    CacheObjectBinaryProcessorImpl proc = ((CacheObjectBinaryProcessorImpl) (grid(0)).context().cacheObjects());
    proc.marshal(new GridBinaryTestClasses.TestObjectContainer());
    proc.marshal(new GridBinaryTestClasses.TestObjectAllTypes());
    // Actual test.
    BinaryObject binaryObj = builder(GridBinaryTestClasses.TestObjectContainer.class.getName()).setField("foo", toBinary(new GridBinaryTestClasses.TestObjectAllTypes())).build();
    assertTrue(binaryObj.<GridBinaryTestClasses.TestObjectContainer>deserialize().foo instanceof GridBinaryTestClasses.TestObjectAllTypes);
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)

Example 8 with CacheObjectBinaryProcessorImpl

use of org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl in project ignite by apache.

the class ClientBinaryTypePutRequest method process.

/**
 * {@inheritDoc}
 */
@SuppressWarnings("unchecked")
@Override
public ClientResponse process(ClientConnectionContext ctx) {
    BinaryContext binCtx = ((CacheObjectBinaryProcessorImpl) ctx.kernalContext().cacheObjects()).binaryContext();
    binCtx.updateMetadata(meta.typeId(), meta);
    return super.process(ctx);
}
Also used : CacheObjectBinaryProcessorImpl(org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl) BinaryContext(org.apache.ignite.internal.binary.BinaryContext)

Aggregations

CacheObjectBinaryProcessorImpl (org.apache.ignite.internal.processors.cache.binary.CacheObjectBinaryProcessorImpl)8 BinaryObject (org.apache.ignite.binary.BinaryObject)3 BinaryContext (org.apache.ignite.internal.binary.BinaryContext)2 IgniteCacheObjectProcessor (org.apache.ignite.internal.processors.cacheobject.IgniteCacheObjectProcessor)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteIllegalStateException (org.apache.ignite.IgniteIllegalStateException)1 IGNITE_REST_START_ON_CLIENT (org.apache.ignite.IgniteSystemProperties.IGNITE_REST_START_ON_CLIENT)1 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 IgniteKernal (org.apache.ignite.internal.IgniteKernal)1 ATTR_JMX_PORT (org.apache.ignite.internal.IgniteNodeAttributes.ATTR_JMX_PORT)1 ATTR_LATE_AFFINITY_ASSIGNMENT (org.apache.ignite.internal.IgniteNodeAttributes.ATTR_LATE_AFFINITY_ASSIGNMENT)1 COPYRIGHT (org.apache.ignite.internal.IgniteVersionUtils.COPYRIGHT)1 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)1 GridBinaryTestClasses (org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses)1 GridClusterStateProcessor (org.apache.ignite.internal.processors.cluster.GridClusterStateProcessor)1 IGridClusterStateProcessor (org.apache.ignite.internal.processors.cluster.IGridClusterStateProcessor)1 OsDiscoveryNodeValidationProcessor (org.apache.ignite.internal.processors.nodevalidation.OsDiscoveryNodeValidationProcessor)1 PlatformNoopProcessor (org.apache.ignite.internal.processors.platform.PlatformNoopProcessor)1 LT (org.apache.ignite.internal.util.typedef.internal.LT)1