Gnutella Forums  

Go Back   Gnutella Forums > Current Gnutella Client Forums > Phex (Cross-platform) > General Discussion
Register FAQ The Twelve Commandments Members List Calendar Arcade Find the Best VPN Today's Posts

General Discussion For anything which doesn't fit somewhere else (for PHEX users)


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old July 2nd, 2011
Disciple
 
Join Date: June 2nd, 2011
Location: Bremen (Germany)
Posts: 17
giorgiob is a great assister to others; your light through the dark tunnel
Default Using Phex as a library.

Hi all,

I have been experimenting with the following scenario.

I want to write a program that
(1) starts Phex in headless mode,
(2) submits a query,
(3) waits until the query has completed,
(4) gets information about the query hits,
(5) downloads some selected hits
(6) marks the query as completed

I have managed to do step (1). For this, I have taken the Phex main class, and made the main method into a normal method that I can call from my code.
After this method has finished, phex is running and waiting for input.
I can access Phex through the Servent instance.

To perform (2) I wanted to get a QueryManager from the Servent instance and call sendDynamicQuery(). At this point I am pretty lost since I do not know what kinds of parameters I should use here. Also, I do not know exactly how to track the query (3).

Are there any examples for this? Or maybe where are these functionalities implemented in Phex? E.g. what class/method does the program execute when the user submits a query from the GUI? It would be interesting to look at the source code.

Thank you in advance and best greetings
G
Reply With Quote
  #2 (permalink)  
Old July 3rd, 2011
Phex Developer
 
Join Date: May 8th, 2001
Location: Stuttgart, Germany
Posts: 988
GregorK is flying high
Default

I know Phex is not optimal here and the handling should be improved. I hope this helps you anyway.

For step 2 here ist some pseudo code for the steps to do:

SearchContainer searchContainer = QueryManager.getSearchContainer()
Search newSearch = searchContainer.createSearch( searchString );
newSearch.startSearching( new DefaultSearchProgress(DEFAULT_QUERY_TIMEOUT, DESIRED_RESULTS) );

To get results add a method like this somewhere:
@EventTopicSubscriber(topic=PhexEventTopics.Search _Data)
public void onSearchDataEvent( String topic, SearchDataEvent event )
{
if ( newSearch != event.getSource() )
{
return;
}
if ( event.getType() == SearchDataEvent.SEARCH_HITS_ADDED )
{
RemoteFile[] newSearchResults = event.getSearchData();
....
}
}

And register the method by calling this in the class constructor:
Phex.getEventService().processAnnotations( this );


There is no real way to do (3), the query results can come in minutes after the search is triggered, there is no official end. The UI uses a combination of timeout and a pseudo progress indicator using the number of received results.
Ask your DefaultSearchProgress instance if it thinks the search is over. But still expect results to come in afterwards.

Can you tell me more about the kind of application you like to embed Phex into?

Look at SearchControllPanel to see how the UI does it.

Gregor
__________________
Reply With Quote
  #3 (permalink)  
Old July 3rd, 2011
Disciple
 
Join Date: June 2nd, 2011
Location: Bremen (Germany)
Posts: 17
giorgiob is a great assister to others; your light through the dark tunnel
Default

Hi Gregor,

thanks for the information.

My idea is to be able to run searches in a batch fashion. For example, if I would like
to look for files matching "Bach", "Mozart", "Haydn", I can write a text file containing
these key words.

Then I launch my program, this starts Phex, reads the text files with the searches, and starts to search (for each search I want to specify the maximum number of hits and a time out after which the search is complete). Based on the hits, it decides what to download. It shuts down when all searches and downloads are completed (it can also have a time out so that a search or download that takes too long is abandoned).

So my first attempt is to write one or more interface classes to "drive" Phex.
As I said, I managed to build a Phex Runner to start Phex as part of a larger
application. For this I just copied the content of the main class into my own method
and did a few adaptations.

Best greetings
Reply With Quote
  #4 (permalink)  
Old July 3rd, 2011
Disciple
 
Join Date: June 2nd, 2011
Location: Bremen (Germany)
Posts: 17
giorgiob is a great assister to others; your light through the dark tunnel
Default

Hi again,

thanks a lot for the hints! I have (2) and (4) working. For (3) I will use a time out.

Now I will look at the code inside the GUI to understand how to download
files. If I have problems I will ask you again.

As we had discussed a few weeks ago, if I can get these functions to work, I can
make a small API and submit it to you. If you find it is OK you can include it
to the code.

Many greetings
Giorgio
Reply With Quote
  #5 (permalink)  
Old July 3rd, 2011
Phex Developer
 
Join Date: May 8th, 2001
Location: Stuttgart, Germany
Posts: 988
GregorK is flying high
Default

Look at inner class SearchResultsPanel.SWQuickDownloadAction to see the code how a RemoteFile object from the search results is either added to an already existing download or to start a new download.

Of course I would be happy if you can help with offering an API to make it easier for others to use this code.
__________________
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -7. The time now is 01:53 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
SEO by vBSEO 3.6.0 ©2011, Crawlability, Inc.

Copyright © 2020 Gnutella Forums.
All Rights Reserved.