use of org.cubeengine.module.log.action.BaseAction in project modules-extra by CubeEngine.
the class ActionEntityBlock method countUniqueEntities.
protected final int countUniqueEntities() {
Set<UUID> uuids = new HashSet<>();
uuids.add(this.entity.uuid);
int count = 1;
for (BaseAction action : this.getAttached()) {
if (!uuids.contains(((ActionEntityBlock) action).entity.uuid)) {
uuids.add(((ActionEntityBlock) action).entity.uuid);
count++;
}
}
return count;
}
use of org.cubeengine.module.log.action.BaseAction in project modules-extra by CubeEngine.
the class ListenerHanging method onHangingBreak.
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onHangingBreak(HangingBreakEvent event) {
if (event.getCause() == HangingBreakEvent.RemoveCause.PHYSICS) {
Hanging hanging = event.getEntity();
Location location = hanging.getLocation();
BaseAction cause = this.plannedHangingBreak.get(location);
if (cause != null) {
if (cause instanceof ActionPlayerBlock) {
HangingBreak action;
if (hanging instanceof ItemFrame) {
action = this.newAction(ItemframeBreak.class, location.getWorld());
ItemStack item = ((ItemFrame) hanging).getItem();
if (action != null && item != null) {
((ItemframeBreak) action).item = item;
}
} else if (hanging instanceof Painting) {
action = this.newAction(PaintingBreak.class, location.getWorld());
((PaintingBreak) action).art = ((Painting) hanging).getArt();
} else {
action = this.newAction(HangingBreak.class, location.getWorld());
}
if (action != null) {
action.setLocation(location);
action.setHanging(hanging);
action.player = ((ActionPlayerBlock) cause).player;
action.setCause(cause);
this.logAction(action);
}
}
// else // TODO
}
// else TODO this.module.getLog().info("Unexpected HangingBreakEvent");
}
}
use of org.cubeengine.module.log.action.BaseAction in project modules-extra by CubeEngine.
the class Lookup method general.
/**
* Creates a Lookup excluding nothing
*
* @param module the module
*
* @return the new Lookup
*/
public static Lookup general(Log module) {
Lookup lookup = new Lookup(module);
lookup.queryParameter = new QueryParameter(module);
// exclude none
lookup.queryParameter.setActions(new HashSet<Class<? extends BaseAction>>(), false);
lookup.queryParameter.since(new Date(System.currentTimeMillis() - TimeUnit.DAYS.toMillis(30)));
return lookup;
}
use of org.cubeengine.module.log.action.BaseAction in project modules-extra by CubeEngine.
the class QueryManager method doEmptyLogs.
private void doEmptyLogs(int amount) {
final Queue<BaseAction> logs = new LinkedList<>();
try {
// Wait if still doing inserts
this.latch.acquire();
if (queuedLogs.isEmpty()) {
return;
}
boolean onlyRefHolders = true;
for (// log <amount> next logs...
int i = 0; // log <amount> next logs...
i < amount; // log <amount> next logs...
i++) {
if (this.queuedLogs.peek() instanceof ReferenceHolder) {
if (onlyRefHolders) {
logs.offer(this.queuedLogs.poll());
}
break;
} else {
onlyRefHolders = false;
BaseAction toLog = this.queuedLogs.poll();
if (toLog == null) {
break;
}
logs.offer(toLog);
}
}
for (BaseAction log : logs) {
Integer count = this.curStatistics.get(log.getClass());
if (count == null) {
count = 0;
}
this.curStatistics.put(log.getClass(), ++count);
}
Profiler.startProfiling("logging");
int logSize = logs.size();
List<DBObject> toLog = new ArrayList<>();
for (BaseAction log : logs) {
log.save();
toLog.add(log.getTarget());
log.getTarget().put("action", log.getClass().getName());
}
// Batch insert
this.collection.insert(toLog);
long nanos = Profiler.endProfiling("logging");
timeSpend += nanos;
logsLogged += logSize;
if (logSize == batchSize) {
timeSpendFullLoad += nanos;
logsLoggedFullLoad += logSize;
}
if (logSize > this.module.getConfiguration().showLogInfoInConsole) {
this.module.getLog().debug("{} logged in: {} ms | remaining logs: {} | AVG/AVG-FULL {} / {} micros", logSize, TimeUnit.NANOSECONDS.toMillis(nanos), queuedLogs.size(), TimeUnit.NANOSECONDS.toMicros(timeSpend / logsLogged), TimeUnit.NANOSECONDS.toMicros(timeSpendFullLoad / logsLoggedFullLoad));
}
} catch (Exception ex) {
module.getLog().error(ex, "Error while logging!");
this.queuedLogs.addAll(logs);
if (latch.availablePermits() == 0) {
this.latch.release();
}
// end profiling so we can start again later
Profiler.endProfiling("logging");
} finally {
if (latch.availablePermits() == 0) {
latch.release();
}
if (!queuedLogs.isEmpty()) {
this.futureStore = this.storeExecutor.submit(this.storeRunner);
} else {
if (shutDownLatch != null) {
this.shutDownLatch.countDown();
}
}
}
}
use of org.cubeengine.module.log.action.BaseAction in project modules-extra by CubeEngine.
the class QueryManager method doQueryLookup.
private void doQueryLookup() {
if (queuedLookups.isEmpty()) {
return;
}
QueuedSqlParams poll = this.queuedLookups.poll();
final QueryAction queryAction = poll.action;
final Lookup lookup = poll.lookup;
final User user = poll.user;
// limit 10000
DBCursor cursor = this.collection.find(poll.query);
QueryResults results = new QueryResults(lookup, module);
for (DBObject entry : cursor) {
try {
@SuppressWarnings("unchecked") Class<? extends BaseAction> action = (Class<? extends BaseAction>) Class.forName((String) entry.get("action"));
results.addResult(module.getCore().getConfigFactory().load(action, entry));
} catch (ClassNotFoundException e) {
module.getLog().warn(e, "Could not find Action for DBObject! {}", entry.get("action"));
}
}
lookup.setQueryResults(results);
if (user != null && user.isOnline()) {
module.getCore().getTaskManager().runTask(module, (Runnable) () -> {
switch(queryAction) {
case SHOW:
lookup.show(user);
return;
case ROLLBACK:
lookup.rollback(user, false);
return;
case ROLLBACK_PREVIEW:
lookup.rollback(user, true);
return;
case REDO:
lookup.redo(user, false);
return;
case REDO_PREVIEW:
lookup.redo(user, true);
}
});
}
if (!queuedLookups.isEmpty()) {
this.futureLookup = this.lookupExecutor.submit(this.lookupRunner);
}
}
Aggregations