FreewaySearch.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.xnap.plugin.freeway |
![]() |
![]() |
XNap 3 |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
| Metric | Description | |
|---|---|---|
/*
* XNap - A P2P framework and client.
*
* See the file AUTHORS for copyright information.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xnap.plugin.freeway;
import java.util.ArrayList;
import org.apache.log4j.Logger;
import org.gnu.freeway.DaemonSocket;
import org.gnu.freeway.protocol.afs.esed2.AFSUtils;
import org.gnu.freeway.protocol.afs.esed2.RootNode;
import org.gnu.freeway.protocol.afs.esed2.SearchResultCallback;
import org.gnu.freeway.protocol.afs.esed2.SendQueriesContext;
import org.gnu.freeway.protocol.afs.esed2.TestTerminateThread;
import org.gnu.freeway.protocol.afs.swing.SController;
import org.gnu.freeway.util.AbstractAction;
import org.gnu.freeway.util.ConfigurationService;
import org.gnu.freeway.util.CronService;
import org.gnu.freeway.util.StateService;
import org.gnu.freeway.util.Task;
import org.gnu.freeway.util.crypto.HashCode160;
import org.xnap.XNap;
import org.xnap.search.AbstractSearch;
import org.xnap.search.SearchFilter;
import org.xnap.search.SearchHandler;
/**
*
*/
public class FreewaySearch extends AbstractSearch
implements SearchResultCallback, TestTerminateThread
{
private SearchHandler handler;
private SController controller;
private boolean done = false;
private DaemonSocket socket = null;
private SendJob sendJob = null;
private static Logger logger = Logger.getLogger(FreewaySearch.class);
/**
* @param filter
*/
public FreewaySearch(SearchFilter filter, SController controller)
{
super(filter);
this.controller = controller;
}
/*
* @see org.xnap.search.Search#getStatus()
*/
public String getStatus()
{
if (done) {
return XNap.tr("Done");
}
else {
return XNap.tr("Running");
}
}
/*
* @see org.xnap.search.Search#isDone()
*/
public boolean isDone()
{
return done;
}
/*
* @see org.xnap.search.Search#start(org.xnap.search.SearchHandler)
*/
public void start(SearchHandler handler)
{
this.handler = handler;
done = false;
socket = DaemonSocket.create
((ConfigurationService)controller.service(ConfigurationService.class),
controller.getPreferences());
if (socket == null) {
done = true;
}
else {
startSearch();
}
}
/**
*
*/
private void startSearch()
{
HashCode160[] keys;
final SendQueriesContext sqc;
Task receiveThread;
String[] keywords;
ArrayList list = new ArrayList();
int i;
final CronService cron = (CronService)controller.service(CronService.class);
String[] p = getFilter().getText().split("\\s+");
for (i=0; i<p.length; i++) {
if (p[i].length()>0) {
list.add(p[i]);
}
}
if (list.size() == 0) {
System.out.println("no keywords left");
}
keywords = (String[]) list.toArray(new String[list.size()]);
keys = AFSUtils.parseKeywords(keywords);
if (keys.length==0) {
done = true;
return;
}
sqc = new SendQueriesContext(keys, socket);
sqc.setTimeOut(0x00FFFFFF); // "forever" is 6 months...
sendJob = new SendJob(cron, sqc);
cron.addJob(sendJob, 0, 0);
Task receiver = new Task("GNUNet SearchResult Receiver", new ReceiveJob(sqc));
receiver.launch();
}
/*
* @see org.xnap.search.Search#stop()
*/
public void stop()
{
done = true;
// socket.closeTemporarily();
((CronService) controller.service(CronService.class)).deleteJob(sendJob, 0);
socket.destroy();
}
private class SendJob extends AbstractAction
{
CronService cron;
SendQueriesContext sqc;
public SendJob(CronService cron, SendQueriesContext sqc)
{
this.cron = cron;
this.sqc = sqc;
}
public void perform() throws Throwable
{
logger.debug("sending query again");
sqc.repeatedlySend(cron, controller.getPolicy());
}
}
private class ReceiveJob extends AbstractAction
{
SendQueriesContext sqc;
ReceiveJob(SendQueriesContext sqc)
{
this.sqc = sqc;
}
public void perform()
{
logger.debug("Receiving...");
sqc.receive((ConfigurationService) controller.service(ConfigurationService.class),
(StateService) controller.service(StateService.class),
FreewaySearch.this, FreewaySearch.this);
FreewaySearch.this.stop();
}
}
/*
* @see org.gnu.freeway.protocol.afs.esed2.SearchResultCallback#searchResult(org.gnu.freeway.protocol.afs.esed2.RootNode)
*/
public void searchResult(RootNode node)
{
handler.resultReceived(new FreewaySearchResult(node));
}
/*
* @see org.gnu.freeway.protocol.afs.esed2.SearchResultCallback#newNameFor(org.gnu.freeway.protocol.afs.esed2.RootNode, java.lang.String)
*/
public void newNameFor(RootNode arg0, String arg1)
{
// TODO Auto-generated method stub
}
/*
* @see org.gnu.freeway.protocol.afs.esed2.TestTerminateThread#test()
*/
public boolean test()
{
return done;
}
}
The table below shows all metrics for FreewaySearch.java.
| Metric | Value | Description | |
|---|---|---|---|



