⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tokenpipe.java

📁 semantic web framework
💻 JAVA
字号:
/*
 *  (c) Copyright Hewlett-Packard Company 2001 
 *  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.

 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
 * * $Id: TokenPipe.java,v 1.2 2002/01/04 12:47:53 jjc Exp $
   
   AUTHOR:  Jeremy J. Carroll
*/
/*
 * TokenPipe.java
 *
 * Created on June 22, 2001, 12:32 AM
 */

package com.hp.hpl.jena.rdf.arp;


/**
 *
 * @author  jjc
 
 */
// 5000: 9.7 8.0 7.8 7.9 8.0
// 2000: 9.2 7.7 7.5 7.6 7.7
// 1000: 9.0 7.1 7.1 7.15 7.1
// 800: 8.6 6.9 6.9 6.9 7.1
// 500: 8.6 7.1 7.3 6.9 7.1
// 100: 9.4 7.9 7.8 8.0 7.9
// 10: 15.1 13.7 13.0 13.1 13.0
// 2:  21.2 19.9 19.5 19.8 19.9
class TokenPipe implements TokenManager {

    private final Token pipe[];
    private int lastIn, lastOut;
    final ARPFilter arp;
    private Token last;
    /** Creates new TokenPipe */
    TokenPipe(ARPFilter arp,int sz) {
        this.arp = arp;
        pipe = new Token[sz];
        lastIn = 0;
        lastOut = 0;
    }
    TokenPipe(ARPFilter arp) {
        this(arp,200);
    }

    synchronized void putNextToken(Token t) {
        int ix = (lastIn+1)%pipe.length;
        while ( ix == lastOut ) {
            try {
              wait();
            }
            catch (InterruptedException e) {
                throw new CoRoutineDeathException();
            }
        }
        // we can put one in here.
        pipe[ix] = t;
        lastIn = ix;
        notifyAll();
    }
    
    private boolean atEOF = false;
    synchronized public Token getNextToken() {
        if ( atEOF ) {
	    last = new Token(RDFParserConstants.EOF,null);
	    return last;
	}
        while ( lastIn == lastOut ) {
            try {
              wait();
            }
            catch (InterruptedException e) {
                throw new CoRoutineDeathException();
            }
        }
        lastOut = (lastOut+1)%pipe.length;
        Token rslt = pipe[lastOut];
        notifyAll();
        //System.out.print(rslt.toString()+" ");
        if ( rslt.kind == RDFParserConstants.EOF )
            atEOF = true;
	last = rslt;
        return rslt;
    }
    
    /** This gets the next token from the input stream.
     * A token of kind 0 (<EOF>) should be returned on EOF.
 */
    
    synchronized public Token getLastToken() {
	return last;
    }
	
}

class CoRoutineDeathException extends RuntimeException {
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -