All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.sumologic.log4j.http.SumoBufferFlushingTask Maven / Gradle / Ivy

There is a newer version: 2.12
Show newest version
/**
 *    _____ _____ _____ _____    __    _____ _____ _____ _____
 *   |   __|  |  |     |     |  |  |  |     |   __|     |     |
 *   |__   |  |  | | | |  |  |  |  |__|  |  |  |  |-   -|   --|
 *   |_____|_____|_|_|_|_____|  |_____|_____|_____|_____|_____|
 *
 *                UNICORNS AT WARP SPEED SINCE 2010
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.sumologic.log4j.http;

import com.sumologic.log4j.aggregation.BufferFlushingTask;
import com.sumologic.log4j.queue.BufferWithEviction;
import org.apache.log4j.helpers.LogLog;

import java.util.List;

/**
 * @author: Jose Muniz ([email protected])
 */
public class SumoBufferFlushingTask extends BufferFlushingTask {

    private SumoHttpSender sender;
    private long maxFlushInterval;
    private long messagesPerRequest;
    private String name;

    public SumoBufferFlushingTask(BufferWithEviction queue) {
        super(queue);
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setSender(SumoHttpSender sender) {
        this.sender = sender;
    }

    public void setMessagesPerRequest(long messagesPerRequest) {
        this.messagesPerRequest = messagesPerRequest;
    }

    public void setMaxFlushInterval(long maxFlushInterval) {
        this.maxFlushInterval = maxFlushInterval;
    }

    @Override
    protected long getMaxFlushInterval() {
        return maxFlushInterval;
    }

    @Override
    protected long getMessagesPerRequest() {
        return messagesPerRequest;
    }

    @Override
    protected String getName() {
        return name;
    }

    @Override
    protected String aggregate(List messages) {
        StringBuilder builder = new StringBuilder(messages.size() * 10);
        for (String message: messages) {
            builder.append(message);
        }
        return builder.toString();
    }

    @Override
    protected void sendOut(String body, String name) {
        if (sender != null && sender.isInitialized()) {
            sender.send(body, name);
        } else {
            LogLog.error("HTTPSender is not initialized");
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy