From: David ‘Bombe’ Roden Date: Mon, 10 Sep 2012 11:08:57 +0000 (+0200) Subject: Implement removal of contexts. X-Git-Tag: 0.8.3^2~47 X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=commitdiff_plain;h=95404485c0987d8192337e7f44f37a09ed7818ea;ds=sidebyside Implement removal of contexts. --- diff --git a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java index 59abc8e..ded6da9 100644 --- a/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java +++ b/src/main/java/net/pterodactylus/sone/core/WebOfTrustUpdater.java @@ -183,6 +183,26 @@ public class WebOfTrustUpdater extends AbstractService { return false; } + /** + * Removes the given context from the given own identity. + * + * @param ownIdentity + * The own identity to remove the context from + * @param context + * The context to remove + */ + public void removeContext(OwnIdentity ownIdentity, String context) { + RemoveContextJob removeContextJob = new RemoveContextJob(ownIdentity, context); + if (!updateJobs.contains(removeContextJob)) { + logger.log(Level.FINER, "Adding Context Job: " + removeContextJob); + try { + updateJobs.put(removeContextJob); + } catch (InterruptedException ie1) { + /* the queue is unbounded so it should never block. */ + } + } + } + // // SERVICE METHODS // @@ -553,4 +573,41 @@ public class WebOfTrustUpdater extends AbstractService { } + /** + * Job that removes a context from an {@link OwnIdentity}. + * + * @author David ‘Bombe’ Roden + */ + private class RemoveContextJob extends WebOfTrustContextUpdateJob { + + /** + * Creates a new remove-context job. + * + * @param ownIdentity + * The own identity whose contexts to manage + * @param context + * The context to remove + */ + public RemoveContextJob(OwnIdentity ownIdentity, String context) { + super(ownIdentity, context); + } + + /** + * {@inheritDoc} + */ + @Override + @SuppressWarnings("synthetic-access") + public void run() { + try { + webOfTrustConnector.removeContext(ownIdentity, context); + ownIdentity.removeContext(context); + finish(true); + } catch (PluginException pe1) { + logger.log(Level.WARNING, String.format("Could not remove Context “%2$s” to Own Identity %1$s!", ownIdentity, context), pe1); + finish(false); + } + } + + } + }