Search in sources :

Example 1 with LockModeOwner

use of org.exist.storage.lock.LockTable.LockModeOwner in project exist by eXist-db.

the class LockTableUtils method stateToXml.

public static void stateToXml(final LockTable lockTable, final boolean includeStack, final Writer writer) throws XMLStreamException {
    final GregorianCalendar cal = new GregorianCalendar();
    final Map<String, Map<LockType, List<LockModeOwner>>> attempting = lockTable.getAttempting();
    final Map<String, Map<LockType, Map<LockMode, Map<String, LockCountTraces>>>> acquired = lockTable.getAcquired();
    final XMLOutputFactory outputFactory = XMLOutputFactory.newFactory();
    final XMLStreamWriter xmlWriter = outputFactory.createXMLStreamWriter(writer);
    xmlWriter.writeStartDocument();
    xmlWriter.writeStartElement("lock-table");
    final XMLGregorianCalendar xmlCal = TimeUtils.getInstance().newXMLGregorianCalendar(cal);
    xmlWriter.writeAttribute("timestamp", xmlCal.toXMLFormat());
    // acquired locks
    xmlWriter.writeStartElement("acquired");
    for (final Map.Entry<String, Map<LockType, Map<LockMode, Map<String, LockCountTraces>>>> acquire : acquired.entrySet()) {
        xmlWriter.writeStartElement("lock");
        xmlWriter.writeAttribute("id", acquire.getKey());
        for (final Map.Entry<LockType, Map<LockMode, Map<String, LockCountTraces>>> type : acquire.getValue().entrySet()) {
            xmlWriter.writeStartElement("type");
            xmlWriter.writeAttribute("id", type.getKey().name());
            for (final Map.Entry<LockMode, Map<String, LockCountTraces>> lockModeOwners : type.getValue().entrySet()) {
                xmlWriter.writeStartElement("mode");
                xmlWriter.writeAttribute("id", lockModeOwners.getKey().name());
                for (final Map.Entry<String, LockCountTraces> ownerHoldCount : lockModeOwners.getValue().entrySet()) {
                    xmlWriter.writeStartElement("thread");
                    xmlWriter.writeAttribute("id", ownerHoldCount.getKey());
                    final LockCountTraces holdCount = ownerHoldCount.getValue();
                    xmlWriter.writeAttribute("hold-count", Integer.toString(holdCount.count));
                    if (holdCount.traces != null && includeStack) {
                        for (int i = 0; i < holdCount.traces.size(); i++) {
                            xmlWriter.writeStartElement("stack-trace");
                            xmlWriter.writeAttribute("index", Integer.toString(i));
                            final StackTraceElement[] trace = holdCount.traces.get(i);
                            for (int j = 0; j < trace.length; j++) {
                                xmlWriter.writeStartElement("call");
                                final StackTraceElement call = trace[j];
                                xmlWriter.writeAttribute("index", Integer.toString(j));
                                xmlWriter.writeAttribute("class", call.getClassName());
                                xmlWriter.writeAttribute("method", call.getMethodName());
                                xmlWriter.writeAttribute("file", call.getFileName());
                                xmlWriter.writeAttribute("line", Integer.toString(call.getLineNumber()));
                                xmlWriter.writeCharacters(call.toString());
                                xmlWriter.writeEndElement();
                            }
                            xmlWriter.writeEndElement();
                        }
                    }
                    xmlWriter.writeEndElement();
                }
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeEndElement();
        }
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();
    // attempting locks
    xmlWriter.writeStartElement("attempting");
    for (final Map.Entry<String, Map<Lock.LockType, List<LockTable.LockModeOwner>>> attempt : attempting.entrySet()) {
        xmlWriter.writeStartElement("lock");
        xmlWriter.writeAttribute("id", attempt.getKey());
        for (final Map.Entry<Lock.LockType, List<LockTable.LockModeOwner>> type : attempt.getValue().entrySet()) {
            xmlWriter.writeStartElement("type");
            xmlWriter.writeAttribute("id", type.getKey().name());
            for (final LockTable.LockModeOwner lockModeOwner : type.getValue()) {
                xmlWriter.writeStartElement("mode");
                xmlWriter.writeAttribute("id", lockModeOwner.getLockMode().name());
                xmlWriter.writeStartElement("thread");
                xmlWriter.writeAttribute("id", lockModeOwner.getOwnerThread());
                if (lockModeOwner.trace != null && includeStack) {
                    xmlWriter.writeStartElement("stack-trace");
                    for (int i = 0; i < lockModeOwner.trace.length; i++) {
                        xmlWriter.writeStartElement("call");
                        final StackTraceElement call = lockModeOwner.trace[i];
                        xmlWriter.writeAttribute("index", Integer.toString(i));
                        xmlWriter.writeAttribute("class", call.getClassName());
                        xmlWriter.writeAttribute("method", call.getMethodName());
                        xmlWriter.writeAttribute("file", call.getFileName());
                        xmlWriter.writeAttribute("line", Integer.toString(call.getLineNumber()));
                        xmlWriter.writeCharacters(call.toString());
                        xmlWriter.writeEndElement();
                    }
                    xmlWriter.writeEndElement();
                }
                xmlWriter.writeEndElement();
                xmlWriter.writeEndElement();
            }
            xmlWriter.writeEndElement();
        }
        xmlWriter.writeEndElement();
    }
    xmlWriter.writeEndElement();
    xmlWriter.writeEndElement();
    xmlWriter.writeEndDocument();
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) LockType(org.exist.storage.lock.Lock.LockType) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) LockModeOwner(org.exist.storage.lock.LockTable.LockModeOwner) List(java.util.List) LockCountTraces(org.exist.storage.lock.LockTable.LockCountTraces) LockModeOwner(org.exist.storage.lock.LockTable.LockModeOwner) GregorianCalendar(java.util.GregorianCalendar) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) LockMode(org.exist.storage.lock.Lock.LockMode) XMLGregorianCalendar(javax.xml.datatype.XMLGregorianCalendar) Map(java.util.Map)

Example 2 with LockModeOwner

use of org.exist.storage.lock.LockTable.LockModeOwner in project exist by eXist-db.

the class LockTableUtils method stateToString.

public static String stateToString(final LockTable lockTable, final boolean includeStack) {
    final Map<String, Map<LockType, List<LockModeOwner>>> attempting = lockTable.getAttempting();
    final Map<String, Map<LockType, Map<LockMode, Map<String, LockCountTraces>>>> acquired = lockTable.getAcquired();
    final StringBuilder builder = new StringBuilder();
    builder.append(EOL).append("Acquired Locks").append(EOL).append("------------------------------------").append(EOL);
    for (final Map.Entry<String, Map<LockType, Map<LockMode, Map<String, LockCountTraces>>>> acquire : acquired.entrySet()) {
        builder.append(acquire.getKey()).append(EOL);
        for (final Map.Entry<LockType, Map<LockMode, Map<String, LockCountTraces>>> type : acquire.getValue().entrySet()) {
            builder.append('\t').append(type.getKey()).append(EOL);
            for (final Map.Entry<LockMode, Map<String, LockCountTraces>> lockModeOwners : type.getValue().entrySet()) {
                builder.append("\t\t").append(lockModeOwners.getKey()).append('\t');
                boolean firstOwner = true;
                for (final Map.Entry<String, LockCountTraces> ownerHoldCount : lockModeOwners.getValue().entrySet()) {
                    if (!firstOwner) {
                        builder.append(", ");
                    } else {
                        firstOwner = false;
                    }
                    final LockCountTraces holdCount = ownerHoldCount.getValue();
                    builder.append(ownerHoldCount.getKey()).append(" (count=").append(holdCount.count).append(")");
                    if (holdCount.traces != null && includeStack) {
                        for (int i = 0; i < holdCount.traces.size(); i++) {
                            final StackTraceElement[] trace = holdCount.traces.get(i);
                            builder.append(EOL).append("\t\t\tTrace ").append(i).append(": ").append(EOL);
                            for (StackTraceElement stackTraceElement : trace) {
                                builder.append("\t\t\t\t").append(stackTraceElement).append(EOL);
                            }
                        }
                    }
                }
                builder.append(EOL);
            }
        }
    }
    builder.append(EOL).append(EOL);
    builder.append("Attempting Locks").append(EOL).append("------------------------------------").append(EOL);
    for (final Map.Entry<String, Map<Lock.LockType, List<LockTable.LockModeOwner>>> attempt : attempting.entrySet()) {
        builder.append(attempt.getKey()).append(EOL);
        for (final Map.Entry<Lock.LockType, List<LockTable.LockModeOwner>> type : attempt.getValue().entrySet()) {
            builder.append('\t').append(type.getKey()).append(EOL);
            for (final LockTable.LockModeOwner lockModeOwner : type.getValue()) {
                builder.append("\t\t").append(lockModeOwner.getLockMode()).append('\t').append(lockModeOwner.getOwnerThread());
                if (lockModeOwner.trace != null && includeStack) {
                    builder.append(EOL).append("\t\t\tTrace ").append(": ").append(EOL);
                    for (int i = 0; i < lockModeOwner.trace.length; i++) {
                        builder.append("\t\t\t\t").append(lockModeOwner.trace[i]).append(EOL);
                    }
                }
                builder.append(EOL);
            }
        }
    }
    return builder.toString();
}
Also used : LockCountTraces(org.exist.storage.lock.LockTable.LockCountTraces) LockModeOwner(org.exist.storage.lock.LockTable.LockModeOwner) LockMode(org.exist.storage.lock.Lock.LockMode) LockType(org.exist.storage.lock.Lock.LockType) LockModeOwner(org.exist.storage.lock.LockTable.LockModeOwner) List(java.util.List) Map(java.util.Map)

Aggregations

List (java.util.List)2 Map (java.util.Map)2 LockMode (org.exist.storage.lock.Lock.LockMode)2 LockType (org.exist.storage.lock.Lock.LockType)2 LockCountTraces (org.exist.storage.lock.LockTable.LockCountTraces)2 LockModeOwner (org.exist.storage.lock.LockTable.LockModeOwner)2 GregorianCalendar (java.util.GregorianCalendar)1 XMLGregorianCalendar (javax.xml.datatype.XMLGregorianCalendar)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1