1 package org.ultramonkey.l7.model;
3 import java.util.HashSet;
5 import org.apache.log4j.Logger;
8 * <p>class L7SyncCommand</p>
9 * <p>Copyright(c) NTT COMWARE 2008</p>
12 public class L7SyncCommand {
13 protected static Logger debugLogger = Logger.getLogger(LogCategorySet.SYNC_SYNC);
15 protected HashSet<Integer> categorySet;
17 protected int serverMode = 0;
19 private static final int ACT_MODE = 1;
21 private static final int SBY_MODE = 2;
23 private static final int MODE_ERROR = 3;
25 private static final int UNDESIGNED_MODE = 0;
27 private int MODE_LOCATION = 0;
29 private int CATEGORY_START_LOCATION = MODE_LOCATION + 1;
31 protected Logger logger = Logger.getLogger(LogCategorySet.SYNC_SYNC);
38 public L7SyncCommand(String[] args) {
39 // debug log(constructor)
40 if (debugLogger.isDebugEnabled()) {
41 debugLogger.debug("11232 class L7SyncCommand created.");
44 categorySet = new HashSet<Integer>();
46 this.checkArgument(args);
47 } catch (MessageView m) {
48 System.out.println(Message.SYNC_INVALID_ARGUMENT + " L7SyncCommand.");
49 logger.info("21032 " + Message.SYNC_INVALID_ARGUMENT + " L7SyncCommand.");
54 * <p> checks arguments</p>
56 * @param args argument value from command line
59 protected void checkArgument(String[] args) throws MessageView {
60 // debug log(in method)
61 if (debugLogger.isDebugEnabled()) {
62 StringBuffer buf = new StringBuffer();
64 .append("L7SyncCommand::checkArgument(String[] args) throws MessageView in args= ");
65 if (0 != args.length) {
66 for (int i = 0; i < args.length; i++) {
67 if (args.length - 1 == i) {
68 buf.append(args[i].toString());
71 buf.append(args[i].toString() + ",");
76 debugLogger.debug("11233 " + buf.toString());
79 if (0 == args.length) {
80 setServerMode(UNDESIGNED_MODE);
81 } else if (args[MODE_LOCATION].equals("-a")) {
82 setServerMode(ACT_MODE);
83 if (args.length <= CATEGORY_START_LOCATION) {
84 throw new MessageView(40024, LogCategorySet.SYNC_SYNC,
85 Message.SYNC_INVALID_ARGUMENT + " checkArgument.");
87 for (int i = CATEGORY_START_LOCATION; i < args.length; i++) {
89 setCaterogyIdSet(SyncCategoryIdSet.toCategoryId(args[i]));
90 } catch (MessageView m) {
91 throw new MessageView(40025, LogCategorySet.SYNC_SYNC,
92 Message.SYNC_INVALID_ARGUMENT + " checkArgument.");
95 } else if (args[MODE_LOCATION].equals("-s")) {
96 setServerMode(SBY_MODE);
98 setServerMode(MODE_ERROR);
99 throw new MessageView(40026, LogCategorySet.SYNC_SYNC,
100 Message.SYNC_INVALID_ARGUMENT + " checkArgument.");
103 // debug log(out method)
104 if (debugLogger.isDebugEnabled()) {
105 StringBuffer buf = new StringBuffer();
107 .append("L7SyncCommand::checkArgument(String[] args) throws MessageView out ");
108 debugLogger.debug("11234 " + buf.toString());
114 * <p> starts L7GUI synchronous processing</p>
118 public static void main(String[] args) {
119 // debug log(in method)
120 if (debugLogger.isDebugEnabled()) {
121 StringBuffer buf = new StringBuffer();
122 buf.append("L7SyncCommand::main(String[] args) in args= ");
123 if (0 == args.length) {
126 for (int i = 0; i < args.length; i++) {
127 if (args.length - 1 == i) {
128 buf.append(args[i].toString());
131 buf.append(args[i].toString() + ",");
134 debugLogger.debug("11235 " + buf.toString());
137 if (0 == args.length) {
138 L7SyncCommand.usage();
141 L7SyncCommand l7SyncCommand = new L7SyncCommand(args);
142 l7SyncCommand.start();
144 // debug log(out method)
145 if (debugLogger.isDebugEnabled()) {
146 StringBuffer buf = new StringBuffer();
147 buf.append("L7SyncCommand::main(String[] args) out ");
148 debugLogger.debug("11236 " + buf.toString());
154 * <p> starts active or stand-by processing</p>
157 protected void start() {
158 // debug log(in method)
159 if (debugLogger.isDebugEnabled()) {
160 StringBuffer buf = new StringBuffer();
161 buf.append("L7SyncCommand::start() in ");
162 debugLogger.debug("11237 " + buf.toString());
165 L7SyncManager l7SyncManager = new L7SyncManager();
166 switch (serverMode) {
169 l7SyncManager.syncAct(getCategoryIdSet());
170 } catch (MessageView m) {
171 System.out.println(m.message);
177 l7SyncManager.syncSby();
178 } catch (MessageView m) {
179 System.out.println(m.message);
183 System.out.println(Message.SYNC_INVALID_SERVER_MODE);
186 // debug log(out method)
187 if (debugLogger.isDebugEnabled()) {
188 StringBuffer buf = new StringBuffer();
189 buf.append("L7SyncCommand::start() out ");
190 debugLogger.debug("11238 " + buf.toString());
196 * <p> shows how to use L7SyncCommand</p>
199 protected static void usage() {
200 // debug log(in method)
201 if (debugLogger.isDebugEnabled()) {
202 StringBuffer buf = new StringBuffer();
203 buf.append("L7SyncCommand::usage() in ");
204 debugLogger.debug("11239 " + buf.toString());
208 "Usage: L7SyncCommand -a [CATEGORY]...\n" +
209 " L7SyncCommand -s\n" +
212 " -a active mode. send specified category data to standby server.\n" +
213 " -s standby mode. receive data from active server.\n" +
216 " l7vsd_log log settings of l7vsd\n" +
217 " adm_log log settings of l7vsadm\n" +
218 " snmp_log log settings of l7agent\n" +
219 " log_all all log settings\n" +
220 " adm_info command settings of l7vsadm\n" +
221 " replication_info replication settings of l7vsd\n" +
222 " snmp_info interval settings of l7agent\n" +
223 " monitor global settings of l7directord.cf\n" +
224 " service virtual settings of l7directord.cf\n" +
225 " userdata user data of l7gui\n"
228 // debug log(out method)
229 if (debugLogger.isDebugEnabled()) {
230 StringBuffer buf = new StringBuffer();
231 buf.append("L7SyncCommand::usage() out ");
232 debugLogger.debug("11240 " + buf.toString());
238 * <p> gets CategoryIdSet</p>
240 * @return categorySet
242 protected HashSet<Integer> getCategoryIdSet() {
243 // debug log(in method)
244 if (debugLogger.isDebugEnabled()) {
245 StringBuffer buf = new StringBuffer();
246 buf.append("L7SyncCommand::getCategoryIdSet() in ");
247 debugLogger.debug("11241 " + buf.toString());
250 // debug log(out method)
251 if (debugLogger.isDebugEnabled()) {
252 StringBuffer buf = new StringBuffer();
253 buf.append("L7SyncCommand::getCategoryIdSet() out ");
254 buf.append("return= " + categorySet.toString());
255 debugLogger.debug("11242 " + buf.toString());
262 * <p> sets CaterogyIdSet</p>
266 protected void setCaterogyIdSet(Integer categoryId) {
267 // debug log(in method)
268 if (debugLogger.isDebugEnabled()) {
269 StringBuffer buf = new StringBuffer();
270 buf.append("L7SyncCommand::setCaterogyIdSet() in ");
271 debugLogger.debug("11243 " + buf.toString());
273 categorySet.add(categoryId);
275 // debug log(out method)
276 if (debugLogger.isDebugEnabled()) {
277 StringBuffer buf = new StringBuffer();
278 buf.append("L7SyncCommand::setCaterogyIdSet() out ");
279 debugLogger.debug("11244 " + buf.toString());
284 * <p> gets serverMode</p>
288 protected int getServerMode() {
289 // debug log(in method)
290 if (debugLogger.isDebugEnabled()) {
291 StringBuffer buf = new StringBuffer();
292 buf.append("L7SyncCommand::getServerMode() in ");
293 debugLogger.debug("11245 " + buf.toString());
295 // debug log(out method)
296 if (debugLogger.isDebugEnabled()) {
297 StringBuffer buf = new StringBuffer();
298 buf.append("L7SyncCommand::getServerMode() out ");
299 buf.append("return= " + serverMode);
300 debugLogger.debug("11246 " + buf.toString());
306 * <p> sets serverMode</p>
310 protected void setServerMode(int mode) {
311 // debug log(in method)
312 if (debugLogger.isDebugEnabled()) {
313 StringBuffer buf = new StringBuffer();
314 buf.append("L7SyncCommand::setServerMode() in ");
315 buf.append("mode= " + mode);
316 debugLogger.debug("11247 " + buf.toString());
318 // debug log(out method)
319 if (debugLogger.isDebugEnabled()) {
320 StringBuffer buf = new StringBuffer();
321 buf.append("L7SyncCommand::getServerMode() out ");
322 debugLogger.debug("11248 " + buf.toString());