-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentDataReceive.java
316 lines (256 loc) · 8.1 KB
/
ContentDataReceive.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
import java.io.ObjectInputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Vector;
import java.sql.*;
import java.util.Random;
public class ContentDataReceive extends Thread
{
ServerSocket ss;
Socket s;
ObjectInputStream ois;
public ContentDataReceive()
{
try
{
ss=new ServerSocket(1021);
}
catch (Exception e)
{
e.printStackTrace();
}
start();
}
public void run()
{
try
{
while(true)
{
s=ss.accept();
ois=new ObjectInputStream(s.getInputStream());
Vector recv=(Vector)ois.readObject();
String nodename=""+recv.get(0);
String dom=""+recv.get(1);
String des=""+recv.get(2);
String dist=""+recv.get(3);
Middle.content.insertRow(Middle.content.getRowCount(),recv);
System.out.println("Middle.conmap"+Middle.conmap);
System.out.println("Middle.conmap_dep"+Middle.conmap_dep);
if(Middle.conmap.containsKey(nodename+dom))
{
String val=Middle.conmap.get(nodename+dom);
System.out.println("val1"+val);
Middle.conmap.remove(nodename+dom);
Middle.conmap.put(nodename+dom,val+"---"+des);
}
else
{
Middle.conmap.put(nodename+dom,des);
}
if(Middle.conmap_dep.containsKey(nodename))
{
String val=Middle.conmap_dep.get(nodename);
System.out.println("val2"+val);
Middle.conmap_dep.remove(nodename);
Middle.conmap_dep.put(nodename,val+"---"+des);
}
else
{
Middle.conmap_dep.put(nodename,des);
}
DBConnection obj = new DBConnection();
Connection con = obj.getConnection();
Statement st = con.createStatement();
String f="";
int i=st.executeUpdate("insert into contentmap values ('"+nodename+"','"+dom+"','"+des +"','"+dist+"')");
if( i==1)
{
System.out.println("Register Successfully");
}
else
{
System.out.println("Register Failed");
}
st.close();
con.close();
Vector por=new Vector();
Vector dis=new Vector();
DBConnection obj1 = new DBConnection();
Connection con1 = obj1.getConnection();
Statement st1 = con1.createStatement();
ResultSet rs = st1.executeQuery("select * from submap where domain='"+dom+"'");
while(rs.next())
{
String nname=rs.getString(1);
por.add(rs.getString(2));
dis.add(rs.getString(4));
}
System.out.println("port vector"+por);
System.out.println("dist"+dis);
for(int r=0;r<por.size();r++)
{
String resultvalue="";
Random r2=new Random();
String token="T"+r2.nextInt(10)+""+r2.nextInt(10)+""+r2.nextInt(10)+""+r2.nextInt(10);
Connection con2 = obj.getConnection();
Statement st2 = con2.createStatement();
ResultSet rs1 = st2.executeQuery("select description,distance from contentmap where domain='"+dom+"'");
//filtered result
while(rs1.next())
{
String que=rs1.getString(1);
int tempdis=Integer.parseInt(rs1.getString(2));
System.out.println(que);
System.out.println(tempdis);
if(true)
{
Vector vec=new Vector();
String dis1=(String)dis.get(r);
int dis2=Integer.parseInt(dis1);
if(tempdis>=(dis2-50) && tempdis<=(dis2+50))
{
vec.add(que);
}
System.out.println(vec);
for(int k=0;k<vec.size();k++)
{
resultvalue=resultvalue+"---3--->"+vec.get(k);
}
}
}
System.out.println("new"+resultvalue);
if(resultvalue !=null && !resultvalue.isEmpty()){
resultvalue=""+token+resultvalue;
} else {
resultvalue="";
}
resultvalue=resultvalue+"&&"+"filter";
System.out.println("filter"+resultvalue);
String port1=(String)por.get(r);
int port2=Integer.parseInt(port1);
System.out.println("port"+por.get(r));
SendData sd=new SendData();
sd.SendResponse(resultvalue,port2);
}
for(int r=0;r<por.size();r++)
{
String resultvalue="";
Random r2=new Random();
String token="T"+r2.nextInt(10)+""+r2.nextInt(10)+""+r2.nextInt(10)+""+r2.nextInt(10);
Connection con2 = obj.getConnection();
Statement st2 = con2.createStatement();
ResultSet rs1 = st1.executeQuery("select description,distance from contentmap where domain='"+dom+"'");
while(rs1.next())
{
String que=rs1.getString(1);
int tempdis=Integer.parseInt(rs1.getString(2));
System.out.println(que);
System.out.println(tempdis);
if(true)
{
Vector vec=new Vector();
String dis1=(String)dis.get(r);
int dis2=Integer.parseInt(dis1);
//if(tempdis>=(dis2-50) && tempdis<=(dis2+50))
//{
vec.add(que);
//}
System.out.println(vec);
for(int k=0;k<vec.size();k++)
{
resultvalue=resultvalue+"---2--->"+vec.get(k);
}
}
}
System.out.println("new"+resultvalue);
if(resultvalue !=null && !resultvalue.isEmpty()){
resultvalue=""+token+resultvalue;
} else {
resultvalue="";
}
resultvalue=resultvalue+"&&"+"independent";
System.out.println("independent"+resultvalue);
String port1=(String)por.get(r);
int port2=Integer.parseInt(port1);
System.out.println("port"+por.get(r));
SendData sd=new SendData();
sd.SendResponse(resultvalue,port2);
}
//MBR filtering
/* DBConnection objm = new DBConnection();
Connection conm = objm.getConnection();
Statement stm = conm.createStatement();
ResultSet rsm = stm.executeQuery("select * from submap");
while(rs.next())
{
String nname=rs.getString(1);
por.add(rs.getString(2));
dis.add(rs.getString(4));
}
*/
con1.close();
st1.close();
DBConnection obj3 = new DBConnection();
Connection con3 = obj3.getConnection();
Statement st3 = con3.createStatement();
ResultSet rsm = st3.executeQuery("select * from submap");
while(rsm.next())
{
String nname=rsm.getString(1);
por.add(rsm.getString(2));
dis.add(rsm.getString(4));
}
//changed till here
for(int r=0;r<por.size();r++)
{
String resultvalue="";
Random r2=new Random();
String token="T"+r2.nextInt(10)+""+r2.nextInt(10)+""+r2.nextInt(10)+""+r2.nextInt(10);
Connection con2 = obj.getConnection();
Statement st2 = con2.createStatement();
ResultSet rs1 = st2.executeQuery("select description,distance from contentmap");
while(rs1.next())
{
String que=rs1.getString(1);
int tempdis=Integer.parseInt(rs1.getString(2));
System.out.println(que);
System.out.println(tempdis);
if(true)
{
Vector vec=new Vector();
String dis1=(String)dis.get(r);
int dis2=Integer.parseInt(dis1);
if(tempdis>=(dis2-50) && tempdis<=(dis2+50))
{
vec.add(que);
}
System.out.println(vec);
for(int k=0;k<vec.size();k++)
{
resultvalue=resultvalue+"---1--->"+vec.get(k);
}
}
}
System.out.println("new"+resultvalue);
if(resultvalue !=null && !resultvalue.isEmpty()){
resultvalue=""+token+resultvalue;
} else {
resultvalue="";
}
resultvalue=resultvalue+"&&"+"dependent";
System.out.println("dependent"+resultvalue);
String port1=(String)por.get(r);
int port2=Integer.parseInt(port1);
System.out.println("port"+por.get(r));
SendData sd=new SendData();
sd.SendResponse(resultvalue,port2);
}
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
}