Add default constructor that creates a random ID.
[jSite2.git] / src / net / pterodactylus / jsite / core / Request.java
index 47349ca..15dae81 100644 (file)
@@ -1,6 +1,6 @@
 /*
- * jSite2 - Request.java -
- * Copyright © 2008 David Roden
+ * jSite-next - Request.java -
+ * Copyright © 2009 David Roden
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 
 package net.pterodactylus.jsite.core;
 
+import net.pterodactylus.jsite.util.IdGenerator;
+import net.pterodactylus.util.number.Hex;
+
 /**
- * A request is an ongoing download or upload reported by the freenet node.
- * 
- * @author David ‘Bombe’ Roden <bombe@freenetproject.org>
- * @version $Id$
+ * Wraps a request that is executed by the Freenet node.
+ *
+ * @author <a href="mailto:bombe@pterodactylus.net">David ‘Bombe’ Roden</a>
  */
 public class Request {
 
-       /** The identifier of the request. */
-       private final String identifier;
+       /** The ID of the request. */
+       private final String id;
+
+       /** The client token of the request. */
+       private String clientToken;
+
+       /**
+        * Creates a new request with a random ID.
+        */
+       public Request() {
+               this(Hex.toHex(IdGenerator.generateId()));
+       }
+
+       /**
+        * Creates a new request.
+        *
+        * @param id
+        *            The ID of the request
+        */
+       public Request(String id) {
+               this.id = id;
+       }
+
+       /**
+        * Returns the ID of the request.
+        *
+        * @return The request’s ID
+        */
+       public String getId() {
+               return id;
+       }
 
        /**
-        * Creates a new request with the given identifier.
-        * 
-        * @param identifier
-        *            The identifier of the request
+        * Returns the client token of the request.
+        *
+        * @return The request’s client token
         */
-       Request(String identifier) {
-               this.identifier = identifier;
+       public String getClientToken() {
+               return clientToken;
        }
 
        /**
-        * Returns the identifier of the request. It is unique per node.
-        * 
-        * @return The identifier of the request
+        * Sets the client token of the request
+        *
+        * @param clientToken
+        *            The request’s new client token
         */
-       public String getIdentifier() {
-               return identifier;
+       public void setClientToken(String clientToken) {
+               this.clientToken = clientToken;
        }
 
 }