KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > config > schema > setup > FatalIllegalConfigurationChangeHandler


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.config.schema.setup;
5
6 import org.apache.commons.lang.ArrayUtils;
7
8 import com.tc.config.schema.IllegalConfigurationChangeHandler;
9 import com.tc.config.schema.dynamic.ConfigItem;
10 import com.tc.logging.TCLogger;
11 import com.tc.logging.TCLogging;
12
13 /**
14  * An {@link com.tc.config.schema.IllegalConfigurationChangeHandler} that prints
15  * a message to the screen and the logs, and then exits.
16  *
17  * NOTE: this code should no longer be engaged since the configuration modes
18  * were slimmed down to production and development. In production the client
19  * config is checked to match that of the servers. In development, the
20  * client's config simply applies to that client, whereas it used to be
21  * broadcast to other clients. Basically, config values cannot change after
22  * startup anymore.
23  */

24 public class FatalIllegalConfigurationChangeHandler implements IllegalConfigurationChangeHandler {
25
26   private static TCLogger logger;
27
28   private TCLogger getLogger() {
29     if(logger == null) {
30       logger = TCLogging.getLogger(FatalIllegalConfigurationChangeHandler.class);
31     }
32     
33     return logger;
34   }
35   
36   public void changeFailed(ConfigItem item, Object JavaDoc oldValue, Object JavaDoc newValue) {
37     String JavaDoc text = "Error: Terracotta is using an inconsistent configuration.\n\n"
38                   + "The configuration that this client is using is different from the one used by\n"
39                   + "the connected production server.\n\n" + "Specific information: " + item + " has changed.\n"
40                   + " Old value: " + describe(oldValue) + "\n" + " New value: " + describe(newValue) + "\n";
41
42     System.err.println(text);
43     getLogger().fatal(text);
44     System.exit(3);
45   }
46
47   private String JavaDoc describe(Object JavaDoc o) {
48     if (o == null) return "<null>";
49     if (o.getClass().isArray()) return ArrayUtils.toString(o);
50     else return o.toString();
51   }
52
53 }
54
Popular Tags