SONIVIS
v0.9

de.sonivis.tool.mwapiconnector
Class ThreadedMWApiBot

java.lang.Object
  extended by de.sonivis.tool.mwapiconnector.ThreadedMWApiBot

public class ThreadedMWApiBot
extends java.lang.Object

HTTP client for querying the MediaWiki API.

This new bot is based on Apache HttpClient in Version 4.0beta2 that went through a code rewrite and fixed a lot of bugs of the older versions.

The second difference is that it offers a method for threaded execution of a Collection of requests, namely performAllRequests(String).


Field Summary
static java.lang.String CHARSET
          Request response content encoding.
static int MAX_TOTAL_CONNECTIONS
          Number of maximum active threads in threaded execution mode.
static java.lang.String NAME
          Name of the bot.
static java.lang.String VERSION
          Version information.
 
Constructor Summary
protected ThreadedMWApiBot()
          Constructor.
  ThreadedMWApiBot(java.lang.String url)
          Constructor.
  ThreadedMWApiBot(java.net.URL url)
          Constructor.
 
Method Summary
protected  HttpGetThread createQueryThread(IWikiApiRequest iwar)
          Turn an IWikiApiRequest into an HttpGetThread.
 void finalize()
          
 HttpClient getClient()
          Retrieve the HttpClient.
 HttpHost getTarget()
          Retrieve the target HttpHost.
 java.lang.String getWikiPath()
          Return the path to the wiki to examine.
 void performAllRequests(java.lang.String comment)
          Execute all requests pending in HttpRequestQueue.
 void performRequest(IWikiApiRequest war)
          Execute an HTTP request.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CHARSET

public static final java.lang.String CHARSET
Request response content encoding.

See Also:
Constant Field Values

NAME

public static final java.lang.String NAME
Name of the bot.

See Also:
Constant Field Values

VERSION

public static final java.lang.String VERSION
Version information.

See Also:
Constant Field Values

MAX_TOTAL_CONNECTIONS

public static final int MAX_TOTAL_CONNECTIONS
Number of maximum active threads in threaded execution mode.

See Also:
Constant Field Values
Constructor Detail

ThreadedMWApiBot

protected ThreadedMWApiBot()
Constructor.

Groups the basic setup activities for the bot. It takes care of the socket connections, the protocol schemes, the connection management setup, the user agent string, the request response content encoding and creates the internal HttpClient.


ThreadedMWApiBot

public ThreadedMWApiBot(java.net.URL url)
Constructor.

Specify the URL to the base directory of a MediaWiki installation. Do not provide something like index.php or Main_Page in the URL. Whether the trailing slash is present or not doesn't matter. Note, that the wiki path (anything else than the domain name or IP) will be statically tied to the class.

The constructor currently has no way to tell if it is really a MediaWiki} installation URL that was provided. If not so, the

Parameters:
url - A URL to a MediaWiki installation.
See Also:
ThreadedMWApiBot(), wikiConnect(URL)

ThreadedMWApiBot

public ThreadedMWApiBot(java.lang.String url)
                 throws java.net.MalformedURLException
Constructor.

Basically the same as ThreadedMWApiBot(URL) except for the format of the parameter.

Parameters:
url - The String holding the URL to a MediaWiki installation.
Throws:
java.net.MalformedURLException - if specified url cannot be transformed into a URL.
See Also:
ThreadedMWApiBot(URL)
Method Detail

performAllRequests

public final void performAllRequests(java.lang.String comment)
Execute all requests pending in HttpRequestQueue.

The method loops through the HttpRequestQueue and polls for the top-most pending IWikiApiRequest and creates a HttpGet request with the internal wiki path settings of this class. Based on the successful creation of the request and the configured target a HttpGetThread is instanced and started.

When the {@link HttpRequestQueue} is empty then, this thread goes to {@link Thread#sleep(long) sleep} for some seconds before it checks the queue again. This way, follow-up requests produced by the {@link IWikiApiRequest}s should also be covered. If the thread nap happens to be interrupted the method calls itself recursively.

The argument is supposed to be a short string providing printable information on what kinds of queries are to be executed within the loop. The method is set to produce some progress information on standard out.

Parameters:
comment - Information on the queries to be executed. Will be used for progress output.
See Also:
HttpGetThread, HttpRequestQueue

createQueryThread

protected final HttpGetThread createQueryThread(IWikiApiRequest iwar)
Turn an IWikiApiRequest into an HttpGetThread.

Parameters:
iwar - The IWikiApiRequest to transform.
Returns:
The HttpGetThread created from the argument

performRequest

public final void performRequest(IWikiApiRequest war)
Execute an HTTP request.

The specified IWikiApiRequest is turned into an HttpRequest with the executable query string of the IWikiApiRequest having the wiki path prepended. The IWikiApiRequest defines the request method itself.

After the request was executed the bot inspects the server status and frees the connection in case of error. The error information is preserved and put out, the returned server status code is associated with the IWikiApiRequest.

The response content is streamed into a reader and on success passed to the XMLPreparer to create an XML document from the content that is fed back to the IWikiApiRequest.

Parameters:
war - The IWikiApiRequest to be executed.
See Also:
IWikiApiRequest

getWikiPath

public final java.lang.String getWikiPath()
Return the path to the wiki to examine.

Returns:
path to the wiki

getClient

public final HttpClient getClient()
Retrieve the HttpClient.

Returns:
the client

getTarget

public final HttpHost getTarget()
Retrieve the target HttpHost.

Returns:
the target

finalize

public void finalize()
              throws java.lang.Throwable

Overrides:
finalize in class java.lang.Object
Throws:
java.lang.Throwable
See Also:
Object.finalize()

SONIVIS
v0.9

Copyright 2006-2009 SONIVIS:Team. All Rights Reserved.