Author: xor
Date: 2009-03-17 06:49:19 +0000 (Tue, 17 Mar 2009)
New Revision: 26052
Added:
trunk/freenet/src/freenet/pluginmanager/PluginReplySenderBlocking.java
Removed:
trunk/freenet/src/freenet/pluginmanager/PluginTalkerBlocking.java
Modified:
trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java
trunk/freenet/src/freenet/pluginmanager/PluginTalker.java
Log:
Merge PluginTalkerBlocking into PluginTalker: The name "PluginTalkerBlocking"
would not make sense because it is also still able to send non-blocking
messages.
Added: trunk/freenet/src/freenet/pluginmanager/PluginReplySenderBlocking.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginReplySenderBlocking.java
(rev 0)
+++ trunk/freenet/src/freenet/pluginmanager/PluginReplySenderBlocking.java
2009-03-17 06:49:19 UTC (rev 26052)
@@ -0,0 +1,37 @@
+package freenet.pluginmanager;
+
+import freenet.pluginmanager.PluginTalker.Result;
+import freenet.support.Logger;
+import freenet.support.SimpleFieldSet;
+import freenet.support.api.Bucket;
+
+public class PluginReplySenderBlocking extends PluginReplySender {
+
+ protected volatile PluginTalker.Result mResult;
+
+ public PluginReplySenderBlocking(String myPluginName, String
myConnectionIdentifier) {
+ super(myPluginName, myConnectionIdentifier);
+ }
+
+ @Override
+ public synchronized void send(SimpleFieldSet params, Bucket bucket) {
+ if(mResult == null) {
+ mResult = new Result(params, bucket);
+ notifyAll();
+ } else {
+ Logger.error(this, "PluginTalker.sendBlocking() is
being used with a FCP call which results in more than 1 reply");
+ }
+ }
+
+ public Result getResult() {
+ while(mResult == null) {
+ try {
+ wait();
+ } catch (InterruptedException e) {
+ }
+ }
+
+ return mResult;
+ }
+
+}
\ No newline at end of file
Modified: trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java
2009-03-17 06:36:56 UTC (rev 26051)
+++ trunk/freenet/src/freenet/pluginmanager/PluginRespirator.java
2009-03-17 06:49:19 UTC (rev 26052)
@@ -62,9 +62,5 @@
public PluginTalker getPluginTalker(FredPluginTalker fpt, String
pluginname, String identifier) throws PluginNotFoundException {
return new PluginTalker(fpt, node, pluginname, identifier);
}
-
- public PluginTalkerBlocking getPluginTalkerBlocking(FredPluginTalker
fpt, String pluginname, String identifier)
- throws PluginNotFoundException {
- return new PluginTalkerBlocking(fpt, node, pluginname,
identifier);
- }
+
}
Modified: trunk/freenet/src/freenet/pluginmanager/PluginTalker.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginTalker.java 2009-03-17
06:36:56 UTC (rev 26051)
+++ trunk/freenet/src/freenet/pluginmanager/PluginTalker.java 2009-03-17
06:49:19 UTC (rev 26052)
@@ -10,7 +10,7 @@
import freenet.support.api.Bucket;
/**
- * @author saces
+ * @author saces, xor
*
*/
public class PluginTalker {
@@ -66,4 +66,35 @@
}, "FCPPlugin talk runner for " + this);
}
+
+ public static class Result {
+ public SimpleFieldSet params;
+ public Bucket data;
+
+ public Result(SimpleFieldSet myParams, Bucket myData) {
+ params = myParams;
+ data = myData;
+ }
+ }
+
+ /**
+ * Sends a FCP message and blocks execution until the answer was
received and then returns the answer.
+ * This can be used to simplify code which uses FCP very much,
especially UI code which needs the result of FCP calls directly.
+ *
+ * When using sendBlocking(), please make sure that you only ever call
it for FCP functions which only send() a single result!
+ * Results which are sent by the plugin after the first result are
dispatched to the asynchronous onReply() function of your
+ * FredPluginTalker, however this behavior is deprecated and not
guranteed to work.
+ */
+ public Result sendBlocking(final SimpleFieldSet plugparams, final
Bucket data2) {
+ final PluginReplySenderBlocking replySender = new
PluginReplySenderBlocking(pluginName, connectionIdentifier);
+
+ node.executor.execute(new Runnable() {
+
+ public void run() {
+ plugin.handle(replySender, plugparams, data2,
access);
+ }
+ }, "PluginTalkerBlocking " + connectionIdentifier);
+
+ return replySender.getResult();
+ }
}
Deleted: trunk/freenet/src/freenet/pluginmanager/PluginTalkerBlocking.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginTalkerBlocking.java
2009-03-17 06:36:56 UTC (rev 26051)
+++ trunk/freenet/src/freenet/pluginmanager/PluginTalkerBlocking.java
2009-03-17 06:49:19 UTC (rev 26052)
@@ -1,87 +0,0 @@
-/* This code is part of Freenet. It is distributed under the GNU General
- * Public License, version 2 (or at your option any later version). See
- * http://www.gnu.org/ for further details of the GPL. */
-package freenet.pluginmanager;
-
-import freenet.node.Node;
-import freenet.support.Logger;
-import freenet.support.SimpleFieldSet;
-import freenet.support.api.Bucket;
-
-/**
- * A PluginTalker which has a sendBlocking() function which directly returns
the result of the FCP call to the caller.
- * This can be used to simplify code which uses FCP very much, especially UI
code which needs the result of FCP calls directly.
- *
- * @author xor
- */
-public class PluginTalkerBlocking extends PluginTalker {
-
- public PluginTalkerBlocking(FredPluginTalker myPluginTalker, Node
myNode, String myPluginName, String myConnectionIdentifier)
- throws PluginNotFoundException {
- super(myPluginTalker, myNode, myPluginName,
myConnectionIdentifier);
- // TODO Auto-generated constructor stub
- }
-
- public static class Result {
- public SimpleFieldSet params;
- public Bucket data;
-
- public Result(SimpleFieldSet myParams, Bucket myData) {
- params = myParams;
- data = myData;
- }
- }
-
- protected class PluginReplySenderBlocking extends PluginReplySender {
-
- protected final PluginReplySender nonBlockingReplySender;
- protected volatile Result mResult;
-
- public PluginReplySenderBlocking() {
- super(pluginName, connectionIdentifier);
- nonBlockingReplySender = replysender;
- }
-
- @Override
- public synchronized void send(SimpleFieldSet params, Bucket
bucket) {
- if(mResult == null) {
- mResult = new Result(params, bucket);
- notifyAll();
- } else {
- Logger.error(this, "PluginTalkerBlocking is
being used with a FCP call which results in more than 1 reply");
- nonBlockingReplySender.send(params, bucket);
- }
- }
-
- public Result getResult() {
- while(mResult == null) {
- try {
- wait();
- } catch (InterruptedException e) {
- }
- }
-
- return mResult;
- }
-
- }
-
- /**
- * When using sendBlocking(), please make sure that you only ever call
it for FCP functions which only send() a single result!
- * Results which are sent by the plugin after the first result are
dispatched to the asynchronous onReply() function of your
- * FredPluginTalker, however this behavior is deprecated and not
guranteed to work.
- */
- public Result sendBlocking(final SimpleFieldSet plugparams, final
Bucket data2) {
- final PluginReplySenderBlocking replySender = new
PluginReplySenderBlocking();
-
- node.executor.execute(new Runnable() {
-
- public void run() {
- plugin.handle(replySender, plugparams, data2,
access);
- }
- }, "PluginTalkerBlocking " + connectionIdentifier);
-
- return replySender.getResult();
- }
-
-}
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs