Changeset 8869


Ignore:
Timestamp:
2004-12-21T15:38:56+13:00 (19 years ago)
Author:
schweer
Message:

notifications will only be sent if the collectionConfig.xml of the collection has an entry <nofiy host=hostId/>, with hostId being the name and port of the host the notifications should be sent to (for most cases, this will be localhost:8080). note that the alerting service (/research/schweer/gsdl3/packages/gsdl-as) has to be deployed at /alerting for this to work, and soap for localsite has to be enabled.

Location:
trunk/gsdl3/src/java/org/greenstone/gsdl3
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/BuildManager.java

    r8860 r8869  
    33import org.greenstone.gsdl3.gs3build.doctypes.*;
    44import org.greenstone.gsdl3.gs3build.indexers.*;
     5import org.greenstone.gsdl3.gs3build.notifier.NotifierManager;
    56import org.greenstone.gsdl3.gs3build.extractor.*;
    67import org.greenstone.gsdl3.gs3build.classifier.*;
     
    1718    ClassifierManager classifierManager;
    1819    ExtractorManager  extractorManager;
     20    NotifierManager   notifierManager;
    1921    DocumentList      docList;
    2022    List              inputRoots;
     
    5658    this.classifierManager = new ClassifierManager(this.docList, collectionManager.getDatabase());
    5759    this.indexerManager = new IndexerManager(this.docList);
     60    this.notifierManager = new NotifierManager();
    5861   
    5962    // configure the collection - this will add classifiers, indexers, recognisers to the various managers.
     
    129132   
    130133    // TODO: validation phase
     134    this.notifierManager.detectEvents(this.collectionManager);
    131135   
    132136    if (this.archiveDir != null) {
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/CollectionManager.java

    r8859 r8869  
    6666  String             collectionName;
    6767  String             qualifiedCollectionName; // used as the database name
     68  String             notifyHost;
    6869
    6970  BuildManager       buildManager;
     
    375376    { this.configureBrowsers(children.item(c), collectionConfig);
    376377    }
     378    else if (name.equals(GSXML.NOTIFY_ELEM))
     379    {
     380        this.notifyHost = ((Element) children.item(c)).getAttribute(GSXML.NOTIFY_HOST_ATT);
     381    }
    377382    // TODO: other elements - make a factory-method approach here...
    378383    else
     
    573578      return collectionName;
    574579  }
     580
     581/**
     582 * @return
     583 */
     584public String getNotifyHost() {
     585    return notifyHost;
    575586}
    576 
     587}
     588
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/gs3build/notifier/NotifierManager.java

    r8868 r8869  
    1616   
    1717    public void detectEvents(CollectionManager collManager) {
     18        String notifyHost = collManager.getNotifyHost();
     19        if (notifyHost == null)
     20            return;
    1821       
    1922        System.out.println("detecting events");
     
    2932            // AccessionDate >= CollectionLastRebuiltDate
    3033            ResultSet results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate >= " + lastBuild);
    31             notify(collectionName, host, results, collManager.getDatabase(), collManager.getBuildDate(), "new_document");
     34            notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "new_document");
    3235           
    3336            // detect modified documents. A document is modified if and only if
     
    3538            // IndexedDate >= CollectionLastRebuiltDate
    3639            results = statement.executeQuery("SELECT DocID FROM document WHERE DocType != 'GSMETADATA' AND AccessionDate < " + lastBuild + " AND IndexedDate >= " + lastBuild);
    37             notify(collectionName, host, results, collManager.getDatabase(), collManager.getBuildDate(), "document_modified");
     40            notify(collectionName, host, notifyHost, results, collManager.getDatabase(), collManager.getBuildDate(), "document_modified");
    3841           
    3942            // TODO deleted docs?
     
    5558     * @throws SQLException
    5659     */
    57     private void notify(String collName, String hostURL, ResultSet results, GS3SQLConnection database, Date date, String eventType) {
     60    private void notify(String collName, String hostURL, String notifyHost, ResultSet results, GS3SQLConnection database, Date date, String eventType) {
    5861        try {
    59             URL url = new URL("http://localhost:8080/alerting/service");
     62            System.out.println("notifyHost is " + notifyHost);
     63            URL url = new URL("http://" + notifyHost + "/alerting/service");
    6064            System.out.println("trying to send to " + url);
    6165           
     
    8286                    writer.write("&collectionID=");
    8387                    writer.write(URLEncoder.encode(collName, "UTF-8"));
    84                     // TODO add collection name to event
    8588                    writer.write("&hostID=");
    8689                    writer.write(URLEncoder.encode(hostURL, "UTF-8"));
     
    109112                    e1.printStackTrace();
    110113                }
    111 //             
    112 //              Call call = new Call();
    113 //              call.setTargetObjectURI("alerting");
    114 //              call.setMethodName("receiveEvent");
    115 //              call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
    116 //              Vector params = new Vector();
    117 //              params.addElement(new Parameter("event", Map.class, event, null));
    118 //              call.setParams(params);
    119 //              try {
    120 //                    Response resp = call.invoke(url, "");
    121 //                    if (!resp.generatedFault()) {
    122 //                        System.out.println("successfully posted event");
    123 //                        return;
    124 //                    }
    125 //                    System.err.println("Posting event was unsuccessful:");
    126 //                    System.err.println(resp.getFault().getFaultString());
    127 //                   
    128 //                    Vector entries = resp.getFault().getDetailEntries();
    129 //                    for (Iterator i = entries.iterator(); i.hasNext(); ) {
    130 //                      org.w3c.dom.Element entry = (org.w3c.dom.Element)i.next( );
    131 //                      System.err.println(entry.getFirstChild().getNodeValue( ));
    132 //                    }
    133 //                } catch (SOAPException e1) {
    134 //                    System.err.println("Exception while posting event: ");
    135 //                    e1.printStackTrace();
    136 //                }
    137114            }
    138115        } catch (SQLException e) {
  • trunk/gsdl3/src/java/org/greenstone/gsdl3/util/GSXML.java

    r8726 r8869  
    5858    public static final String LEVEL_ELEM = "level";
    5959    public static final String SHORTNAME_ATT = "shortname";
     60    public static final String NOTIFY_ELEM = "notify";
     61    public static final String NOTIFY_HOST_ATT = "host";
    6062
    6163    // elems for the pages to be processed by xslt
Note: See TracChangeset for help on using the changeset viewer.