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

📄 bufferoctopusclass.java

📁 数据仓库工具
💻 JAVA
字号:
/*
LoaderGenerator - tool for generated xml, sql and doml file needed for Octopus.


    Copyright (C) 2003  Together

    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 (at your option) 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 org.webdocwf.util.loader;

import java.util.*;

/**
 *
 * BufferClass class is used for writing system out in to internal buffer.
 * This class is a Singleton.
 * @author Radoslav Dutina
 * @version 1.0
 */
public class BufferOctopusClass {

  static private BufferOctopusClass instance;
  private  ArrayList buffer;
  private static boolean isUsed=false;

  /**
   * Returns the single instance, creating one if it's the
   * first time this method is called.
   * @return BufferClass The single instance.
   */
  static public BufferOctopusClass getInstance() {
    if (instance == null) {
      instance = new BufferOctopusClass();
    }
    return instance;
  }

  /**
   *  A private constructor since this is a Singleton
   */
  private BufferOctopusClass() {
    init();
  }

  /**
   * Loads properties and initializes the instance.
   */
  private void init(){
    buffer=new ArrayList();
  }

  /**
   * This method write system out to parameter buffer
   * @param msg is parameter value
   */
  public synchronized void writeToBuffer(String msg){
    if(isUsed==true){
      buffer.add(0,msg);
      notify();
    }
  }

  /**
   * This method read value from parameter buffer
   * @return parameter value
   */
  public synchronized String readFromBuffer(){
    if(buffer.isEmpty()){
      try{
        wait();
      }catch(Exception ex){
        //
      }
    }
    String ret="";
    if(buffer.size()>0)
      ret=(String) buffer.remove(buffer.size()-1);
    notify();
    if( ret == null )
    	ret = "";
    return ret;
  }

  /**
   * This mehod read value from parmeter isUsed
   * @return value of parameter
   */
  public boolean IsUsed(){
    return isUsed;
  }

  /**
   * This method clear parameter bufrrer
   */
  public void empty () {
    buffer.clear();
  }

  /**
   * This method set the value of patameter isUsed
   */
  public void setUsed(){
    isUsed=true;
  }
}

⌨️ 快捷键说明

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