I have server and client applications with apache-mina framework. I need to send a large arraylist (contains 10000 custom objects) from server to client. I first thought to use GSON strings to pass the arraylist, but I think, creating that kind of huge strings and sending it is not a proper way.
In my client app, I wrote a method to connect :
public void connect() throws InterruptedException
{
Thread t = new Thread(new Runnable()
{
@Override
public void run()
{
connector = new NioSocketConnector();
connector.getSessionConfig().setReadBufferSize(1024);
TextLineCodecFactory t = new TextLineCodecFactory(Charset.forName("UTF-8"));
t.setEncoderMaxLineLength(100000);
t.setDecoderMaxLineLength(100000);
connector.getFilterChain().addLast("logger", new LoggingFilter());
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(t));
connector.setHandler(handler);
ConnectFuture future = connector.connect(new InetSocketAddress("localhost", PORT));
future.awaitUninterruptibly();
if (!future.isConnected())
{
return;
}
IoSession session = future.getSession();
session.getConfig().setUseReadOperation(true);
session.getCloseFuture().awaitUninterruptibly();
connector.dispose();
}
});
t.start();
Thread.sleep(1000);
}
What filter should I use to send objects or containers without converting them into strings ? Is it about BufferedWriteFilter or WriteRequestFilter ? If so how can I use them ?
I found the answer.
By using ObjectSerializationCodecFactory on both client and server side, I can pass custom objects and collections.
ObjectSerializationCodecFactory oscf = new ObjectSerializationCodecFactory();
oscf.setDecoderMaxObjectSize(1048576);
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(oscf)