Package xbird.util.datetime

Examples of xbird.util.datetime.StopWatch


    public void testPut10000000() {
        put(10000000);
    }

    public void put(int times) {
        StopWatch sw = new StopWatch("[Long2LongHashTest] testPut" + times);
        List<Long> keys = new ArrayList<Long>(times / 3);
        Long2LongHash hash = new Long2LongHash(times / 3);
        Random random = new Random(System.currentTimeMillis());
        for(int i = 0; i < times; i++) {
            long key = random.nextLong();
View Full Code Here


        this.locks = new SoftHashMap<String, ReadWriteLock>(32);
    }

    public final void handleRequest(@Nonnull final SocketChannel inChannel, @Nonnull final Socket socket)
            throws IOException {
        final StopWatch sw = new StopWatch();
        if(!inChannel.isBlocking()) {
            inChannel.configureBlocking(true);
        }

        InputStream in = socket.getInputStream();
        DataInputStream dis = new DataInputStream(in);

        String fname = IOUtils.readString(dis);
        String dirPath = IOUtils.readString(dis);
        long len = dis.readLong();
        boolean append = dis.readBoolean();
        boolean ackRequired = dis.readBoolean();
        boolean hasAdditionalHeader = dis.readBoolean();
        if(hasAdditionalHeader) {
            readAdditionalHeader(dis, fname, dirPath, len, append, ackRequired);
        }

        final File file;
        if(dirPath == null) {
            file = new File(baseDir, fname);
        } else {
            File dir = FileUtils.resolvePath(baseDir, dirPath);
            file = new File(dir, fname);
        }

        preFileAppend(file, append);
        final FileOutputStream dst = new FileOutputStream(file, append);
        final String fp = file.getAbsolutePath();
        final ReadWriteLock filelock = accquireLock(fp, locks);
        final FileChannel fileCh = dst.getChannel();
        final long startPos = file.length();
        try {
            NIOUtils.transferFullyFrom(inChannel, 0, len, fileCh); // REVIEWME really an atomic operation?
        } finally {
            IOUtils.closeQuietly(fileCh, dst);
            releaseLock(fp, filelock, locks);
            postFileAppend(file, startPos, len);
        }
        if(ackRequired) {
            OutputStream out = socket.getOutputStream();
            DataOutputStream dos = new DataOutputStream(out);
            dos.writeLong(len);
            postAck(file, startPos, len);
        }

        if(LOG.isDebugEnabled()) {
            SocketAddress remoteAddr = socket.getRemoteSocketAddress();
            LOG.debug("Received a " + (append ? "part of file '" : "file '")
                    + file.getAbsolutePath() + "' of " + len + " bytes from " + remoteAddr + " in "
                    + sw.toString());
        }
    }
View Full Code Here

        System.gc();

        String queryStr = IOUtils.toString(new FileInputStream(queryFilePath));
        queryStr = queryStr.replace("fn:doc(\"auction.xml\")", "fn:doc('" + TARGET_FILE + "')");

        final StopWatch sw = new StopWatch("[Xbird_file] " + queryFilePath);
        final XQueryProcessor processor = new XQueryProcessor();
        // parse
        XQueryModule mod = processor.parse(queryStr, new File(queryFilePath).toURI());
        // execute              
        FastMultiByteArrayOutputStream out = new FastMultiByteArrayOutputStream();
View Full Code Here

        String queryStr = IOUtils.toString(new FileInputStream(queryFilePath));
        queryStr = queryStr.replace("fn:doc(\"auction.xml\")", "fn:collection('"
                + TARGET_COLLECTION + "')");

        final StopWatch sw = new StopWatch("[Xbird_collection] " + queryFilePath);
        final XQueryProcessor processor = new XQueryProcessor();
        // parse
        XQueryModule mod = processor.parse(queryStr, new File(queryFilePath).toURI());
        // execute
        FastMultiByteArrayOutputStream out = new FastMultiByteArrayOutputStream();
View Full Code Here

        if(sync) {
            InputStream in = socket.getInputStream();
            din = new DataInputStream(in);
        }
        final DataOutputStream dos = new DataOutputStream(out);
        final StopWatch sw = new StopWatch();
        FileInputStream src = null;
        final long nbytes;
        try {
            src = new FileInputStream(file);
            FileChannel fc = src.getChannel();

            String fileName = file.getName();
            IOUtils.writeString(fileName, dos);
            IOUtils.writeString(writeDirPath, dos);
            long xferBytes = (count == -1L) ? fc.size() : count;
            dos.writeLong(xferBytes);
            dos.writeBoolean(append); // append=false
            dos.writeBoolean(sync);
            if(handler == null) {
                dos.writeBoolean(false);
            } else {
                dos.writeBoolean(true);
                handler.writeAdditionalHeader(dos);
            }

            // send file using zero-copy send
            nbytes = fc.transferTo(fromPos, xferBytes, channel);
            if(LOG.isDebugEnabled()) {
                LOG.debug("Sent a file '" + file.getAbsolutePath() + "' of " + nbytes
                        + " bytes to " + dstSockAddr.toString() + " in " + sw.toString());
            }

            if(sync) {// receive ack in sync mode
                long remoteRecieved = din.readLong();
                if(remoteRecieved != xferBytes) {
View Full Code Here

        if(sync) {
            InputStream in = socket.getInputStream();
            din = new DataInputStream(in);
        }
        final DataOutputStream dos = new DataOutputStream(out);
        final StopWatch sw = new StopWatch();
        try {
            IOUtils.writeString(fileName, dos);
            IOUtils.writeString(writeDirPath, dos);
            long nbytes = data.size();
            dos.writeLong(nbytes);
            dos.writeBoolean(append);
            dos.writeBoolean(sync);
            if(handler == null) {
                dos.writeBoolean(false);
            } else {
                dos.writeBoolean(true);
                handler.writeAdditionalHeader(dos);
            }

            // send file using zero-copy send
            data.writeTo(out);

            if(LOG.isDebugEnabled()) {
                LOG.debug("Sent a file data '" + fileName + "' of " + nbytes + " bytes to "
                        + dstSockAddr.toString() + " in " + sw.toString());
            }

            if(sync) {// receive ack in sync mode
                long remoteRecieved = din.readLong();
                if(remoteRecieved != nbytes) {
View Full Code Here

    public void loadDocument(InputStream is) throws XQueryException {
        if(!(is instanceof FastBufferedInputStream)) {
            is = new FastBufferedInputStream(is);
        }
        _handler.init();
        final StopWatch sw = new StopWatch();
        try {
            _reader.parse(new InputSource(is));
        } catch (IOException ie) {
            throw new DynamicError("Invalid source", ie);
        } catch (SAXException se) {
            throw new DynamicError("Parse failed", se);
        }
        if(LOG.isDebugEnabled()) {
            LOG.debug("Elasped time of building a DTM: " + sw.elapsed() + " msec");
        }
        this._docid = nextDocumentId();
        if(_store instanceof IProfiledDocumentTable) {
            ((IProfiledDocumentTable) _store).setProfiling(true);
        }
View Full Code Here

                out.writeBoolean(true);
                RemoteSequence remote = (RemoteSequence) result;
                remote.writeExternal(out);
            } else {
                out.writeBoolean(false);
                final StopWatch sw = new StopWatch("Elapsed time for encoding `$" + getName()
                        + '\'');
                final XQEventEncoder encoder = new XQEventEncoder(out);
                try {
                    encoder.emit(result);
                } catch (XQueryException xqe) {
View Full Code Here

        if(hasResult) {
            final boolean isRemoteSeq = in.readBoolean();
            if(isRemoteSeq) {
                this._result = RemoteSequence.readFrom(in);
            } else {
                final StopWatch sw = new StopWatch("Elapsed time for decoding `$" + getName()
                        + '\'');
                final XQEventDecoder decoder = new XQEventDecoder(in);
                try {
                    this._result = decoder.decode();
                } catch (XQueryException xqe) {
View Full Code Here

    public void testIntLruMap() {
        StringBuilder buf = new StringBuilder(1024);
        System.gc();
        long free = SystemUtils.getHeapFreeMemory();
        buf.append(" free(init): " + free);
        StopWatch sw = new StopWatch("testIntLruMap");
        IntLRUMap<Integer> lru = new IntLRUMap<Integer>(LIMIT);
        for(int i = 0; i < LOOP; i++) {
            lru.put(i, i);
        }
        Random random = new Random();
        for(int i = 0; i < LOOP / 2; i++) {
            int r = random.nextInt(LOOP - 1);
            lru.put(r, r);
        }
        buf.insert(0, sw.toString());
        long used = free - SystemUtils.getHeapFreeMemory();
        buf.append(", used(before GC): " + used);
        System.gc();
        used = free - SystemUtils.getHeapFreeMemory();
        buf.append(", used(after GC): " + used);
View Full Code Here

TOP

Related Classes of xbird.util.datetime.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.