Author: batosai
Date: 2008-06-15 15:16:57 +0000 (Sun, 15 Jun 2008)
New Revision: 20354
Modified:
trunk/apps/WoT/src/plugins/WoT/FCPHandler.java
trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
trunk/apps/WoT/src/plugins/WoT/WoT.java
Log:
Make IdentityFetcher an implementation of FcpListener. Should do the same with
IdentityInserter.
Modified: trunk/apps/WoT/src/plugins/WoT/FCPHandler.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/FCPHandler.java 2008-06-15 14:14:02 UTC
(rev 20353)
+++ trunk/apps/WoT/src/plugins/WoT/FCPHandler.java 2008-06-15 15:16:57 UTC
(rev 20354)
@@ -1,8 +1,10 @@
package plugins.WoT;
import java.io.IOException;
+import java.io.InputStream;
import java.net.UnknownHostException;
+import net.pterodactylus.fcp.AllData;
import net.pterodactylus.fcp.ClientGet;
import net.pterodactylus.fcp.ClientHello;
import net.pterodactylus.fcp.ClientPutDiskDir;
@@ -26,6 +28,7 @@
private SSKKeypair sskKeypair;
private boolean insertSuccessfull;
private IdentityFetcher fetcher;
+ private InputStream pis;
public FCPHandler(String host, int port) throws UnknownHostException,
IOException, InterruptedException {
@@ -62,11 +65,6 @@
return insertSuccessfull;
}
- public void getFile (String uri) throws IOException {
- fcp.sendMessage(new ClientGet(uri, "WoTfetcher"));
-
- }
-
// This is lame, I'll find a better way to notify it later
public void addIdentityFetcher(IdentityFetcher id) {
fetcher = id;
@@ -98,4 +96,6 @@
notify();
}
}
+
+
}
Modified: trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java 2008-06-15 14:14:02 UTC
(rev 20353)
+++ trunk/apps/WoT/src/plugins/WoT/IdentityFetcher.java 2008-06-15 15:16:57 UTC
(rev 20354)
@@ -1,48 +1,359 @@
package plugins.WoT;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Iterator;
import java.util.List;
+import net.pterodactylus.fcp.AllData;
import net.pterodactylus.fcp.ClientGet;
+import net.pterodactylus.fcp.CloseConnectionDuplicateClientName;
+import net.pterodactylus.fcp.ConfigData;
+import net.pterodactylus.fcp.DataFound;
+import net.pterodactylus.fcp.EndListPeerNotes;
+import net.pterodactylus.fcp.EndListPeers;
+import net.pterodactylus.fcp.EndListPersistentRequests;
+import net.pterodactylus.fcp.FCPPluginReply;
+import net.pterodactylus.fcp.FcpConnection;
+import net.pterodactylus.fcp.FcpListener;
+import net.pterodactylus.fcp.FcpMessage;
+import net.pterodactylus.fcp.FinishedCompression;
+import net.pterodactylus.fcp.GetFailed;
+import net.pterodactylus.fcp.IdentifierCollision;
+import net.pterodactylus.fcp.NodeData;
+import net.pterodactylus.fcp.NodeHello;
+import net.pterodactylus.fcp.Peer;
+import net.pterodactylus.fcp.PeerNote;
+import net.pterodactylus.fcp.PeerRemoved;
+import net.pterodactylus.fcp.PersistentGet;
+import net.pterodactylus.fcp.PersistentPut;
+import net.pterodactylus.fcp.PersistentPutDir;
+import net.pterodactylus.fcp.PersistentRequestModified;
+import net.pterodactylus.fcp.PersistentRequestRemoved;
+import net.pterodactylus.fcp.PluginInfo;
+import net.pterodactylus.fcp.ProtocolError;
+import net.pterodactylus.fcp.PutFailed;
+import net.pterodactylus.fcp.PutFetchable;
+import net.pterodactylus.fcp.PutSuccessful;
+import net.pterodactylus.fcp.SSKKeypair;
+import net.pterodactylus.fcp.SimpleProgress;
+import net.pterodactylus.fcp.StartedCompression;
+import net.pterodactylus.fcp.SubscribedUSKUpdate;
+import net.pterodactylus.fcp.TestDDAComplete;
+import net.pterodactylus.fcp.TestDDAReply;
+import net.pterodactylus.fcp.URIGenerated;
+import net.pterodactylus.fcp.UnknownNodeIdentifier;
+import net.pterodactylus.fcp.UnknownPeerNoteType;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
import com.db4o.query.Predicate;
-public class IdentityFetcher {
+public class IdentityFetcher implements FcpListener{
private ObjectContainer db;
- private FCPHandler fcp;
+ private FcpConnection fcp;
+ private boolean fileFetched;
+ private InputStream pis;
+ private String identifier = "WoTfetcher";
+
/**
* Creates the IdentityInserter
*
* @param db Connection to the database
*/
- public IdentityFetcher(ObjectContainer db, FCPHandler fcp) {
+ public IdentityFetcher(ObjectContainer db, FcpConnection fcp) {
this.db = db;
this.fcp = fcp;
- // TODO Find a better way to be notified of updates
- fcp.addIdentityFetcher(this);
+ fcp.addFcpListener(this);
+ }
+
+ public void fetch(Identity identity) throws IOException,
InterruptedException {
+ synchronized (this) {
+ fcp.sendMessage(new
ClientGet(identity.getFullRequestURI(), identifier));
+ this.wait();
+ }
- List<Identity> identitiesToInsert = db.query(new
Predicate<Identity> () {
- public boolean match (Identity identity) {
- // We only get identities we do not own
- return !(identity instanceof OwnIdentity);
- }
- });
-
- Iterator<Identity> it = identitiesToInsert.iterator();
-
- while(it.hasNext()) {
- System.out.println(it.next().getRequestURI());
+ if(fileFetched) {
+ // TODO Make the identity update itself from the file
}
}
- public void fetch(Identity identity) throws IOException {
- fcp.getFile(identity.getFullRequestURI());
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedNodeHello(FcpConnection fcpConnection, NodeHello
nodeHello) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedCloseConnectionDuplicateClientName(FcpConnection
fcpConnection, CloseConnectionDuplicateClientName
closeConnectionDuplicateClientName) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedSSKKeypair(FcpConnection fcpConnection, SSKKeypair
sskKeypair) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPeer(FcpConnection fcpConnection, Peer peer) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedEndListPeers(FcpConnection fcpConnection,
EndListPeers endListPeers) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPeerNote(FcpConnection fcpConnection, PeerNote
peerNote) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedEndListPeerNotes(FcpConnection fcpConnection,
EndListPeerNotes endListPeerNotes) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPeerRemoved(FcpConnection fcpConnection,
PeerRemoved peerRemoved) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see FcpListener#receivedNodeData(FcpConnection, NodeData)
+ */
+ public void receivedNodeData(FcpConnection fcpConnection, NodeData
nodeData) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see FcpListener#receivedTestDDAReply(FcpConnection, TestDDAReply)
+ */
+ public void receivedTestDDAReply(FcpConnection fcpConnection,
TestDDAReply testDDAReply) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedTestDDAComplete(FcpConnection fcpConnection,
TestDDAComplete testDDAComplete) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPersistentGet(FcpConnection fcpConnection,
PersistentGet persistentGet) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPersistentPut(FcpConnection fcpConnection,
PersistentPut persistentPut) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedEndListPersistentRequests(FcpConnection
fcpConnection, EndListPersistentRequests endListPersistentRequests) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedURIGenerated(FcpConnection fcpConnection,
URIGenerated uriGenerated) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedDataFound(FcpConnection fcpConnection, DataFound
dataFound) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedAllData(FcpConnection fcpConnection, AllData
allData) {
+ if(allData.getIdentifier() == identifier) {
+ fileFetched = true;
+ pis = allData.getPayloadInputStream();
+ synchronized (this) {
+ notify();
+ }
+ }
}
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedSimpleProgress(FcpConnection fcpConnection,
SimpleProgress simpleProgress) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedStartedCompression(FcpConnection fcpConnection,
StartedCompression startedCompression) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receviedFinishedCompression(FcpConnection fcpConnection,
FinishedCompression finishedCompression) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedUnknownPeerNoteType(FcpConnection fcpConnection,
UnknownPeerNoteType unknownPeerNoteType) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedUnknownNodeIdentifier(FcpConnection fcpConnection,
UnknownNodeIdentifier unknownNodeIdentifier) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedConfigData(FcpConnection fcpConnection, ConfigData
configData) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedGetFailed(FcpConnection fcpConnection, GetFailed
getFailed) {
+ if(getFailed.getIdentifier() == identifier) {
+ fileFetched = false;
+ synchronized (this) {
+ notify();
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPutFailed(FcpConnection fcpConnection, PutFailed
putFailed) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedIdentifierCollision(FcpConnection fcpConnection,
IdentifierCollision identifierCollision) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPersistentPutDir(FcpConnection fcpConnection,
PersistentPutDir persistentPutDir) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPersistentRequestRemoved(FcpConnection
fcpConnection, PersistentRequestRemoved persistentRequestRemoved) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedSubscribedUSKUpdate(FcpConnection fcpConnection,
SubscribedUSKUpdate subscribedUSKUpdate) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPluginInfo(FcpConnection fcpConnection, PluginInfo
pluginInfo) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedFCPPluginReply(FcpConnection fcpConnection,
FCPPluginReply fcpPluginReply) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPersistentRequestModified(FcpConnection
fcpConnection, PersistentRequestModified persistentRequestModified) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPutSuccessful(FcpConnection fcpConnection,
PutSuccessful putSuccessful) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedPutFetchable(FcpConnection fcpConnection,
PutFetchable putFetchable) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedProtocolError(FcpConnection fcpConnection,
ProtocolError protocolError) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void receivedMessage(FcpConnection fcpConnection, FcpMessage
fcpMessage) {
+ /* empty. */
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public void connectionClosed(FcpConnection fcpConnection) {
+ /* empty. */
+ }
+
}
Modified: trunk/apps/WoT/src/plugins/WoT/WoT.java
===================================================================
--- trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-06-15 14:14:02 UTC (rev
20353)
+++ trunk/apps/WoT/src/plugins/WoT/WoT.java 2008-06-15 15:16:57 UTC (rev
20354)
@@ -12,6 +12,8 @@
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
+import net.pterodactylus.fcp.FcpConnection;
+
import com.db4o.Db4o;
import com.db4o.ObjectContainer;
import com.db4o.ObjectSet;
@@ -35,7 +37,7 @@
}; // Identities with negative score have zero
capacity
private IdentityInserter identityInserter;
- private FCPHandler fcp;
+ private FcpConnection fcp;
private ObjectContainer db;
@@ -51,7 +53,11 @@
public WoT(String host, int port) throws UnknownHostException,
IOException, InterruptedException {
db = Db4o.openFile("WoT.db4o");
- fcp = new FCPHandler(host,port);
+
+ fcp = new FcpConnection(host,port);
+ fcp.connect();
+
+ //fcp = new FCPHandler(host,port);
//identityInserter = new IdentityInserter(db, fcp);
//identityInserter.start();
@@ -66,7 +72,7 @@
private void close() {
//identityInserter.stop();
- fcp.close();
+ fcp.disconnect();
db.close();
}