package cn.edu.ruc.iir.producer;

import cn.edu.ruc.iir.model.Message;
import cn.edu.ruc.iir.model.Table;

/**
 * Producer interface
 *
 * @author guodong
 */
public interface Producer<T>
{
    /**
     * Register a topic to corresponding table.
     *
     * @param db database name
     * @param table table name
     * @param topic kafka topic name
     * */
    void registerTopic(String db, String table, String topic);

    /**
     * Send a message to table
     *
     * @param table table object
     * @param message message object
     *
     * @return if succeed, return true, else false
     * */
    boolean sendMessage(Table table, Message message);

    boolean sendMessage(Table table, T key, String value, long timestamp);

    boolean sendMessage(Table table, T key, String value, long timestamp, String delimiter);

    /**
     * Load messages in file into table
     *
     * @param table table object
     * @param file path of file which contains messages
     * @param delimiter delimiter for each message, which contains multiple fields
     * */
    boolean loadMessages(Table table, String file, String delimiter);

    /**
     * Shutdown producer
     * */
    void shutdown();
}
