Ce contenu n'est pas disponible dans la langue sélectionnée.
6.3. Using an Advanced Externalizer
- Define and implement the
readObject()
andwriteObject()
methods. - Link externalizers with marshaller classes.
- Register the advanced externalizer.
6.3.1. Implement the Methods Copier lienLien copié sur presse-papiers!
readObject()
and writeObject()
methods. The following is a sample definition:
Example 6.2. Define and Implement the Methods
Note
6.3.2. Link Externalizers with Marshaller Classes Copier lienLien copié sur presse-papiers!
getTypeClasses()
to discover the classes that this externalizer can marshall and to link the readObject()
and writeObject()
classes.
ReplicableCommandExternalizer
indicates that it can externalize several command types. This sample marshalls all commands that extend the ReplicableCommand
interface but the framework only supports class equality comparison so it is not possible to indicate that the classes marshalled are all children of a particular class or interface.
@Override public Set<Class<? extends List>> getTypeClasses() { return Util.<Class<? extends List>>asSet( Util.<List>loadClass("java.util.Collections$SingletonList", null)); }
@Override
public Set<Class<? extends List>> getTypeClasses() {
return Util.<Class<? extends List>>asSet(
Util.<List>loadClass("java.util.Collections$SingletonList", null));
}
6.3.3. Register the Advanced Externalizer (Declaratively) Copier lienLien copié sur presse-papiers!
Procedure 6.1. Register the Advanced Externalizer
- Add the
global
element to theinfinispan
element:<infinispan> <global /> </infinispan>
<infinispan> <global /> </infinispan>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Add the
serialization
element to theglobal
element as follows:<infinispan> <global> <serialization /> </global> </infinispan>
<infinispan> <global> <serialization /> </global> </infinispan>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Add the
advancedExternalizers
element to add information about the new advanced externalizer as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow - Define the externalizer class using the
externalizerClass
attribute as follows:Copy to Clipboard Copied! Toggle word wrap Toggle overflow Replace the $IdViaAnnotationObj and $AdvancedExternalizer values as required.
6.3.4. Register the Advanced Externalizer (Programmatically) Copier lienLien copié sur presse-papiers!
Example 6.3. Registering the Advanced Externalizer Programmatically
GlobalConfigurationBuilder builder = ... builder.serialization() .addAdvancedExternalizer(new Person.PersonExternalizer());
GlobalConfigurationBuilder builder = ...
builder.serialization()
.addAdvancedExternalizer(new Person.PersonExternalizer());
6.3.5. Register Multiple Externalizers Copier lienLien copié sur presse-papiers!
GlobalConfiguration.addExternalizer()
accepts varargs
. Before registering the new externalizers, ensure that their IDs are already defined using the @Marshalls
annotation.
Example 6.4. Registering Multiple Externalizers
builder.serialization() .addAdvancedExternalizer(new Person.PersonExternalizer(), new Address.AddressExternalizer());
builder.serialization()
.addAdvancedExternalizer(new Person.PersonExternalizer(),
new Address.AddressExternalizer());