On Monday 14 April 2008 21:01, saces at freenetproject.org wrote:
> Author: saces
> Date: 2008-04-14 20:01:15 +0000 (Mon, 14 Apr 2008)
> New Revision: 19336
>
> Added:
> trunk/plugins/KeyExplorer/VerySimpleGet.java
> trunk/plugins/KeyExplorer/VerySimpleGetter.java
> Log:
> add a getter for KeyExplorer
>
> Added: trunk/plugins/KeyExplorer/VerySimpleGet.java
> ===================================================================
> --- trunk/plugins/KeyExplorer/VerySimpleGet.java
(rev 0)
> +++ trunk/plugins/KeyExplorer/VerySimpleGet.java 2008-04-14 20:01:15 UTC
(rev 19336)
> @@ -0,0 +1,99 @@
> +/**
> + *
> + */
> +package plugins.KeyExplorer;
> +
> +import java.io.IOException;
> +
> +import freenet.client.FetchContext;
> +import freenet.client.async.BaseSingleFileFetcher;
> +import freenet.client.async.ClientRequester;
> +import freenet.keys.ClientKey;
> +import freenet.keys.ClientKeyBlock;
> +import freenet.keys.KeyDecodeException;
> +import freenet.keys.TooBigException;
> +import freenet.node.LowLevelGetException;
> +import freenet.node.RequestScheduler;
> +import freenet.support.Logger;
> +import freenet.support.api.Bucket;
> +
> +/**
> + * @author saces
> + *
> + */
> +public class VerySimpleGet extends BaseSingleFileFetcher {
> +
> + private boolean finished = false;
> + private LowLevelGetException error;
> + private Bucket data;
> + private final Object waiter = new Object();
> + private boolean ismetadata;
> +
> + public VerySimpleGet(ClientKey key2, int maxRetries2, FetchContext
> ctx2,
ClientRequester parent2) {
> + super(key2, maxRetries2, ctx2, parent2);
> + }
> +
> + public void onFailure(LowLevelGetException e, Object token,
RequestScheduler sheduler) {
> + error = e;
> + finished = true;
> + Logger.error(this, "TODO", e);
> + synchronized(waiter)
> + {
> + waiter.notifyAll();
> + }
> + }
> +
> + public void onSuccess(ClientKeyBlock block, boolean fromStore, Object
token, RequestScheduler sheduler) {
> + data = extract(block);
> + ismetadata = block.isMetadata();
> + if(data == null) return; // failed
> + finished = true;
> + Logger.error(this, "TODO", new Error("TODO"));
> + synchronized(waiter)
> + {
> + waiter.notifyAll();
> + }
> + }
> +
> + public Bucket waitForCompletion() throws LowLevelGetException {
> + while(!finished) {
> + try {
> + synchronized(waiter)
> + {
> + waiter.wait();
> + }
> + } catch (InterruptedException e) {
> + // Ignore
> + }
> + }
> + Logger.error(this, "TODO", new Error("TODO"));
> + if(error != null) throw error;
> + return data;
> + }
> +
> + private Bucket extract(ClientKeyBlock block) {
> + Bucket tempdata;
> + try {
> + // FIXME What is the maximim size of an decompressed
> 32K chunk?
2GB. :) You may want to impose a smaller limit! In the node, we decompress
into a temporary file and then parse that, although fproxy imposes a limit of
2MB for content directly fetched without a warning, so that's a de facto
limit.
> + tempdata = block.decode(getContext().bucketFactory,
> 1024*1024, false);
> + } catch (KeyDecodeException e1) {
> + if(Logger.shouldLog(Logger.MINOR, this))
> + Logger.minor(this, "Decode failure: "+e1, e1);
> + onFailure(new
> LowLevelGetException(LowLevelGetException.DECODE_FAILED),
null, null);
> + return null;
> + } catch (TooBigException e) {
> + Logger.error(this, "Should never happens: "+e, e);
> + onFailure(new
> LowLevelGetException(LowLevelGetException.INTERNAL_ERROR),
null, null);
> + return null;
> + } catch (IOException e) {
> + Logger.error(this, "Could not capture data - disk
> full?: "+e, e);
> + onFailure(new
> LowLevelGetException(LowLevelGetException.DECODE_FAILED),
null, null);
> + return null;
> + }
> + return tempdata;
> + }
> +
> + public boolean isMetadata() {
> + return ismetadata;
> + }
> +}
>
> Added: trunk/plugins/KeyExplorer/VerySimpleGetter.java
> ===================================================================
> --- trunk/plugins/KeyExplorer/VerySimpleGetter.java
(rev 0)
> +++ trunk/plugins/KeyExplorer/VerySimpleGetter.java 2008-04-14 20:01:15 UTC
(rev 19336)
> @@ -0,0 +1,49 @@
> +/**
> + *
> + */
> +package plugins.KeyExplorer;
> +
> +import freenet.client.async.ClientGetState;
> +import freenet.client.async.ClientRequestScheduler;
> +import freenet.client.async.ClientRequester;
> +import freenet.keys.FreenetURI;
> +import freenet.support.Logger;
> +
> +/**
> + * @author saces
> + *
> + */
> +public class VerySimpleGetter extends ClientRequester {
> +
> + private FreenetURI uri;
> +
> + /**
> + * @param priorityclass
> + * @param chkscheduler
> + * @param sskscheduler
> + * @param client2
> + *
> + */
> + public VerySimpleGetter(short priorityclass, ClientRequestScheduler
chkscheduler, ClientRequestScheduler sskscheduler, FreenetURI uri2, Object
client2) {
> + super(priorityclass, chkscheduler, sskscheduler, client2);
> + uri = uri2;
> + }
> +
> + public FreenetURI getURI() {
> + return uri;
> + }
> +
> + public boolean isFinished() {
> + Logger.error(this, "TODO", new Error("TODO"));
> + return false;
> + }
> +
> + public void notifyClients() {
> + Logger.error(this, "TODO", new Error("TODO"));
> + }
> +
> + public void onTransition(ClientGetState oldState, ClientGetState
> newState)
{
> + Logger.error(this, "TODO", new Error("TODO"));
> + }
> +
> +}
>
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
>
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL:
<https://emu.freenetproject.org/pipermail/devl/attachments/20080414/1b7287ca/attachment.pgp>