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

📄 basicroutingpolicy.java

📁 High performance DB query
💻 JAVA
字号:
/* * @(#)$Id: BasicRoutingPolicy.java,v 1.6 2004/07/02 23:59:21 huebsch Exp $ * * Copyright (c) 2001-2004 Regents of the University of California. * All rights reserved. * * This file is distributed under the terms in the attached BERKELEY-LICENSE * file. If you do not find these files, copies can be found by writing to: * Computer Science Division, Database Group, Universite of California, * 617 Soda Hall #1776, Berkeley, CA 94720-1776. Attention: Berkeley License * * Copyright (c) 2003-2004 Intel Corporation. All rights reserved. * * This file is distributed under the terms in the attached INTEL-LICENSE file. * If you do not find these files, copies can be found by writing to: * Intel Research Berkeley, 2150 Shattuck Avenue, Suite 1300, * Berkeley, CA, 94704.  Attention:  Intel License Inquiry. */package pier.helpers.routingpolicy;import java.util.ArrayList;import java.util.HashMap;import java.util.Iterator;import org.apache.log4j.Logger;import pier.data.Tuple;import pier.operators.Eddy;import services.Output;import util.BitID;import util.logging.LogMessage;/** * Class BasicRoutingPolicy * * This class is a simple, "first" operator routing policy * Builds a special nextOp map thats used to quickly determine where to send the tuple */public class BasicRoutingPolicy extends RoutingPolicy {    private static Logger logger = Logger.getLogger(BasicRoutingPolicy.class);    /*     * map of done bits -> next operator list.  The first operator in the     *  list for a given signature will be the operator chosen     *  Note that there is another way to do this - can also have 'next ready'     *  stored and then compute the next op from that.  TBD how I will actually     *  do this.     */    protected HashMap nextOperatorMap;    /**     * Constructor BasicRoutingPolicy     *     *     * @param sourceInitMap     * @param doneReadyMap     */    public BasicRoutingPolicy(HashMap sourceInitMap, HashMap doneReadyMap) {        super(sourceInitMap, doneReadyMap);        // build the next operator map based on the two maps        nextOperatorMap = buildOperatorMap(sourceInitMap, doneReadyMap);        if (Output.debuggingEnabled) {            logger.debug(new LogMessage(new Object[]{"nextOperatorMap: ",                                                     nextOperatorMap}));        }    }    /**     * Method buildOperatorMap     * We build this map on eddy initialization so we dont have to mess with bit operations at     * runtime.     *     * @param sourceInitMap     * @param doneReadyMap     * @return     */    protected HashMap buildOperatorMap(HashMap sourceInitMap,                                       HashMap doneReadyMap) {        HashMap nextOperatorMap = new HashMap();        // first get the ready bits from the source init map        // get an iterator to the ready bits        Iterator sourceIterator = sourceInitMap.values().iterator();        // iterate by key (done bits)        while (sourceIterator.hasNext()) {            // pull out the ready bits            BitID readyBits = (BitID) (sourceIterator.next());            // the array of possible operators            ArrayList possibleOperators =                new ArrayList(readyBits.cardinality());            // find the bits that are on and thier corresponding position.  Fill in the operator array            int searchIndex = 0;            int operatorIndex = readyBits.nextSetBit(searchIndex);            while (operatorIndex != -1) {                // add this position to the arraylist                possibleOperators.add(new Integer(operatorIndex));                searchIndex = operatorIndex + 1;                operatorIndex = readyBits.nextSetBit(searchIndex);            }            nextOperatorMap.put(readyBits, possibleOperators);        }        // now make operators from the doneready map        Iterator readyIterator = doneReadyMap.values().iterator();        while (readyIterator.hasNext()) {            BitID readyBits = (BitID) (readyIterator.next());            ArrayList possibleOperators =                new ArrayList(readyBits.cardinality());            // find the bits that are on and thier corresponding position.  Fill in the operator array            int searchIndex = 0;            int operatorIndex = readyBits.nextSetBit(searchIndex);            while (operatorIndex != -1) {                // add this position to the arraylist                possibleOperators.add(new Integer(operatorIndex));                searchIndex = operatorIndex + 1;                operatorIndex = readyBits.nextSetBit(searchIndex);            }            nextOperatorMap.put(readyBits, possibleOperators);        }        return nextOperatorMap;    }    /**     * Method getNextOperator     *     *     * Based on the metadata in the tuple (ready, done bits), find     * the next operator to route to according to the routing policy     * Basic just pulls the first operator off the possible list     *     * @param item the tuple to determine the next op for     * @return     */    public int getNextOperator(Tuple item) {        if (Output.debuggingEnabled) {            logger.debug(new LogMessage(new Object[]{"Readybits: ",                                                     (BitID) item.getMetadata(                                                         Eddy.READY_BITS)}));        }        // simply look up the next operator in the next op table and return it        ArrayList possibleOps = (ArrayList) nextOperatorMap.get(                                    (BitID) item.getMetadata(Eddy.READY_BITS));        if ((possibleOps == null) || (possibleOps.size() < 1)) {            if (Output.debuggingEnabled) {                logger.debug(new LogMessage(new Object[]{                    "Error finding next op!", }));                return -1;            }        }        // grab the first operator        Integer nextOp = (Integer) possibleOps.get(0);        // would re-optimize routing strategy here (if we decided to do such a wacky thing), or could be done batched        if (Output.debuggingEnabled) {            logger.debug(new LogMessage(new Object[]{"Next op: ",                                                     nextOp.intValue() + ""}));        }        return nextOp.intValue();    }}

⌨️ 快捷键说明

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