use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class CacheObjectBinaryProcessorImpl method buildEnum.
/**
* {@inheritDoc}
*/
@Override
public BinaryObject buildEnum(String typeName, String name) throws BinaryObjectException {
A.notNullOrEmpty(typeName, "enum type name");
A.notNullOrEmpty(name, "enum name");
int typeId = binaryCtx.typeId(typeName);
BinaryMetadata metadata = metadata0(typeId);
if (metadata == null)
throw new BinaryObjectException("Failed to get metadata for type [typeId=" + typeId + ", typeName='" + typeName + "']");
Integer ordinal = metadata.getEnumOrdinalByName(name);
typeName = binaryCtx.userTypeName(typeName);
if (ordinal == null)
throw new BinaryObjectException("Failed to resolve enum ordinal by name [typeId=" + typeId + ", typeName='" + typeName + "', name='" + name + "']");
return new BinaryEnumObjectImpl(binaryCtx, typeId, null, ordinal);
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class CacheObjectBinaryProcessorImpl method updateMetadata.
/**
* {@inheritDoc}
*/
@Override
public void updateMetadata(File metadataDir, BooleanSupplier stopChecker) throws IgniteCheckedException {
if (!metadataDir.exists())
return;
try {
ConcurrentMap<Integer, BinaryMetadataHolder> metaCache = new ConcurrentHashMap<>();
new BinaryMetadataFileStore(metaCache, ctx, log, metadataDir).restoreMetadata();
Collection<BinaryMetadata> metadata = F.viewReadOnly(metaCache.values(), BinaryMetadataHolder::metadata);
// Check the compatibility of the binary metadata.
for (BinaryMetadata newMeta : metadata) {
BinaryMetadata oldMeta = binaryMetadata(newMeta.typeId());
if (oldMeta != null)
BinaryUtils.mergeMetadata(oldMeta, newMeta, null);
}
// Update cluster metadata.
for (BinaryMetadata newMeta : metadata) {
if (stopChecker.getAsBoolean())
return;
if (Thread.interrupted())
throw new IgniteInterruptedCheckedException("Thread has been interrupted.");
addMeta(newMeta.typeId(), newMeta.wrap(binaryContext()), false);
}
} catch (BinaryObjectException e) {
throw new IgniteCheckedException(e);
}
}
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, boolean failIfUnregistered) throws BinaryObjectException {
assert newMeta != null;
assert newMeta instanceof BinaryTypeImpl;
BinaryMetadata newMeta0 = ((BinaryTypeImpl) newMeta).metadata();
if (failIfUnregistered) {
failIfUnregistered(typeId, newMeta0);
return;
}
try {
GridFutureAdapter<MetadataUpdateResult> fut = transport.requestMetadataUpdate(newMeta0);
if (fut == null) {
if (log.isDebugEnabled()) {
log.debug("Metadata update was skipped [typeId=" + typeId + ", typeName=" + newMeta.typeName() + ']');
}
return;
}
long t0 = System.nanoTime();
MetadataUpdateResult res = fut.get();
if (log.isDebugEnabled()) {
IgniteInternalTx tx = ctx.cache().context().tm().tx();
log.debug("Completed metadata update [typeId=" + typeId + ", typeName=" + newMeta.typeName() + ", waitTime=" + MILLISECONDS.convert(System.nanoTime() - t0, NANOSECONDS) + "ms" + ", fut=" + fut + ", tx=" + CU.txString(tx) + ']');
}
assert res != null;
if (res.rejected())
throw res.error();
else if (!ctx.clientNode())
metadataFileStore.waitForWriteCompletion(typeId, res.typeVersion());
} catch (IgniteCheckedException e) {
IgniteCheckedException ex = e;
if (ctx.isStopping()) {
ex = new NodeStoppingException("Node is stopping.");
ex.addSuppressed(e);
}
throw new BinaryObjectException("Failed to update metadata for type: " + newMeta.typeName(), ex);
}
}
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 + "]")));
}
use of org.apache.ignite.binary.BinaryObjectException in project ignite by apache.
the class BinaryConfigurationConsistencySelfTest method customConfig.
/**
* @return Custom BinaryConfiguration.
* @param compactFooter Compact footer.
*/
private BinaryConfiguration customConfig(boolean compactFooter) {
BinaryConfiguration c = new BinaryConfiguration();
c.setIdMapper(new BinaryBasicIdMapper(true));
c.setSerializer(new BinarySerializer() {
@Override
public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
// No-op.
}
@Override
public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
// No-op.
}
});
c.setCompactFooter(compactFooter);
BinaryTypeConfiguration btc = new BinaryTypeConfiguration("org.MyClass");
btc.setIdMapper(BinaryContext.defaultIdMapper());
btc.setEnum(false);
btc.setSerializer(new BinarySerializer() {
@Override
public void writeBinary(Object obj, BinaryWriter writer) throws BinaryObjectException {
// No-op.
}
@Override
public void readBinary(Object obj, BinaryReader reader) throws BinaryObjectException {
// No-op.
}
});
c.setTypeConfigurations(Arrays.asList(btc));
return c;
}
Aggregations