在Weblogic 11g服务器上通过网络发送hashMap时实现压缩 [英] Implement compression while sending hashMap over the network on Weblogic 11g server

查看:155
本文介绍了在Weblogic 11g服务器上通过网络发送hashMap时实现压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个hashMap,它需要通过网络从服务器传播到客户端。现在,当大小增加到套接字缓冲区提供的某个限制之外时,将引发以下异常。

I have a hashMap that needs to travel from server to client over network. Now when the size increases beyond some limit provided at socket buffer the following exception is thrown.

原因:weblogic.socket.MaxMessageSizeExceededException:传入消息大小: 3002880字节超出了配置的最大值:协议的 t3字节: 3000000字节

Caused by: weblogic.socket.MaxMessageSizeExceededException: Incoming message of size: '3002880' bytes exceeds the configured maximum of: '3000000' bytes for protocol: 't3'

在搜索时我发现应该增加套接字的大小,但这不是必需的,因为这不是一个很好的解决方案。

While googling it out I found that the socket size should be increased but that is not required as this is not such a good solution.

然后,我尝试先压缩HashMap,然后再使用 DeflaterOutputStream / InflaterInputStream。但是这里的挑战在于, ObjectOutputStream对象是由weblogic类创建的,并且在尝试创建ObjectOutputStream来使压缩工作时应该嵌入deflater / Inflater流。

Then I am trying to compress the HashMap before sending using "DeflaterOutputStream/InflaterInputStream". But the challenge here is that the "ObjectOutputStream" object is created by weblogic classes and the deflater/Inflater streams are supposed to be embed while trying to create the ObjectOutputStream to make compression work.

有什么方法可以做到这一点?

Is there some way I can do this?

也可以有一些方法来启用weblogic使用的t3协议压缩来自动使用压缩。我已经对t3协议是否可行进行了一些研究,但似乎t3协议不支持此协议。但是我不确定Weblogic的某些新版本是否支持。

Also could there be some way to just enable the compression at t3 protocol used by weblogic to automatically use the compression. I have done some research on whether it is possible or not at t3 protocol but it seems t3 protocol does not support this. But I am not sure whether some new version of weblogic support this or not.

我还考虑将HashMap分解为套接字缓冲区大小的块,但是

I was also thinking of breaking the HashMap in to the chunks of "Socket buffer size" but it will require to change the existing design and is not preferred as of now.

请对此发表您的看法。

推荐答案

您可以将Map包装到另一个对象中,例如

You could wrap the Map into another object, e.g. called Payload and make all communications be part of a compressed object.

public class Payload<T extends Serializable> {
    private T payload;
    public Payload( T payload ) {
        this.payload = payload;
    }
    private T get() {
        return payload;
    }

  public static final boolean ENABLE_COMPRESSION = BooleanUtils.toBooleanDefaultIfNull( BooleanUtils.toBooleanObject( System.getProperty( "serialization.gzip.enabled" ) ), true );

    private void writeObject( ObjectOutputStream oos ) throws IOException {
        if ( ENABLE_COMPRESSION ) {
            GZIPOutputStream zos = new GZIPOutputStream( oos, 65536 );
            ObjectOutputStream sender = new ObjectOutputStream( zos );
            sender.writeObject( payload );
            sender.flush();
            zos.finish();
        } else {
            oos.defaultWriteObject();
        }
    }

    @SuppressWarnings( "unchecked" )
    private void readObject( ObjectInputStream ois ) throws ClassNotFoundException, IOException {
        if ( ENABLE_COMPRESSION ) {
            GZIPInputStream zis = new GZIPInputStream( ois, 65536 );
            ObjectInputStream receiver = new ObjectInputStream( zis );
            payload = (T) receiver.readObject();
        } else {
            ois.defaultReadObject();
        }
    }
}

然后在发送任何对象时,

Then when sending any object, it will be sent wrapped within a Payload object and therefore compressed.

public Payload<Map> someRemoteCall() {
    Map map = new HashMap();
    populate( map ); // do whatever needs to be done to fill up the map.
    Payload<Map> payload = new Payload<Map>( map );
    return payload;
}

很明显,这可能涉及对接口的某些更改,这可能是不希望的,但到目前为止

Obviously it may involve some changes to interfaces which may be undesirable, but so far it's the best I've found for this.

希望这会有所帮助。

这篇关于在Weblogic 11g服务器上通过网络发送hashMap时实现压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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