-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRIDCThread.java
More file actions
300 lines (193 loc) · 8.08 KB
/
RIDCThread.java
File metadata and controls
300 lines (193 loc) · 8.08 KB
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
import java.io.*;
import oracle.stellent.ridc.*;
import oracle.stellent.ridc.model.*;
import oracle.stellent.ridc.protocol.*;
import oracle.stellent.ridc.protocol.intradoc.*;
import oracle.stellent.ridc.common.log.*;
import oracle.stellent.ridc.model.serialize.*;
import oracle.stellent.ridc.protocol.http.*;
import java.util.*;
import java.text.DecimalFormat;
/*
* @Sterin
*
* This is a class used to test the basic functionality
* of submitting a checkin to Content Server using RIDC.
*/
public class RIDCThread {
/**
* @param args
*/
public static void main(String[] args) {
// Create a new IdcClientManager
IdcClientManager manager = new IdcClientManager ();
Properties prop = new Properties();
InputStream input = null;
List<SubmitToUCM> clients = new ArrayList<SubmitToUCM>();
try{
input = new FileInputStream("config.properties");
// load a properties file
prop.load(input);
String URL = prop.getProperty("url");
// Create a new IdcClient Connection using idc protocol (i.e. socket connection to Content Server)
IdcClient idcClient = manager.createClient (URL);
IdcContext userContext = new IdcContext (prop.getProperty("user"),prop.getProperty("password"));
// Create an HdaBinderSerializer; this is not necessary, but it allows us to serialize the request and response data binders
HdaBinderSerializer serializer = new HdaBinderSerializer ("UTF-8", idcClient.getDataFactory ());
// Create a new binder for submitting a search
File[] files = new File(prop.getProperty("FolderToUpload")).listFiles();
int count =0;
long startTimeS = System.currentTimeMillis();
for (File file : files) {
if (file.isDirectory()) {
continue;
}
else {
// DataBinder dataBinder = createBinderFromFile(idcClient,prop,file);
count++;
SubmitToUCM STU = new SubmitToUCM (idcClient,prop,file,userContext,count);
serializer.serializeBinder (System.out, STU.dataBinder);
//STU.doCheckinAndDisplayResponce();
clients.add(STU);
// STU.start();
// Send the request to Content Server
} // end of else
} // end Sof files loop
// Starting all threads
List<SubmitToUCM> BatchArray = new ArrayList<SubmitToUCM>();
int BatchC=Integer.parseInt(prop.getProperty("BatchSize"));
for(int k=0; k<clients.size();k++)
{
BatchArray.add (clients.get(k));
clients.get(k).start();
if ( (k+1) % BatchC == 0)
{
checkThreadStatus(BatchArray);
BatchArray.clear();
}
// System.out.println(clients.get(k).isAlive());
}
// checking all threads
checkThreadStatus(BatchArray);
long endTimeS = System.currentTimeMillis();
System.out.println("Time for check in of "+ count + " files " + (endTimeS - startTimeS)/1000.0 + " seconds");
} catch (IdcClientException ice){
ice.printStackTrace();
}
catch (IOException ioe){
ioe.printStackTrace();
}
} // end of main
public static void checkThreadStatus(List<SubmitToUCM> clients)
{
for(int k=0; k<clients.size();k++)
{
if (clients.get(k).isAlive())
{
System.out.println(clients.get(k).ThreadName +" still uploading_______----_______ ");
clients.get(k).join();
}
else {
System.out.println(clients.get(k).ThreadName + " was able to check in " + clients.get(k).timeRequired + " milliseconds" );
}
} // end of checkThreadStatus
} // end of checkThreadStatus
} // end of class
class SubmitToUCM implements Runnable {
private Thread t;
private IdcClient idcClient;
public String ThreadName;
public String URL;
// public File primaryFile;
public DataBinder dataBinder;
private IdcContext userContext;
public long timeRequired;
SubmitToUCM (IdcClient idcClient,Properties prop,File primaryFile,IdcContext userContext,int count)
{
this.idcClient = idcClient;
this.userContext = userContext;
this.dataBinder = idcClient.createBinder();
this.ThreadName = "Upload "+ count;
this.URL=prop.getProperty("url");
try {
// Databinder for checkin request
dataBinder.putLocal("IdcService", "CHECKIN_UNIVERSAL");
// File primaryFile = new File( prop.getProperty("primaryFile") );
dataBinder.addFile("primaryFile",primaryFile);
List<String> skipwords = new ArrayList<String>();
skipwords.add("url");
skipwords.add("user");
skipwords.add("password");
skipwords.add("primaryFile");
skipwords.add("FolderToUpload");
for (String key : prop.stringPropertyNames()) {
boolean skip=true;
for(String str: skipwords) {
if(str.trim().contains(key))
skip=false;
}
if (skip)
dataBinder.putLocal(key,prop.getProperty(key));
}
String name = primaryFile.getName();
this.ThreadName = this.ThreadName+" "+name;
int pos = name.lastIndexOf(".");
if (pos > 0) {
name = name.substring(0, pos);
}
if (prop.containsKey("dDocTitle"))
dataBinder.putLocal("dDocTitle",prop.getProperty("dDocTitle")+" "+name);
else
dataBinder.putLocal("dDocTitle",name);
} catch (IOException ioe){
ioe.printStackTrace();
}
} // end of Constructor
public void run(){
try {
long startTime = System.currentTimeMillis();
ServiceResponse response = this.idcClient.sendRequest(this.userContext,this.dataBinder);
// Get the data binder for the response from Content Server
DataBinder responseData = response.getResponseAsBinder();
// Write the response data binder to stdout
// serializer.serializeBinder (System.out, responseData);
System.out.println("_________________________________________________");
System.out.println("ContentID : " + responseData.getLocal("dDocName"));
System.out.println("dID : " + responseData.getLocal("dID"));
System.out.println("Title : " + responseData.getLocal("dDocTitle"));
System.out.println("Size : " + readableFileSize (Long.parseLong(responseData.getLocal("dFileSize"))) +"\n\n");
String GET_FILE_URL;
GET_FILE_URL=this.URL+"?IdcService=DOC_INFO&dID="+responseData.getLocal("dID")+"&dDocName="+responseData.getLocal("dDocName");
System.out.println("DOC INFO : "+ GET_FILE_URL);
long endTime = System.currentTimeMillis();
this.timeRequired = (endTime - startTime);
System.out.println("Time for check in " + this.timeRequired + " milliseconds");
System.out.println("_________________________________________________");
}catch (IdcClientException ice){
ice.printStackTrace();
}
} // end of doCheckinAndDisplayResponce
public static String readableFileSize(long size) {
if(size <= 0) return "0";
final String[] units = new String[] { "B", "kB", "MB", "GB", "TB" };
int digitGroups = (int) (Math.log10(size)/Math.log10(1024));
return new DecimalFormat("#,##0.#").format(size/Math.pow(1024, digitGroups)) + " " + units[digitGroups];
}
public void start () {
System.out.println("Starting "+this.ThreadName);
if (t == null) {
t = new Thread (this);
t.start ();
}
} // end of start
public boolean isAlive(){
return t.isAlive();
} //end of isAlive
public void join(){
try {
System.out.println("Waiting for >>>>>>>>>>>>>>>>>>>>>> "+this.ThreadName);
t.join();// Waiting for c1 to finish
} catch (InterruptedException ie) {
}
} // end of join
} // end of SubmitToUCM