diff options
author | Kelly Rauchenberger <fefferburbia@gmail.com> | 2008-09-28 15:25:27 +0000 |
---|---|---|
committer | Kelly Rauchenberger <fefferburbia@gmail.com> | 2008-09-28 15:25:27 +0000 |
commit | 0bed7609d62da9132801ff2dee9311e2edb9f934 (patch) | |
tree | a8a2e6f8cd26c604213055573d86442af412671c /client/trunk/src/com | |
parent | c3b736f341ae87b48341c2b5fb18983b3dbfbbb0 (diff) | |
download | instadisc-0bed7609d62da9132801ff2dee9311e2edb9f934.tar.gz instadisc-0bed7609d62da9132801ff2dee9311e2edb9f934.tar.bz2 instadisc-0bed7609d62da9132801ff2dee9311e2edb9f934.zip |
Client: Completed step 8
Refs #69
Diffstat (limited to 'client/trunk/src/com')
-rw-r--r-- | client/trunk/src/com/fourisland/instadisc/DownloadItem/PushMode.java | 39 | ||||
-rw-r--r-- | client/trunk/src/com/fourisland/instadisc/Item/Item.java | 22 |
2 files changed, 37 insertions, 24 deletions
diff --git a/client/trunk/src/com/fourisland/instadisc/DownloadItem/PushMode.java b/client/trunk/src/com/fourisland/instadisc/DownloadItem/PushMode.java index eb5ab5c..2e5a6ca 100644 --- a/client/trunk/src/com/fourisland/instadisc/DownloadItem/PushMode.java +++ b/client/trunk/src/com/fourisland/instadisc/DownloadItem/PushMode.java | |||
@@ -8,7 +8,6 @@ import java.io.InputStream; | |||
8 | import java.net.ServerSocket; | 8 | import java.net.ServerSocket; |
9 | import java.net.Socket; | 9 | import java.net.Socket; |
10 | import java.net.SocketException; | 10 | import java.net.SocketException; |
11 | import java.util.HashMap; | ||
12 | import java.util.logging.Level; | 11 | import java.util.logging.Level; |
13 | import java.util.logging.Logger; | 12 | import java.util.logging.Logger; |
14 | 13 | ||
@@ -19,13 +18,19 @@ public class PushMode implements DownloadItemMode | |||
19 | 18 | ||
20 | public void modeInitalize() | 19 | public void modeInitalize() |
21 | { | 20 | { |
22 | idt = new InstaDiscThread(); | 21 | XmlRpc xmlrpc = new XmlRpc("initalizePort"); |
22 | int port = (Integer) xmlrpc.execute(); | ||
23 | |||
24 | idt = new InstaDiscThread(port); | ||
23 | new Thread(idt).start(); | 25 | new Thread(idt).start(); |
24 | } | 26 | } |
25 | 27 | ||
26 | public void modeDeinitalize() | 28 | public void modeDeinitalize() |
27 | { | 29 | { |
28 | idt.kill(); | 30 | idt.kill(); |
31 | |||
32 | XmlRpc xmlrpc = new XmlRpc("deinitalizePort"); | ||
33 | xmlrpc.execute(); | ||
29 | } | 34 | } |
30 | 35 | ||
31 | public void requestRetained() { | 36 | public void requestRetained() { |
@@ -53,6 +58,12 @@ class InstaDiscThread implements Runnable { | |||
53 | 58 | ||
54 | boolean cancelled = false; | 59 | boolean cancelled = false; |
55 | ServerSocket svr; | 60 | ServerSocket svr; |
61 | int port; | ||
62 | |||
63 | public InstaDiscThread(int port) | ||
64 | { | ||
65 | this.port = port; | ||
66 | } | ||
56 | 67 | ||
57 | public void cancel() { | 68 | public void cancel() { |
58 | cancelled = true; | 69 | cancelled = true; |
@@ -62,7 +73,7 @@ class InstaDiscThread implements Runnable { | |||
62 | try | 73 | try |
63 | { | 74 | { |
64 | svr = new ServerSocket(); | 75 | svr = new ServerSocket(); |
65 | java.net.InetSocketAddress addr = new java.net.InetSocketAddress(1204); | 76 | java.net.InetSocketAddress addr = new java.net.InetSocketAddress(port); |
66 | svr.bind(addr); | 77 | svr.bind(addr); |
67 | while (!cancelled) | 78 | while (!cancelled) |
68 | { | 79 | { |
@@ -90,6 +101,8 @@ class InstaDiscThread implements Runnable { | |||
90 | 101 | ||
91 | public void kill() | 102 | public void kill() |
92 | { | 103 | { |
104 | cancel(); | ||
105 | |||
93 | try | 106 | try |
94 | { | 107 | { |
95 | svr.close(); | 108 | svr.close(); |
@@ -144,24 +157,6 @@ class HandleItemThread implements Runnable { | |||
144 | result.append(Character.toString((char) buffer[j])); | 157 | result.append(Character.toString((char) buffer[j])); |
145 | } | 158 | } |
146 | 159 | ||
147 | String[] headers = result.toString().split("\n"); | ||
148 | HashMap<String, String> headerMap = new HashMap<String, String>(); | ||
149 | i = 0; | ||
150 | while (1 == 1) | ||
151 | { | ||
152 | try | ||
153 | { | ||
154 | String[] nameVal = headers[i].split(": "); | ||
155 | String name = nameVal[0]; | ||
156 | String value = nameVal[1].trim().replace("__INSTADISC__", ": "); | ||
157 | headerMap.put(name, value); | ||
158 | } catch (Exception ex) | ||
159 | { | ||
160 | break; | ||
161 | } | ||
162 | i++; | ||
163 | } | ||
164 | |||
165 | try | 160 | try |
166 | { | 161 | { |
167 | s.close(); | 162 | s.close(); |
@@ -170,7 +165,7 @@ class HandleItemThread implements Runnable { | |||
170 | Logger.getLogger(HandleItemThread.class.getName()).log(Level.SEVERE, null, ex); | 165 | Logger.getLogger(HandleItemThread.class.getName()).log(Level.SEVERE, null, ex); |
171 | } | 166 | } |
172 | 167 | ||
173 | Item idI = new Item(headerMap); | 168 | Item idI = new Item(result.toString()); |
174 | idI.start(); | 169 | idI.start(); |
175 | } catch (IOException ex) | 170 | } catch (IOException ex) |
176 | { | 171 | { |
diff --git a/client/trunk/src/com/fourisland/instadisc/Item/Item.java b/client/trunk/src/com/fourisland/instadisc/Item/Item.java index 2fe97dc..272ce2d 100644 --- a/client/trunk/src/com/fourisland/instadisc/Item/Item.java +++ b/client/trunk/src/com/fourisland/instadisc/Item/Item.java | |||
@@ -21,8 +21,26 @@ public class Item { | |||
21 | 21 | ||
22 | HashMap<String, String> headerMap; | 22 | HashMap<String, String> headerMap; |
23 | 23 | ||
24 | public Item(HashMap<String, String> headerMap) { | 24 | public Item(String result) { |
25 | this.headerMap = headerMap; | 25 | String[] headers = result.toString().split("\n"); |
26 | HashMap<String, String> tempHeaderMap = new HashMap<String, String>(); | ||
27 | int i = 0; | ||
28 | while (1 == 1) | ||
29 | { | ||
30 | try | ||
31 | { | ||
32 | String[] nameVal = headers[i].split(": "); | ||
33 | String name = nameVal[0]; | ||
34 | String value = nameVal[1].trim().replace("__INSTADISC__", ": "); | ||
35 | tempHeaderMap.put(name, value); | ||
36 | } catch (Exception ex) | ||
37 | { | ||
38 | break; | ||
39 | } | ||
40 | i++; | ||
41 | } | ||
42 | |||
43 | this.headerMap = tempHeaderMap; | ||
26 | } | 44 | } |
27 | 45 | ||
28 | public void start() { | 46 | public void start() { |