Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

ClassLoaderCodec Implementations

Ignite will come with 2 OSGI class loader codecs out of the box, pessimistic and optimistic, leaving users with opportunity to provide their own custom class loader codecs as well (potentially for non-OSGI environments).

In general in OSGi, the same package may be exported by multiple bundles and therefore an FQN may not be sufficient to look up the correct class loader. In such cases, the codec implementation must employ a pessimistic approach  approach and encode enough information (for example, the bundle symbolic name, plus the bundle version) for the deserializer to be able to resolve the FQN to the correct class loader. Such implementation will work for all use cases, but it introduces some overhead and increases the size of the serialized messages.

...

Code Block
public class ClassLoaderPessimisticCodec implements ClassLoaderCodec {
    public ClassLoaderPessimisticCodec() {}
 
    @Nullable public Object encodeClassLoader(Class<?> cls, ClassLoader clsLdr) throws IgniteException {
        // TODO
        return bundleName + bundleVersion;
    }

	public ClassLoader decodeClassLoader(String fqn, @Nullable Object encodedClsLdr) throws IgniteException {
        // TODO: get class loader for a bundle based on encoded information.
        ...
    }
}

 

Here's how the optimistic (opportunistic :)))) codec implementation might look like:

...