1 package com
.google
.appengine
.tools
.development
;
6 * Utility methods for managing {@link DevAppServer} port related service
10 public class DevAppServerPortPropertyHelper
{
11 public static final int DEFAULT_PORT
= 0;
12 public static final String SYSTEM_PROPERTY_STATIC_SERVER_PORT_NUM_PREFIX
=
13 "com.google.appengine.devappserver_server.";
15 private DevAppServerPortPropertyHelper() {
19 * Adds a service property to configure {@link DevAppServer} to use the
20 * the specified port for the named server's main instance to the passed in
21 * service properties. To read the added service property use
22 * {@link #getPort(String, Map)}.
24 public static int setPort(String serverName
, int port
, Map
<String
, String
> serviceProperties
) {
25 return setPort(serverName
, LocalEnvironment
.MAIN_INSTANCE
, port
, serviceProperties
);
29 * Adds a service property to configure {@link DevAppServer} to use the
30 * the specified port for the specified server instance to the passed in
31 * service properties. To read the added service property use
32 * {@link #getPort(String, Map)}.
33 * @param serverName the server name.
34 * @param instance the server instance or {link {@link LocalEnvironment#MAIN_INSTANCE} for the
36 * @param port the port for the specified server instance.
37 * @param serviceProperties the service properties.
39 public static int setPort(String serverName
, int instance
, int port
, Map
<String
,
40 String
> serviceProperties
) {
41 String propertyName
= getInstancePropertyName(serverName
, instance
);
42 serviceProperties
.put(propertyName
, Integer
.toString(port
));
47 * Returns the configured port for the named server's main instance from the
48 * the provided service properties or {@link #DEFAULT_PORT} if no port has
49 * been configured. To add the service property to configure the port use
50 * {@link #setPort(String, int, Map)}.
52 public static int getPort(String serverName
, Map
<String
, String
> serviceProperties
) {
53 return getPort(serverName
, LocalEnvironment
.MAIN_INSTANCE
, serviceProperties
);
57 * Returns the configured port for the specified server instance from the
58 * the provided service properties or {@link #DEFAULT_PORT} if no port has
59 * been configured. To add the service property to configure the port use
60 * {@link #setPort(String, int, Map)}.
62 * @param serverName the server name.
63 * @param instance the server instance or {link {@link LocalEnvironment#MAIN_INSTANCE} for the
65 * @param serviceProperties the service properties.
67 public static int getPort(String serverName
, int instance
,
68 Map
<String
, String
> serviceProperties
) {
69 String propertyName
= getInstancePropertyName(serverName
, instance
);
70 if (serviceProperties
.containsKey(propertyName
)) {
71 return Integer
.parseInt(serviceProperties
.get(propertyName
));
77 private static String
getInstancePropertyName(String serverName
, int instance
) {
78 String instanceSpec
= instance
== LocalEnvironment
.MAIN_INSTANCE ?
"" : "." + instance
;
79 return SYSTEM_PROPERTY_STATIC_SERVER_PORT_NUM_PREFIX
+ serverName
+ instanceSpec
+ ".port";