1.9.30 sync.
[gae.git] / java / src / main / com / google / appengine / api / utils / SystemProperty.java
blob5f244886fafe195c127c396f0f119406f56e3089
1 // Copyright 2009 Google Inc. All Rights Reserved.
3 package com.google.appengine.api.utils;
5 /**
6 * Global system properties which are set by App Engine.
7 * <p>
8 * Example code:
9 * <pre>
10 * if (SystemProperty.environment.value() == SystemProperty.Environment.Value.Production) {
11 * // do something that's production-only
12 * }
13 * String version = SystemProperty.version.get();
14 * </pre>
17 public class SystemProperty {
19 /**
20 * The current executing environment. Has the key,
21 * {@code "com.google.appengine.runtime.environment"}.
22 * Has the values {@code "Production"} and {@code "Development"}.
24 public static final Environment environment = new Environment();
26 /**
27 * The current executing runtime version. Has the key,
28 * {@code "com.google.appengine.runtime.version"}.
29 * A Version value is composed of period-separated integers, for example,
30 * "1.2.8".
32 public static final SystemProperty version =
33 new SystemProperty("com.google.appengine.runtime.version");
35 /**
36 * The application identifier for the current application. Has the
37 * key, {@code "com.google.appengine.application.id"}.
39 public static final SystemProperty applicationId =
40 new SystemProperty("com.google.appengine.application.id");
42 /**
43 * The version identifier for the current application version. Result is of
44 * the form {@literal <major>.<minor>} where {@literal <major>} is the version
45 * name supplied at deploy time and {@literal <minor>} is a timestamp value
46 * maintained by App Engine. Has the key
47 * {@code "com.google.appengine.application.version"}.
49 public static final SystemProperty applicationVersion =
50 new SystemProperty("com.google.appengine.application.version");
52 /**
53 * @deprecated Use {@link
54 * com.google.appengine.api.modules.ModulesService#getCurrentInstanceId()}
56 @Deprecated
57 public static final SystemProperty instanceReplicaId =
58 new SystemProperty("deprecated");
60 /**
61 * The current executing environment. Has the key,
62 * {@code "com.google.appengine.runtime.environment"}.
63 * The set of values are specified by {@link Environment.Value Value}.
65 public static class Environment extends SystemProperty {
67 /**
68 * The set of possible values for Environment.
70 public enum Value {
71 Production,
72 Development;
74 public String value() {
75 return toString();
79 private Environment() {
80 super("com.google.appengine.runtime.environment");
83 /**
84 * Returns the Value that the SystemProperty is set to.
86 * @return null if the Environment is not set, or is set to a value that
87 * does not correspond to any predefined {@code Value}.
89 public Value value() {
90 try {
91 String propertyValue = get();
92 return propertyValue != null ? Value.valueOf(get()) : null;
93 } catch (IllegalArgumentException e) {
94 return null;
98 /**
99 * Sets the Environment to {@code value}. Equivalent to
100 * {@code set(value.value())}.
103 public void set(Value value) {
104 set(value.value());
108 private SystemProperty(String key) {
109 this.key = key;
112 private String key;
115 * The key for the system property.
117 public String key() {
118 return key;
122 * Gets the value of the system property.
123 * Equivalent to {@code System.getProperty(key())}.
125 public String get() {
126 return System.getProperty(key());
130 * Sets the value of the system property.
131 * Equivalent to {@code System.setProperty(key(), value)}.
133 public void set(String value) {
134 System.setProperty(key(), value);