Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
Merge branch 'reindex-page' into 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmason committed Jul 2, 2012
2 parents 0fedf4c + 1e8f214 commit da5e04d
Show file tree
Hide file tree
Showing 4 changed files with 348 additions and 139 deletions.
65 changes: 58 additions & 7 deletions zanata-war/src/main/java/org/zanata/action/ReindexActionBean.java
Expand Up @@ -8,6 +8,9 @@
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.Startup;
import org.jboss.seam.annotations.security.Restrict;
import org.joda.time.Period;
import org.joda.time.format.PeriodFormatter;
import org.joda.time.format.PeriodFormatterBuilder;

@Name("reindexAction")
@Scope(ScopeType.APPLICATION)
Expand All @@ -24,33 +27,81 @@ public Collection<ReindexClassOptions> getClasses()
return reindexAsync.getReindexOptions();
}

public boolean isReindexing()
public boolean isInProgress()
{
return reindexAsync.isReindexing();
return reindexAsync.getProcessHandle().isInProgress();
}

public boolean isReindexError()
public boolean isError()
{
return reindexAsync.hasError();
return reindexAsync.getProcessHandle().hasError();
}

public int getReindexCount()
{
return reindexAsync.getObjectCount();
return reindexAsync.getProcessHandle().getMaxProgress();
}

public int getReindexProgress()
{
return reindexAsync.getObjectProgress();
return reindexAsync.getProcessHandle().getCurrentProgress();
}

public void reindexDatabase()
{
if (!reindexAsync.isReindexing())
if (!reindexAsync.getProcessHandle().isInProgress())
{
reindexAsync.prepareReindex();
reindexAsync.startReindex();
}
}

public void cancel()
{
reindexAsync.getProcessHandle().stop();
}

public boolean isCanceled()
{
return reindexAsync.getProcessHandle().shouldStop();
}

public boolean isStarted()
{
return reindexAsync.getProcessHandle().isStarted();
}

// TODO move to common location with ViewAllStatusAction
private static final PeriodFormatterBuilder PERIOD_FORMATTER_BUILDER =
new PeriodFormatterBuilder()
.appendDays().appendSuffix(" day", " days")
.appendSeparator(", ")
.appendHours().appendSuffix(" hour", " hours")
.appendSeparator(", ")
.appendMinutes().appendSuffix(" min", " mins");

private String formatTimePeriod( long durationInMillis )
{
PeriodFormatter formatter = PERIOD_FORMATTER_BUILDER.toFormatter();
Period period = new Period( durationInMillis );

if( period.toStandardMinutes().getMinutes() <= 0 )
{
return "less than a minute"; // TODO Localize
}
else
{
return formatter.print( period.normalizedStandard() );
}
}

public String getElapsedTime()
{
return formatTimePeriod(reindexAsync.getProcessHandle().getElapsedTime());
}

public String getEstimatedTimeRemaining()
{
return formatTimePeriod(reindexAsync.getProcessHandle().getEstimatedTimeRemaining());
}
}

0 comments on commit da5e04d

Please sign in to comment.