Search in sources :

Example 6 with BinaryContext

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

the class GridAbstractTest method createStandaloneBinaryMarshaller.

/**
     * Create instance of {@link BinaryMarshaller} suitable for use
     * without starting a grid upon given {@link IgniteConfiguration}.
     * @return Binary marshaller.
     * @throws IgniteCheckedException if failed.
     */
protected BinaryMarshaller createStandaloneBinaryMarshaller(IgniteConfiguration cfg) throws IgniteCheckedException {
    BinaryMarshaller marsh = new BinaryMarshaller();
    BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), cfg, new NullLogger());
    marsh.setContext(new MarshallerContextTestImpl());
    IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, cfg);
    return marsh;
}
Also used : NullLogger(org.apache.ignite.logger.NullLogger) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl)

Example 7 with BinaryContext

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

the class IgniteTestResources method getMarshaller.

/**
     * @return Marshaller.
     * @throws IgniteCheckedException If failed.
     */
@SuppressWarnings("unchecked")
public static synchronized Marshaller getMarshaller() throws IgniteCheckedException {
    String marshallerName = System.getProperty(MARSH_CLASS_NAME, GridTestProperties.getProperty(GridTestProperties.MARSH_CLASS_NAME));
    Marshaller marsh;
    if (marshallerName == null)
        marsh = new BinaryMarshaller();
    else {
        try {
            Class<? extends Marshaller> cls = (Class<? extends Marshaller>) Class.forName(marshallerName);
            marsh = cls.newInstance();
        } catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
            throw new IgniteCheckedException("Failed to create test marshaller [marshaller=" + marshallerName + ']', e);
        }
    }
    marsh.setContext(new MarshallerContextTestImpl());
    if (marsh instanceof BinaryMarshaller) {
        BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), new IgniteConfiguration(), new NullLogger());
        IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, new IgniteConfiguration());
    }
    return marsh;
}
Also used : BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) Marshaller(org.apache.ignite.marshaller.Marshaller) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryContext(org.apache.ignite.internal.binary.BinaryContext)

Example 8 with BinaryContext

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

the class PlatformContextImpl method processMetadata.

/** {@inheritDoc} */
@SuppressWarnings("ConstantConditions")
@Override
public void processMetadata(BinaryRawReaderEx reader) {
    Collection<BinaryMetadata> metas = PlatformUtils.readCollection(reader, new PlatformReaderClosure<BinaryMetadata>() {

        @Override
        public BinaryMetadata read(BinaryRawReaderEx reader) {
            int typeId = reader.readInt();
            String typeName = reader.readString();
            String affKey = reader.readString();
            Map<String, BinaryFieldMetadata> fields = PlatformUtils.readLinkedMap(reader, new PlatformReaderBiClosure<String, BinaryFieldMetadata>() {

                @Override
                public IgniteBiTuple<String, BinaryFieldMetadata> read(BinaryRawReaderEx reader) {
                    String name = reader.readString();
                    int typeId = reader.readInt();
                    int fieldId = reader.readInt();
                    return new IgniteBiTuple<String, BinaryFieldMetadata>(name, new BinaryFieldMetadata(typeId, fieldId));
                }
            });
            Map<String, Integer> enumMap = null;
            boolean isEnum = reader.readBoolean();
            if (isEnum) {
                int size = reader.readInt();
                enumMap = new LinkedHashMap<>(size);
                for (int idx = 0; idx < size; idx++) enumMap.put(reader.readString(), reader.readInt());
            }
            // Read schemas
            int schemaCnt = reader.readInt();
            List<BinarySchema> schemas = null;
            if (schemaCnt > 0) {
                schemas = new ArrayList<>(schemaCnt);
                for (int i = 0; i < schemaCnt; i++) {
                    int id = reader.readInt();
                    int fieldCnt = reader.readInt();
                    List<Integer> fieldIds = new ArrayList<>(fieldCnt);
                    for (int j = 0; j < fieldCnt; j++) fieldIds.add(reader.readInt());
                    schemas.add(new BinarySchema(id, fieldIds));
                }
            }
            return new BinaryMetadata(typeId, typeName, fields, affKey, schemas, isEnum, enumMap);
        }
    });
    BinaryContext binCtx = cacheObjProc.binaryContext();
    for (BinaryMetadata meta : metas) binCtx.updateMetadata(meta.typeId(), meta);
}
Also used : IgniteBiTuple(org.apache.ignite.lang.IgniteBiTuple) PlatformReaderBiClosure(org.apache.ignite.internal.processors.platform.utils.PlatformReaderBiClosure) ArrayList(java.util.ArrayList) BinaryRawReaderEx(org.apache.ignite.internal.binary.BinaryRawReaderEx) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) LinkedHashMap(java.util.LinkedHashMap) BinaryFieldMetadata(org.apache.ignite.internal.binary.BinaryFieldMetadata) BinarySchema(org.apache.ignite.internal.binary.BinarySchema) List(java.util.List) ArrayList(java.util.ArrayList) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap)

Example 9 with BinaryContext

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

the class GridCacheUtilsSelfTest method binaryMarshaller.

/**
     * @return Binary marshaller.
     * @throws IgniteCheckedException if failed.
     */
private BinaryMarshaller binaryMarshaller() throws IgniteCheckedException {
    IgniteConfiguration iCfg = new IgniteConfiguration();
    BinaryConfiguration bCfg = new BinaryConfiguration();
    iCfg.setBinaryConfiguration(bCfg);
    BinaryContext ctx = new BinaryContext(BinaryCachingMetadataHandler.create(), iCfg, new NullLogger());
    BinaryMarshaller marsh = new BinaryMarshaller();
    marsh.setContext(new MarshallerContextTestImpl(null));
    IgniteUtils.invoke(BinaryMarshaller.class, marsh, "setBinaryContext", ctx, iCfg);
    return marsh;
}
Also used : NullLogger(org.apache.ignite.logger.NullLogger) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) BinaryConfiguration(org.apache.ignite.configuration.BinaryConfiguration) BinaryMarshaller(org.apache.ignite.internal.binary.BinaryMarshaller) GridBinaryMarshaller(org.apache.ignite.internal.binary.GridBinaryMarshaller) BinaryContext(org.apache.ignite.internal.binary.BinaryContext) MarshallerContextTestImpl(org.apache.ignite.marshaller.MarshallerContextTestImpl)

Aggregations

BinaryContext (org.apache.ignite.internal.binary.BinaryContext)9 BinaryMarshaller (org.apache.ignite.internal.binary.BinaryMarshaller)7 NullLogger (org.apache.ignite.logger.NullLogger)6 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 MarshallerContextTestImpl (org.apache.ignite.marshaller.MarshallerContextTestImpl)5 GridBinaryMarshaller (org.apache.ignite.internal.binary.GridBinaryMarshaller)4 HashMap (java.util.HashMap)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 BinaryConfiguration (org.apache.ignite.configuration.BinaryConfiguration)2 BinaryMetadata (org.apache.ignite.internal.binary.BinaryMetadata)2 Marshaller (org.apache.ignite.marshaller.Marshaller)2 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)1 IgniteException (org.apache.ignite.IgniteException)1 BinaryObject (org.apache.ignite.binary.BinaryObject)1 BinaryType (org.apache.ignite.binary.BinaryType)1 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)1