[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [ecf-dev] Issue adding custom serialization to ecf provider
|
Hi Peter,
On 4/28/2017 5:06 AM, Peter Hermsdorf wrote:
hi all,
i'm currently trying to implement custom serialization for the ecf
generic remote service provider using the kryo library.
A problem occurs with deserializing instances of
org.eclipse.ecf.remoteservice.RemoteServiceRegistrationImpl.Properties.
Thats an inner class derived from java.util.Hastable. There occurs a
NullPointer Exception when Kryo tries to add Elements to this Map
(Hastable.class around Line 465).
The Reason: the field table of Hashtable does not get initialized.
Initialization is done in the constructor. But because the derived
Properties class hides the no-arg constructor of hastable the
deserialization framework creates an instance of the class Properties
"magically", but of course without calling the no-op Constructor of
hastable. So the member table is null and leads to that problem.
Hmm. Would adding a no-arg constructor to
RemoteServiceRegistrationImpl.Properties help? That could be done
pretty easily, but I'm not sure if that will work with Kryo's
deserialization behavior.
i.e. something like:
protected Properties() {
super();
}
Of course this is in the first step a problem with the
non-java-default serialization,
I thought it was required/expected that the superclass null/empty
constructor would always be called if subclass null constructor is
called (serialization or otherwise). Otherwise, I don't think
superclasses can ever guarantee proper initialization.
but it's an more or less obvious issue for a DTO Object...
Has anyone experienced this problem or has any ideas on how to
workaround this?
Any ideas, comments or suggestions are more than welcome!
My Setup:
I registered custom IHostContainerSelector and
IConsumerContainerSelector where i'm registering a custom serializer
~like this:
@Override
protected IRemoteServiceContainer createContainer(final
ContainerTypeDescription containerTypeDescription,
final String containerTypeDescriptionName,
@SuppressWarnings("rawtypes") final Map properties)
throws SelectContainerException {
final IRemoteServiceContainer serviceContainer =
super.createContainer(containerTypeDescription,
containerTypeDescriptionName, properties);
final ISharedObjectContainer container =
(ISharedObjectContainer) serviceContainer.getContainer();
container.setSharedObjectMessageSerializer(new
KryoSharedMessageSerializer());
...
The MessageSerializer:
public class KryoSharedMessageSerializer implements
ISharedObjectMessageSerializer {
Kryo kryo = new Kryo();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
public KryoSharedMessageSerializer() {
kryo.setInstantiatorStrategy(new
Kryo.DefaultInstantiatorStrategy(new StdInstantiatorStrategy()));
kryo.setClassLoader(this.getClass().getClassLoader());
}
@Override
public byte[] serializeMessage(final ID sharedObjectID, final
Object message) throws IOException {
baos.reset();
final Output output = new Output(baos);
kryo.writeClassAndObject(output, message);
output.close();
return baos.toByteArray();
}
@Override
public Object deserializeMessage(final byte[] data) throws
IOException, ClassNotFoundException {
return kryo.readClassAndObject(new Input(data));
}
}
Thanks, bye Peter
_______________________________________________
ecf-dev mailing list
ecf-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or
unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/ecf-dev