@@ -0,0 +1,1897 @@
+/**%0A * %0A */%0Apackage cn.strong.fastdfs.client;%0A%0Aimport io.netty.channel.Channel;%0Aimport io.netty.channel.nio.NioEventLoopGroup;%0Aimport io.netty.channel.pool.FixedChannelPool;%0Aimport io.netty.util.concurrent.Future;%0A%0Aimport java.io.IOException;%0Aimport java.net.InetSocketAddress;%0A%0Aimport javax.annotation.PreDestroy;%0A%0Aimport rx.Observable;%0A%0Aimport cn.strong.fastdfs.client.protocol.request.Request;%0Aimport cn.strong.fastdfs.client.protocol.response.Receiver;%0Aimport cn.strong.fastdfs.ex.FastdfsException;%0A%0A/**%0A * FastDFS %E8%BF%9E%E6%8E%A5%E4%BA%A4%E4%BA%92%E6%A8%A1%E6%9D%BF%E7%B1%BB%0A * %0A * @author liulongbiao%0A *%0A */%0Apublic class FastdfsTemplate %7B%0A%0A%09final NioEventLoopGroup group;%0A%09final FastdfsChannelPoolMap poolMap;%0A%0A%09public FastdfsTemplate(Settings settings) %7B%0A%09%09if (settings == null) %7B%0A%09%09%09settings = new Settings();%0A%09%09%7D%0A%09%09group = new NioEventLoopGroup(settings.getEventLoopThreads());%0A%09%09poolMap = new FastdfsChannelPoolMap(group, settings);%0A%09%7D%0A%0A%09/**%0A%09 * %E8%AE%BF%E9%97%AE Fastdfs %E6%9C%8D%E5%8A%A1%E5%99%A8%0A%09 * %0A%09 * @param addr%0A%09 * @param sender%0A%09 * @param decoder%0A%09 * @return%0A%09 */%0A%09public %3CT%3E Observable%3CT%3E execute(InetSocketAddress addr, Request request, Receiver%3CT%3E receiver) %7B%0A%09%09FixedChannelPool pool = poolMap.get(addr);%0A%09%09pool.acquire().addListener((Future%3CChannel%3E f) -%3E %7B%0A%09%09%09if (f.isCancelled()) %7B%0A%09%09%09%09receiver.tryError(new FastdfsException(%22connection is canceled%22));%0A%09%09%09%7D else if (!f.isSuccess()) %7B%0A%09%09%09%09receiver.tryError(f.cause());%0A%09%09%09%7D else %7B%0A%09%09%09%09Channel ch = f.getNow();%0A%09%09%09%09receiver.observable().doAfterTerminate(() -%3E %7B%0A%09%09%09%09%09pool.release(ch);%0A%09%09%09%09%7D);%0A%09%09%09%09try %7B%0A%09%09%09%09%09ch.attr(Receiver.RECEIVER).set(receiver);%0A%09%09%09%09%09ch.writeAndFlush(request);%0A%09%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09%09receiver.tryError(e);%0A%09%09%09%09%7D%0A%09%09%09%7D%0A%09%09%7D);%0A%09%09return receiver.observable();%0A%09%7D%0A%0A%09@PreDestroy%0A%09public void close() throws IOException %7B%0A%09%09if (poolMap != null) %7B%0A%09%09%09try %7B%0A%09%09%09%09poolMap.close();%0A%09%09%09%7D catch (Exception e) %7B%0A%09%09%09%09// ignore%0A%09%09%09%7D%0A%09%09%7D%0A%09%09if (group != null) %7B%0A%09%09%09group.shutdownGracefully();%0A%09%09%7D%0A%09%7D%0A%7D%0A

add FastdfsTemplate