count++; accTime += (System.currentTimeMillis() - start); LOG.debug( "found " + qname + ": " + result.getLength() + " in " + (System.currentTimeMillis() - start) + "ms.");
    public NodeSet findElementsByTagName(byte type, DocumentSet docs,            QName qname, NodeSelector selector) {//    	final long start = System.currentTimeMillis();        final ExtArrayNodeSet result = new ExtArrayNodeSet(docs.getLength(),                256);        final SymbolTable symbols = broker.getSymbols();        DocumentImpl doc;        int docId;        int len;        short collectionId;        long gid;        VariableByteInput is = null;        ElementValue ref;        short sym, nsSym;        Collection collection;        NodeProxy p;        final short nodeType = (type == ElementValue.ATTRIBUTE ? Node.ATTRIBUTE_NODE                : Node.ELEMENT_NODE);        final Lock lock = dbElement.getLock();//        StringBuffer debug = new StringBuffer();//        debug.append(qname.toString()).append(": ");        for (Iterator i = docs.getCollectionIterator(); i.hasNext();) {            collection = (Collection) i.next();            collectionId = collection.getId();            if (type == ElementValue.ATTRIBUTE_ID) {                ref = new ElementValue((byte) type, collectionId, qname                        .getLocalName());            } else {                sym = symbols.getSymbol(qname.getLocalName());                nsSym = symbols.getNSSymbol(qname.getNamespaceURI());                ref = new ElementValue((byte) type, collectionId, sym, nsSym);            }            try {            	lock.acquire(Lock.READ_LOCK);            	is = dbElement.getAsStream(ref);            	            	if (is == null) continue;            	while (is.available() > 0) {            		docId = is.readInt();            		len = is.readInt();            		if ((doc = docs.getDoc(docId)) == null) {            			is.skip(len * 4);            			continue;            		}            		gid = 0;            		for (int k = 0; k < len; k++) {//            			if(result.getLength() > 1000)//            				continue;            			gid = gid + is.readLong();            			if(selector == null)            				p = new NodeProxy(doc, gid, nodeType, StorageAddress.read(is));            			else {            				p = selector.match(doc, gid);            				if(p != null) {            					p.setInternalAddress(StorageAddress.read(is));            					p.setNodeType(nodeType);            				} else            					is.skip(3);            			}            			if(p != null) {//            				debug.append(StorageAddress.toString(p.getInternalAddress())).append(':');//            				debug.append(gid).append(' ');            				result.add(p, len);            			}            		}            	}            } catch (EOFException e) {            	//EOFExceptions are expected here            } catch (LockException e) {                LOG.warn(                        "findElementsByTagName(byte, DocumentSet, QName, NodeSelector) - "                                + "failed to acquire lock", e);            } catch (IOException e) {                LOG.warn(                        "findElementsByTagName(byte, DocumentSet, QName, NodeSelector) - "                                + "io exception while reading elements for "                                + qname, e);            } finally {                lock.release();            }        }//        LOG.debug(debug.toString());        //		result.sort();//        LOG.debug(//        		"found "//        		+ qname//				+ ": "//				+ result.getLength()//				+ " in "//				+ (System.currentTimeMillis() - start)//				+ "ms.");        return result;    }