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

[7484 byte] By [Ehsan.Sa] at [2007-11-27 2:09:06]
# 1
(a) you can't(b) why do you want to?(c) why not just create a new SearchClient when you need it, instead of trying to cart it around with the serialized SearchAgent?(d) in your present code that's exactly what you're doing, so what's the problem again?
ejpa at 2007-7-12 1:59:07 > top of Java-index,Core,Core APIs...
# 2

Thanks for the reply.

But the agent is suppose to move from one place to another place so it should be serializable, but the Searchclient is not so for this reason the agent can not register itself with the manager. This means that I won't have the agent because no one can see it and can't use it.

Ehsan.Sa at 2007-7-12 1:59:07 > top of Java-index,Core,Core APIs...
# 3

Eh? If you don't have SearchClient as a serializable field you can serialize your agent, and if your agent needs a SearchClient it can construct one when neceesary, just as your code above appears to do now. What state does the SearchClient have that you would need to serialize along with your agent?

ejpa at 2007-7-12 1:59:07 > top of Java-index,Core,Core APIs...