Skip to content

Commit

Permalink
refactor:修改bug,优化代码路径
Browse files Browse the repository at this point in the history
1. 修复删除文件路径错误的bug fix #90
2. 支持缩略图生成按尺寸(width,height)和按比例缩放 fix #87
3. 重构核心代码路径
4. 修复问题 fix #91, fix #53
  • Loading branch information
tobato committed Dec 24, 2018
1 parent 1dbe781 commit 5d4a05e
Show file tree
Hide file tree
Showing 142 changed files with 2,883 additions and 1,550 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
@@ -1,3 +1,16 @@
## 1.26.5 (2018-12-30)

Features:

- 重构代码路径,优化内部模块关系
- 支持缩略图生成按尺寸(width,height)和按比例缩放(#87 @BigBroB
- 支持上传图片选择Group (#53 @595979101)
- 在上传文件时既可以选择组名又可以添加metadata (#91 @WildSaCk)

BugFixes:

- 修复删除文件路径错误的bug(#90 @xfxf521 )

## 1.26.4 (2018-11-10)

Features:
Expand Down
21 changes: 16 additions & 5 deletions src/main/java/com/github/tobato/fastdfs/FdfsClientConstants.java
@@ -1,23 +1,34 @@
package com.github.tobato.fastdfs;

/**
* 客户端常量配置
*
* @author tobato
* FDFSClient常量配置
*
* @author tobato
*/
public class FdfsClientConstants {

private FdfsClientConstants() {
// hide for constants
}

/** 配置文件前缀 */
/**
* 支持图片类型
*/
public static final String[] SUPPORT_IMAGE_TYPE = {"JPG", "JPEG", "PNG", "GIF", "BMP", "WBMP"};

/**
* 配置文件前缀
*/
public static final String ROOT_CONFIG_PREFIX = "fdfs";

/**
* 缩略图配置
*/
public static final String THUMB_IMAGE_CONFIG_PREFIX = "fdfs.thumb-image";

/**
* 连接池配置
*/
public static final String POOL_CONFIG_PREFIX = "fdfs.pool";

// public static final String CONFIG_PREFIX = "fdfs";
}
@@ -1,4 +1,4 @@
package com.github.tobato.fastdfs.conn;
package com.github.tobato.fastdfs.domain.conn;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -7,11 +7,10 @@

/**
* 表示一个客户端与服务端的连接
*
* <p>
* 负责连接的管理
*
* @author tobato
*
* @author tobato
*/
public interface Connection {

Expand All @@ -22,37 +21,37 @@ public interface Connection {

/**
* 连接是否关闭
*
*
* @return
*/
boolean isClosed();

/**
* 测试连接是否有效
*
*
* @return
*/
boolean isValid();

/**
* 获取输出流
*
*
* @return
* @throws IOException
*/
public OutputStream getOutputStream() throws IOException;

/**
* 获取输入流
*
*
* @return 输入流
* @throws IOException 获取输入流错误
*/
public InputStream getInputStream() throws IOException;

/**
* 获取字符集
*
*
* @return 字符集
*/
public Charset getCharset();
Expand Down
@@ -1,32 +1,34 @@
package com.github.tobato.fastdfs.conn;

import java.net.InetSocketAddress;
package com.github.tobato.fastdfs.domain.conn;

import com.github.tobato.fastdfs.domain.proto.FdfsCommand;
import com.github.tobato.fastdfs.exception.FdfsException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.tobato.fastdfs.exception.FdfsException;
import com.github.tobato.fastdfs.proto.FdfsCommand;
import java.net.InetSocketAddress;

/**
* 连接池管理
*
* <p>
* <pre>
* 负责借出连接,在连接上执行业务逻辑,然后归还连
* </pre>
*
* @author tobato
*
* @author tobato
*/
@Component
public class ConnectionManager {

/** 连接池 */
/**
* 连接池
*/
@Autowired
private FdfsConnectionPool pool;
/** 日志 */
/**
* 日志
*/
protected static final Logger LOGGER = LoggerFactory.getLogger(ConnectionManager.class);

/**
Expand All @@ -38,7 +40,7 @@ public ConnectionManager() {

/**
* 构造函数
*
*
* @param pool
*/
public ConnectionManager(FdfsConnectionPool pool) {
Expand All @@ -48,7 +50,7 @@ public ConnectionManager(FdfsConnectionPool pool) {

/**
* 获取连接并执行交易
*
*
* @param address
* @param command
* @return
Expand All @@ -64,7 +66,7 @@ public <T> T executeFdfsCmd(InetSocketAddress address, FdfsCommand<T> command) {

/**
* 执行交易
*
*
* @param conn
* @param command
* @return
Expand Down Expand Up @@ -94,7 +96,7 @@ protected <T> T execute(InetSocketAddress address, Connection conn, FdfsCommand<

/**
* 获取连接
*
*
* @param address
* @return
*/
Expand Down
@@ -1,4 +1,4 @@
package com.github.tobato.fastdfs.conn;
package com.github.tobato.fastdfs.domain.conn;

import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;
Expand All @@ -8,18 +8,21 @@

/**
* 连接池配置
*
* @author tobato
*
* @author tobato
*/
@Component
@ConfigurationProperties(prefix = FdfsClientConstants.POOL_CONFIG_PREFIX)
public class ConnectionPoolConfig extends GenericKeyedObjectPoolConfig {

/** 从池中借出的对象的最大数目 */
/**
* 从池中借出的对象的最大数目
*/
public static final int FDFS_MAX_TOTAL = 50;

/** 在空闲时检查有效性, 默认false */
/**
* 在空闲时检查有效性, 默认false
*/
public static final boolean FDFS_TEST_WHILE_IDLE = true;

/**
Expand Down Expand Up @@ -48,10 +51,14 @@ public class ConnectionPoolConfig extends GenericKeyedObjectPoolConfig {
*/
public static final int FDFS_NUM_TESTS_PEREVICTION_RUN = -1;

/** 默认jmx域名 */
/**
* 默认jmx域名
*/
public static final String FDFS_JMX_NAME_BASE = "com.github.tobato.fastdfs.conn:type=FdfsConnectionPool";

/** 默认jmx prefix名称 */
/**
* 默认jmx prefix名称
*/
public static final String FDFS_JMX_NAME_PREFIX = "fdfsPool";

public ConnectionPoolConfig() {
Expand Down
@@ -1,4 +1,12 @@
package com.github.tobato.fastdfs.conn;
package com.github.tobato.fastdfs.domain.conn;

import com.github.tobato.fastdfs.domain.proto.CmdConstants;
import com.github.tobato.fastdfs.domain.proto.OtherConstants;
import com.github.tobato.fastdfs.domain.proto.mapper.BytesUtil;
import com.github.tobato.fastdfs.exception.FdfsConnectException;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStream;
Expand All @@ -8,35 +16,31 @@
import java.nio.charset.Charset;
import java.util.Arrays;

import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.github.tobato.fastdfs.exception.FdfsConnectException;
import com.github.tobato.fastdfs.proto.CmdConstants;
import com.github.tobato.fastdfs.proto.OtherConstants;
import com.github.tobato.fastdfs.proto.mapper.BytesUtil;

/**
* 默认连接实现
*
* @author tobato
*
* @author tobato
*/
public class DefaultConnection implements Connection {

/** 封装socket */
/**
* 封装socket
*/
private Socket socket;

/** 字符集 */
/**
* 字符集
*/
private Charset charset;

/** 日志 */
/**
* 日志
*/
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultConnection.class);

/**
* 创建与服务端连接
*
*
* @param address
* @param soTimeout
* @param connectTimeout
Expand Down Expand Up @@ -112,7 +116,7 @@ public boolean isValid() {

/**
* 获取输出流
*
*
* @return
* @throws IOException
*/
Expand All @@ -122,7 +126,7 @@ public OutputStream getOutputStream() throws IOException {

/**
* 获取输入流
*
*
* @return
* @throws IOException
*/
Expand All @@ -132,7 +136,7 @@ public InputStream getInputStream() throws IOException {

/**
* 获取字符集
*
*
* @return
*/
public Charset getCharset() {
Expand Down
@@ -1,41 +1,40 @@
package com.github.tobato.fastdfs.conn;

import java.net.InetSocketAddress;
package com.github.tobato.fastdfs.domain.conn;

import org.apache.commons.pool2.KeyedPooledObjectFactory;
import org.apache.commons.pool2.impl.GenericKeyedObjectPool;
import org.apache.commons.pool2.impl.GenericKeyedObjectPoolConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.net.InetSocketAddress;

/**
* 定义Fdfs连接池对象
*
* <p>
* <pre>
* 定义了对象池要实现的功能,对一个地址进行池化Map Pool
* </pre>
*
* @author tobato
*
* @author tobato
*/
@Component
public class FdfsConnectionPool extends GenericKeyedObjectPool<InetSocketAddress, Connection> {

/**
* 默认构造函数
*
*
* @param factory
* @param config
*/
@Autowired
public FdfsConnectionPool(KeyedPooledObjectFactory<InetSocketAddress, Connection> factory,
GenericKeyedObjectPoolConfig config) {
GenericKeyedObjectPoolConfig config) {
super(factory, config);
}

/**
* 默认构造函数
*
*
* @param factory
*/
public FdfsConnectionPool(KeyedPooledObjectFactory<InetSocketAddress, Connection> factory) {
Expand Down

0 comments on commit 5d4a05e

Please sign in to comment.