简体   繁体   中英

For Ignite, how can I use the same classes in different packages without overriding Marshaller?

Hello and thanks in advance!

I'm tring to use embedded Ignite when app projects have different packages like "com.eta.one" and "com.eta.another" .

I set BinaryTypeConfiguration for "com.eta.*" with new BinaryBasicNameMapper(true) . So, I enable simple class name resolution with true . And I was hoping this is how it should work. But it doesn't work for me.

It seems like I can specify my own Marshaller, but it's marked as 'deprecated'. I've solved same problem while testing Hazelcast (~ similar technology) setting 'global serializer'.

I use code below in two projects in different packages.

String packageWithModels = "com.eta.*";
BinaryTypeConfiguration binaryTypeConfiguration = new BinaryTypeConfiguration()
    .setTypeName(packageWithModels)
    .setIdMapper(new BinaryBasicIdMapper(true))
    .setNameMapper(new BinaryBasicNameMapper(true));
BinaryConfiguration binaryConfiguration = new BinaryConfiguration()
    .setTypeConfigurations(Collections.singleton(binaryTypeConfiguration));
IgniteConfiguration cfg = new IgniteConfiguration()
    .setBinaryConfiguration(binaryConfiguration);

Ignite ignite = Ignition.start(cfg);

IgniteCache<Integer, MyObject> cache = ignite.getOrCreateCache("myCacheMyObject");
MyObject myObject = new MyObject();
myObject.setText("Hello World!");

MyObject before = cache.get(1);
System.out.println("before:" + before);
cache.put(1, myObject);
MyObject after = cache.get(1);
System.out.println("after:" + after);

Question:

  • Is there a way to do use same classes with different packages?
  • Wondering if these classes can contain different sets of fields? In a different order?
  • It would also be very nice if I can avoid manually registering all types. And it seems like a bad idea to use the deprecated Marshaler change feature.

Update 09.11.20 16:19:

I tried to use the global mapper as the @alamar suggested. So, BinaryConfiguration changed and BinaryTypeConfiguration removed:

BinaryConfiguration binaryConfiguration = new BinaryConfiguration()
                .setIdMapper(new BinaryBasicIdMapper(true))
                .setNameMapper(new BinaryBasicNameMapper(true));

But the situation didn't change. Still showing error java.lang.ClassNotFoundException: com.eta.one.MyObject when com.eta.another project is subsequently launched. Really strange if this doesn't work specifically for java, although I don't understand where I could have gone wrong.

BinaryBasicNameMapper should work - it's used by .Net plugin which works. I don't think that you can use wildcards in type name, so no "com.eta.*" for you. You can still set this mapper globally.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM