0N/A/*
2362N/A * Copyright (c) 2002, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Aimport java.net.*;
0N/Aimport java.util.*;
0N/Aimport java.io.IOException;
0N/A
0N/A/**
0N/A * This class provides a partial implementation of the HttpCallback
0N/A * interface. Use this class if you want to use the requestURI as a means
0N/A * of tracking multiple invocations of a request (on the server).
0N/A * In this case, you implement the modified request() method, which includes
0N/A * an integer count parameter. This parameter indicates the number of times
0N/A * (starting at zero) the request URI has been received.
0N/A */
0N/A
0N/Apublic abstract class AbstractCallback implements HttpCallback {
0N/A
0N/A Map requests;
0N/A
0N/A static class Request {
0N/A URI uri;
0N/A int count;
0N/A
0N/A Request (URI u) {
0N/A uri = u;
0N/A count = 0;
0N/A }
0N/A }
0N/A
0N/A AbstractCallback () {
0N/A requests = Collections.synchronizedMap (new HashMap());
0N/A }
0N/A
0N/A /**
0N/A * handle the given request and generate an appropriate response.
0N/A * @param msg the transaction containing the request from the
0N/A * client and used to send the response
0N/A */
0N/A public void request (HttpTransaction msg) {
0N/A URI uri = msg.getRequestURI();
0N/A Request req = (Request) requests.get (uri);
0N/A if (req == null) {
0N/A req = new Request (uri);
0N/A requests.put (uri, req);
0N/A }
0N/A request (msg, req.count++);
0N/A }
0N/A
0N/A /**
0N/A * Same as HttpCallback interface except that the integer n
0N/A * is provided to indicate sequencing of repeated requests using
0N/A * the same request URI. n starts at zero and is incremented
0N/A * for each successive call.
0N/A *
0N/A * @param msg the transaction containing the request from the
0N/A * client and used to send the response
0N/A * @param n value is 0 at first call, and is incremented by 1 for
0N/A * each subsequent call using the same request URI.
0N/A */
0N/A abstract public void request (HttpTransaction msg, int n);
0N/A}