Skip to content

Commit 8cb5dbb

Browse files
committed
bug fix...
bug :- long time to process data server queue in main server flow.
1 parent aaeee56 commit 8cb5dbb

File tree

5 files changed

+24
-7
lines changed

5 files changed

+24
-7
lines changed

ProgramTester.jar

923 Bytes
Binary file not shown.

nbproject/private/private.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/2" lastBookmarkId="0"/>
44
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
55
<group>
6+
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/src/net/logSer/LogHandler.java</file>
67
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/src/net/mainSer/SerDetails.java</file>
8+
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/src/net/mainSer/userStatus/UserStatusLog.java</file>
9+
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/src/net/flow/mainSerFlows/MainSerFlow.java</file>
710
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/test/net/flow/MainLogFlowTest.java</file>
811
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/test/net/flow/MainDataFlowTest.java</file>
912
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/src/programtester/config/Configurator.java</file>
1013
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/src/lib/ui/gui/QuestionPage.java</file>
1114
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/test/net/flow/MainSerFlowTest.java</file>
12-
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/src/net/mainSer/userStatus/UserStatus.java</file>
15+
<file>file:/C:/My%20folder/Fun/Data/Program%20Tester/src/net/mainSer/userStatus/UserFactory.java</file>
1316
</group>
1417
</open-files>
1518
</project-private>

src/net/logSer/LogHandler.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ public static boolean setBackupLog(String url){
140140
return false;
141141
}
142142
} catch (Exception ex) {
143+
System.out.println("Setting backup server fail..");
143144
return false;
144145
}
145146
}

src/net/mainSer/SerDetails.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @author Neel Patel
2323
*/
2424
public class SerDetails {
25+
private static long QUE_LEN = 6;
2526
private SerDetails(){}
2627
private static IntRemoteLog log;
2728
private static IntDataSer mainDataSer;
@@ -67,6 +68,7 @@ public static synchronized String getMainDataSer(){
6768
*/
6869
private synchronized static String findDataSer(){
6970
IntDataSer d=dataSer.keySet().parallelStream()
71+
//.filter(i->isAlive(i))
7072
.reduce((x,y)->{
7173
if(dataSer.get(x)>dataSer.get(y))
7274
return y;
@@ -100,7 +102,7 @@ private static boolean isAlive(IntDataSer d){
100102
* @return URI of log server, null if log sever is not reachable
101103
exception occur
102104
*/
103-
public static synchronized String getLogSer(){
105+
public static String getLogSer(){
104106
try {
105107
if(log.aya())
106108
return log.toUrl();
@@ -159,6 +161,14 @@ public static boolean setLogSer(String url){
159161
reason.
160162
*/
161163
public static boolean registerDataSer(String url){
164+
System.out.println("data ser reg :- "+url);
165+
long c = new HashSet<IntDataSer>(dataSer.keySet()).parallelStream().peek(i->{
166+
if(!isAlive(i)){
167+
dataSer.remove(i);
168+
}
169+
}).count();
170+
if(c>QUE_LEN)
171+
return false;
162172
try {
163173
IntDataSer ds=(IntDataSer)Naming.lookup(url);
164174
if(ds.aya()){
@@ -207,7 +217,7 @@ public synchronized static boolean registerMainDataSer(String url){
207217

208218
public synchronized static Set<String> getAllDataSer(){
209219
Set<String> s=new HashSet<String>();
210-
new HashSet<IntDataSer>(dataSer.keySet()).stream().forEach(i->{
220+
new HashSet<IntDataSer>(dataSer.keySet()).parallelStream().forEach(i->{
211221
try {
212222
if(isAlive(i)){
213223
s.add(i.toUrl());

src/net/mainSer/userStatus/UserFactory.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ public static synchronized String init(String lp){
5252
IntRemoteLog ir=new UserStatusLog();
5353
int port=getDefaultRMIPort();
5454
String uri=UrlTools.registerObj(ir, port,"userState");
55+
((UserStatusLog)ir).setUrl(uri);
56+
5557
readProgramDetails();
5658
readUserDetail(getDefaultUserDetailPath());
5759
System.out.println("user factory uri :- "+uri);
@@ -152,7 +154,7 @@ public static synchronized IntUserStatus getUser(String uName){
152154
* @param log String of log
153155
* @return true if processed successfully, false otherwise.
154156
*/
155-
public synchronized static boolean processLog(String log){
157+
public static synchronized boolean processLog(String log){
156158
try{
157159
String uName=LogTools.getLogProperty(log, "username");
158160
//String passwd=LogTools.getLogProperty(log, "password");
@@ -171,6 +173,7 @@ else if(status==TEST_FILE_ERROR)
171173
return u.update(pid, 0);
172174
else return false;
173175
}catch(Exception ex){
176+
System.out.println("Log Processing fail :- "+log);
174177
return false;
175178
}
176179
}
@@ -181,7 +184,7 @@ else if(status==TEST_FILE_ERROR)
181184
* @param pid programId.
182185
* @return credit of the program.
183186
*/
184-
public static synchronized int getCredit(long pid){
187+
public static int getCredit(long pid){
185188
return problems.stream().filter(i->i.getProgramID()==pid)
186189
.mapToInt(i->i.getCredit()).findAny().orElse(-1);
187190
}
@@ -194,8 +197,8 @@ public static void proBack(String uri){
194197
try {
195198
IntLogProc lp=(IntLogProc)Naming.lookup(uri);
196199
List<String> l=lp.getLogs(null,null);
197-
l.stream().forEach(i->processLog(i));
198-
System.out.println("Log recovered");
200+
long c=l.stream().peek(i->processLog(i)).count();
201+
System.out.println("Log recovered "+c);
199202
} catch (Exception ex) {
200203
System.err.println("Error in log recovery!!");
201204
}

0 commit comments

Comments
 (0)