01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.config.schema.setup;
05:
06: import org.apache.commons.lang.ArrayUtils;
07:
08: import com.tc.config.schema.IllegalConfigurationChangeHandler;
09: 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
25: IllegalConfigurationChangeHandler {
26:
27: private static TCLogger logger;
28:
29: private TCLogger getLogger() {
30: if (logger == null) {
31: logger = TCLogging
32: .getLogger(FatalIllegalConfigurationChangeHandler.class);
33: }
34:
35: return logger;
36: }
37:
38: public void changeFailed(ConfigItem item, Object oldValue,
39: Object newValue) {
40: String text = "Error: Terracotta is using an inconsistent configuration.\n\n"
41: + "The configuration that this client is using is different from the one used by\n"
42: + "the connected production server.\n\n"
43: + "Specific information: "
44: + item
45: + " has changed.\n"
46: + " Old value: "
47: + describe(oldValue)
48: + "\n"
49: + " New value: " + describe(newValue) + "\n";
50:
51: System.err.println(text);
52: getLogger().fatal(text);
53: System.exit(3);
54: }
55:
56: private String describe(Object o) {
57: if (o == null)
58: return "<null>";
59: if (o.getClass().isArray())
60: return ArrayUtils.toString(o);
61: else
62: return o.toString();
63: }
64:
65: }
|