Source Code Cross Referenced for UnixTasks.java in  » Portal » Open-Portal » com » sun » portal » fabric » util » os » 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 » Portal » Open Portal » com.sun.portal.fabric.util.os 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: UnixTasks.java,v 1.10 2006/09/04 11:15:15 mr161608 Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.fabric.util.os;
014:
015:        import com.sun.portal.fabric.util.FileUtil;
016:        import com.sun.portal.admin.common.context.PSConfigContext;
017:        import com.sun.portal.log.common.PortalLogger;
018:
019:        import java.util.logging.Logger;
020:        import java.util.logging.Level;
021:        import java.util.*;
022:        import java.io.*;
023:
024:        public abstract class UnixTasks extends OSTasksImpl {
025:
026:            private String finalPatchList = "";
027:            private static final String CRONTAB = "/usr/bin/crontab";
028:            private static Logger logger = PortalLogger
029:                    .getLogger(UnixTasks.class);
030:
031:            public UnixTasks(PSConfigContext globalContext) {
032:                super (globalContext);
033:            }
034:
035:            public void schedule() {
036:                String event = getValue(MINUTE) + " " + getValue(HOUR)
037:                        + " * * " + getValue(DAYOFTHEWEEK) + " "
038:                        + getValue(COMMAND);
039:
040:                try {
041:                    String fileName = "/tmp/ps_schedule."
042:                            + Long.toString(System.currentTimeMillis());
043:                    File f = new File(fileName);
044:                    FileWriter fw = new FileWriter(f);
045:                    Process p = Runtime.getRuntime().exec(CRONTAB + " -l");
046:                    InputStream is = p.getInputStream();
047:                    BufferedReader br = new BufferedReader(
048:                            new InputStreamReader(is));
049:                    boolean exist = false;
050:                    String line;
051:                    while ((line = br.readLine()) != null) {
052:                        if (line.equals(event)) {
053:                            exist = true;
054:                        }
055:                        fw.write(line + "\n");
056:                    }
057:                    if (!exist) {
058:                        fw.write(event + "\n");
059:                    }
060:                    fw.close();
061:                    p = Runtime.getRuntime().exec(CRONTAB + " " + fileName);
062:                    p.waitFor();
063:                    f.delete();
064:                } catch (Exception e) {
065:                    logger.log(Level.SEVERE, e.toString());
066:                }
067:            }
068:
069:            public void unschedule() {
070:                String event = getValue(MINUTE) + " " + getValue(HOUR)
071:                        + " * * " + getValue(DAYOFTHEWEEK) + " "
072:                        + getValue(COMMAND);
073:
074:                try {
075:                    String fileName = "/tmp/ps_unschedule."
076:                            + Long.toString(System.currentTimeMillis());
077:                    File f = new File(fileName);
078:                    FileWriter fw = new FileWriter(f);
079:                    Process p = Runtime.getRuntime().exec(CRONTAB + " -l");
080:                    InputStream is = p.getInputStream();
081:                    BufferedReader br = new BufferedReader(
082:                            new InputStreamReader(is));
083:                    String line;
084:                    while ((line = br.readLine()) != null) {
085:                        if (!line.equals(event)) {
086:                            fw.write(line + "\n");
087:                        }
088:                    }
089:                    fw.close();
090:                    p = Runtime.getRuntime().exec(CRONTAB + " " + fileName);
091:                    p.waitFor();
092:                    f.delete();
093:                } catch (Exception e) {
094:                    logger.log(Level.SEVERE, e.toString());
095:                }
096:            }
097:
098:            public ArrayList schedules() {
099:                String requestCommand = getValue(COMMAND);
100:
101:                ArrayList al = new ArrayList();
102:                try {
103:                    Process p = Runtime.getRuntime().exec(CRONTAB + " -l");
104:                    InputStream is = p.getInputStream();
105:                    BufferedReader br = new BufferedReader(
106:                            new InputStreamReader(is));
107:                    String line;
108:                    while ((line = br.readLine()) != null) {
109:                        if (!line.startsWith("#")) {
110:                            String[] strings = line.split("[ \t]");
111:                            String minute = strings[0];
112:                            String hour = strings[1];
113:                            String day = strings[2];
114:                            String month = strings[3];
115:                            String dayOfTheWeek = strings[4];
116:                            String command = "";
117:                            for (int i = 5; i < strings.length; i++) {
118:                                command = command + " " + strings[i];
119:                            }
120:                            if (command.trim().equals(requestCommand.trim())) {
121:                                String schedule = command.trim() + " | "
122:                                        + dayOfTheWeek + "@" + hour + ":"
123:                                        + minute;
124:                                al.add(schedule);
125:                            }
126:                        }
127:                    }
128:                } catch (Exception e) {
129:                    logger.log(Level.SEVERE, e.toString());
130:                }
131:                return al;
132:            }
133:
134:            private void getFinalPatchList() {
135:                String command = "/bin/pkginfo";
136:                execUtil.storeOutput(true);
137:                execUtil.exec(command, null);
138:                String result = execUtil.getOutput();
139:                StringTokenizer tokens = new StringTokenizer(result, "\n");
140:
141:                while (tokens.hasMoreTokens()) {
142:                    String token = tokens.nextToken();
143:                    if ((token.indexOf("SUNW") != -1)
144:                            && (token.indexOf("Portal Server") != -1)) {
145:                        String subStr = token.substring(token.indexOf("SUNW"));
146:                        String pkgName = subStr.substring(0, subStr
147:                                .indexOf(" "));
148:                        String pkginfoFilePath = "/var/sadm/pkg/" + pkgName
149:                                + "/pkginfo";
150:                        File pkginfoFile = new File(pkginfoFilePath);
151:                        String patchList = null;
152:                        if (pkginfoFile.exists()) {
153:                            patchList = FileUtil.findTextInFile(pkginfoFile,
154:                                    "PATCHLIST=");
155:                            if (patchList != null && patchList.length() != 0) {
156:                                if (patchList.substring(10) != null
157:                                        && patchList.substring(10).length() != 0) {
158:                                    finalPatchList = finalPatchList + " "
159:                                            + patchList.substring(10);
160:                                }
161:                            }
162:                        }
163:                    }
164:                    finalPatchList = removeRepeatedPatches(finalPatchList);
165:                }
166:
167:            }
168:
169:            public String getPatchInfo() {
170:                StringBuffer sb = new StringBuffer();
171:                getFinalPatchList();
172:                if (!finalPatchList.equals("") && finalPatchList.length() != 0) {
173:                    sb
174:                            .append("\nCurrently, following patches are installed: \n");
175:                    sb.append("------------------------------------------- \n");
176:                    sb.append(finalPatchList.substring(1));
177:                } else {
178:                    sb
179:                            .append("\nCurrently, there are no patches installed !!\n");
180:                }
181:                return sb.toString();
182:            }
183:
184:            public String getPatchVerbose() {
185:                StringBuffer sb = new StringBuffer();
186:                getFinalPatchList();
187:                if (!finalPatchList.equals("") && finalPatchList.length() != 0) {
188:                    StringTokenizer tokens = new StringTokenizer(finalPatchList
189:                            .substring(1), " ");
190:                    sb.append("\n");
191:                    while (tokens.hasMoreTokens()) {
192:                        String token = tokens.nextToken();
193:                        sb.append(token);
194:                        sb.append("-------------------------------------- \n");
195:                        String patchDir = "/var/sadm/patch/" + token;
196:                        File readmeFile = new File(patchDir + "/README."
197:                                + token);
198:                        if (!FileUtil.directoryExists(patchDir)) {
199:                            sb
200:                                    .append("For some unknown reason, no more details about this patch is available. \n");
201:                        } else if (!readmeFile.exists()) {
202:                            sb
203:                                    .append(readmeFile
204:                                            + " is not readable or does not exists, no more information available for this patch. \n");
205:                        } else {
206:                            sb.append(FileUtil.findTextInFile(readmeFile,
207:                                    "Synopsis")
208:                                    + "\n");
209:                        }
210:                    }
211:                } else {
212:                    sb
213:                            .append("\nCurrently, there are no patches installed !!\n");
214:                }
215:                return sb.toString();
216:            }
217:
218:            private String removeRepeatedPatches(String finalPatchList) {
219:                StringTokenizer patches = new StringTokenizer(finalPatchList,
220:                        " ");
221:                String PatchList = "";
222:                HashSet set = new HashSet();
223:
224:                while (patches.hasMoreTokens()) {
225:                    String tmp = (String) patches.nextToken();
226:                    if (set.add(tmp))
227:                        PatchList = PatchList + " " + tmp;
228:                }
229:                return PatchList;
230:            }
231:
232:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.