Search in sources :

Example 1 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class ActionFactory method createHangingItem.

/**
 * HangingItemAction.
 *
 * @param actionType type
 * @param hanging    hanging
 * @param nonPlayer  nonPlayer
 * @return Handler
 */
public static Handler createHangingItem(String actionType, Hanging hanging, String nonPlayer) {
    final Handler a = createHangingItem(actionType, hanging, (OfflinePlayer) null);
    a.setSourceName(nonPlayer);
    return a;
}
Also used : Handler(me.botsko.prism.api.actions.Handler)

Example 2 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class ActionFactory method createBlock.

/**
 * Create Handler.
 *
 * @param actionType type
 * @param block      block
 * @param nonPlayer  not a player
 * @return Handler
 */
public static Handler createBlock(String actionType, BlockState block, String nonPlayer) {
    final Handler a = createBlock(actionType, block, (OfflinePlayer) null);
    a.setSourceName(nonPlayer);
    return a;
}
Also used : Handler(me.botsko.prism.api.actions.Handler)

Example 3 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class RecordingTask method insertActionsIntoDatabase.

/**
 * Create a Insertion.
 */
void insertActionsIntoDatabase() {
    int actionsRecorded = 0;
    int perBatch = actionsPerInsert;
    if (perBatch < 1) {
        perBatch = 1000;
    }
    if (!RecordingQueue.getQueue().isEmpty()) {
        if (Prism.getPrismDataSource().isPaused()) {
            Prism.log("Prism database paused. An external actor has paused database processing..." + "scheduling next recording");
            scheduleNextRecording();
            return;
        }
        long start = System.currentTimeMillis();
        Prism.debug("Beginning batch insert from queue. " + start);
        try (Connection conn = Prism.getPrismDataSource().getConnection()) {
            if ((conn == null) || (conn.isClosed())) {
                if (RecordingManager.failedDbConnectionCount == 0) {
                    Prism.log("Prism database error. Connection should be there but it's not. " + "Leaving actions to log in queue.");
                }
                RecordingManager.failedDbConnectionCount++;
                if (RecordingManager.failedDbConnectionCount > plugin.getConfig().getInt("prism.query.max-failures-before-wait")) {
                    Prism.log("Too many problems connecting. Giving up for a bit.");
                    scheduleNextRecording();
                }
                Prism.debug("Database connection still missing, incrementing count.");
                return;
            } else {
                RecordingManager.failedDbConnectionCount = 0;
            }
        } catch (SQLException e) {
            e.printStackTrace();
            Prism.getPrismDataSource().handleDataSourceException(e);
            return;
        }
        InsertQuery batchedQuery;
        try {
            batchedQuery = Prism.getPrismDataSource().getDataInsertionQuery();
            batchedQuery.createBatch();
        } catch (Exception e) {
            e.printStackTrace();
            if (e instanceof SQLException) {
                Prism.getPrismDataSource().handleDataSourceException((SQLException) e);
            }
            Prism.debug("Database connection issue;");
            RecordingManager.failedDbConnectionCount++;
            return;
        }
        int i = 0;
        while (!RecordingQueue.getQueue().isEmpty()) {
            final Handler a = RecordingQueue.getQueue().poll();
            // poll() returns null if queue is empty
            if (a == null) {
                break;
            }
            if (a.isCanceled()) {
                continue;
            }
            batchedQuery.insertActionIntoDatabase(a);
            actionsRecorded++;
            // Break out of the loop and just commit what we have
            if (i >= perBatch) {
                Prism.debug("Recorder: Batch max exceeded, running insert. Queue remaining: " + RecordingQueue.getQueue().size());
                break;
            }
            i++;
        }
        long batchDoneTime = System.currentTimeMillis();
        long batchingTime = batchDoneTime - start;
        // The main delay is here
        try {
            batchedQuery.processBatch();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // Save the current count to the queue for short historical data
        long batchProcessedEnd = System.currentTimeMillis();
        long batchRunTime = batchProcessedEnd - batchDoneTime;
        plugin.queueStats.addRunInfo(new QueueStats.TaskRunInfo(actionsRecorded, batchingTime, batchRunTime));
    }
}
Also used : InsertQuery(me.botsko.prism.database.InsertQuery) SQLException(java.sql.SQLException) Connection(java.sql.Connection) Handler(me.botsko.prism.api.actions.Handler) QueueStats(me.botsko.prism.measurement.QueueStats) SQLException(java.sql.SQLException)

Example 4 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class ActionFactory method createPortal.

/**
 * PortalCreateHandler.
 *
 * @param actionType type
 * @param newBlockState new state
 * @param oldBlockState old state
 * @param nonPlayer  nonplayer
 * @return Handler
 */
public static Handler createPortal(String actionType, BlockState newBlockState, BlockState oldBlockState, String nonPlayer) {
    final Handler a = createPortal(actionType, newBlockState, oldBlockState, (OfflinePlayer) null);
    a.setSourceName(nonPlayer);
    return a;
}
Also used : Handler(me.botsko.prism.api.actions.Handler)

Example 5 with Handler

use of me.botsko.prism.api.actions.Handler in project Prism-Bukkit by prism.

the class ActionFactory method createBlockChange.

/**
 * Handles Spread, Fade and Form events.
 *
 * @param actionType type
 * @param loc        Location
 * @param oldMat     old
 * @param oldData    old data
 * @param newMat     new
 * @param newData    new data
 * @param nonPlayer  nonplayer.
 * @return Handler.
 */
public static Handler createBlockChange(String actionType, Location loc, Material oldMat, BlockData oldData, Material newMat, BlockData newData, String nonPlayer) {
    final Handler a = createBlockChange(actionType, loc, oldMat, oldData, newMat, newData, (OfflinePlayer) null);
    a.setSourceName(nonPlayer);
    return a;
}
Also used : Handler(me.botsko.prism.api.actions.Handler)

Aggregations

Handler (me.botsko.prism.api.actions.Handler)20 QueryResult (me.botsko.prism.actionlibs.QueryResult)6 SubHandler (me.botsko.prism.commandlibs.SubHandler)5 ActionMessage (me.botsko.prism.actionlibs.ActionMessage)4 ActionsQuery (me.botsko.prism.actionlibs.ActionsQuery)4 QueryParameters (me.botsko.prism.actionlibs.QueryParameters)4 EventHandler (org.bukkit.event.EventHandler)4 Connection (java.sql.Connection)3 SQLException (java.sql.SQLException)3 Player (org.bukkit.entity.Player)3 PreparedStatement (java.sql.PreparedStatement)2 BlockStateChange (me.botsko.prism.api.BlockStateChange)2 BlockState (org.bukkit.block.BlockState)2 ItemStack (org.bukkit.inventory.ItemStack)2 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Pattern (java.util.regex.Pattern)1