Search in sources :

Example 11 with BinaryObjectException

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

the class CacheObjectBinaryProcessorImpl method addMeta.

/** {@inheritDoc} */
@Override
public void addMeta(final int typeId, final BinaryType newMeta) throws BinaryObjectException {
    assert newMeta != null;
    assert newMeta instanceof BinaryTypeImpl;
    BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
    try {
        BinaryMetadataHolder metaHolder = metadataLocCache.get(typeId);
        BinaryMetadata oldMeta = metaHolder != null ? metaHolder.metadata() : null;
        BinaryMetadata mergedMeta = BinaryUtils.mergeMetadata(oldMeta, newMeta0);
        MetadataUpdateResult res = transport.requestMetadataUpdate(mergedMeta).get();
        assert res != null;
        if (res.rejected())
            throw res.error();
    } catch (IgniteCheckedException e) {
        throw new BinaryObjectException("Failed to update meta data for type: " + newMeta.typeName(), e);
    }
}
Also used : BinaryTypeImpl(org.apache.ignite.internal.binary.BinaryTypeImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryMetadata(org.apache.ignite.internal.binary.BinaryMetadata) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 12 with BinaryObjectException

use of org.apache.ignite.binary.BinaryObjectException 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)

Example 13 with BinaryObjectException

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

the class BinaryObjectBuilderAdditionalSelfTest method testWrongMetadataNullField2.

/**
     *
     */
public void testWrongMetadataNullField2() {
    BinaryObjectBuilder builder = binaries().builder("SomeType1");
    builder.setField("dateField", null);
    builder.setField("objectField", null, Integer.class);
    BinaryObject obj = builder.build();
    try {
        builder = binaries().builder(obj);
        builder.setField("dateField", new Date());
        builder.build();
    } catch (BinaryObjectException ex) {
        assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
    }
    builder = binaries().builder(obj);
    try {
        builder.setField("objectField", new GridBinaryTestClasses.Company());
        builder.build();
        fail("BinaryObjectBuilder accepted wrong metadata");
    } catch (BinaryObjectException ex) {
        assertTrue(ex.getMessage().startsWith("Wrong value has been set"));
    }
}
Also used : BinaryObject(org.apache.ignite.binary.BinaryObject) BinaryObjectBuilder(org.apache.ignite.binary.BinaryObjectBuilder) GridBinaryTestClasses(org.apache.ignite.internal.binary.mutabletest.GridBinaryTestClasses) Date(java.util.Date) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 14 with BinaryObjectException

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

the class CacheObjectBinaryProcessorImpl method affinityKey.

/**
     * @param po Binary object.
     * @return Affinity key.
     */
public Object affinityKey(BinaryObject po) {
    // Fast path for already cached field.
    if (po instanceof BinaryObjectEx) {
        int typeId = ((BinaryObjectEx) po).typeId();
        T1<BinaryField> fieldHolder = affKeyFields.get(typeId);
        if (fieldHolder != null) {
            BinaryField field = fieldHolder.get();
            return field != null ? field.value(po) : po;
        }
    }
    // Slow path if affinity field is not cached yet.
    try {
        BinaryType meta = po instanceof BinaryObjectEx ? ((BinaryObjectEx) po).rawType() : po.type();
        if (meta != null) {
            String name = meta.affinityKeyFieldName();
            if (name != null) {
                BinaryField field = meta.field(name);
                affKeyFields.putIfAbsent(meta.typeId(), new T1<>(field));
                return field.value(po);
            } else
                affKeyFields.putIfAbsent(meta.typeId(), new T1<BinaryField>(null));
        } else if (po instanceof BinaryObjectEx) {
            int typeId = ((BinaryObjectEx) po).typeId();
            String name = binaryCtx.affinityKeyFieldName(typeId);
            if (name != null)
                return po.field(name);
        }
    } catch (BinaryObjectException e) {
        U.error(log, "Failed to get affinity field from binary object: " + po, e);
    }
    return po;
}
Also used : BinaryField(org.apache.ignite.binary.BinaryField) BinaryType(org.apache.ignite.binary.BinaryType) BinaryObjectEx(org.apache.ignite.internal.binary.BinaryObjectEx) T1(org.apache.ignite.internal.util.typedef.T1) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 15 with BinaryObjectException

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

the class ClientMetadataRequestFuture method requestMetadata.

/** */
void requestMetadata() {
    boolean noSrvsInCluster;
    synchronized (this) {
        while (!aliveSrvNodes.isEmpty()) {
            ClusterNode srvNode = aliveSrvNodes.poll();
            try {
                if (log.isDebugEnabled())
                    log.debug("Requesting metadata for typeId " + typeId + " from node " + srvNode.id());
                ioMgr.sendToGridTopic(srvNode, GridTopic.TOPIC_METADATA_REQ, new MetadataRequestMessage(typeId), GridIoPolicy.SYSTEM_POOL);
                if (discoMgr.node(srvNode.id()) == null)
                    continue;
                pendingNode = srvNode;
                break;
            } catch (IgniteCheckedException ignored) {
                U.warn(log, "Failed to request marshaller mapping from remote node (proceeding with the next one): " + srvNode);
            }
        }
        noSrvsInCluster = pendingNode == null;
    }
    if (noSrvsInCluster)
        onDone(MetadataUpdateResult.createFailureResult(new BinaryObjectException("All server nodes have left grid, cannot request metadata [typeId: " + typeId + "]")));
}
Also used : ClusterNode(org.apache.ignite.cluster.ClusterNode) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Aggregations

BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)42 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)9 BinaryObject (org.apache.ignite.binary.BinaryObject)8 Date (java.util.Date)4 HashMap (java.util.HashMap)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 TreeMap (java.util.TreeMap)4 BinarySerializer (org.apache.ignite.binary.BinarySerializer)4 BinaryType (org.apache.ignite.binary.BinaryType)4 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 BigInteger (java.math.BigInteger)2 Time (java.sql.Time)2 Timestamp (java.sql.Timestamp)2 ConcurrentMap (java.util.concurrent.ConcurrentMap)2 BinaryBasicIdMapper (org.apache.ignite.binary.BinaryBasicIdMapper)2 BinaryInvalidTypeException (org.apache.ignite.binary.BinaryInvalidTypeException)2 BinaryObjectBuilder (org.apache.ignite.binary.BinaryObjectBuilder)2 BinaryTypeConfiguration (org.apache.ignite.binary.BinaryTypeConfiguration)2 BinaryEnumObjectImpl (org.apache.ignite.internal.binary.BinaryEnumObjectImpl)2