Serializing SearchClient in Yahoo SDK
Hello
I am writing an agent that will search the web using the yahoo web services. My problem is that I need the agent to be Serializable but the class SearchClient which is responsible for all communication between the client and yahoo webservice is not, so I cant't run my agent.
Does anyone have any idea howI can make the SearchClient class Serializable. bello is the code for the agent.
import java.io.*;
import java.util.*;
import java.rmi.*;
import java.rmi.server.*;
import net.jini.discovery.*;
import com.yahoo.search.*;
import java.io.IOException;
import com.yahoo.search.*;
import yinyang.*;
publicclass SearchAgentextends StaticAgentimplements Serializable{
// -
// variables --
// -
// -
// constructor
// -
public SearchAgent(){
super("BioSem_Manager","BioSem_SearchDomain");
}
// -
// methods -
// -
//-
/** register description - immplements abstract method
*/
//-
public String getDescription(){
return"Uses Yahoo to search pages containing the given term";
}
//-
/** register services - immplements abstract method
*/
//-
public String getServices(){return"Search";}
//-
/** perform the agent service: abstract method
@param service the service name, String
@param par the parameter object, Object
@return The result of the service, AgentServiceResult
*/
//-
public AgentServiceResult performService(String service, Object par){
AgentServiceResult res =new AgentServiceResult();
if (service.equals("Search")){
return doSearch(par.toString());
}
return res;
}
//-
/** display message
*/
//-
publicvoid displayMessage(String str){
System.out.println(str);
}
//
//search for terms
//-
private AgentServiceResult doSearch(String par){
AgentServiceResult res =new AgentServiceResult();
//System.out.println(par);
SearchClient client =new SearchClient("id");
StringTokenizer goToken =new StringTokenizer(par,"||");
while(goToken.hasMoreTokens()){
// Create the web search request.
WebSearchRequest request =new WebSearchRequest(goToken.nextToken());
request.setResults(10);
try{
// Execute the search.
WebSearchResults results = client.webSearch(request);
// Print out how many hits were found.
System.out.println("Found " + results.getTotalResultsAvailable() +
" hits for"+goToken.nextToken()+" Displaying the first " +
results.getTotalResultsReturned() +".");
// Iterate over the results.
System.out.println("WebSearch:");
for (int i = 0; i < results.listResults().length; i++){
WebSearchResult result = results.listResults()[i];
// Print out the document title and URL.
System.out.println("" + (i + 1) +": " + result.getTitle() +" - " +
result.getUrl()+"-"+result.getSummary());
}
}
catch (IOException e){
// Most likely a network exception of some sort.
System.err.println("Error calling Yahoo! Search Service: " +
e.toString());
e.printStackTrace(System.err);
}
catch (SearchException e){
// An issue with the XML or with the service.
System.err.println("Error calling Yahoo! Search Service: " +
e.toString());
e.printStackTrace(System.err);
}
}
res.setResult(null);
return res;
}
//
//create rdf for each term and store them
//-
privatevoid createRDF(){
}
}// end of SearchAgent

