Changeset 4b6989e for apps/addressbook


Ignore:
Timestamp:
Nov 28, 2009 5:08:02 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d7d058e
Parents:
c10ea84
Message:
  • Addressbook, susidns: Rework addressbook into a HttpServlet?, so susidns can kick it when the subscription list changes
Location:
apps/addressbook
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • apps/addressbook/java/src/net/i2p/addressbook/Servlet.java

    rc10ea84 r4b6989e  
    2222package net.i2p.addressbook;
    2323
    24 import javax.servlet.GenericServlet;
     24import java.util.Random;
     25
    2526import javax.servlet.ServletConfig;
    2627import javax.servlet.ServletException;
    27 import javax.servlet.ServletRequest;
    28 import javax.servlet.ServletResponse;
     28import javax.servlet.http.HttpServlet;
     29import javax.servlet.http.HttpServletRequest;
     30import javax.servlet.http.HttpServletResponse;
    2931
    3032/**
    3133 * A wrapper for addressbook to allow it to be started as a web application.
    3234 *
     35 * This was a GenericServlet, we make it an HttpServlet solely to provide a hook
     36 * for SusiDNS to wake us up when the subscription list changes.
     37 *
    3338 * @author Ragnarok
    3439 *
    3540 */
    36 public class Servlet extends GenericServlet {
     41public class Servlet extends HttpServlet {
     42    private Thread _thread;
     43    private String _nonce;
     44    private static final String PROP_NONCE = "addressbook.nonce";
    3745
    38     /* (non-Javadoc)
    39      * @see javax.servlet.Servlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
     46    /**
     47     * Hack to allow susidns to kick the daemon when the subscription list changes.
     48     * URL must be /addressbook/ with wakeup param set, and nonce param set from system property.
     49     *
     50     * (non-Javadoc)
     51     * see javax.servlet.Servlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
    4052     */
    41     public void service(ServletRequest request, ServletResponse response) {
     53    public void service(HttpServletRequest request, HttpServletResponse response) {
     54        //System.err.println("Got request nonce = " + request.getParameter("nonce"));
     55        if (_thread != null && request.getParameter("wakeup") != null &&
     56            _nonce != null && _nonce.equals(request.getParameter("nonce"))) {
     57            //System.err.println("Sending interrupt");
     58            _thread.interrupt();
     59        }
     60        // no output
    4261    }
    4362
     
    5069            super.init(config);
    5170        } catch (ServletException exp) {
     71            System.err.println("Addressbook init exception: " + exp);
    5272        }
     73        _nonce = "" + Math.abs((new Random()).nextLong());
     74        // put the nonce where susidns can get it
     75        System.setProperty(PROP_NONCE, _nonce);
    5376        String[] args = new String[1];
    5477        args[0] = config.getInitParameter("home");
    55         DaemonThread thread = new DaemonThread(args);
    56         thread.setDaemon(true);
    57         thread.setName("Addressbook");
    58         thread.start();
     78        _thread = new DaemonThread(args);
     79        _thread.setDaemon(true);
     80        _thread.setName("Addressbook");
     81        _thread.start();
    5982        System.out.println("INFO: Starting Addressbook " + Daemon.VERSION);
    60         System.out.println("INFO: config root under " + args[0]);
     83        //System.out.println("INFO: config root under " + args[0]);
    6184    }
    6285
  • apps/addressbook/web.xml

    rc10ea84 r4b6989e  
    1414                <load-on-startup>1</load-on-startup>
    1515        </servlet>
     16
     17    <servlet-mapping>
     18      <servlet-name>addressbook</servlet-name>
     19      <url-pattern>/</url-pattern>
     20    </servlet-mapping>
     21
    1622</web-app>
Note: See TracChangeset for help on using the changeset viewer.