FileDocCategorySizeDatePackage
LocalResourceHTTPServer.javaAPI DocAzureus 3.0.3.43045Thu Mar 01 23:47:30 GMT 2007com.aelitis.azureus.util

LocalResourceHTTPServer

public class LocalResourceHTTPServer extends Object implements TrackerWebPageGenerator

Fields Summary
private static final String
my_ip
private int
my_port
private org.gudy.azureus2.plugins.logging.LoggerChannel
logger
private int
resource_id_next
private Map
published_resources
Constructors Summary
public LocalResourceHTTPServer(org.gudy.azureus2.plugins.PluginInterface _plugin_interface, org.gudy.azureus2.plugins.logging.LoggerChannel _logger)


	  
			 

	  
		logger = _logger;

		resource_id_next = new Random().nextInt(Integer.MAX_VALUE / 2);

		InetAddress bind_address = InetAddress.getByName(my_ip);

		TrackerWebContext context = _plugin_interface.getTracker().createWebContext(
				"Director:localResource", 0, Tracker.PR_HTTP, bind_address);

		my_port = context.getURLs()[0].getPort();

		if (logger != null) {
			logger.log("Local resource publisher running on " + my_ip + ":" + my_port);
		}

		context.addPageGenerator(this);
	
Methods Summary
public booleangenerate(TrackerWebPageRequest request, TrackerWebPageResponse response)

		String path = request.getURL();

		File resource;

		synchronized (this) {

			resource = (File) published_resources.get(path);
		}

		if (resource == null) {

			return (false);
		}

		return (response.useFile(resource.getParent(), "/" + resource.getName()));
	
public java.net.URLpublishResource(java.io.File resource)

		synchronized (this) {

			resource = resource.getCanonicalFile();

			URL result = new URL("http://" + my_ip + ":" + my_port + "/"
					+ resource_id_next++ + "/" + resource.getName());

			published_resources.put(result.getPath(), resource);

			if (logger != null) {
				logger.log("Local resource added: " + resource + " -> " + result);
			}

			return (result);
		}