jaxws/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/transport/http/server/ServerMgr.java
author mkos
Mon, 18 Jan 2016 15:28:46 +0100
changeset 35341 6e00d8d01e71
parent 25871 b80b84e87032
child 43852 93a527059d8a
permissions -rw-r--r--
8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use" Reviewed-by: chegar Contributed-by: kubota.yuji@gmail.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     1
/*
35341
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
     2
 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     4
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    10
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    15
 * accompanied this code).
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    16
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    20
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    23
 * questions.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    24
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    25
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    26
package com.sun.xml.internal.ws.transport.http.server;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    27
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    28
import com.sun.net.httpserver.HttpContext;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    29
import com.sun.net.httpserver.HttpServer;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    30
import com.sun.xml.internal.ws.server.ServerRtException;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    31
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    32
import java.net.InetSocketAddress;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    33
import java.net.URL;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    34
import java.util.HashMap;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    35
import java.util.HashSet;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    36
import java.util.Map;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    37
import java.util.Set;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    38
import java.util.concurrent.ExecutorService;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    39
import java.util.concurrent.Executors;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    40
import java.util.logging.Logger;
35341
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    41
import java.util.Optional;
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    42
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    43
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    44
/**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    45
 * Manages all the WebService HTTP servers created by JAXWS runtime.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    46
 *
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    47
 * @author Jitendra Kotamraju
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    48
 */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    49
final class ServerMgr {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    50
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    51
    private static final ServerMgr serverMgr = new ServerMgr();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    52
    private static final Logger logger =
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    53
        Logger.getLogger(
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    54
            com.sun.xml.internal.ws.util.Constants.LoggingDomain + ".server.http");
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    55
    private final Map<InetSocketAddress,ServerState> servers = new HashMap<InetSocketAddress,ServerState>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    56
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    57
    private ServerMgr() {}
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    58
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    59
    /**
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    60
     * Gets the singleton instance.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    61
     * @return manager instance
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    62
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    63
    static ServerMgr getInstance() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    64
        return serverMgr;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    65
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    66
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    67
    /*
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    68
     * Creates a HttpContext at the given address. If there is already a server
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    69
     * it uses that server to create a context. Otherwise, it creates a new
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    70
     * HTTP server. This sever is added to servers Map.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    71
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    72
    /*package*/ HttpContext createContext(String address) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    73
        try {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    74
            HttpServer server;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    75
            ServerState state;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    76
            URL url = new URL(address);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    77
            int port = url.getPort();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    78
            if (port == -1) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    79
                port = url.getDefaultPort();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    80
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    81
            InetSocketAddress inetAddress = new InetSocketAddress(url.getHost(),
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    82
                port);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    83
            synchronized(servers) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    84
                state = servers.get(inetAddress);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    85
                if (state == null) {
35341
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    86
                    final int finalPortNum = port;
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    87
                    Optional<ServerState> stateOpt =
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    88
                               servers.values()
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    89
                                       .stream()
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    90
                                       .filter(s -> s.getServer()
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    91
                                                     .getAddress()
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    92
                                                     .getPort() == finalPortNum)
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    93
                                       .findAny();
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
    94
35341
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    95
                    if (inetAddress.getAddress().isAnyLocalAddress() &&
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    96
                        stateOpt.isPresent()) {
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    97
                        state = stateOpt.get();
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    98
                    } else {
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
    99
                        logger.fine("Creating new HTTP Server at "+inetAddress);
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   100
                        // Creates server with default socket backlog
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   101
                        server = HttpServer.create(inetAddress, 0);
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   102
                        server.setExecutor(Executors.newCachedThreadPool());
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   103
                        String path = url.toURI().getPath();
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   104
                        logger.fine("Creating HTTP Context at = "+path);
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   105
                        HttpContext context = server.createContext(path);
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   106
                        server.start();
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   107
35341
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   108
                        // we have to get actual inetAddress from server, which can differ from the original in some cases.
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   109
                        // e.g. A port number of zero will let the system pick up an ephemeral port in a bind operation,
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   110
                        // or IP: 0.0.0.0 - which is used to monitor network traffic from any valid IP address
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   111
                        inetAddress = server.getAddress();
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   112
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   113
                        logger.fine("HTTP server started = "+inetAddress);
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   114
                        state = new ServerState(server, path);
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   115
                        servers.put(inetAddress, state);
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   116
                        return context;
6e00d8d01e71 8146086: Publishing two webservices on same port fails with "java.net.BindException: Address already in use"
mkos
parents: 25871
diff changeset
   117
                    }
12009
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   118
                }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   119
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   120
            server = state.getServer();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   121
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   122
            if (state.getPaths().contains(url.getPath())) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   123
              String err = "Context with URL path "+url.getPath()+ " already exists on the server "+server.getAddress();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   124
              logger.fine(err);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   125
              throw new IllegalArgumentException(err);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   126
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   127
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   128
            logger.fine("Creating HTTP Context at = "+url.getPath());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   129
            HttpContext context = server.createContext(url.getPath());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   130
            state.oneMoreContext(url.getPath());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   131
            return context;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   132
        } catch(Exception e) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   133
            throw new ServerRtException("server.rt.err",e );
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   134
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   135
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   136
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   137
    /*
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   138
     * Removes a context. If the server doesn't have anymore contexts, it
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   139
     * would stop the server and server is removed from servers Map.
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   140
     */
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   141
    /*package*/ void removeContext(HttpContext context) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   142
        InetSocketAddress inetAddress = context.getServer().getAddress();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   143
        synchronized(servers) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   144
            ServerState state = servers.get(inetAddress);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   145
            int instances = state.noOfContexts();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   146
            if (instances < 2) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   147
                ((ExecutorService)state.getServer().getExecutor()).shutdown();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   148
                state.getServer().stop(0);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   149
                servers.remove(inetAddress);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   150
            } else {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   151
                state.getServer().removeContext(context);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   152
                state.oneLessContext(context.getPath());
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   153
            }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   154
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   155
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   156
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   157
    private static final class ServerState {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   158
        private final HttpServer server;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   159
        private int instances;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   160
        private Set<String> paths = new HashSet<String>();
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   161
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   162
        ServerState(HttpServer server, String path) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   163
            this.server = server;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   164
            this.instances = 1;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   165
            paths.add(path);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   166
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   167
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   168
        public HttpServer getServer() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   169
            return server;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   170
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   171
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   172
        public void oneMoreContext(String path) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   173
            ++instances;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   174
            paths.add(path);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   175
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   176
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   177
        public void oneLessContext(String path) {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   178
            --instances;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   179
            paths.remove(path);
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   180
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   181
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   182
        public int noOfContexts() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   183
            return instances;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   184
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   185
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   186
        public Set<String> getPaths() {
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   187
          return paths;
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   188
        }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   189
    }
4abb694f273a 7150322: Stop using drop source bundles in jaxws
ohair
parents:
diff changeset
   190
}