Removed unused code

Added check to avoid Timeout and Null row fetched (max attempts 5)

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/user/speciesdiscovery@117433 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Francesco Mangiacrapa 2015-07-22 15:19:38 +00:00
parent 030b1eeb45
commit 7822e080af
9 changed files with 276 additions and 610 deletions

View File

@ -930,7 +930,7 @@ public class SearchController {
case DARWIN_CORE: fileName += ".xml"; break;
}
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save "+fileFormat.toString()+" As... ", fileName, true);
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save "+fileFormat.toString()+" As... ", fileName, false);
WorskpaceExplorerSaveNotificationListener listener = new WorskpaceExplorerSaveNotificationListener(){
@ -1001,7 +1001,7 @@ public class SearchController {
private void saveTaxonomyJobErrorFile() {
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save the file with job Error/s As...", fileName, true);
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save the file with job Error/s As...", fileName, false);
WorskpaceExplorerSaveNotificationListener listener = new WorskpaceExplorerSaveNotificationListener(){
@ -1056,7 +1056,7 @@ public class SearchController {
String fileName = jobTaxonomyModel.getName() +" from "+dataSourceName+" - DWCA.zip";
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save DWCA As...", fileName, true);
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save DWCA As...", fileName, false);
WorskpaceExplorerSaveNotificationListener listener = new WorskpaceExplorerSaveNotificationListener(){
@ -1139,7 +1139,7 @@ public class SearchController {
private void saveOccurrenceJobError() {
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save the Error File As...", fileName, true);
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save the Error File As...", fileName, false);
WorskpaceExplorerSaveNotificationListener listener = new WorskpaceExplorerSaveNotificationListener(){
@ -1217,7 +1217,7 @@ public class SearchController {
String fileName = jobOccurrencesModel.getJobName() +" from "+dataSourceName+" - "+suffix+"."+extension;
final String dataSources = dataSourceName;
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save "+jobOccurrencesModel.getFileFormat().toString() +" As...", fileName, true);
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save "+jobOccurrencesModel.getFileFormat().toString() +" As...", fileName, false);
WorskpaceExplorerSaveNotificationListener listener = new WorskpaceExplorerSaveNotificationListener(){
@Override
@ -1308,7 +1308,7 @@ public class SearchController {
case DARWIN_CORE_ARCHIVE: fileName += ".zip"; break;
}
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save "+fileFormat.toString() +" As...", fileName, true);
final WorkspaceExplorerSaveDialog navigator = new WorkspaceExplorerSaveDialog("Save "+fileFormat.toString() +" As...", fileName, false);
WorskpaceExplorerSaveNotificationListener listener = new WorskpaceExplorerSaveNotificationListener(){
@Override

View File

@ -41,7 +41,6 @@ import com.extjs.gxt.ui.client.widget.form.SimpleComboValue;
import com.extjs.gxt.ui.client.widget.form.TextArea;
import com.extjs.gxt.ui.client.widget.form.TextField;
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
import com.google.gwt.core.shared.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
@ -491,7 +490,6 @@ public class SpeciesSearchFormPanel extends ContentPanel {
String searchTerm = searchField.getValue();
if (buttSimpleSearch.isEnabled() && searchTerm!=null && searchTerm.length()!=0) {
GWT.log("search...");
// if(isActiveAdvanced){
search(searchTerm,
advSearchPanelsManager.getUpperBoundLatitudeField().getValue(),
@ -514,26 +512,9 @@ public class SpeciesSearchFormPanel extends ContentPanel {
protected void search(String searchTerm, Number upperBoundLongitude, Number upperBoundLatitude, Number lowerBoundLongitude, Number lowerBoundLatitude, Date fromDate, Date toDate, List<DataSourceModel> listDataSources, String groupRank, SpeciesCapability resultType, List<DataSourceModel> listDataSourceForSynonyms, List<DataSourceModel> listDataSourceForUnfold)
{
GWT.log("Searching...");
mask("Searching...");
//searchButton.setEnabled(false);
/*
GWT.log(searchTerm);
GWT.log(upperBoundLongitude!=null?upperBoundLongitude.toString():"upperBoundLongitude");
GWT.log(upperBoundLatitude!=null? upperBoundLatitude.toString():"upperBoundLatitude");
GWT.log(lowerBoundLongitude!=null? lowerBoundLongitude.toString():"lowerBoundLongitude");
GWT.log(lowerBoundLatitude!=null? lowerBoundLatitude.toString():"lowerBoundLatitude");
GWT.log(fromDate!=null? fromDate.toString():"fromDate");
GWT.log(toDate!=null? toDate.toString():"toDate");
for (DataSourceModel dataSourceModel : listDataSources) {
GWT.log(dataSourceModel.toString());
}
GWT.log(groupRank);
GWT.log(resultType.toString());
GWT.log(listDataSourceForSynonyms!=null?listDataSourceForSynonyms.toString():"");
GWT.log(listDataSourceForUnfold!=null?listDataSourceForUnfold.toString():"");
*/
SearchType type = null;
if (ConstantsSpeciesDiscovery.SCIENTIFIC_NAME.equals(searchType.getSimpleValue())) type = SearchType.BY_SCIENTIFIC_NAME;
if (ConstantsSpeciesDiscovery.COMMON_NAME.equals(searchType.getSimpleValue())) type = SearchType.BY_COMMON_NAME;

View File

@ -442,15 +442,12 @@ public class OccurrenceGridJob extends ContentPanel{
else{
String name = baseModelData.get(JobTaxonomyModel.JOBNAME);
MessageBox.alert(INFO, "The job "+ name+ " " + ConstantsSpeciesDiscovery.CAN_NOT_BE_RE_SUBMITTED_UNTIL_IT_HAS_COMPLETED, null);
}
}
}
private void createGridToolBar(){
buttonInfo = new Button(INFO);
buttonInfo.setScale(ButtonScale.MEDIUM);

View File

@ -17,8 +17,9 @@ import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.ui.AbstractImagePrototype;
/**
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* The Class OccurrenceJobSpeciesPanel.
*
* @author Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
*/
public class OccurrenceJobSpeciesPanel extends ContentPanel {
@ -48,12 +49,23 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
protected Window speciesJobWindow = new Window();
/**
* Gets the single instance of OccurrenceJobSpeciesPanel.
*
* @param eventBus the event bus
* @return single instance of OccurrenceJobSpeciesPanel
*/
public static synchronized OccurrenceJobSpeciesPanel getInstance(EventBus eventBus) {
if (instance == null)
instance = new OccurrenceJobSpeciesPanel(eventBus);
return instance;
}
/**
* Instantiates a new occurrence job species panel.
*
* @param eventBus the event bus
*/
private OccurrenceJobSpeciesPanel(EventBus eventBus) {
this.eventBus = eventBus;
this.gridJob = new OccurrenceGridJob(eventBus);
@ -64,6 +76,9 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
// createToolBar();
}
/**
* Creates the species job window.
*/
private void createSpeciesJobWindow(){
lc = new LayoutContainer();
@ -84,10 +99,9 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
lastOperation.setHtml(LASTOPERATION + OPERATIONONE);
// cp.add(vp);
lc.add(lastOperation);
lc.add(cp);
//
speciesJobWindow.setHeading(WINDOWTITLE);
speciesJobWindow.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.getBluePlace16px()));
speciesJobWindow.setSize(1020, 600);
@ -96,50 +110,29 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
speciesJobWindow.add(lc);
}
// private void createToolBar(){
// ToolBar toolbar = new ToolBar();
//
// Button btnJobs = new Button("Species Jobs");
// btnJobs.setIcon(AbstractImagePrototype.create(Resources.INSTANCE.getJob()));
//
// btnJobs.addSelectionListener(new SelectionListener<ButtonEvent>() {
//
// @Override
// public void componentSelected(ButtonEvent ce) {
//
// speciesJobWindow.show();
// }
//
// });
// toolbar.add(btnJobs);
// this.setTopComponent(toolbar);
// }
/**
*
* @param jobsModel
* @return true if almost one progress bar is ongoing
* Adds the list job.
*
* @param jobsModel the jobs model
*/
public boolean addListJob(List<JobOccurrencesModel> jobsModel){
boolean isLoading = false;
for(final JobOccurrencesModel jobModel : jobsModel){
isLoading = addJob(jobModel);
}
return isLoading;
public void addListJob(List<JobOccurrencesModel> jobsModel){
for(final JobOccurrencesModel jobModel : jobsModel)
addJob(jobModel);
}
/**
* Adds the job.
*
* @param jobModel the job model
* @return true, if successful
*/
public boolean addJob(final JobOccurrencesModel jobModel){
boolean isLoading = false;
// Log.trace("add job :" +jobModel);
OccurrenceJobSpeciesProgressBar jobsBar = hashProgressBars.get(jobModel.getJobIdentifier());
if(jobsBar!=null){ //is update
@ -158,23 +151,15 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
// Log.trace("jobsBar " +jobModel.getName() + " completed, return" );
return true;
}
updateProgressBarView(jobsBar, jobModel);
gridJob.updateStatus(jobModel, jobsBar);
updateProgressBarView(jobsBar, jobModel);
gridJob.updateStatus(jobModel, jobsBar);
}
else{ //create new grid item that contains new progress bar
OccurrenceJobSpeciesProgressBar jobProgressBar = new OccurrenceJobSpeciesProgressBar(jobModel.getJobIdentifier(), jobModel.getDownloadState().toString());
gridJob.addJobIntoGrid(jobModel, jobProgressBar);
updateProgressBarView(jobProgressBar, jobModel);
// hashTableContentPanels.put(jobModel.getIdentifier(), panelTable); //add contentPanel into hashTableContentPanels
hashProgressBars.put(jobModel.getJobIdentifier(), jobProgressBar); //add progressBar into hashProgressBars
hashLoadCompletedNotify.put(jobModel.getJobIdentifier(), false); //add false (at load completed event) into hashLoadCompletedNotify
}
@ -186,6 +171,13 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
}
/**
* Update progress bar view.
*
* @param jobsBar the jobs bar
* @param jobModel the job model
* @return true, if successful
*/
private boolean updateProgressBarView(OccurrenceJobSpeciesProgressBar jobsBar, JobOccurrencesModel jobModel){
switch (jobModel.getDownloadState()) {
@ -198,7 +190,6 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
case SAVING:{
lastOperation.setHtml(LASTOPERATION + jobModel.getJobName() + " saving");
jobsBar.getElement().getStyle().setBorderColor("#7093DB");
// jobsBar.progressStart();
jobsBar.setProgressText(SAVING);
break;
}
@ -206,13 +197,10 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
case COMPLETED:{
lastOperation.setHtml(LASTOPERATION + jobModel.getJobName() + " completed");
jobsBar.getElement().getStyle().setBorderColor("#000000");
// jobsBar.progressStop();
jobsBar.updateProgressWithoutPercentage(100);
jobsBar.setCompleted(true);
jobsBar.updateText(COMPLETED);
break;
}
@ -224,23 +212,16 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
jobsBar.setProgressText(SAVING);
jobsBar.updateProgressWithPercentage(jobModel.getPercentage());
// jobsBar.progressStart();
return true;
}
case SAVED:{
lastOperation.setHtml(LASTOPERATION + jobModel.getJobName() + " saved");
jobsBar.getElement().getStyle().setBorderColor("#000000");
// jobsBar.progressStop();
jobsBar.updateProgressWithoutPercentage(100);
// jobsBar.updateProgressWithPercentage(jobModel.getPercentage(), jobModel.getDownloadState().toString());
jobsBar.setCompleted(true);
jobsBar.updateText(COMPLETED);
break;
}
@ -248,19 +229,16 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
jobsBar.getElement().getStyle().setBorderColor("#f00");
jobsBar.updateText("loading " + jobModel.getJobName() + " with failures");
break;
}
case FAILED:{
jobsBar.getElement().getStyle().setBorderColor("#f00");
// jobsBar.progressStop();
jobsBar.setProgressText(FAILED);
jobsBar.updateProgressWithPercentage(jobModel.getPercentage());
jobsBar.setCompleted(true);
jobsBar.updateText(FAILED);
break;
}
@ -270,57 +248,50 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
jobsBar.updateText("loading " + jobModel.getJobName() + " with failures");
jobsBar.updateProgressWithoutPercentage(100);
jobsBar.setCompleted(true);
break;
}
}
return false;
return false;
}
/**
* Removes the species job.
*
* @param hashHPKey the hash hp key
*/
public void removeSpeciesJob(String hashHPKey) {
ContentPanel cp = hashTableContentPanels.get(hashHPKey);
vp.remove(cp);
lastOperation.setHtml(LASTOPERATION + cp.getId() + " deleted");
hashProgressBars.remove(hashHPKey); //remove progress bar from hash
hashTableContentPanels.remove(hashHPKey); //remove hp from hash
hashLoadCompletedNotify.remove(hashHPKey); //remove notify event
vp.layout();
}
/**
* Delete progress completed.
*
* @param progressIdFound the progress id found
*/
@SuppressWarnings("unused")
private void deleteProgressCompleted(List<String> progressIdFound){
List<String> progressIdNotFound = new ArrayList<String>();
for(String key : hashTableContentPanels.keySet()){
// System.out.println("Key " + key );
if(!progressIdFound.contains(key)){ //if key isn't not found - progress is completed so is removed
// System.out.println("Key is not present " + key );
OccurrenceJobSpeciesProgressBar bulkPB = hashProgressBars.get(key);
lastOperation.setHtml(LASTOPERATION + bulkPB.getProgressText() + " uploading completed");
// bulkPB.updateProgress(100);
progressIdNotFound.add(key);
}
}
for(String key : progressIdNotFound){
OccurrenceJobSpeciesProgressBar bulkPB = hashProgressBars.get(key);
lastOperation.setHtml(LASTOPERATION + bulkPB.getProgressText() + " uploading completed");
// vp.remove(hashHorizontalPanels.get(key)); //remove hp from view
hashProgressBars.remove(key); //remove progress bar from hash
hashTableContentPanels.remove(key); //remove hp from hash
}
@ -329,10 +300,18 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
cp.layout();
}
/**
* Gets the species job window.
*
* @return the species job window
*/
public Window getSpeciesJobWindow() {
return speciesJobWindow;
}
/**
* Reset structures.
*/
public void resetStructures(){
this.gridJob.resetStore();
@ -343,10 +322,13 @@ public class OccurrenceJobSpeciesPanel extends ContentPanel {
hashLoadCompletedNotify.clear();
}
/**
* Gets the grid job.
*
* @return the grid job
*/
public OccurrenceGridJob getGridJob() {
return gridJob;
}
}

View File

@ -6,41 +6,14 @@ public class OccurrenceJobSpeciesProgressBar extends ProgressBar {
private String progressText;
private float progress;
// private final Timer timer;
private boolean isCompleted = false;
public OccurrenceJobSpeciesProgressBar(String idJob, final String text) {
this.progressText = text;
setSize(140, 20);
updateProgress(progress, text);
// timer = new Timer() {
// float i;
//
// @Override
// public void run() {
// updateProgress(i / 100, progressText);
// i += 5;
// if (i > 105) {
// if(!isCompleted)
// i = 0;
// }
// }
// };
}
/*
public void progressStart(){
timer.scheduleRepeating(500);
}
public void progressStop(){
timer.cancel();
}
*/
public void updateProgressWithoutPercentage(float counter) {
progress = counter / 100;
updateProgress(progress, progressText);

View File

@ -14,8 +14,6 @@ public class TaxonomyJobSpeciesProgressBar extends ProgressBar {
this.progressText = text;
setSize(240, 20);
// setBounds(10, 10, 200, Style.DEFAULT);
updateProgress(progress, text);
timer = new Timer() {

View File

@ -11,17 +11,27 @@ import org.gcube.portlets.user.speciesdiscovery.server.stream.CloseableIterator;
import org.gcube.portlets.user.speciesdiscovery.shared.FetchingElement;
/**
* @author "Federico De Faveri defaveri@isti.cnr.it"
* The Class Fetcher.
*
* @author "Federico De Faveri defaveri@isti.cnr.it"
*
* updated by Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it
* @param <T> the generic type
*/
public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
protected Logger logger = Logger.getLogger(Fetcher.class);
protected final int MAX_CONSECUTIVE_ATTEMPTS_ON_NULL = 5;
protected FetchingBuffer<T> buffer;
protected CloseableIterator<T> source;
protected boolean complete = false;
/**
* Instantiates a new fetcher.
*
* @param source the source
* @param buffer the buffer
*/
public Fetcher(CloseableIterator<T> source, FetchingBuffer<T> buffer) {
this.source = source;
this.complete = false;
@ -29,6 +39,8 @@ public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
}
/**
* Gets the source.
*
* @return the source
*/
public CloseableIterator<T> getSource() {
@ -36,6 +48,8 @@ public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
}
/**
* Sets the source.
*
* @param source the source to set
*/
public void setSource(CloseableIterator<T> source) {
@ -50,6 +64,7 @@ public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
T next = null;
int count = 0;
int countNullItems = 0;
try {
while(source!=null && source.hasNext() && !complete) {
@ -58,26 +73,26 @@ public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
next = source.next();
if(next!=null){
logger.trace("item "+count++ +" fetch new row: "+next.getId());
logger.info("item "+count++ +" fetch new row: "+next.getId());
buffer.add(next);
}
else{
logger.trace("fetch new row: null");
countNullItems++;
logger.warn("fetch new row is null!! It is the number: "+countNullItems);
if(MAX_CONSECUTIVE_ATTEMPTS_ON_NULL==countNullItems){
logger.warn("Fetched "+MAX_CONSECUTIVE_ATTEMPTS_ON_NULL+ " null rows, MAX ATTEMPTS reached, complete fetch true and closing stream!!");
silentClose();
}
}
} catch (Exception e) {
logger.error("Error in source.next() " + e.getMessage(), e);
e.printStackTrace();
silentClose();
}
}
} catch (Exception e) {
logger.error("Error in add row " + e.getMessage());
// System.out.println("Error in add row " + e.getMessage());
// e.printStackTrace();
silentClose();
}
@ -86,10 +101,11 @@ public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
logger.trace("exit fetch run - complete true");
complete = true;
// System.out.println("#################################TOTAL " + count);
}
/**
* Silent close.
*/
protected void silentClose()
{
try {
@ -99,12 +115,20 @@ public class Fetcher<T extends FetchingElement> implements Runnable, Closeable {
}
}
/* (non-Javadoc)
* @see java.io.Closeable#close()
*/
public void close() throws IOException
{
complete = true;
source.close();
}
/**
* Checks if is complete.
*
* @return true, if is complete
*/
public boolean isComplete()
{
return complete;

View File

@ -55,41 +55,33 @@ public class FetchingSession<T extends FetchingElement> implements Closeable {
public void startFetching()
{
fetcherThread = new Thread(fetcher);
logger.trace("###fetcherThread start");
logger.info("fetcherThread: "+fetcherThread.getId()+" start...");
// System.out.println("#######fetcherThread start");
fetcherThread.start();
}
public void close() throws IOException
{
new Thread(){
@Override
public void run() {
try {
Long startTime = System.currentTimeMillis();
logger.trace("##new thread run for closing old fetcher... time: "+startTime);
fetcher.close();
//logger.trace("###fetcherThread close - OK");
Long endTime = System.currentTimeMillis() - startTime;
String time = String.format("%d msc %d sec", endTime, TimeUnit.MILLISECONDS.toSeconds(endTime));
logger.trace("##old fetcher has been closed.. in " + time);
logger.info("fetcherThread: "+fetcherThread.getId()+" closed!");
} catch (IOException e) {
logger.error("An error occurred in fetcher Thread close ",e);
e.printStackTrace();
}
};
}.start();
}
public boolean isComplete()
{
public boolean isComplete(){
return fetcher.isComplete();
}