randomroutingpolicy.java
来自「High performance DB query」· Java 代码 · 共 83 行
JAVA
83 行
/* * @(#)$Id: RandomRoutingPolicy.java,v 1.7 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 org.apache.log4j.Logger;import pier.data.Tuple;import pier.operators.Eddy;import services.LocalNode;import services.Output;import util.BitID;import util.logging.LogMessage;/** * Class RandomRoutingPolicy * * Uses the nextOp map from BasicRoutingPolicy, but routes to random op, rather than first */public class RandomRoutingPolicy extends BasicRoutingPolicy { private static Logger logger = Logger.getLogger(RandomRoutingPolicy.class); /** * Constructor RandomRoutingPolicy * * * @param sourceInitMap * @param doneReadyMap */ public RandomRoutingPolicy(HashMap sourceInitMap, HashMap doneReadyMap) { super(sourceInitMap, doneReadyMap); } /** * Method getNextOperator * * * Based on the ready bits, find * the next operator to route to according to the routing policy * * @param item the tuple to determine the next op for * @return the index of the operator to send the tuple to */ public int getNextOperator(Tuple item) { if (Output.debuggingEnabled) { logger.debug(new LogMessage(new Object[]{ "getNextOperator for tuple from table: ", item.getTableName()})); } // pull out the array of possible operators - this corresponds exactly to the ready bits, but // for simplicity/efficiency at runtime, this is the index into the eddy's operator list // The "optimal" operator should be at the front of the list. In this case, its random ArrayList possibleOps = (ArrayList) nextOperatorMap.get( (BitID) item.getMetadata(Eddy.READY_BITS)); // randomly pick one of the possible operators Integer nextOp = (Integer) possibleOps.get( LocalNode.myRandom.nextInt(possibleOps.size())); return nextOp.intValue(); }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?