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

📄 gcengine.java

📁 一个类似于openJMS分布在ObjectWeb之下的JMS消息中间件。
💻 JAVA
字号:
/* * Copyright (C) 2004 - 2005 ScalAgent Distributed Technologies * * 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. */package fr.dyade.aaa.agent;import java.io.IOException;import java.util.Hashtable;import java.util.Enumeration;import java.util.Vector;import org.objectweb.util.monolog.api.BasicLevel;import org.objectweb.util.monolog.api.Logger;import fr.dyade.aaa.util.*;/** *  Implementation of Engine that used Group-Commit in order to improve  * performance. */final class GCEngine extends Engine {  int loop = 0;  int NbMaxLoop = 50;  GCEngine() throws Exception {    super();    NbMaxLoop = Integer.getInteger("NbMaxLoop", NbMaxLoop).intValue();    needToBeCommited = false;  }  /**   * Commit the agent reaction in case of rigth termination:<ul>   * <li>suppress the processed notification from message queue,   * then deletes it ;   * <li>push all new notifications in qin and qout, and saves them ;   * <li>saves the agent state ;   * <li>then commit the transaction to validate all changes.   * </ul>   */  void commit() throws Exception {    if (logmon.isLoggable(BasicLevel.DEBUG)) {      logmon.log(BasicLevel.DEBUG, getName() + ", commit reaction");    }    loop += 1;    AgentServer.getTransaction().begin();    // Suppress the processed notification from message queue ..    qin.pop();    // .. then deletes it ..    msg.delete();    // .. and frees it.    msg.free();    // Dispatch local messages    for (int i=0; i<mq.size(); ) {      Message m = (Message) mq.elementAt(i);      if (logmon.isLoggable(BasicLevel.DEBUG)) {        logmon.log(BasicLevel.DEBUG, getName() + ", dispatch: " + m);      }      if (m.to.getTo() == AgentServer.getServerId()) {        // !AF! Need to be synchronized in order to avoid interaction        // !AF! in stamp handling.        post(m);        mq.removeElementAt(i);      } else {        i += 1;      }    }    // !AF! It's dangerous to call validate outside of a transaction,    // !AF! we really need to enclose this code in a begin/release    validate();    // Saves the agent state then commit the transaction.    if (agent != null) agent.save();    if (needToBeCommited || (qin.size() == 0) || (loop > NbMaxLoop)) {      if (logmon.isLoggable(BasicLevel.INFO)) {        logmon.log(BasicLevel.INFO, getName() + ", commit: " + loop);      }      loop = 0;      // Post all notifications temporary keeped in mq in the rigth consumers,      // then saves changes.      dispatch();      AgentServer.getTransaction().commit();      // The transaction has commited, then validate all messages.      Channel.validate();    }    AgentServer.getTransaction().release();  }}

⌨️ 快捷键说明

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