jboss marshell序列化整合netty

1、关于JBOSS的Marshalling的简介

       JBoss Marshalling 是一个Java对象的序列化API包,修正了JDK自带的序列化包的很多问题,但又保持跟 java.io.Serializable 接口的兼容;同时增加了一些可调的参数和附加的特性,而这些参数和特性可通过工厂类进行配置。

2、关于JBoss的Marshalling的配置

      2.1 服务端的配置

        

      2.2 客户端的配置

        

        2.3  直接发送和接收对象

          

3、关于JBoss的Marshalling的工厂类

[java]  view plain   copy
  print ?
  1. import io.netty.handler.codec.marshalling.DefaultMarshallerProvider;  
  2. import io.netty.handler.codec.marshalling.DefaultUnmarshallerProvider;  
  3. import io.netty.handler.codec.marshalling.MarshallerProvider;  
  4. import io.netty.handler.codec.marshalling.MarshallingDecoder;  
  5. import io.netty.handler.codec.marshalling.MarshallingEncoder;  
  6. import io.netty.handler.codec.marshalling.UnmarshallerProvider;  
  7.   
  8. import org.jboss.marshalling.MarshallerFactory;  
  9. import org.jboss.marshalling.Marshalling;  
  10. import org.jboss.marshalling.MarshallingConfiguration;  
  11.   
  12. /** 
  13.  * Marshalling工厂 
  14.  *  
  15.  */  
  16. public final class MarshallingCodeCFactory {  
  17.   
  18.     /** 
  19.      * 创建Jboss Marshalling解码器MarshallingDecoder 
  20.      *  
  21.      * @return MarshallingDecoder 
  22.      */  
  23.     public static MarshallingDecoder buildMarshallingDecoder() {  
  24.         // 首先通过Marshalling工具类的精通方法获取Marshalling实例对象 参数serial标识创建的是java序列化工厂对象。  
  25.         final MarshallerFactory marshallerFactory = Marshalling  
  26.                 .getProvidedMarshallerFactory("serial");  
  27.         // 创建了MarshallingConfiguration对象,配置了版本号为5  
  28.         final MarshallingConfiguration configuration = new MarshallingConfiguration();  
  29.         configuration.setVersion(5);  
  30.         // 根据marshallerFactory和configuration创建provider  
  31.         UnmarshallerProvider provider = new DefaultUnmarshallerProvider(  
  32.                 marshallerFactory, configuration);  
  33.         // 构建Netty的MarshallingDecoder对象,俩个参数分别为provider和单个消息序列化后的最大长度  
  34.         MarshallingDecoder decoder = new MarshallingDecoder(provider,  
  35.                 1024 * 1024 * 1);  
  36.         return decoder;  
  37.     }  
  38.   
  39.     /** 
  40.      * 创建Jboss Marshalling编码器MarshallingEncoder 
  41.      *  
  42.      * @return MarshallingEncoder 
  43.      */  
  44.     public static MarshallingEncoder buildMarshallingEncoder() {  
  45.         final MarshallerFactory marshallerFactory = Marshalling  
  46.                 .getProvidedMarshallerFactory("serial");  
  47.         final MarshallingConfiguration configuration = new MarshallingConfiguration();  
  48.         configuration.setVersion(5);  
  49.         MarshallerProvider provider = new DefaultMarshallerProvider(  
  50.                 marshallerFactory, configuration);  
  51.         // 构建Netty的MarshallingEncoder对象,MarshallingEncoder用于实现序列化接口的POJO对象序列化为二进制数组  
  52.         MarshallingEncoder encoder = new MarshallingEncoder(provider);  
  53.         return encoder;  
  54.     }  
  55. }  
4、服务端的实现

[java]  view plain   copy
  print ?
    • 0
      点赞
    • 0
      收藏
      觉得还不错? 一键收藏
    • 0
      评论

    “相关推荐”对你有帮助么?

    • 非常没帮助
    • 没帮助
    • 一般
    • 有帮助
    • 非常有帮助
    提交
    评论
    添加红包

    请填写红包祝福语或标题

    红包个数最小为10个

    红包金额最低5元

    当前余额3.43前往充值 >
    需支付:10.00
    成就一亿技术人!
    领取后你会自动成为博主和红包主的粉丝 规则
    hope_wisdom
    发出的红包
    实付
    使用余额支付
    点击重新获取
    扫码支付
    钱包余额 0

    抵扣说明:

    1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
    2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

    余额充值