// Path: eventstore-client/src/main/java/de/qyotta/eventstore/EventStoreSettings.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PRIVATE)
// @AllArgsConstructor(access = AccessLevel.PRIVATE)
// @SuppressWarnings("nls")
// public class EventStoreSettings {
//    private static final String DEFAULT_PASSWORD = "changeit";
//    private static final String DEFAULT_USERNAME = "admin";
//    private static final String DEFAULT_SCHEME = "Basic";
//    private static final String DEFAULT_REALM = "ES";
//    private static final String DEFAULT_HOST = "http://127.0.0.1:2113";
//    private static final int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 10000;
//    private static final int DEFAULT_SOCKET_TIMEOUT_MILLIS = 10000;
// 
//    private String host;
//    private String realm;
//    private String scheme;
//    private String userName;
//    private String password;
//    private Integer connectionTimeoutMillis;
//    private Integer socketTimeoutMillis;
//    private File cacheDirectory;
//    private boolean cacheResponses;
// 
//    public static EventStoreSettings.EventStoreSettingsBuilder withDefaults() {
//       return EventStoreSettings.builder()
//             .host(DEFAULT_HOST)
//             .realm(DEFAULT_REALM)
//             .scheme(DEFAULT_SCHEME)
//             .userName(DEFAULT_USERNAME)
//             .password(DEFAULT_PASSWORD)
//             .connectionTimeoutMillis(DEFAULT_CONNECTION_TIMEOUT_MILLIS)
//             .socketTimeoutMillis(DEFAULT_SOCKET_TIMEOUT_MILLIS)
//             .cacheDirectory(new File(System.getProperty("java.io.tmpdir") + "/es"))
//             .cacheResponses(true);
//    }
// 
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/HttpClientFactory.java
// public class HttpClientFactory {
// 
//    public static CloseableHttpClient httpClient(final EventStoreSettings settings) {
//       if (settings.isCacheResponses()) {
//          return newClosableCachingHttpClient(settings);
//       }
//       return newClosableHttpClient(settings);
//    }
// 
//    private static CloseableHttpClient newClosableHttpClient(EventStoreSettings settings) {
//       return HttpClientBuilder.create()
// 
//             .setDefaultRequestConfig(requestConfig(settings))
//             .setDefaultCredentialsProvider(credentialsProvider(settings))
//             .setRedirectStrategy(new LaxRedirectStrategy())
//             .setRetryHandler(new StandardHttpRequestRetryHandler())
//             .setKeepAliveStrategy(new de.qyotta.eventstore.utils.DefaultConnectionKeepAliveStrategy())
//             .setConnectionManagerShared(true)
// 
//             .build();
//    }
// 
//    private static CloseableHttpClient newClosableCachingHttpClient(EventStoreSettings settings) {
//       final CacheConfig cacheConfig = CacheConfig.custom()
//             .setMaxCacheEntries(Integer.MAX_VALUE)
//             .setMaxObjectSize(Integer.MAX_VALUE)
//             .build();
// 
//       settings.getCacheDirectory()
//             .mkdirs();
// 
//       return CachingHttpClientBuilder.create()
//             .setHttpCacheStorage(new FileCacheStorage(cacheConfig, settings.getCacheDirectory()))
//             .setCacheConfig(cacheConfig)
//             .setDefaultRequestConfig(requestConfig(settings))
//             .setDefaultCredentialsProvider(credentialsProvider(settings))
//             .setRedirectStrategy(new LaxRedirectStrategy())
//             .setRetryHandler(new StandardHttpRequestRetryHandler())
//             .setKeepAliveStrategy(new de.qyotta.eventstore.utils.DefaultConnectionKeepAliveStrategy())
//             .setConnectionManagerShared(true)
// 
//             .build();
//    }
// 
//    private static RequestConfig requestConfig(final EventStoreSettings settings) {
//       return RequestConfig.custom()
//             .setConnectTimeout(settings.getConnectionTimeoutMillis())
//             .setSocketTimeout(settings.getSocketTimeoutMillis())
//             .build();
//    }
// 
//    private static CredentialsProvider credentialsProvider(final EventStoreSettings settings) {
//       final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
//       credentialsProvider.setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials(settings.getUserName(), settings.getPassword()));
//       return credentialsProvider;
//    }
// 
// }


import org.apache.http.impl.client.CloseableHttpClient;
import de.qyotta.eventstore.EventStoreSettings;
import de.qyotta.eventstore.utils.HttpClientFactory;
package de.qyotta.eventstore.communication;



public class EsContextDefaultImpl implements ESContext {

   private final CloseableHttpClient httpclient;
   private final ESReader reader;
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/EventStoreSettings.java
// @Getter
// @Setter
// @Builder(toBuilder = true)
// @ToString
// @EqualsAndHashCode
// @NoArgsConstructor(access = AccessLevel.PRIVATE)
// @AllArgsConstructor(access = AccessLevel.PRIVATE)
// @SuppressWarnings("nls")
// public class EventStoreSettings {
//    private static final String DEFAULT_PASSWORD = "changeit";
//    private static final String DEFAULT_USERNAME = "admin";
//    private static final String DEFAULT_SCHEME = "Basic";
//    private static final String DEFAULT_REALM = "ES";
//    private static final String DEFAULT_HOST = "http://127.0.0.1:2113";
//    private static final int DEFAULT_CONNECTION_TIMEOUT_MILLIS = 10000;
//    private static final int DEFAULT_SOCKET_TIMEOUT_MILLIS = 10000;
// 
//    private String host;
//    private String realm;
//    private String scheme;
//    private String userName;
//    private String password;
//    private Integer connectionTimeoutMillis;
//    private Integer socketTimeoutMillis;
//    private File cacheDirectory;
//    private boolean cacheResponses;
// 
//    public static EventStoreSettings.EventStoreSettingsBuilder withDefaults() {
//       return EventStoreSettings.builder()
//             .host(DEFAULT_HOST)
//             .realm(DEFAULT_REALM)
//             .scheme(DEFAULT_SCHEME)
//             .userName(DEFAULT_USERNAME)
//             .password(DEFAULT_PASSWORD)
//             .connectionTimeoutMillis(DEFAULT_CONNECTION_TIMEOUT_MILLIS)
//             .socketTimeoutMillis(DEFAULT_SOCKET_TIMEOUT_MILLIS)
//             .cacheDirectory(new File(System.getProperty("java.io.tmpdir") + "/es"))
//             .cacheResponses(true);
//    }
// 
// }
// 
// Path: eventstore-client/src/main/java/de/qyotta/eventstore/utils/HttpClientFactory.java
// public class HttpClientFactory {
// 
//    public static CloseableHttpClient httpClient(final EventStoreSettings settings) {
//       if (settings.isCacheResponses()) {
//          return newClosableCachingHttpClient(settings);
//       }
//       return newClosableHttpClient(settings);
//    }
// 
//    private static CloseableHttpClient newClosableHttpClient(EventStoreSettings settings) {
//       return HttpClientBuilder.create()
// 
//             .setDefaultRequestConfig(requestConfig(settings))
//             .setDefaultCredentialsProvider(credentialsProvider(settings))
//             .setRedirectStrategy(new LaxRedirectStrategy())
//             .setRetryHandler(new StandardHttpRequestRetryHandler())
//             .setKeepAliveStrategy(new de.qyotta.eventstore.utils.DefaultConnectionKeepAliveStrategy())
//             .setConnectionManagerShared(true)
// 
//             .build();
//    }
// 
//    private static CloseableHttpClient newClosableCachingHttpClient(EventStoreSettings settings) {
//       final CacheConfig cacheConfig = CacheConfig.custom()
//             .setMaxCacheEntries(Integer.MAX_VALUE)
//             .setMaxObjectSize(Integer.MAX_VALUE)
//             .build();
// 
//       settings.getCacheDirectory()
//             .mkdirs();
// 
//       return CachingHttpClientBuilder.create()
//             .setHttpCacheStorage(new FileCacheStorage(cacheConfig, settings.getCacheDirectory()))
//             .setCacheConfig(cacheConfig)
//             .setDefaultRequestConfig(requestConfig(settings))
//             .setDefaultCredentialsProvider(credentialsProvider(settings))
//             .setRedirectStrategy(new LaxRedirectStrategy())
//             .setRetryHandler(new StandardHttpRequestRetryHandler())
//             .setKeepAliveStrategy(new de.qyotta.eventstore.utils.DefaultConnectionKeepAliveStrategy())
//             .setConnectionManagerShared(true)
// 
//             .build();
//    }
// 
//    private static RequestConfig requestConfig(final EventStoreSettings settings) {
//       return RequestConfig.custom()
//             .setConnectTimeout(settings.getConnectionTimeoutMillis())
//             .setSocketTimeout(settings.getSocketTimeoutMillis())
//             .build();
//    }
// 
//    private static CredentialsProvider credentialsProvider(final EventStoreSettings settings) {
//       final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
//       credentialsProvider.setCredentials(new AuthScope(null, -1), new UsernamePasswordCredentials(settings.getUserName(), settings.getPassword()));
//       return credentialsProvider;
//    }
// 
// }


// Path: eventstore-client/src/main/java/de/qyotta/eventstore/communication/EsContextDefaultImpl.java
import org.apache.http.impl.client.CloseableHttpClient;
import de.qyotta.eventstore.EventStoreSettings;
import de.qyotta.eventstore.utils.HttpClientFactory;

package de.qyotta.eventstore.communication;



public class EsContextDefaultImpl implements ESContext {

   private final CloseableHttpClient httpclient;
   private final ESReader reader;
   private final EventStoreSettings settings;