2020 */
2121public abstract class AmazonS3Factory {
2222
23- public static final String ACCESS_KEY = "s3fs_access_key" ;
24- public static final String SECRET_KEY = "s3fs_secret_key" ;
25- public static final String REQUEST_METRIC_COLLECTOR_CLASS = "s3fs_request_metric_collector_class" ;
26- public static final String CONNECTION_TIMEOUT = "s3fs_connection_timeout" ;
27- public static final String MAX_CONNECTIONS = "s3fs_max_connections" ;
28- public static final String MAX_ERROR_RETRY = "s3fs_max_retry_error" ;
29- public static final String PROTOCOL = "s3fs_protocol" ;
30- public static final String PROXY_DOMAIN = "s3fs_proxy_domain" ;
31- public static final String PROXY_HOST = "s3fs_proxy_host" ;
32- public static final String PROXY_PASSWORD = "s3fs_proxy_password" ;
33- public static final String PROXY_PORT = "s3fs_proxy_port" ;
34- public static final String PROXY_USERNAME = "s3fs_proxy_username" ;
35- public static final String PROXY_WORKSTATION = "s3fs_proxy_workstation" ;
36- public static final String SOCKET_SEND_BUFFER_SIZE_HINT = "s3fs_socket_send_buffer_size_hint" ;
37- public static final String SOCKET_RECEIVE_BUFFER_SIZE_HINT = "s3fs_socket_receive_buffer_size_hint" ;
38- public static final String SOCKET_TIMEOUT = "s3fs_socket_timeout" ;
39- public static final String USER_AGENT = "s3fs_user_agent" ;
23+ public static final String ACCESS_KEY = "s3fs_access_key" ;
24+ public static final String SECRET_KEY = "s3fs_secret_key" ;
25+ public static final String REQUEST_METRIC_COLLECTOR_CLASS = "s3fs_request_metric_collector_class" ;
26+ public static final String CONNECTION_TIMEOUT = "s3fs_connection_timeout" ;
27+ public static final String MAX_CONNECTIONS = "s3fs_max_connections" ;
28+ public static final String MAX_ERROR_RETRY = "s3fs_max_retry_error" ;
29+ public static final String PROTOCOL = "s3fs_protocol" ;
30+ public static final String PROXY_DOMAIN = "s3fs_proxy_domain" ;
31+ public static final String PROXY_HOST = "s3fs_proxy_host" ;
32+ public static final String PROXY_PASSWORD = "s3fs_proxy_password" ;
33+ public static final String PROXY_PORT = "s3fs_proxy_port" ;
34+ public static final String PROXY_USERNAME = "s3fs_proxy_username" ;
35+ public static final String PROXY_WORKSTATION = "s3fs_proxy_workstation" ;
36+ public static final String SOCKET_SEND_BUFFER_SIZE_HINT = "s3fs_socket_send_buffer_size_hint" ;
37+ public static final String SOCKET_RECEIVE_BUFFER_SIZE_HINT = "s3fs_socket_receive_buffer_size_hint" ;
38+ public static final String SOCKET_TIMEOUT = "s3fs_socket_timeout" ;
39+ public static final String USER_AGENT = "s3fs_user_agent" ;
4040
41- protected Logger logger = LoggerFactory .getLogger (getClass ());
41+ protected Logger logger = LoggerFactory .getLogger (getClass ());
4242
4343 /**
4444 * should return a new AmazonS3
45- * @param credentialsProvider AWSCredentialsProvider mandatory
46- * @param clientConfiguration ClientConfiguration mandatory
45+ *
46+ * @param credentialsProvider AWSCredentialsProvider mandatory
47+ * @param clientConfiguration ClientConfiguration mandatory
4748 * @param requestMetricsCollector RequestMetricCollector mandatory
4849 * @return {@link com.amazonaws.services.s3.AmazonS3}
4950 */
50- protected abstract AmazonS3 createAmazonS3 (AWSCredentialsProvider credentialsProvider , ClientConfiguration clientConfiguration , RequestMetricCollector requestMetricsCollector );
51+ protected abstract AmazonS3 createAmazonS3 (AWSCredentialsProvider credentialsProvider , ClientConfiguration clientConfiguration , RequestMetricCollector requestMetricsCollector );
5152
52- public AmazonS3 getAmazonS3 (URI uri , Properties props ) {
53- AmazonS3 client = createAmazonS3 (getCredentialsProvider (props ), getClientConfiguration (props ), getRequestMetricsCollector (props ));
54- if (uri .getHost () != null )
55- client .setEndpoint (uri .getHost ());
56- return client ;
57- }
53+ public AmazonS3 getAmazonS3 (URI uri , Properties props ) {
54+ AmazonS3 client = createAmazonS3 (getCredentialsProvider (props ), getClientConfiguration (props ), getRequestMetricsCollector (props ));
55+ if (uri .getHost () != null )
56+ client .setEndpoint (uri .getHost ());
57+ return client ;
58+ }
5859
59- protected AWSCredentialsProvider getCredentialsProvider (Properties props ) {
60- AWSCredentialsProvider credentialsProvider ;
61- if (props .getProperty (ACCESS_KEY ) == null && props .getProperty (SECRET_KEY ) == null )
62- credentialsProvider = new DefaultAWSCredentialsProviderChain ();
63- else
64- credentialsProvider = new StaticCredentialsProvider (getAWSCredentials (props ));
65- return credentialsProvider ;
66- }
60+ protected AWSCredentialsProvider getCredentialsProvider (Properties props ) {
61+ AWSCredentialsProvider credentialsProvider ;
62+ if (props .getProperty (ACCESS_KEY ) == null && props .getProperty (SECRET_KEY ) == null )
63+ credentialsProvider = new DefaultAWSCredentialsProviderChain ();
64+ else
65+ credentialsProvider = new StaticCredentialsProvider (getAWSCredentials (props ));
66+ return credentialsProvider ;
67+ }
6768
68- protected RequestMetricCollector getRequestMetricsCollector (Properties props ) {
69- RequestMetricCollector requestMetricCollector = null ;
70- if (props .containsKey (REQUEST_METRIC_COLLECTOR_CLASS )) {
71- try {
72- requestMetricCollector = (RequestMetricCollector ) Class .forName (props .getProperty (REQUEST_METRIC_COLLECTOR_CLASS )).newInstance ();
73- } catch (Throwable t ) {
74- throw new IllegalArgumentException ("Can't instantiate REQUEST_METRIC_COLLECTOR_CLASS " + props .getProperty (REQUEST_METRIC_COLLECTOR_CLASS ), t );
75- }
76- }
77- return requestMetricCollector ;
78- }
69+ protected RequestMetricCollector getRequestMetricsCollector (Properties props ) {
70+ RequestMetricCollector requestMetricCollector = null ;
71+ if (props .containsKey (REQUEST_METRIC_COLLECTOR_CLASS )) {
72+ try {
73+ requestMetricCollector = (RequestMetricCollector ) Class .forName (props .getProperty (REQUEST_METRIC_COLLECTOR_CLASS )).newInstance ();
74+ } catch (Throwable t ) {
75+ throw new IllegalArgumentException ("Can't instantiate REQUEST_METRIC_COLLECTOR_CLASS " + props .getProperty (REQUEST_METRIC_COLLECTOR_CLASS ), t );
76+ }
77+ }
78+ return requestMetricCollector ;
79+ }
7980
80- protected ClientConfiguration getClientConfiguration (Properties props ) {
81- ClientConfiguration clientConfiguration = new ClientConfiguration ();
82- if (props .getProperty (CONNECTION_TIMEOUT ) != null )
83- clientConfiguration .setConnectionTimeout (Integer .parseInt (props .getProperty (CONNECTION_TIMEOUT )));
84- if (props .getProperty (MAX_CONNECTIONS ) != null )
85- clientConfiguration .setMaxConnections (Integer .parseInt (props .getProperty (MAX_CONNECTIONS )));
86- if (props .getProperty (MAX_ERROR_RETRY ) != null )
87- clientConfiguration .setMaxErrorRetry (Integer .parseInt (props .getProperty (MAX_ERROR_RETRY )));
88- if (props .getProperty (PROTOCOL ) != null )
89- clientConfiguration .setProtocol (Protocol .valueOf (props .getProperty (PROTOCOL )));
90- if (props .getProperty (PROXY_DOMAIN ) != null )
91- clientConfiguration .setProxyDomain (props .getProperty (PROXY_DOMAIN ));
92- if (props .getProperty (PROXY_HOST ) != null )
93- clientConfiguration .setProxyHost (props .getProperty (PROXY_HOST ));
94- if (props .getProperty (PROXY_PASSWORD ) != null )
95- clientConfiguration .setProxyPassword (props .getProperty (PROXY_PASSWORD ));
96- if (props .getProperty (PROXY_PORT ) != null )
97- clientConfiguration .setProxyPort (Integer .parseInt (props .getProperty (PROXY_PORT )));
98- if (props .getProperty (PROXY_USERNAME ) != null )
99- clientConfiguration .setProxyUsername (props .getProperty (PROXY_USERNAME ));
100- if (props .getProperty (PROXY_WORKSTATION ) != null )
101- clientConfiguration .setProxyWorkstation (props .getProperty (PROXY_WORKSTATION ));
102- int socketSendBufferSizeHint = 0 ;
103- if (props .getProperty (SOCKET_SEND_BUFFER_SIZE_HINT ) != null )
104- socketSendBufferSizeHint = Integer .parseInt (props .getProperty (SOCKET_SEND_BUFFER_SIZE_HINT ));
105- int socketReceiveBufferSizeHint = 0 ;
106- if (props .getProperty (SOCKET_RECEIVE_BUFFER_SIZE_HINT ) != null )
107- socketReceiveBufferSizeHint = Integer .parseInt (props .getProperty (SOCKET_RECEIVE_BUFFER_SIZE_HINT ));
108- clientConfiguration .setSocketBufferSizeHints (socketSendBufferSizeHint , socketReceiveBufferSizeHint );
109- if (props .getProperty (SOCKET_TIMEOUT ) != null )
110- clientConfiguration .setSocketTimeout (Integer .parseInt (props .getProperty (SOCKET_TIMEOUT )));
111- if (props .getProperty (USER_AGENT ) != null )
112- clientConfiguration .setUserAgent (props .getProperty (USER_AGENT ));
113- return clientConfiguration ;
114- }
81+ protected ClientConfiguration getClientConfiguration (Properties props ) {
82+ ClientConfiguration clientConfiguration = new ClientConfiguration ();
83+ if (props .getProperty (CONNECTION_TIMEOUT ) != null )
84+ clientConfiguration .setConnectionTimeout (Integer .parseInt (props .getProperty (CONNECTION_TIMEOUT )));
85+ if (props .getProperty (MAX_CONNECTIONS ) != null )
86+ clientConfiguration .setMaxConnections (Integer .parseInt (props .getProperty (MAX_CONNECTIONS )));
87+ if (props .getProperty (MAX_ERROR_RETRY ) != null )
88+ clientConfiguration .setMaxErrorRetry (Integer .parseInt (props .getProperty (MAX_ERROR_RETRY )));
89+ if (props .getProperty (PROTOCOL ) != null )
90+ clientConfiguration .setProtocol (Protocol .valueOf (props .getProperty (PROTOCOL )));
91+ if (props .getProperty (PROXY_DOMAIN ) != null )
92+ clientConfiguration .setProxyDomain (props .getProperty (PROXY_DOMAIN ));
93+ if (props .getProperty (PROXY_HOST ) != null )
94+ clientConfiguration .setProxyHost (props .getProperty (PROXY_HOST ));
95+ if (props .getProperty (PROXY_PASSWORD ) != null )
96+ clientConfiguration .setProxyPassword (props .getProperty (PROXY_PASSWORD ));
97+ if (props .getProperty (PROXY_PORT ) != null )
98+ clientConfiguration .setProxyPort (Integer .parseInt (props .getProperty (PROXY_PORT )));
99+ if (props .getProperty (PROXY_USERNAME ) != null )
100+ clientConfiguration .setProxyUsername (props .getProperty (PROXY_USERNAME ));
101+ if (props .getProperty (PROXY_WORKSTATION ) != null )
102+ clientConfiguration .setProxyWorkstation (props .getProperty (PROXY_WORKSTATION ));
103+ int socketSendBufferSizeHint = 0 ;
104+ if (props .getProperty (SOCKET_SEND_BUFFER_SIZE_HINT ) != null )
105+ socketSendBufferSizeHint = Integer .parseInt (props .getProperty (SOCKET_SEND_BUFFER_SIZE_HINT ));
106+ int socketReceiveBufferSizeHint = 0 ;
107+ if (props .getProperty (SOCKET_RECEIVE_BUFFER_SIZE_HINT ) != null )
108+ socketReceiveBufferSizeHint = Integer .parseInt (props .getProperty (SOCKET_RECEIVE_BUFFER_SIZE_HINT ));
109+ clientConfiguration .setSocketBufferSizeHints (socketSendBufferSizeHint , socketReceiveBufferSizeHint );
110+ if (props .getProperty (SOCKET_TIMEOUT ) != null )
111+ clientConfiguration .setSocketTimeout (Integer .parseInt (props .getProperty (SOCKET_TIMEOUT )));
112+ if (props .getProperty (USER_AGENT ) != null )
113+ clientConfiguration .setUserAgent (props .getProperty (USER_AGENT ));
114+ return clientConfiguration ;
115+ }
115116
116- protected BasicAWSCredentials getAWSCredentials (Properties props ) {
117- return new BasicAWSCredentials (props .getProperty (ACCESS_KEY ), props .getProperty (SECRET_KEY ));
118- }
117+ protected BasicAWSCredentials getAWSCredentials (Properties props ) {
118+ return new BasicAWSCredentials (props .getProperty (ACCESS_KEY ), props .getProperty (SECRET_KEY ));
119+ }
119120}
0 commit comments