2.14. hot Rod Java Client Marshalling
热 Rod 是一种二进制 TCP 协议,要求您将 Java 对象转换为二进制格式,以便可以通过线路或存储到磁盘传输它们。
默认情况下,Data Grid 使用 ProtoStream API 将 Java 对象编码并解码为协议缓冲器(Protobuf);语言中立、向后兼容的格式。但是,您也可以实施并使用自定义 marshallers。
2.14.1. 配置 SerializationContextInitializer 实现 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
您可以将 ProtoStream SerializationContextInitializer 接口的实现添加到 Hot Rod 客户端配置,以便 Data Grid marshalls 自定义 Java 对象。
流程
-
将
SerializationContextInitializer实现添加到 Hot Rod 客户端配置中,如下所示:
hotrod-client.properties
infinispan.client.hotrod.context-initializers=org.infinispan.example.LibraryInitializerImpl,org.infinispan.example.AnotherExampleSciImpl
infinispan.client.hotrod.context-initializers=org.infinispan.example.LibraryInitializerImpl,org.infinispan.example.AnotherExampleSciImpl
编程配置
2.14.2. 配置自定义 Marshallers 复制链接链接已复制到粘贴板!
复制链接链接已复制到粘贴板!
将 Hot Rod 客户端配置为使用自定义 marshallers。
流程
-
实施
org.infinispan.commons.marshall.Marshaller接口。 - 在 Hot Rod 客户端配置中指定您的类的完全限定名称。
将您的 Java 类添加到 Data Grid deserialization whitelist 中。
在以下示例中,只允许带有
Person或Employee的完全限定名称的类:ConfigurationBuilder clientBuilder = new ConfigurationBuilder(); clientBuilder.marshaller("org.infinispan.example.marshall.CustomMarshaller") .addJavaSerialWhiteList(".*Person.*", ".*Employee.*"); ...ConfigurationBuilder clientBuilder = new ConfigurationBuilder(); clientBuilder.marshaller("org.infinispan.example.marshall.CustomMarshaller") .addJavaSerialWhiteList(".*Person.*", ".*Employee.*"); ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow