01: /*
02: * Copyright 2001 Sun Microsystems, Inc. All rights reserved.
03: * PROPRIETARY/CONFIDENTIAL. Use of this product is subject to license terms.
04: */
05:
06: package com.sun.portal.subscriptions.admin.util;
07:
08: import java.util.*;
09: import java.io.*;
10: import java.lang.*;
11: import com.sun.portal.subscriptions.admin.SubscriptionsAdminConstants;
12:
13: public class WinOSTask implements Task {
14: static {
15: System.loadLibrary("scheduleTask");
16: }
17:
18: static public void main(String[] args) {
19: if (args.length < 5) {
20: System.out
21: .println("Usage:CronController action org serverroot hours minutes days_of_week");
22: return;
23: }
24: WinOSTask cron = new WinOSTask();
25: cron.init(args[0], args[1], args[2]);
26: cron.setValue(HOURS, args[3]);
27: cron.setValue(MINUTES, args[4]);
28: cron.setValue(DAYS_OF_WEEK, args[5]);
29: cron.Update();
30: }
31:
32: HashMap valuesMap = new HashMap();
33: String name = null;
34: String organization = null;
35: String serverRoot = null;
36:
37: public WinOSTask() {
38: }
39:
40: public void init(String name, String org, String serverRoot) {
41: System.out.println("init:" + name);
42: this .name = name;
43: this .organization = org;
44: this .serverRoot = serverRoot;
45:
46: boolean success = getScheduledTask(name, valuesMap);
47: if (success)
48: return;
49: String cmd = name;//TODO - elaborate the Windows equivalent
50: }
51:
52: public void Remove() {
53: Update(true);
54: }
55:
56: public void Update() {
57: Update(false);
58: }
59:
60: private void Update(boolean isDelete) {
61: if (isDelete) {
62: System.out.println("Deleting task:" + name);
63: deleteScheduledTask(name);
64: } else {
65: System.out.println("Updating task:" + name);
66: scheduleTask(name, valuesMap);
67: }
68: }
69:
70: /**
71: * Find a configuration parameter
72: */
73: public String getValue(String param) {
74: return (String) valuesMap.get(param);
75: }
76:
77: /**
78: * sets a value in the cron
79: */
80: public void setValue(String key, String value) {
81: if (valuesMap != null) {
82: if (valuesMap.containsKey(key)) {
83: valuesMap.remove(key);
84: }
85: valuesMap.put(key, value);
86: }
87: }
88:
89: native static boolean scheduleTask(String taskName,
90: HashMap valuesMap);
91:
92: native static boolean getScheduledTask(String taskName,
93: HashMap valuesMap);
94:
95: native static boolean deleteScheduledTask(String taskName);
96: }
|