protected EventLog wrap(String cls, IObject obj) { EventLog el = new EventLog(); el.setEntityType(cls); el.setEntityId(obj.getId()); el.setAction("UPDATE"); return el; } }
@Override public Object retrieve(String field) { if (field == null) { return null; } else if (field.equals(ID)) { return getId(); } else if (field.equals(ENTITYID)) { return getEntityId(); } else if (field.equals(ENTITYTYPE)) { return getEntityType(); } else if (field.equals(ACTION)) { return getAction(); } else if (field.equals(EVENT)) { return getEvent(); } else if (field.equals(DETAILS)) { return getDetails(); } else { if (_dynamicFields != null) { return _dynamicFields.get(field); } return null; } }
@Override public void putAt(String field, Object value) { if (field == null) { return; } else if (field.equals(ID)) { setId((Long) value); } else if (field.equals(ENTITYID)) { setEntityId((java.lang.Long)value); } else if (field.equals(ENTITYTYPE)) { setEntityType((java.lang.String)value); } else if (field.equals(ACTION)) { setAction((java.lang.String)value); } else if (field.equals(EVENT)) { setEvent((ome.model.meta.Event)value); } else if (field.equals(DETAILS)) { setDetails((ome.model.internal.Details)value); } else { if (_dynamicFields == null) { _dynamicFields = new java.util.HashMap<String, Object>(); } _dynamicFields.put(field,value); } }
public EventLog( java.lang.Long _entityId,java.lang.String _entityType,java.lang.String _action,ome.model.meta.Event _event ) { this(null, true); setEntityId(_entityId); setEntityType(_entityType); setAction(_action); setEvent(_event); }
/** * Main constructor. */ public EventLog (Long id, boolean loaded) { setId(id); if (loaded) { getDetails().setContext(this); } else { if (this.id == null) { throw new ApiUsageException("Id cannot be null for a proxy"); } unload(); } }
sb.append("EventLogs in readOnly transaction:\n"); for (EventLog eventLog : logs) { sb.append(eventLog.getAction()); sb.append(" "); sb.append(eventLog); sb.append(eventLog.getEntityType()); sb.append(" "); sb.append(eventLog.getEntityId()); sb.append("\b"); List<Object[]> batchData = new ArrayList<Object[]>(); for (EventLog l : logs) { Event e = l.getEvent(); if (e.getId() == null) { throw new RuntimeException("Transient event"); .add(new Object[] { id++, -35L, l.getEntityId(), l.getEntityType(), l.getAction(), l.getEvent().getId() });
/** * Loads {@link #reps} {@link EventLog} instances and returns them. * This is the first phase used by the {@link PixelDataThread}. A later * phase will invoke {@link #handleEventLog(EventLog, Session, ServiceFactory)} * with the returned instance. */ @Transactional(readOnly = false) public Object doWork(Session session, ServiceFactory sf) { List<EventLog> logs = new ArrayList<EventLog>(); while (logs.size() < this.reps) { try { logs.add(loader.next()); } catch (NoSuchElementException nsee) { if (!loader.hasNext()) { break; }; } } // Preload for (EventLog el : logs) { EventLog live = (EventLog) session.get(EventLog.class, el.getId()); Event evt = live.getEvent(); el.setEvent(evt); } return logs; }
/** * Removes and returns the next {@link EventLog} instance or null if none is * present. Also cleans up any tracking information for the given * {@link EventLog}. * * @return See above. */ public synchronized EventLog remove() { if (logs.size() == 0) { contained.clear(); return null; // EARLY EXIT } adding = false; EventLog log = logs.remove(0); // None of these can be null as long as the log is still contained Map<String, Set<String>> class2action = contained .get(log.getEntityId()); Set<String> actions = class2action.get(log.getEntityType()); assert actions.remove(log.getAction()); if (actions.size() == 0) { class2action.remove(log.getEntityType()); if (class2action.size() == 0) { contained.remove(log.getEntityId()); } } return log; }
/** * use like removeEventLog */ public void removeEventLogSet(java.util.Collection<ome.model.meta.EventLog> targets ) { if (! _loaded ) errorIfUnloaded(); if (getLogs() == null) { throwNullCollectionException("Logs"); } getLogs().removeAll( targets ); java.util.Iterator<ome.model.meta.EventLog> it = targets.iterator(); while ( it.hasNext() ) { ome.model.meta.EventLog target = it.next(); target.setEvent ( null ); } }
/** * Handles only single elements from the {@link PersistentEventLogLoader} * in order to keep transactions short and safe. * * @see <a href="https://trac.openmicroscopy.org/ome/ticket/5814">ticket:5814</a> */ public void handleEventLog(EventLog eventLog, Session session, ServiceFactory sf) { final long start = System.currentTimeMillis(); final boolean handled = process(eventLog.getEntityId(), sf, session); final String msg = String.format("EventLog:%s(entityId=%s) [%s ms.]", eventLog.getId(), eventLog.getEntityId(), (System.currentTimeMillis() - start)); if (handled) { log.info("HANDLED "+ msg); } else { log.debug("SKIPPED "+ msg); } }
p.addId(el.getEntityId()); sb.append(klass); sb.append(":"); sb.append(el.getEntityId()); sb.append(" - "); sb.append(el.getAction()); sb.append("\n");
public ome.model.meta.EventLog newInstance() { return new ome.model.meta.EventLog(); }
public void rollback(EventLog el) { if (excludes.contains(el.getEntityType())) { if (log.isDebugEnabled()) { log.debug("Skipping rollback of " + el.getEntityType()); } } backlog.add(el); }
public Collection<EventLog> matches(String klass, String action) { List<EventLog> rv = new ArrayList<EventLog>(); for (EventLog el : logs.get(klass)) { if (el.getAction().equals(action)) { rv.add(el); } } return rv; } }
@Override public long more() { long diff = lastEventLog().getEntityId() - getCurrentId(); return diff < 0 ? 0 : diff; }
logger.info("Backlog locked:" + log.getEntityType() + ":Id_" + log.getEntityId()); if (log == null || log.getEntityType() == null || log.getEntityId() == null || log.getAction() == null) { throw new IllegalArgumentException( "EventLog must contain entityType, entityId, and action"); .get(log.getEntityId()); contained.put(log.getEntityId(), class2action); Set<String> actions = class2action.get(log.getEntityType()); if (actions == null) { actions = new HashSet<String>(); class2action.put(log.getEntityType(), actions); boolean contained = actions.contains(log.getAction()); if (contained) { if (logger.isInfoEnabled()) { logger.info("Already in backlog:" + log.getEntityType() + ":Id_" + log.getEntityId()); actions.add(log.getAction()); logs.add(log); if (logger.isInfoEnabled()) { logger.info("Added to backlog:" + log.getEntityType() + ":Id_" + log.getEntityId());
/** * use like addEventLog. */ public void addEventLogSet(java.util.Collection<ome.model.meta.EventLog> targets) { if (! _loaded ) errorIfUnloaded(); if (getLogs() == null) { throwNullCollectionException("Logs"); } getLogs().addAll( targets ); java.util.Iterator<ome.model.meta.EventLog> it = targets.iterator(); while ( it.hasNext() ) { ome.model.meta.EventLog target = it.next(); // If this relationship is not ordered, then we will // "attempt" the setting even if it is loaded. if (target != null) { target.setEvent ( this ); } } }
public ome.model.meta.EventLog proxy() { return new ome.model.meta.EventLog(this.id, false); }
public void clearLogs() { if (log.isDebugEnabled()) { log.debug("Clearing EventLogs."); } List<EventLog> logs = getLogs(); if (!logs.isEmpty()) { boolean foundAdminType = false; final Multimap<String, EventLog> map = ArrayListMultimap.create(); for (EventLog el : getLogs()) { String t = el.getEntityType(); if (Experimenter.class.getName().equals(t) || ExperimenterGroup.class.getName().equals(t) || GroupExperimenterMap.class.getName().equals(t)) { foundAdminType = true; } map.put(t, el); } if (ctx == null) { log.error("No context found for publishing"); } else { // publish message if administrative type is modified if (foundAdminType) { this.ctx.publishEvent(new UserGroupUpdateEvent(this)); } this.ctx.publishEvent(new EventLogsMessage(this, map)); } } cd.clearLogs(); }
protected void handleEventLog(FullTextSession session, EventLog eventLog) { String act = eventLog.getAction(); Class type = asClassOrNull(eventLog.getEntityType()); if (type != null) { long id = eventLog.getEntityId();