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);
}
}
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;
}
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"));
}
}
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;
}
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 + "]")));
}
Aggregations