Source code for /engineering/autohit-2003/src/autohit/common/AutohitLogDrainRouting.javaOriginal file AutohitLogDrainRouting.java
   1 /**
   2  * AUTOHIT 2003
   3  * Copyright Erich P Gatejen (c) 1989,1997,2003,2004
   4  * 
   5  * This program is free software; you can redistribute it and/or modify 
   6  * it under the terms of the GNU General Public License as published by 
   7  * the Free Software Foundation; either version 2 of the License, or (at
   8  * your option) any later version.
   9  * This program is distributed in the hope that it will be useful, but
  10  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  11  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  12  * more details.
  13  * 
  14  * You should have received a copy of the GNU General Public License along
  15  * with this program; if not, write to the Free Software Foundation, Inc.,
  16  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17  *
  18  * Additional license information can be found in the documentation.
  19  * @author Erich P Gatejen
  20  */
  21 package autohit.common;
  22 
  23 import java.util.Hashtable;
  24 import java.io.Writer;
  25 import java.io.FileOutputStream;
  26 import java.io.OutputStreamWriter;
  27 
  28 /**
  29  * An routing subclass of AutohitLogDrain.  It assumes the will put all the
  30  * entries in FILES, based on the sender ID.  You must call setup() before using this.
  31  * It will create a new log, if it doesn't exist for the sender ID.
  32  * this!
  33  * <p>
  34  * The path needs to be in the form of /path/...path/filename with no extention.
  35  * @author Erich P. Gatejen
  36  * @version 1.0
  37  * <i>Version History</i>
  38  * <code>EPG - Rewrite - 28Jul03</code> 
  39  */
  40 public class AutohitLogDrainRouting extends AutohitLogDrain {
  41 
  42 	public Hashtable	routingtable;
  43 	private String		path;
  44 
  45 	/**
  46 	 * The subclass uses this to set the Writer.  the Writer is the
  47 	 * field myWriter.
  48 	 * @param id
  49 	 */
  50 	public void setWriter(String id) throws Exception {
  51 		
  52 		if (routingtable.containsKey(id)) {
  53 			myWriter = (Writer)routingtable.get(id);
  54 		} else {
  55 			FileOutputStream fios = new FileOutputStream(path + id + AutohitProperties.literal_FS_LOG_EXTENSION,true);
  56 			myWriter = new OutputStreamWriter(fios);
  57 			routingtable.put(id,myWriter);
  58 		}
  59 	}
  60 
  61 	/**
  62 	 * The subclass uses this to discard the Writer.  It says this id isn't
  63 	 * being used anymore.
  64 	 * @param id
  65 	 */
  66 	public void discardWriter(String id) throws Exception {
  67 		
  68 		if (routingtable.containsKey(id)) {
  69 			OutputStreamWriter fios = (OutputStreamWriter)routingtable.get(id);
  70 			try {
  71 				fios.close();
  72 			} catch (Exception ee) {
  73 				// do nothing.
  74 			}
  75 			routingtable.remove(id);
  76 		}
  77 	}
  78 
  79 
  80 	/**
  81 	 * The subclass should implement this to do any initialization.
  82 	 */
  83 	public void initchain() {
  84 		routingtable = new Hashtable();
  85 	}
  86 	
  87 	/**
  88 	 * This must be called before it is used.
  89 	 * @param basepath points to the path and base filename of the logs.  The log ID will be appended to this to make the real filename.
  90 	 */
  91 	public void setup(String  basepath) {
  92 		path = basepath;
  93 	}
  94 }