Source Code Cross Referenced for ViewLogImpl.java in  » ESB » cbesb-1.2 » com » bostechcorp » cbesb » console » server » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » ESB » cbesb 1.2 » com.bostechcorp.cbesb.console.server 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * ChainBuilder ESB
003:         *          Visual Enterprise Integration
004:         * 
005:         * Copyright (C) 2006 Bostech Corporation
006:         * 
007:         * This program is free software; you can redistribute it and/or modify it 
008:         * under the terms of the GNU General Public License as published by the 
009:         * Free Software Foundation; either version 2 of the License, or (at your option) 
010:         * any later version.
011:         *
012:         * This program is distributed in the hope that it will be useful, 
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
014:         * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
015:         * for more details.
016:         * 
017:         * You should have received a copy of the GNU General Public License along with 
018:         * this program; if not, write to the Free Software Foundation, Inc., 
019:         * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
020:         *
021:         *
022:         * $Id: ReadErrorTableImpl.java 3829 2006-12-14 21:10:05Z elu $
023:         */
024:        package com.bostechcorp.cbesb.console.server;
025:
026:        import java.io.File;
027:        import java.io.FileNotFoundException;
028:        import java.io.IOException;
029:        import java.io.RandomAccessFile;
030:        import java.util.ArrayList;
031:        import java.util.List;
032:        import java.util.regex.Matcher;
033:        import java.util.regex.Pattern;
034:
035:        import javax.servlet.http.HttpSession;
036:
037:        import com.bostechcorp.cbesb.common.util.EsbPathHelper;
038:        import com.bostechcorp.cbesb.console.common.Constants;
039:        import com.bostechcorp.cbesb.console.common.LogData;
040:        import com.bostechcorp.cbesb.console.common.LogViewProperties;
041:        import com.bostechcorp.cbesb.console.common.ServerSideException;
042:        import com.bostechcorp.cbesb.console.help.FileHelper;
043:        import com.bostechcorp.cbesb.console.rpc.ViewLog;
044:
045:        //TODO we need to handle the polling of log to support then session timeout  
046:        //public class ViewLogImpl extends ConsoleRemoteServiceServlet implements ViewLog {
047:        public class ViewLogImpl extends ConsoleRemoteServiceServlet implements 
048:                ViewLog {
049:
050:            private static final long serialVersionUID = 1L;
051:
052:            private static RandomAccessFile cbserverRAF = null;
053:
054:            private static RandomAccessFile tcwrapperRAF = null;
055:
056:            private static RandomAccessFile smwrapperRAF = null;
057:
058:            public static FileHelper cbserverRAFFileHelper = new FileHelper();
059:
060:            public static FileHelper tcwrapperRAFFileHelper = new FileHelper();
061:
062:            public static FileHelper smwrapperRAFFileHelper = new FileHelper();
063:
064:            private static long cbserverLength = 0;
065:
066:            private static long tcwrapperLength = 0;
067:
068:            private static long smwrapperLength = 0;
069:
070:            private static boolean flag;
071:
072:            private File cbesbServerFile;
073:
074:            private File smwrapperFile;
075:
076:            private File tcwrapperFile;
077:            public LogViewProperties properties = null;
078:
079:            String path = EsbPathHelper.getCbesbHomeDir();
080:
081:            public ViewLogImpl() {
082:
083:                if (!flag) {
084:
085:                    cbesbServerFile = new File(path + File.separator + "log"
086:                            + File.separator + "cbesb_server.log");
087:                    smwrapperFile = new File(path + File.separator + "log"
088:                            + File.separator + "sm_wrapper.log");
089:                    tcwrapperFile = new File(path + File.separator + "log"
090:                            + File.separator + "tc_wrapper.log");
091:                    try {
092:                        if (!cbesbServerFile.exists())
093:                            cbesbServerFile.createNewFile();
094:                        if (!smwrapperFile.exists())
095:                            smwrapperFile.createNewFile();
096:                        if (!tcwrapperFile.exists())
097:                            tcwrapperFile.createNewFile();
098:                        cbserverRAF = new RandomAccessFile(cbesbServerFile, "r");
099:                        tcwrapperRAF = new RandomAccessFile(tcwrapperFile, "r");
100:                        smwrapperRAF = new RandomAccessFile(smwrapperFile, "r");
101:                        cbserverLength = cbesbServerFile.length();
102:                        tcwrapperLength = tcwrapperFile.length();
103:                        smwrapperLength = smwrapperFile.length();
104:                    } catch (FileNotFoundException e1) {
105:                        e1.printStackTrace();
106:                    } catch (IOException e) {
107:                        // TODO Auto-generated catch block
108:                        e.printStackTrace();
109:                    }
110:                    flag = true;
111:                }
112:            }
113:
114:            public LogData read() {
115:                return null;
116:            }
117:
118:            public LogData update(int length, String currentFile)
119:                    throws ServerSideException {
120:                LogData logData = new LogData();
121:                int sizeOld = 0;
122:                if (properties == null) {
123:                    sizeOld = 0;
124:                } else
125:                    sizeOld = properties.getBufferSize();
126:                properties = getProperties();
127:                int size = properties.getBufferSize();
128:                if (properties.getBufferSize() <= 0)
129:                    size = 0;
130:
131:                if (sizeOld < size) {
132:                    cbserverRAFFileHelper.init();
133:                    tcwrapperRAFFileHelper.init();
134:                    smwrapperRAFFileHelper.init();
135:                }
136:                String result = "";
137:
138:                if (currentFile.equalsIgnoreCase("cbesb_server.log")) {
139:                    result = cbserverRAFFileHelper.tail(path + File.separator
140:                            + "log" + File.separator + currentFile, size);
141:
142:                } else if (currentFile.equalsIgnoreCase("tc_wrapper.log")) {
143:                    result = tcwrapperRAFFileHelper.tail(path + File.separator
144:                            + "log" + File.separator + currentFile, size);
145:                } else if (currentFile.equalsIgnoreCase("sm_wrapper.log")) {
146:                    result = smwrapperRAFFileHelper.tail(path + File.separator
147:                            + "log" + File.separator + currentFile, size);
148:                }
149:
150:                logData.setData(result);
151:                logData.setCurrentFile(currentFile);
152:                logData.setProperties(properties);
153:                return logData;
154:            }
155:
156:            private byte[] getFileText(String fileName, int length) {
157:                byte[] result = new byte[length];
158:                try {
159:                    File file = new File(path + File.separator + "log"
160:                            + File.separator + fileName);
161:
162:                    RandomAccessFile raf = new RandomAccessFile(file, "r");
163:                    long len = file.length();
164:
165:                    int lineCount = 0;
166:                    List list = new ArrayList();
167:                    String s = null;
168:                    int lastSize = 0;
169:                    s = raf.readLine();
170:                    if (s == null)
171:                        return null;
172:                    list.add(s.length() + 2);
173:                    lastSize = s.length() + 2;
174:                    while ((s = raf.readLine()) != null) {
175:                        int size = s.length() + 2 + lastSize;
176:                        list.add(size);
177:                        lastSize = size;
178:
179:                        lineCount++;
180:                    }
181:
182:                    int beginningLine = 0;
183:
184:                    if (lineCount > length) {
185:                        beginningLine = lineCount - length;
186:                    }
187:
188:                    int index = 0;
189:                    if (beginningLine == 0)
190:                        index = 0;
191:                    else {
192:                        index = Integer.parseInt(list.get(beginningLine)
193:                                .toString());
194:                    }
195:
196:                    result = new byte[(int) (len - index)];
197:                    raf.seek(index);
198:                    raf.read(result);
199:                } catch (Exception e) {
200:                    return null;
201:                }
202:                return result;
203:            }
204:
205:            public LogData pollingUpdate(int length, String currentFile)
206:                    throws ServerSideException {
207:                return update(length, currentFile);
208:            }
209:
210:            public Boolean validateLogConfigureText(String string) {
211:                if (string.equals("")) {
212:                    return true;
213:                }
214:                Pattern pattern = Pattern.compile("[0-9]+");
215:                Matcher matcher = pattern.matcher(string);
216:                return matcher.matches();
217:            }
218:
219:            public void reset() {
220:                cbserverLength = cbesbServerFile.length();
221:                tcwrapperLength = tcwrapperFile.length();
222:                smwrapperLength = smwrapperFile.length();
223:            }
224:
225:            public LogData inital(int length, String log) {
226:                String path = EsbPathHelper.getCbesbHomeDir();
227:                /*File file = new File(path + File.separator + "log"
228:                 + File.separator + log);*/
229:
230:                LogViewProperties properties = getProperties();
231:                int size = properties.getBufferSize();
232:                if (properties.getBufferSize() <= 0)
233:                    size = 0;
234:
235:                byte[] temp = getFileText(log, size);
236:
237:                String[] string = new String[2];
238:                string[0] = log;
239:                if (temp == null)
240:                    string[1] = new String("");
241:                else
242:                    string[1] = new String(temp);
243:
244:                LogData logData = new LogData();
245:                logData.setData(string[1]);
246:                logData.setProperties(properties);
247:                return logData;
248:            }
249:
250:            public LogViewProperties getProperties() {
251:
252:                int numOfLines = 0;
253:                int refreshRate = 0;
254:                int bufferSize = 0;
255:
256:                try {
257:                    numOfLines = Integer.parseInt(ConsoleSettingUtil
258:                            .getConsoleUserSetting(super .getCurrentUserId())
259:                            .getLogViewerNumOfLine());
260:                    refreshRate = Integer.parseInt(ConsoleSettingUtil
261:                            .getConsoleUserSetting(super .getCurrentUserId())
262:                            .getLogRefreshRate());
263:                    bufferSize = Integer.parseInt(ConsoleSettingUtil
264:                            .getConsoleUserSetting(super .getCurrentUserId())
265:                            .getLogViewerLineBufferSize());
266:
267:                } catch (Exception e) {
268:                    numOfLines = 10;
269:                    refreshRate = 5;
270:                    bufferSize = 600;
271:                    e.printStackTrace();
272:                }
273:                HttpSession session = this .getThreadLocalRequest().getSession();
274:                LogViewProperties logProperties = (LogViewProperties) session
275:                        .getAttribute(Constants.LOG_VIEW_PROPERTIES);
276:                if (logProperties == null) {
277:                    logProperties = new LogViewProperties();
278:
279:                }
280:
281:                logProperties.setInterval(refreshRate);
282:                logProperties.setBufferSize(bufferSize);
283:                logProperties.setNumOfLines(numOfLines);
284:                setProperties(logProperties);
285:
286:                return logProperties;
287:            }
288:
289:            public Boolean setProperties(LogViewProperties props) {
290:                HttpSession session = this.getThreadLocalRequest().getSession();
291:                session.setAttribute(Constants.LOG_VIEW_PROPERTIES, props);
292:                return Boolean.TRUE;
293:            }
294:
295:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.