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;
}
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;
}
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));
}
}
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;
}
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;
}
Aggregations