Search in sources :

Example 1 with BaseAction

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;
}
Also used : BaseAction(org.cubeengine.module.log.action.BaseAction) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 2 with BaseAction

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");
    }
}
Also used : ActionPlayerBlock(org.cubeengine.module.log.action.block.player.ActionPlayerBlock) Hanging(org.bukkit.entity.Hanging) BaseAction(org.cubeengine.module.log.action.BaseAction) ItemFrame(org.bukkit.entity.ItemFrame) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Location(org.spongepowered.api.world.Location) Painting(org.bukkit.entity.Painting) EventHandler(org.bukkit.event.EventHandler)

Example 3 with BaseAction

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;
}
Also used : BaseAction(org.cubeengine.module.log.action.BaseAction) Date(java.util.Date)

Example 4 with BaseAction

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();
            }
        }
    }
}
Also used : ReferenceHolder(org.cubeengine.module.log.action.ReferenceHolder) ArrayList(java.util.ArrayList) BaseAction(org.cubeengine.module.log.action.BaseAction) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) LinkedList(java.util.LinkedList)

Example 5 with BaseAction

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);
    }
}
Also used : User(org.cubeengine.libcube.service.user.User) BaseAction(org.cubeengine.module.log.action.BaseAction) DBObject(com.mongodb.DBObject) BasicDBObject(com.mongodb.BasicDBObject) DBCursor(com.mongodb.DBCursor)

Aggregations

BaseAction (org.cubeengine.module.log.action.BaseAction)9 BasicDBObject (com.mongodb.BasicDBObject)3 DBObject (com.mongodb.DBObject)3 LinkedList (java.util.LinkedList)3 TreeSet (java.util.TreeSet)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 UUID (java.util.UUID)2 Coordinate (org.cubeengine.module.log.action.BaseAction.Coordinate)2 DBCursor (com.mongodb.DBCursor)1 Date (java.util.Date)1 Hanging (org.bukkit.entity.Hanging)1 ItemFrame (org.bukkit.entity.ItemFrame)1 Painting (org.bukkit.entity.Painting)1 EventHandler (org.bukkit.event.EventHandler)1 User (org.cubeengine.libcube.service.user.User)1 Redoable (org.cubeengine.module.log.action.Redoable)1 ReferenceHolder (org.cubeengine.module.log.action.ReferenceHolder)1