@ -30,7 +30,7 @@ import java.util.*;
/ * *
* A singleton of a task queue implemented with zookeeper
* tasks queue implemention
* tasks queue implementat ion
* /
@Service
public class TaskQueueZkImpl implements ITaskQueue {
@ -72,7 +72,7 @@ public class TaskQueueZkImpl implements ITaskQueue {
} catch ( Exception e ) {
logger . error ( "get all tasks from tasks queue exception" , e ) ;
}
return new ArrayList < > ( ) ;
return Collections . emptyList ( ) ;
}
/ * *
@ -196,11 +196,11 @@ public class TaskQueueZkImpl implements ITaskQueue {
}
}
List < String > tasksl ist = getTasksListFromTreeSet ( tasksNum , taskTreeSet ) ;
List < String > tasksL ist = getTasksListFromTreeSet ( tasksNum , taskTreeSet ) ;
logger . info ( "consume tasks: {},there still have {} tasks need to be executed" , Arrays . toString ( tasksl ist . toArray ( ) ) , size - tasksl ist . size ( ) ) ;
logger . info ( "consume tasks: {},there still have {} tasks need to be executed" , Arrays . toString ( tasksL ist . toArray ( ) ) , size - tasksL ist . size ( ) ) ;
return tasksl ist ;
return tasksL ist ;
} else {
Thread . sleep ( Constants . SLEEP_TIME_MILLIS ) ;
}
@ -208,7 +208,7 @@ public class TaskQueueZkImpl implements ITaskQueue {
} catch ( Exception e ) {
logger . error ( "add task to tasks queue exception" , e ) ;
}
return new ArrayList < String > ( ) ;
return Collections . emptyList ( ) ;
}
@ -221,15 +221,15 @@ public class TaskQueueZkImpl implements ITaskQueue {
public List < String > getTasksListFromTreeSet ( int tasksNum , Set < String > taskTreeSet ) {
Iterator < String > iterator = taskTreeSet . iterator ( ) ;
int j = 0 ;
List < String > tasksl ist = new ArrayList < > ( tasksNum ) ;
List < String > tasksL ist = new ArrayList < > ( tasksNum ) ;
while ( iterator . hasNext ( ) ) {
if ( j + + > = tasksNum ) {
break ;
}
String task = iterator . next ( ) ;
tasksl ist . add ( getOriginTaskFormat ( task ) ) ;
tasksL ist . add ( getOriginTaskFormat ( task ) ) ;
}
return tasksl ist ;
return tasksL ist ;
}
/ * *
@ -330,22 +330,13 @@ public class TaskQueueZkImpl implements ITaskQueue {
* /
@Override
public Set < String > smembers ( String key ) {
Set < String > tasksSet = new HashSet < > ( ) ;
try {
List < String > list = zookeeperOperator . getChildrenKeys ( getTasksPath ( key ) ) ;
for ( String task : list ) {
tasksSet . add ( task ) ;
}
return tasksSet ;
return new HashSet < > ( list ) ;
} catch ( Exception e ) {
logger . error ( "get all tasks from tasks queue exception" , e ) ;
}
return tasksSet ;
return Collections . emptySet ( ) ;
}
/ * *