Java
  Home arrow Java arrow Page 3 - Creating a User Interface for a Search Ser...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

Creating a User Interface for a Search Service
By: O'Reilly Media
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2006-11-22

    Table of Contents:
  • Creating a User Interface for a Search Service
  • Changes to the Original Code to Fit the JSP
  • Setting Up the Indexer
  • Making Use of the Configuration Service

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating a User Interface for a Search Service - Setting Up the Indexer


    (Page 3 of 4 )

    Now that the search service is integrated into the application, we’ll configure the indexer to automatically update against the current version of the web site on a regular basis. If you recall from the previous chapter, both the console application and the web service have mechanisms that let you launch the indexer service instead of the search service. The question is, how should the indexer be integrated with jPetStore?

    Embed in jPetStore or Launch Externally?

    The first approach is to make the indexer part of the jPetStore application itself; in other words, to add code to jPetStore that invokes the indexer. jPetStorecould invoke the indexer at the request of a user or on a schedule. Both methods have problems: if we expose a user interface for launching the indexer, we have to wrap it in some kind of secured section of the site for administrative users only. Currently,jPetStorehas no such security built in. Building it just to wrap around the indexer seems like a major stretch—too much complexity, not enough payoff. Which means a manual access point is out.

    The other option is to build a scheduler into thejPetStoreapplication. Regardless of how the architecture, a scheduler would require thejPetStoreapplication to be running for indexing to occur. SincejPetStoreis a web- and container-based application, its lifecycle is entirely dependent on the external hosts. If the web server software is turned off for any reason,jPetStoreshuts down as well. If the interval for the indexer falls in that window, the indexer doesn’t run. In addition, writing scheduling code is completely outside of the problem domain forjPetStore, just as it was for the Simple Spider. ThejPetStoreapplication should do one thing: display animals in a web catalog.

    We have no option but to invoke the indexer from some other location. A good strategy is to leverage an existing scheduler system: on Windows it’s schtasks and on Linux it’s cron. Let’s implement the scheduled indexer on Windows.

    Using the System Scheduler

    For ease of use, we create a batch file for actually launching the service. We want to invoke the Java runtime to run our ConsoleSearch class’s main method, passing in the starting point for jPetStore. The command (and, therefore, the contents of our batch file) looks like this:

      java c:\the\path\to\ConsoleSearch
    /i:http://localhost/jpetstore

    We store that in a file called jpetstoreIndexer.bat. For simplicity’s sake, we’ll store it in c:\commands.

    In order to schedule the indexer to run every night at 2:00 a.m., issue the following command (whiled logged in as a local administrator):

      c>schtasks /create /tn "jpetstore Indexer" /tr:c:\commands\jpetstoreIndexer.bat
              /sc daily /st 02:00:00

    The/tnflag creates a unique name for the text;/trpoints to the actual command to invoke;/scis the time interval; and/stis the specific time to launch the indexer on that interval.

    Similarly, on Linux, edit the crontab file and launch the cron daemon to accomplish the same thing.

    Smell the Roses

    The beauty of this solution is that our application, the Simple Spider, has been repurposed to run in both a container-based environment (Spring) and a direct runtime environment (via the scheduler calling the Java runtime directly) without any extra code whatsoever. Because of its simple architecture and loosely coupled services, the Spider itself can operate just fine in both environments simultaneously. We didn’t have to write a new access point or code a new UI or even make any configuration changes. Even better, we were able to take a single application from our first chapter and repurpose its internal services to two different endpoints without much work. It’s good to step back every now and again and smell the roses, just to realize what a little forethought and adherence to simple principles gets you.

    Principles in Action

    • Keep it simple: use system-provided scheduler and existing console-based access point to application
    • Choose the right tools: schtasks, cron, ConsoleSearch
    • Do one thing, and do it well: neither Spider nor jPetStore worry about the scheduling of the indexer; the scheduler only worries about the index, not the rest of the functionality
    • Strive for transparency: the scheduler knows nothing about the implementation details of the indexer or even where the results of the indexing will end up: it’s all handled in configuration files
    • Allow for extension: none

    More Java Articles
    More By O'Reilly Media


       · This article is an excerpt from the book "Better, Faster, Lighter Java," published...
     

    Buy this book now. This article is excerpted from chapter 10 of the book Better, Faster, Lighter Java, written by Bruce A. Tate and Justin Gehtland (O'Reilly; ISBN: 0596006764). Check it out today at your favorite bookstore. Buy this book now.

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
    Stay green...Green IT