Class BinaryContext
- java.lang.Object
-
- org.apache.ignite.internal.binary.BinaryContext
-
- Direct Known Subclasses:
CacheObjectBinaryProcessorImpl.TestBinaryContext
public class BinaryContext extends Object
Binary context.
-
-
Constructor Summary
Constructors Constructor Description BinaryContext(BinaryMetadataHandler metaHnd, IgniteConfiguration igniteCfg, IgniteLogger log)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static StringaffinityFieldName(Class cls)StringaffinityKeyFieldName(int typeId)Get affinity key field name for type.bytecollectionType(Class<? extends Collection> cls)IgniteConfigurationconfiguration()voidconfigure(BinaryMarshaller marsh)voidconfigure(BinaryMarshaller marsh, BinaryConfiguration binaryCfg)BinaryFieldImplcreateField(int typeId, String fieldName)Create binary field.static BinaryIdMapperdefaultIdMapper()static BinaryInternalMapperdefaultMapper()static BinaryNameMapperdefaultNameMapper()@NotNull BinaryClassDescriptordescriptorForClass(Class<?> cls)BinaryClassDescriptordescriptorForTypeId(boolean userType, int typeId, ClassLoader ldr, boolean registerMeta)intfieldId(int typeId, String fieldName)BinaryIdentityResolveridentity(int typeId)booleanisCompactFooter()IgniteLoggerlog()bytemapType(Class<? extends Map> cls)BinaryMarshallermarshaller()Collection<BinaryType>metadata()@Nullable BinaryTypemetadata(int typeId)BinaryTypemetadata(int typeId, int schemaId)@Nullable BinaryMetadatametadata0(int typeId)booleanmustDeserialize(Class cls)Check whether class must be deserialized anyway.voidonUndeploy(ClassLoader ldr)Undeployment callback invoked when class loader is being undeployed.@NotNull BinaryClassDescriptorregisterClass(Class<?> cls, boolean registerMeta, boolean failIfUnregistered)Attempts registration of the provided class.@NotNull BinaryClassDescriptorregisterClass(Class<?> cls, boolean registerMeta, boolean failIfUnregistered, boolean onlyLocReg)voidregisterClassLocally(BinaryType binaryType, boolean failIfUnregistered, byte platformId)Registers binary type locally.@NotNull BinaryClassDescriptorregisterDescriptor(BinaryClassDescriptor desc, boolean registerMeta, boolean onlyLocReg)Attempts registration of the providedBinaryClassDescriptorin the cluster.BinaryClassDescriptorregisterPredefinedType(Class<?> cls, int id)BinaryClassDescriptorregisterPredefinedType(Class<?> cls, int id, String affFieldName, boolean registered)booleanregisterUserClassName(int typeId, String clsName, boolean failIfUnregistered, boolean onlyLocReg, byte platformId)Register "type ID to class name" mapping on all nodes to allow for mapping requests resolution form client.voidregisterUserType(String clsName, BinaryInternalMapper mapper, @Nullable BinarySerializer serializer, @Nullable BinaryIdentityResolver identity, @Nullable String affKeyFieldName, boolean isEnum, @Nullable Map<String,Integer> enumMap)voidregisterUserTypesSchema()Register user types schemas.voidremoveType(int typeId)BinarySchemaRegistryschemaRegistry(int typeId)Get schema registry for type ID.inttypeId(String typeName)voidunregisterBinarySchemas()Unregister all binary schemas.voidunregisterUserTypeDescriptors()Unregisters the user types descriptors.voidupdateMetadata(int typeId, BinaryMetadata meta, boolean failIfUnregistered)StringuserTypeName(String clsName)
-
-
-
Constructor Detail
-
BinaryContext
public BinaryContext(BinaryMetadataHandler metaHnd, IgniteConfiguration igniteCfg, IgniteLogger log)
- Parameters:
metaHnd- Meta data handler.igniteCfg- Ignite configuration.log- Logger.
-
-
Method Detail
-
log
public IgniteLogger log()
- Returns:
- Logger.
-
marshaller
public BinaryMarshaller marshaller()
- Returns:
- Marshaller.
-
mustDeserialize
public boolean mustDeserialize(Class cls)
Check whether class must be deserialized anyway.- Parameters:
cls- Class.- Returns:
Trueif must be deserialized.
-
configuration
public IgniteConfiguration configuration()
- Returns:
- Ignite configuration.
-
configure
public void configure(BinaryMarshaller marsh) throws BinaryObjectException
- Parameters:
marsh- Binary marshaller.- Throws:
BinaryObjectException- In case of error.
-
configure
public void configure(BinaryMarshaller marsh, BinaryConfiguration binaryCfg) throws BinaryObjectException
- Parameters:
marsh- Binary marshaller.binaryCfg- Binary configuration.- Throws:
BinaryObjectException- In case of error.
-
defaultMapper
public static BinaryInternalMapper defaultMapper()
- Returns:
- Internal mapper used as default.
-
defaultIdMapper
public static BinaryIdMapper defaultIdMapper()
- Returns:
- ID mapper used as default.
-
defaultNameMapper
public static BinaryNameMapper defaultNameMapper()
- Returns:
- Name mapper used as default.
-
registerClass
@NotNull public @NotNull BinaryClassDescriptor registerClass(Class<?> cls, boolean registerMeta, boolean failIfUnregistered) throws BinaryObjectException
Attempts registration of the provided class. If the type is already registered, then an existing descriptor is returned.- Parameters:
cls- Class to register.registerMeta- Iftrue, then metadata will be registered along with the class descriptor.failIfUnregistered- Throw exception if class isn't registered.- Returns:
- Class descriptor.
- Throws:
BinaryObjectException- In case of error.
-
registerClass
@NotNull public @NotNull BinaryClassDescriptor registerClass(Class<?> cls, boolean registerMeta, boolean failIfUnregistered, boolean onlyLocReg) throws BinaryObjectException
- Parameters:
cls- Class.failIfUnregistered- Throw exception if class isn't registered.registerMeta- Iftrue, then metadata will be registered along with the class descriptor.onlyLocReg-trueif descriptor need to register only locally when registration is required at all.- Returns:
- Class descriptor.
- Throws:
BinaryObjectException- In case of error.
-
registerClassLocally
public void registerClassLocally(BinaryType binaryType, boolean failIfUnregistered, byte platformId)
Registers binary type locally.- Parameters:
binaryType- Binary type to register.failIfUnregistered- Whether to fail when not registered.platformId- Platform ID (seeMarshallerPlatformIds).
-
descriptorForClass
@NotNull public @NotNull BinaryClassDescriptor descriptorForClass(Class<?> cls)
- Parameters:
cls- Class.- Returns:
- A descriptor for the given class. If the class hasn't been registered yet, then a new descriptor will be
created, but its
BinaryClassDescriptor.registered()will befalse.
-
descriptorForTypeId
public BinaryClassDescriptor descriptorForTypeId(boolean userType, int typeId, ClassLoader ldr, boolean registerMeta)
- Parameters:
userType- User type or not.typeId- Type ID.ldr- Class loader.registerMeta- Iftrue, then metadata will be registered along with the type descriptor.- Returns:
- Class descriptor.
-
registerDescriptor
@NotNull public @NotNull BinaryClassDescriptor registerDescriptor(BinaryClassDescriptor desc, boolean registerMeta, boolean onlyLocReg)
Attempts registration of the providedBinaryClassDescriptorin the cluster.- Parameters:
desc- Class descriptor to register.registerMeta- Iftrue, then metadata will be registered along with the class descriptor.onlyLocReg-trueif descriptor need to register only locally when registration is required at all.- Returns:
- Registered class descriptor.
-
collectionType
public byte collectionType(Class<? extends Collection> cls)
- Parameters:
cls- Collection class.- Returns:
- Collection type ID.
-
mapType
public byte mapType(Class<? extends Map> cls)
- Parameters:
cls- Map class.- Returns:
- Map type ID.
-
typeId
public int typeId(String typeName)
- Parameters:
typeName- Type name.- Returns:
- Type ID.
-
fieldId
public int fieldId(int typeId, String fieldName)- Parameters:
typeId- Type ID.fieldName- Field name.- Returns:
- Field ID.
-
userTypeName
public String userTypeName(String clsName)
- Parameters:
clsName- Class name.- Returns:
- Type name.
-
affinityFieldName
public static String affinityFieldName(Class cls)
- Parameters:
cls- Class to get affinity field for.- Returns:
- Affinity field name or
nullif field name was not found.
-
registerPredefinedType
public BinaryClassDescriptor registerPredefinedType(Class<?> cls, int id)
- Parameters:
cls- Class.id- Type ID.- Returns:
- GridBinaryClassDescriptor.
-
registerPredefinedType
public BinaryClassDescriptor registerPredefinedType(Class<?> cls, int id, String affFieldName, boolean registered)
- Parameters:
cls- Class.id- Type ID.affFieldName- Affinity field name.- Returns:
- GridBinaryClassDescriptor.
-
registerUserType
public void registerUserType(String clsName, BinaryInternalMapper mapper, @Nullable @Nullable BinarySerializer serializer, @Nullable @Nullable BinaryIdentityResolver identity, @Nullable @Nullable String affKeyFieldName, boolean isEnum, @Nullable @Nullable Map<String,Integer> enumMap) throws BinaryObjectException
- Parameters:
clsName- Class name.mapper- ID mapper.serializer- Serializer.identity- Type identity.affKeyFieldName- Affinity key field name.isEnum- If enum.enumMap- Enum name to ordinal mapping.- Throws:
BinaryObjectException- In case of error.
-
registerUserTypesSchema
public void registerUserTypesSchema()
Register user types schemas.
-
registerUserClassName
public boolean registerUserClassName(int typeId, String clsName, boolean failIfUnregistered, boolean onlyLocReg, byte platformId)Register "type ID to class name" mapping on all nodes to allow for mapping requests resolution form client. OtherBinaryContext's "register" methods and methodregisterClass(Class, boolean, boolean)already call this functionality so use this method only when registering class names whoseClassis unknown.- Parameters:
typeId- Type ID.clsName- Class Name.failIfUnregistered- Iftruethen throwUnregisteredBinaryTypeExceptionwithMappingExchangeResultfuture instead of synchronously awaiting for its completion.onlyLocReg- Whether to register only on the current node.platformId- Platform ID (seeMarshallerPlatformIds).- Returns:
Trueif the mapping was registered successfully.
-
createField
public BinaryFieldImpl createField(int typeId, String fieldName)
Create binary field.- Parameters:
typeId- Type ID.fieldName- Field name.- Returns:
- Binary field.
-
metadata
@Nullable public @Nullable BinaryType metadata(int typeId) throws BinaryObjectException
- Parameters:
typeId- Type ID.- Returns:
- Meta data.
- Throws:
BinaryObjectException- In case of error.
-
metadata0
@Nullable public @Nullable BinaryMetadata metadata0(int typeId) throws BinaryObjectException
- Parameters:
typeId- Type ID- Returns:
- Meta data.
- Throws:
BinaryObjectException- In case of error.
-
metadata
public Collection<BinaryType> metadata() throws BinaryObjectException
- Returns:
- All metadata known to this node.
- Throws:
BinaryObjectException
-
metadata
public BinaryType metadata(int typeId, int schemaId) throws BinaryObjectException
- Parameters:
typeId- Type ID.schemaId- Schema ID.- Returns:
- Meta data.
- Throws:
BinaryObjectException- In case of error.
-
affinityKeyFieldName
public String affinityKeyFieldName(int typeId)
Get affinity key field name for type. First consult to predefined configuration, then delegate to metadata.- Parameters:
typeId- Type ID.- Returns:
- Affinity key field name.
-
identity
public BinaryIdentityResolver identity(int typeId)
- Parameters:
typeId- Type ID.- Returns:
- Type identity.
-
updateMetadata
public void updateMetadata(int typeId, BinaryMetadata meta, boolean failIfUnregistered) throws BinaryObjectException- Parameters:
typeId- Type ID.meta- Meta data.failIfUnregistered- Fail if unregistered.- Throws:
BinaryObjectException- In case of error.
-
isCompactFooter
public boolean isCompactFooter()
- Returns:
- Whether field IDs should be skipped in footer or not.
-
schemaRegistry
public BinarySchemaRegistry schemaRegistry(int typeId)
Get schema registry for type ID.- Parameters:
typeId- Type ID.- Returns:
- Schema registry for type ID.
-
unregisterBinarySchemas
public void unregisterBinarySchemas()
Unregister all binary schemas.
-
unregisterUserTypeDescriptors
public void unregisterUserTypeDescriptors()
Unregisters the user types descriptors.
-
onUndeploy
public void onUndeploy(ClassLoader ldr)
Undeployment callback invoked when class loader is being undeployed. Some marshallers may want to clean their internal state that uses the undeployed class loader somehow.- Parameters:
ldr- Class loader being undeployed.
-
removeType
public void removeType(int typeId)
- Parameters:
typeId- Type ID.
-
-