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


001:        /*
002:         * Copyright 2001 Sun Microsystems, Inc.  All rights reserved.
003:         * PROPRIETARY/CONFIDENTIAL.  Use of this product is subject to license terms.
004:         */
005:
006:        package com.sun.portal.search.admin.util;
007:
008:        import java.util.*;
009:        import java.io.*;
010:        import java.lang.*;
011:        import com.sun.portal.search.admin.CSConfig;
012:        import com.sun.portal.search.util.SearchConfig;
013:        import com.sun.portal.search.admin.cli.RunImportAgent;
014:
015:        /*
016:         * This class should really be renamed UnixOSTask
017:         * since it now supports multiple unix flavors
018:         */
019:
020:        public class SunOSTask implements  Task {
021:
022:            public static final String CRON_BEGIN = "# Search cron entries start here. Don't modify this section";
023:            public static final String CRON_END = "# Search cron entries end here.";
024:            private static final String CRONTAB = "/bin/crontab";
025:            private static final String CRONTAB_HPUX = "/usr/bin/crontab";
026:            private static final String CRONTAB_LINUX = "/usr/bin/crontab";
027:            private static String crontab = CRONTAB;
028:            static {
029:                if (isHP_UX()) {
030:                    crontab = CRONTAB_HPUX;
031:                }
032:                if (isLinux()) {
033:                    crontab = CRONTAB_LINUX;
034:                }
035:            }
036:
037:            static public void main(String[] args) {
038:                if (args.length < 5) {
039:                    System.out.println("Usage:CronController action");
040:                    return;
041:                }
042:                if (isHP_UX())
043:                    CSConfig.init("/var/opt/sun/portal/https-server1/portal");
044:                if (isLinux())
045:                    CSConfig.init("/var/opt/sun/portal/https-server1/portal");
046:                else
047:                    CSConfig.init("/var/opt/SUNWportal/https-server1/portal");
048:                SunOSTask cron = new SunOSTask();
049:                cron.init(args[0]);
050:                cron.setValue(HOURS, args[2]);
051:                cron.setValue(MINUTES, args[3]);
052:                cron.setValue(DAYS_OF_WEEK, args[4]);
053:                cron.Update();
054:            }
055:
056:            HashMap valuesMap = new HashMap();
057:            String name = null;
058:
059:            public SunOSTask() {
060:            }
061:
062:            public void init(String name) {
063:                this .name = name;
064:                String headerName = CSConfig.getServerRoot() + ":" + name;
065:                String cmd = CSConfig.getServerRoot() + File.separator + name; //For StartRobot and StopRobot only
066:                if (name.compareTo("StartImport") == 0) {
067:                    String csid = SearchConfig.getSearchConfig().getValue(
068:                            SearchConfig.CSID);
069:                    cmd = CSConfig.getServerRoot() + File.separator
070:                            + "run-cs-cli " + RunImportAgent.IMPORTMGR_CMD
071:                            + " -c " + CSConfig.getServerRoot()
072:                            + File.separator + "config" + File.separator
073:                            + SearchConfig.SEARCH_CONF + " " + csid
074:                            + " run all >>" + CSConfig.getServerRoot()
075:                            + File.separator + "logs" + File.separator
076:                            + "import.log";
077:                } else if (name.compareTo("StartAutoclassify") == 0) {
078:                    cmd = ScheduleFactory.getCmd(name);
079:                }
080:                setValue(COMMAND, cmd);
081:                try {
082:                    Process process = Runtime.getRuntime()
083:                            .exec(crontab + " -l");
084:                    InputStream instream = process.getInputStream();
085:                    BufferedReader buffReader = new BufferedReader(
086:                            new InputStreamReader(instream));
087:                    String temp = null;
088:                    boolean inSection = false;
089:                    boolean gotIt = false;
090:                    String theName = null;
091:                    while ((temp = buffReader.readLine()) != null) {
092:                        if (inSection) {
093:                            if (temp.startsWith(CRON_END)) {
094:                                break;
095:                            }
096:                            if (temp.startsWith("#")) {
097:                                theName = temp.substring(1);
098:                                continue;
099:                            }
100:                            if (theName != null && theName.equals(headerName)) {
101:                                int i = 0;
102:                                String f[] = new String[6];
103:                                StringTokenizer st = new StringTokenizer(temp,
104:                                        " ");
105:                                while (st.hasMoreTokens()) {
106:                                    f[i] = st.nextToken();
107:                                    if (i == 5) {
108:                                        setValue(HOURS, f[1]);
109:                                        setValue(MINUTES, f[0]);
110:                                        setValue(DAYS_OF_WEEK, f[4]);
111:                                        gotIt = true;
112:                                        break;
113:                                    }
114:                                    i++;
115:                                }
116:                                theName = null;
117:                                if (gotIt) {
118:                                    break;
119:                                }
120:                            }
121:                        } else if (temp.startsWith(CRON_BEGIN)) {
122:                            inSection = true;
123:                        }
124:
125:                    }
126:                } catch (Exception e) {
127:                }
128:            }
129:
130:            public void Remove() {
131:                Update(true);
132:            }
133:
134:            public void Update() {
135:                Update(false);
136:            }
137:
138:            private void Update(boolean isDelete) {
139:                try {
140:                    String headerName = CSConfig.getServerRoot() + ":" + name;
141:                    Process process = Runtime.getRuntime()
142:                            .exec(crontab + " -l");
143:                    InputStream instream = process.getInputStream();
144:                    BufferedReader buffReader = new BufferedReader(
145:                            new InputStreamReader(instream));
146:                    String tmpFileName = "/tmp/ipscron.txt."
147:                            + Long.toString(System.currentTimeMillis());
148:                    FileWriter outf = new FileWriter(tmpFileName);
149:                    String temp = null;
150:                    boolean inSection = false;
151:                    boolean gotIt = false;
152:                    String theName = null;
153:
154:                    while ((temp = buffReader.readLine()) != null) {
155:                        if (gotIt) {
156:                            outf.write(temp + "\n");
157:                            continue;
158:                        }
159:
160:                        if (inSection) {
161:                            if (temp.startsWith(CRON_END)) {
162:                                if (!isDelete) {
163:                                    outf.write("#" + headerName + "\n");
164:                                    outf.write(getValue(MINUTES) + " "
165:                                            + getValue(HOURS) + " * * "
166:                                            + getValue(DAYS_OF_WEEK) + " "
167:                                            + getValue(COMMAND) + "\n");
168:                                }
169:                                outf.write(CRON_END + "\n");
170:                                gotIt = true;
171:                                continue;
172:                            }
173:
174:                            if (temp.startsWith("#")) {
175:                                theName = temp.substring(1);
176:                                if (!isDelete || !theName.equals(headerName)) {
177:                                    outf.write(temp + "\n");
178:                                }
179:                                continue;
180:                            }
181:                            if (theName != null && theName.equals(headerName)) {
182:                                if (!isDelete) {
183:                                    outf.write(getValue(MINUTES) + " "
184:                                            + getValue(HOURS) + " * * "
185:                                            + getValue(DAYS_OF_WEEK) + " "
186:                                            + getValue(COMMAND) + "\n");
187:                                }
188:                                gotIt = true;
189:                                continue;
190:                            }
191:                        } else if (temp.startsWith(CRON_BEGIN)) {
192:                            System.out.println("CRON_BEGIN reached");
193:                            inSection = true;
194:                        }
195:                        outf.write(temp + "\n");
196:                    }
197:                    if (!inSection) {
198:                        outf.write(CRON_BEGIN + "\n");
199:                        outf.write("#" + headerName + "\n");
200:                        outf.write(getValue(MINUTES) + " " + getValue(HOURS)
201:                                + " * * " + getValue(DAYS_OF_WEEK) + " "
202:                                + getValue(COMMAND) + "\n");
203:                        outf.write(CRON_END + "\n");
204:                    }
205:
206:                    outf.close();
207:                    process = Runtime.getRuntime().exec(
208:                            crontab + " " + tmpFileName);
209:                    try {
210:                        process.waitFor();
211:                    } catch (java.lang.InterruptedException e) {
212:                        // Might need to do something here
213:                    }
214:                    File f = new File(tmpFileName);
215:                    f.delete();
216:
217:                } catch (Exception e) {
218:                }
219:                /* need to add the new entry */
220:            }
221:
222:            /**
223:             *  Find a configuration parameter
224:             */
225:            public String getValue(String param) {
226:                return (String) valuesMap.get(param);
227:            }
228:
229:            /**
230:             * sets a value in the cron
231:             */
232:            public void setValue(String key, String value) {
233:                if (valuesMap != null) {
234:                    if (valuesMap.containsKey(key)) {
235:                        valuesMap.remove(key);
236:                    }
237:                    valuesMap.put(key, value);
238:                }
239:            }
240:
241:            /**
242:             * check if operating system is HP-UX
243:             * @return      true if operating system is HP-UX
244:             */
245:            public static boolean isHP_UX() {
246:                if (System.getProperty("os.name").startsWith("HP-UX")) {
247:                    return true;
248:                } else {
249:                    return false;
250:                }
251:            }
252:
253:            /**
254:             * check if operating system is Linux
255:             * @return      true if operating system is Linux
256:             */
257:            public static boolean isLinux() {
258:                if (System.getProperty("os.name").startsWith("Linux")) {
259:                    return true;
260:                } else {
261:                    return false;
262:                }
263:            }
264:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.