对于Ignite,如何在不覆盖Marshaller的情况下在不同的程序包中使用相同的类? [英] For Ignite, how can I use the same classes in different packages without overriding Marshaller?

查看:51
本文介绍了对于Ignite,如何在不覆盖Marshaller的情况下在不同的程序包中使用相同的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,谢谢!

当应用程序项目具有不同的包(例如"com.eta.one" "com.eta.another" )时,我正尝试使用嵌入式Ignite.

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

我使用 new BinaryBasicNameMapper(true)"com.eta.*" 设置了 BinaryTypeConfiguration .因此,我使用 true 启用了简单的类名解析.我希望这是应该起作用的方式.但这对我不起作用.

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.

似乎我可以指定自己的Marshaller,但已将其标记为已弃用".在测试Hazelcast(〜类似技术)设置全局序列化程序"时,我已经解决了相同的问题.

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);

问题:

  • 有没有办法在不同的程序包中使用相同的类?
  • 想知道这些类是否可以包含不同的字段集吗?在一个不同的顺序?
  • 如果我可以避免手动操作,那也很好注册所有类型.而且使用已弃用的 Marshaler 更改功能.
  • 我试图按照@alamar的建议使用全局映射器.因此,更改了 BinaryConfiguration 并删除了 BinaryTypeConfiguration :

    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));
    

    但是情况没有改变.随后启动 com.eta.another 项目时,仍然显示错误 java.lang.ClassNotFoundException:com.eta.one.MyObject .如果这不适用于Java,真是很奇怪,尽管我不知道哪里可能出错.

    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 应该可以工作-.Net插件可以使用它.我认为您不能在类型名称中使用通配符,因此没有"com.eta.*" 可供您使用.您仍然可以全局设置此映射器.

    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.

    这篇关于对于Ignite,如何在不覆盖Marshaller的情况下在不同的程序包中使用相同的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆