1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 package stats;
25 
26 import share.LogWriter;
27 import java.io.File;
28 import java.io.FileWriter;
29 
30 public class SimpleFileOutProducer implements LogWriter {
31 
32 
33     /** initialization, here a filename might be given
34      * or a dbUrL
35      */
initialize(share.DescEntry entry, boolean active)36     public boolean initialize(share.DescEntry entry, boolean active) {
37         return true;
38     }
39 
40     /** Method to print
41      */
println(String msg)42     public void println(String msg) {
43 
44     }
45 
46     /** will mostly be used by outproducers to sum up
47      * the information, maybe write them to a db
48      */
summary(share.DescEntry entry)49     public boolean summary(share.DescEntry entry) {
50         try {
51             String outpath = (String) entry.UserDefinedParams.get("OutputPath");
52             if (outpath==null) {
53                 System.out.println("## Parameter OutputPath isn't defined using default");
54                 return summary_default(entry);
55             }
56             String FileName = entry.longName + ".out";
57             if (!entry.EntryType.equals("component")) {
58                 FileName = entry.longName.substring(0,
59                                 entry.longName.indexOf(":")) + ".out";
60             }
61             util.utils.make_Directories("",outpath);
62             File outputFile = new File(outpath, FileName);
63             FileWriter out = new FileWriter(outputFile.toString(),true);
64             String ls = System.getProperty("line.separator");
65             String date = new java.util.Date().toString();
66             String header = "***** State for "+entry.longName+"( "+ date +" ) ******";
67             out.write(header+ls);
68             if (entry.hasErrorMsg) {
69                 out.write(entry.ErrorMsg+ls);
70                 out.write("Whole "+entry.EntryType+": "+entry.State+ls);
71             } else {
72                 out.write("Whole "+entry.EntryType+": "+entry.State+ls);
73             }
74             String bottom="";
75             for (int i=0;i<header.length();i++) {
76                 bottom += "*";
77             }
78             out.write(bottom+ls);
79             out.write(""+ls);
80             out.close();
81         } catch (java.io.IOException e) {
82 
83         }
84         return true;
85     }
86 
summary_default(share.DescEntry entry)87     public boolean summary_default(share.DescEntry entry) {
88         String header = "***** State for "+entry.longName+" ******";
89         System.out.println(header);
90         if (entry.hasErrorMsg) {
91             System.out.println(entry.ErrorMsg);
92             System.out.println("Whole "+entry.EntryType+": "+entry.State);
93         } else {
94             System.out.println("Whole "+entry.EntryType+": "+entry.State);
95         }
96         for (int i=0;i<header.length();i++) {
97             System.out.print("*");
98         }
99         System.out.println("");
100         return true;
101     }
102 
getWatcher()103     public Object getWatcher() {
104         return null;
105     }
106 
setWatcher(Object watcher)107     public void setWatcher(Object watcher) {
108     }
109 
110 }
111