// Path: appender-core/src/main/java/com/van/logging/IPublishHelper.java
// public interface IPublishHelper<T> {
//     /**
//      * A publish batch is starting.  This is a good place to (re)initialize
//      * a buffer.
//      *
//      * @param context publish context providing useful properties for the
//      * publish operation
//      */
//     void start(PublishContext context);
// 
//     /**
//      * A log event should be published.  Implementations may want to accumulate
//      * this in a batch until {{@link #end(PublishContext)}
//      *
//      * @param context publish context providing useful properties for the
//      * publish operation
//      * @param sequence counter of the sequence of this event in the batch
//      * @param event the log event
//      */
//     void publish(PublishContext context, int sequence, T event);
// 
//     /**
//      * A publish batch has ended.  Implementations should conclude a batch
//      * and clean up resources here.
//      *
//      * @param context publish context providing useful properties for the
//      * publish operation
//      */
//     void end(PublishContext context);
// }
// 
// Path: appender-core/src/main/java/com/van/logging/PublishContext.java
// public class PublishContext {
//     private final String cacheName;
//     private final String hostName;
//     private final String[] tags;
// 
//     /**
//      * Creates an instance with the data provided
//      *
//      * @param cacheName name of the cache used to distinguish it from other caches
//      * @param hostName the host name where the logs are collected (typically
//      * 	the name of the local host)
//      * @param tags additional tags for the event that the logger was initialized with
//      */
//     public PublishContext(String cacheName, String hostName, String[] tags) {
//         this.cacheName = cacheName;
//         this.hostName = hostName;
//         this.tags = tags;
//     }
// 
//     public String getCacheName() {
//         return cacheName;
//     }
// 
//     public String getHostName() {
//         return hostName;
//     }
// 
//     public String[] getTags() {
//         return tags;
//     }
// 
// }
// 
// Path: appender-core/src/main/java/com/van/logging/utils/StringUtils.java
// public class StringUtils {
// 
//     /**
//      * Checks to see if a String is defined and not empty after trimming
//      *
//      * @param s the String to test
//      *
//      * @return true if the string is not null and is not empty
//      */
//     public static boolean isTruthy(String s) {
//         return (null != s && !s.trim().isEmpty());
//     }
// 
//     /**
//      * If the string passed in is not blank or null and did not end with the trailing value, then the trailing value
//      * will be appended to it in the returned value.
//      *
//      * @param s the string to conditionally add the trailing value to. If null, then null will be returned.
//      * @param trailing the trailing value to append. If null, then s will be returned unmodified.
//      *
//      * @return the string s with the trailing value appended as necessary.
//      */
//     public static String addTrailingIfNeeded(String s, String trailing) {
//         String value = s;
//         if ((null != s) && (null != trailing)) {
//             if (isTruthy(s) && !s.endsWith(trailing)) {
//                 value = s + trailing;
//             }
//         }
//         return value;
//     }
// }
// 
// Path: appender-core/src/main/java/com/van/logging/Event.java
// public class Event implements Serializable {
// 
//     static final long serialVersionUID = 1000L;
// 
//     private final String source;
//     private final String type;
//     private final String threadName;
// 
//     private final String message;
// 
//     public Event(String source, String type, String message) {
//         this(source, type, message, Thread.currentThread().getName());
//     }
// 
//     public Event(String source, String type, String message, String threadName) {
//         Objects.requireNonNull(source);
//         Objects.requireNonNull(type);
//         Objects.requireNonNull(message);
//         Objects.requireNonNull(threadName);
//         this.source = source;
//         this.type = type;
//         this.threadName = threadName;
//         this.message = message;
//     }
// 
//     public String getSource() {
//         return source;
//     }
// 
//     public String getType() {
//         return type;
//     }
// 
//     public String getThreadName() {
//         return threadName;
//     }
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("%s %s:%s:%s", threadName, source, type, message);
//     }
// }


import com.van.logging.IPublishHelper;
import com.van.logging.PublishContext;
import com.van.logging.utils.StringUtils;
import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.*;
import org.elasticsearch.common.xcontent.XContentBuilder;
import com.van.logging.Event;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
    public void end(PublishContext context) {
        try {
            if ((null != client) && (null != bulkRequest)) {
                BulkResponse response = client.bulk(bulkRequest, RequestOptions.DEFAULT);
                if (response.hasFailures()) {
                    System.err.println("Elasticsearch publish failures: " + response.buildFailureMessage());
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (null != client) {
                    client.close();
                }
                bulkRequest = null;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static IElasticsearchPublishHelper getPublishHelper(
        String publishHelperNameSpec, ClassLoader classLoader) {
        return getPublishHelper(publishHelperNameSpec, classLoader, false);
    }

    public static IElasticsearchPublishHelper getPublishHelper(
        String publishHelperNameSpec, ClassLoader classLoader, boolean verbose) {
        ElasticsearchPublishHelper helper = null;
// Path: appender-core/src/main/java/com/van/logging/IPublishHelper.java
// public interface IPublishHelper<T> {
//     /**
//      * A publish batch is starting.  This is a good place to (re)initialize
//      * a buffer.
//      *
//      * @param context publish context providing useful properties for the
//      * publish operation
//      */
//     void start(PublishContext context);
// 
//     /**
//      * A log event should be published.  Implementations may want to accumulate
//      * this in a batch until {{@link #end(PublishContext)}
//      *
//      * @param context publish context providing useful properties for the
//      * publish operation
//      * @param sequence counter of the sequence of this event in the batch
//      * @param event the log event
//      */
//     void publish(PublishContext context, int sequence, T event);
// 
//     /**
//      * A publish batch has ended.  Implementations should conclude a batch
//      * and clean up resources here.
//      *
//      * @param context publish context providing useful properties for the
//      * publish operation
//      */
//     void end(PublishContext context);
// }
// 
// Path: appender-core/src/main/java/com/van/logging/PublishContext.java
// public class PublishContext {
//     private final String cacheName;
//     private final String hostName;
//     private final String[] tags;
// 
//     /**
//      * Creates an instance with the data provided
//      *
//      * @param cacheName name of the cache used to distinguish it from other caches
//      * @param hostName the host name where the logs are collected (typically
//      * 	the name of the local host)
//      * @param tags additional tags for the event that the logger was initialized with
//      */
//     public PublishContext(String cacheName, String hostName, String[] tags) {
//         this.cacheName = cacheName;
//         this.hostName = hostName;
//         this.tags = tags;
//     }
// 
//     public String getCacheName() {
//         return cacheName;
//     }
// 
//     public String getHostName() {
//         return hostName;
//     }
// 
//     public String[] getTags() {
//         return tags;
//     }
// 
// }
// 
// Path: appender-core/src/main/java/com/van/logging/utils/StringUtils.java
// public class StringUtils {
// 
//     /**
//      * Checks to see if a String is defined and not empty after trimming
//      *
//      * @param s the String to test
//      *
//      * @return true if the string is not null and is not empty
//      */
//     public static boolean isTruthy(String s) {
//         return (null != s && !s.trim().isEmpty());
//     }
// 
//     /**
//      * If the string passed in is not blank or null and did not end with the trailing value, then the trailing value
//      * will be appended to it in the returned value.
//      *
//      * @param s the string to conditionally add the trailing value to. If null, then null will be returned.
//      * @param trailing the trailing value to append. If null, then s will be returned unmodified.
//      *
//      * @return the string s with the trailing value appended as necessary.
//      */
//     public static String addTrailingIfNeeded(String s, String trailing) {
//         String value = s;
//         if ((null != s) && (null != trailing)) {
//             if (isTruthy(s) && !s.endsWith(trailing)) {
//                 value = s + trailing;
//             }
//         }
//         return value;
//     }
// }
// 
// Path: appender-core/src/main/java/com/van/logging/Event.java
// public class Event implements Serializable {
// 
//     static final long serialVersionUID = 1000L;
// 
//     private final String source;
//     private final String type;
//     private final String threadName;
// 
//     private final String message;
// 
//     public Event(String source, String type, String message) {
//         this(source, type, message, Thread.currentThread().getName());
//     }
// 
//     public Event(String source, String type, String message, String threadName) {
//         Objects.requireNonNull(source);
//         Objects.requireNonNull(type);
//         Objects.requireNonNull(message);
//         Objects.requireNonNull(threadName);
//         this.source = source;
//         this.type = type;
//         this.threadName = threadName;
//         this.message = message;
//     }
// 
//     public String getSource() {
//         return source;
//     }
// 
//     public String getType() {
//         return type;
//     }
// 
//     public String getThreadName() {
//         return threadName;
//     }
// 
//     public String getMessage() {
//         return message;
//     }
// 
//     @Override
//     public String toString() {
//         return String.format("%s %s:%s:%s", threadName, source, type, message);
//     }
// }


// Path: appender-core/src/main/java/com/van/logging/elasticsearch/ElasticsearchPublishHelper.java
import com.van.logging.IPublishHelper;
import com.van.logging.PublishContext;
import com.van.logging.utils.StringUtils;
import org.apache.http.HttpHost;
import org.elasticsearch.action.bulk.BulkRequest;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.*;
import org.elasticsearch.common.xcontent.XContentBuilder;
import com.van.logging.Event;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;

    public void end(PublishContext context) {
        try {
            if ((null != client) && (null != bulkRequest)) {
                BulkResponse response = client.bulk(bulkRequest, RequestOptions.DEFAULT);
                if (response.hasFailures()) {
                    System.err.println("Elasticsearch publish failures: " + response.buildFailureMessage());
                }
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            try {
                if (null != client) {
                    client.close();
                }
                bulkRequest = null;
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    public static IElasticsearchPublishHelper getPublishHelper(
        String publishHelperNameSpec, ClassLoader classLoader) {
        return getPublishHelper(publishHelperNameSpec, classLoader, false);
    }

    public static IElasticsearchPublishHelper getPublishHelper(
        String publishHelperNameSpec, ClassLoader classLoader, boolean verbose) {
        ElasticsearchPublishHelper helper = null;
        if (StringUtils.isTruthy(publishHelperNameSpec)) {