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

📄 loadingfactor.java

📁 一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * JORAM: Java(TM) Open Reliable Asynchronous Messaging * Copyright (C) 2004 - France Telecom R&D * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or any later version. *  * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU * Lesser General Public License for more details. *  * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 * USA. * * Initial developer(s): Nicolas Tachker (ScalAgent) * Contributor(s): */package org.objectweb.joram.mom.dest;import org.objectweb.util.monolog.api.BasicLevel;import org.objectweb.joram.mom.MomTracing;import fr.dyade.aaa.agent.AgentId;import fr.dyade.aaa.agent.Channel;import org.objectweb.joram.shared.messages.Message;import org.objectweb.joram.mom.notifications.*;import java.util.Hashtable;import java.util.Vector;import java.util.Enumeration;import java.io.Serializable;public class LoadingFactor implements Serializable {  public static class Status {    public final static int INIT = 0;    public final static int RUN = 1;    public final static int WAIT = 2;        public final static String[] names =     {"INIT", "RUN", "WAIT"};  }  public static class ConsumerStatus {    public final static int CONSUMER_NO_ACTIVITY = 0;    public final static int CONSUMER_HIGH_ACTIVITY = 1;    public final static int CONSUMER_NORMAL_ACTIVITY = 2;        public final static String[] names =     {"CONSUMER_NO_ACTIVITY",      "CONSUMER_HIGH_ACTIVITY",     "CONSUMER_NORMAL_ACTIVITY"};  }    public static class ProducerStatus {    public final static int PRODUCER_NO_ACTIVITY = 0;    public final static int PRODUCER_HIGH_ACTIVITY = 1;    public final static int PRODUCER_NORMAL_ACTIVITY = 2;        public final static String[] names =     {"PRODUCER_NO_ACTIVITY",     "PRODUCER_HIGH_ACTIVITY",     "PRODUCER_NORMAL_ACTIVITY"};  }    /** status */  private int status;  /** status time */  private long statusTime;  /** consumer status */  private int consumerStatus = 0;  /** producer status */  private int producerStatus = 0;  /** reference to clusterQueueImpl */  public ClusterQueueImpl clusterQueueImpl;  /** producer threshold */  public int producThreshold = -1;  /** consumer threshold */  public int consumThreshold = -1;  /** automatic eval threshold */  public boolean autoEvalThreshold = false;  /** validity period */  public long validityPeriod = -1;  private float rateOfFlow;  private boolean overLoaded;  private int nbOfPendingMessages;  private int nbOfPendingRequests;  public LoadingFactor(ClusterQueueImpl clusterQueueImpl,                       int producThreshold,                       int consumThreshold,                       boolean autoEvalThreshold,                       long validityPeriod) {    this.clusterQueueImpl = clusterQueueImpl;    this.producThreshold = producThreshold;    this.consumThreshold = consumThreshold;    this.autoEvalThreshold = autoEvalThreshold;    this.validityPeriod = validityPeriod;    rateOfFlow = 1;    status = 0;  }  public void setRateOfFlow(float rateOfFlow) {    this.rateOfFlow = rateOfFlow;  }  public float getRateOfFlow() {    return rateOfFlow;  }  public void setWait() {    status = Status.WAIT;    statusTime = System.currentTimeMillis() + validityPeriod;  }  /**   * this method eval the activity   * of consumer and producer.   */  private void evalActivity() {    if (nbOfPendingMessages == 0)      producerStatus = ProducerStatus.PRODUCER_NO_ACTIVITY;    else if (nbOfPendingMessages > producThreshold)      producerStatus = ProducerStatus.PRODUCER_HIGH_ACTIVITY;    else      producerStatus = ProducerStatus.PRODUCER_NORMAL_ACTIVITY;    if (nbOfPendingRequests == 0)      consumerStatus = ConsumerStatus.CONSUMER_NO_ACTIVITY;    else if (nbOfPendingRequests > consumThreshold)      consumerStatus = ConsumerStatus.CONSUMER_HIGH_ACTIVITY;    else      consumerStatus = ConsumerStatus.CONSUMER_NORMAL_ACTIVITY;  }  /**    * update the threshol if autoEvalThreshold is true.   */  private void updateThreshol() {    if (autoEvalThreshold) {      if (MomTracing.dbgDestination.isLoggable(BasicLevel.DEBUG))        MomTracing.dbgDestination.log(BasicLevel.DEBUG,                                       "LoadingFactor.updateThreshol before" +                                      " rateOfFlow=" + rateOfFlow +                                      ", producThreshold=" + producThreshold +                                      ", consumThreshold=" + consumThreshold );      int deltaProd;      int deltaCons;      if (rateOfFlow < 1) {        deltaProd = (int) ((nbOfPendingMessages - producThreshold) * rateOfFlow);        deltaCons = (int) ((nbOfPendingRequests - consumThreshold) * rateOfFlow);      } else {        deltaProd = (int) ((nbOfPendingMessages - producThreshold) / rateOfFlow);        deltaCons = (int) ((nbOfPendingRequests - consumThreshold) / rateOfFlow);      }      if (nbOfPendingMessages > 0) {        if (deltaProd < producThreshold)          producThreshold = producThreshold + deltaProd;        else          producThreshold = deltaProd;      }      if (nbOfPendingRequests > 0) {        if (deltaCons < consumThreshold)          consumThreshold = consumThreshold + deltaCons;        else          consumThreshold = deltaCons;      }      if (MomTracing.dbgDestination.isLoggable(BasicLevel.DEBUG))        MomTracing.dbgDestination.log(BasicLevel.DEBUG,                                       "LoadingFactor.updateThreshol after" +                                      " rateOfFlow=" + rateOfFlow +                                      ", producThreshold=" + producThreshold +                                      ", consumThreshold=" + consumThreshold );    }  }  /**   * eval the rate of flow (means).   * if rateOfFlow > 1 the queue are more pending requests    * than pending messages.   * else if rateOfFlow < 1 the queue are more pending messages    * than pending requests.   * This value is set in all QueueClusterNot notification.   */  public float evalRateOfFlow(int pendingMessages,                              int pendingRequests) {    float currentROF;    nbOfPendingMessages = pendingMessages;    nbOfPendingRequests = pendingRequests;    if (pendingMessages == 0 && pendingRequests == 0)       currentROF = 1;    else if (pendingMessages == 0 && pendingRequests != 0)      currentROF = pendingRequests + 1;    else      currentROF =         new Float(pendingRequests).floatValue() /        new Float(pendingMessages).floatValue();        rateOfFlow = (currentROF + rateOfFlow ) / 2;    if (MomTracing.dbgDestination.isLoggable(BasicLevel.DEBUG))      MomTracing.dbgDestination.log(BasicLevel.DEBUG,                                     "LoadingFactor.evalRateOfFlow" +                                    " pendingMessages = " + pendingMessages +                                    ", pendingRequests = " + pendingRequests +                                    ", rateOfFlow = " + rateOfFlow +                                     ", currentROF = " + currentROF);    return rateOfFlow;  }  /**   * this method eval the rate of flow and activity.   * if necessary send "give or hope" messages, and   * update threshol.   */  public void factorCheck(Hashtable clusters,                          int pendingMessages,                          int pendingRequests) {    nbOfPendingMessages = pendingMessages;    nbOfPendingRequests = pendingRequests;    if (status == Status.WAIT &&         statusTime < System.currentTimeMillis())      status = Status.RUN;        if (MomTracing.dbgDestination.isLoggable(BasicLevel.DEBUG))      MomTracing.dbgDestination.log(BasicLevel.DEBUG,                                     ">> LoadingFactor.factorCheck " +                                    this + "\nclusters = " + clusters);    evalRateOfFlow(pendingMessages,

⌨️ 快捷键说明

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