forked from hibernate/hibernate-search
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
hibernate#48 separate interface and implementation
- Loading branch information
Showing
2 changed files
with
207 additions
and
110 deletions.
There are no files selected for viewing
136 changes: 26 additions & 110 deletions
136
src/main/java/org/hibernate/search/jsr352/MassIndexer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,115 +1,31 @@ | ||
package org.hibernate.search.jsr352; | ||
|
||
import java.util.Properties; | ||
import java.util.Set; | ||
|
||
import javax.batch.operations.JobOperator; | ||
import javax.batch.runtime.BatchRuntime; | ||
|
||
// TODO: separate this class into interface and implementation | ||
public class MassIndexer { | ||
|
||
private boolean optimizeAfterPurge = false; | ||
private boolean optimizeAtEnd = false; | ||
private boolean purgeAtStart = false; | ||
|
||
private int arrayCapacity = 1000; | ||
private int fetchSize = 200000; | ||
private int maxResults = 1000000; | ||
private int partitionCapacity = 250; | ||
private int partitions = 4; | ||
private int threads = 2; | ||
|
||
private final String JOB_NAME = "mass-index"; | ||
|
||
private Set<Class<?>> rootEntities; | ||
|
||
MassIndexer() { | ||
|
||
} | ||
|
||
public long start() { | ||
Properties jobParams = new Properties(); | ||
jobParams.setProperty("fetchSize", String.valueOf(fetchSize)); | ||
jobParams.setProperty("arrayCapacity", String.valueOf(arrayCapacity)); | ||
jobParams.setProperty("maxResults", String.valueOf(maxResults)); | ||
jobParams.setProperty("partitionCapacity", String.valueOf(partitionCapacity)); | ||
jobParams.setProperty("partitions", String.valueOf(partitions)); | ||
jobParams.setProperty("threads", String.valueOf(threads)); | ||
jobParams.setProperty("purgeAtStart", String.valueOf(purgeAtStart)); | ||
jobParams.setProperty("optimizeAfterPurge", String.valueOf(optimizeAfterPurge)); | ||
jobParams.setProperty("optimizeAtEnd", String.valueOf(optimizeAtEnd)); | ||
jobParams.setProperty("rootEntities", String.valueOf(rootEntities)); | ||
JobOperator jobOperator = BatchRuntime.getJobOperator(); | ||
Long executionId = jobOperator.start(JOB_NAME, jobParams); | ||
return executionId; | ||
} | ||
|
||
public void stop(long executionId) { | ||
JobOperator jobOperator = BatchRuntime.getJobOperator(); | ||
jobOperator.stop(executionId); | ||
} | ||
|
||
public MassIndexer arrayCapacity(int arrayCapacity) { | ||
if (arrayCapacity < 1) { | ||
throw new IllegalArgumentException("arrayCapacity must be at least 1"); | ||
} | ||
this.arrayCapacity = arrayCapacity; | ||
return this; | ||
} | ||
|
||
public MassIndexer fetchSize(int fetchSize) { | ||
if (fetchSize < 1) { | ||
throw new IllegalArgumentException("fetchSize must be at least 1"); | ||
} | ||
this.fetchSize = fetchSize; | ||
return this; | ||
} | ||
|
||
public MassIndexer maxResults(int maxResults) { | ||
if (maxResults < 1) { | ||
throw new IllegalArgumentException("maxResults must be at least 1"); | ||
} | ||
this.maxResults = maxResults; | ||
return this; | ||
} | ||
|
||
public MassIndexer optimizeAfterPurge(boolean optimizeAfterPurge) { | ||
this.optimizeAfterPurge = optimizeAfterPurge; | ||
return this; | ||
} | ||
|
||
public MassIndexer optimizeAtEnd(boolean optimizeAtEnd) { | ||
this.optimizeAtEnd = optimizeAtEnd; | ||
return this; | ||
} | ||
|
||
public MassIndexer partitionCapacity(int partitionCapacity) { | ||
if (partitionCapacity < 1) { | ||
throw new IllegalArgumentException("partitionCapacity must be at least 1"); | ||
} | ||
this.partitionCapacity = partitionCapacity; | ||
return this; | ||
} | ||
|
||
public MassIndexer partitions(int partitions) { | ||
if (partitions < 1) { | ||
throw new IllegalArgumentException("partitions must be at least 1"); | ||
} | ||
this.partitions = partitions; | ||
return this; | ||
} | ||
|
||
public MassIndexer purgeAtStart(boolean purgeAtStart) { | ||
this.purgeAtStart = purgeAtStart; | ||
return this; | ||
} | ||
|
||
public MassIndexer threads(int threads) { | ||
if (threads < 1) { | ||
throw new IllegalArgumentException("threads must be at least 1"); | ||
} | ||
this.threads = threads; | ||
return this; | ||
} | ||
public interface MassIndexer { | ||
|
||
public long start(); | ||
public void stop(long executionId); | ||
|
||
public MassIndexer arrayCapacity(int arrayCapacity); | ||
public MassIndexer fetchSize(int fetchSize); | ||
public MassIndexer maxResults(int maxResults); | ||
public MassIndexer optimizeAfterPurge(boolean optimizeAfterPurge); | ||
public MassIndexer optimizeAtEnd(boolean optimizeAtEnd); | ||
public MassIndexer partitionCapacity(int partitionCapacity); | ||
public MassIndexer partitions(int partitions); | ||
public MassIndexer purgeAtStart(boolean purgeAtStart); | ||
public MassIndexer rootEntities(Set<Class<?>> rootEntities); | ||
public MassIndexer threads(int threads); | ||
|
||
public int getArrayCapacity(); | ||
public int getFetchSize(); | ||
public int getMaxResults(); | ||
public boolean isOptimizeAfterPurge(); | ||
public boolean isOptimizeAtEnd(); | ||
public int getPartitionCapacity(); | ||
public int getPartitions(); | ||
public boolean isPurgeAtStart(); | ||
public Set<Class<?>> getRootEntities(); | ||
public int getThreads(); | ||
} |
181 changes: 181 additions & 0 deletions
181
src/main/java/org/hibernate/search/jsr352/MassIndexerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
package org.hibernate.search.jsr352; | ||
|
||
import java.util.Properties; | ||
import java.util.Set; | ||
|
||
import javax.batch.operations.JobOperator; | ||
import javax.batch.runtime.BatchRuntime; | ||
|
||
public class MassIndexerImpl implements MassIndexer { | ||
|
||
private boolean optimizeAfterPurge = false; | ||
private boolean optimizeAtEnd = false; | ||
private boolean purgeAtStart = false; | ||
|
||
private int arrayCapacity = 1000; | ||
private int fetchSize = 200000; | ||
private int maxResults = 1000000; | ||
private int partitionCapacity = 250; | ||
private int partitions = 4; | ||
private int threads = 2; | ||
|
||
private final String JOB_NAME = "mass-index"; | ||
|
||
private Set<Class<?>> rootEntities; | ||
|
||
MassIndexerImpl() { | ||
|
||
} | ||
|
||
@Override | ||
public long start() { | ||
Properties jobParams = new Properties(); | ||
jobParams.setProperty("fetchSize", String.valueOf(fetchSize)); | ||
jobParams.setProperty("arrayCapacity", String.valueOf(arrayCapacity)); | ||
jobParams.setProperty("maxResults", String.valueOf(maxResults)); | ||
jobParams.setProperty("partitionCapacity", String.valueOf(partitionCapacity)); | ||
jobParams.setProperty("partitions", String.valueOf(partitions)); | ||
jobParams.setProperty("threads", String.valueOf(threads)); | ||
jobParams.setProperty("purgeAtStart", String.valueOf(purgeAtStart)); | ||
jobParams.setProperty("optimizeAfterPurge", String.valueOf(optimizeAfterPurge)); | ||
jobParams.setProperty("optimizeAtEnd", String.valueOf(optimizeAtEnd)); | ||
jobParams.setProperty("rootEntities", String.valueOf(rootEntities)); | ||
JobOperator jobOperator = BatchRuntime.getJobOperator(); | ||
Long executionId = jobOperator.start(JOB_NAME, jobParams); | ||
return executionId; | ||
} | ||
|
||
@Override | ||
public void stop(long executionId) { | ||
JobOperator jobOperator = BatchRuntime.getJobOperator(); | ||
jobOperator.stop(executionId); | ||
} | ||
|
||
@Override | ||
public MassIndexer arrayCapacity(int arrayCapacity) { | ||
if (arrayCapacity < 1) { | ||
throw new IllegalArgumentException("arrayCapacity must be at least 1"); | ||
} | ||
this.arrayCapacity = arrayCapacity; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MassIndexer fetchSize(int fetchSize) { | ||
if (fetchSize < 1) { | ||
throw new IllegalArgumentException("fetchSize must be at least 1"); | ||
} | ||
this.fetchSize = fetchSize; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MassIndexer maxResults(int maxResults) { | ||
if (maxResults < 1) { | ||
throw new IllegalArgumentException("maxResults must be at least 1"); | ||
} | ||
this.maxResults = maxResults; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MassIndexer optimizeAfterPurge(boolean optimizeAfterPurge) { | ||
this.optimizeAfterPurge = optimizeAfterPurge; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MassIndexer optimizeAtEnd(boolean optimizeAtEnd) { | ||
this.optimizeAtEnd = optimizeAtEnd; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MassIndexer partitionCapacity(int partitionCapacity) { | ||
if (partitionCapacity < 1) { | ||
throw new IllegalArgumentException("partitionCapacity must be at least 1"); | ||
} | ||
this.partitionCapacity = partitionCapacity; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MassIndexer partitions(int partitions) { | ||
if (partitions < 1) { | ||
throw new IllegalArgumentException("partitions must be at least 1"); | ||
} | ||
this.partitions = partitions; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MassIndexer purgeAtStart(boolean purgeAtStart) { | ||
this.purgeAtStart = purgeAtStart; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MassIndexer threads(int threads) { | ||
if (threads < 1) { | ||
throw new IllegalArgumentException("threads must be at least 1."); | ||
} | ||
this.threads = threads; | ||
return this; | ||
} | ||
|
||
@Override | ||
public MassIndexer rootEntities(Set<Class<?>> rootEntities) { | ||
if (rootEntities == null) { | ||
throw new NullPointerException("rootEntities cannot be NULL."); | ||
} else if (rootEntities.isEmpty()) { | ||
throw new NullPointerException("rootEntities must have at least 1 element."); | ||
} | ||
this.rootEntities = rootEntities; | ||
return this; | ||
} | ||
|
||
@Override | ||
public boolean isOptimizeAfterPurge() { | ||
return optimizeAfterPurge; | ||
} | ||
|
||
public boolean isOptimizeAtEnd() { | ||
return optimizeAtEnd; | ||
} | ||
|
||
public boolean isPurgeAtStart() { | ||
return purgeAtStart; | ||
} | ||
|
||
public int getArrayCapacity() { | ||
return arrayCapacity; | ||
} | ||
|
||
public int getFetchSize() { | ||
return fetchSize; | ||
} | ||
|
||
public int getMaxResults() { | ||
return maxResults; | ||
} | ||
|
||
public int getPartitionCapacity() { | ||
return partitionCapacity; | ||
} | ||
|
||
public int getPartitions() { | ||
return partitions; | ||
} | ||
|
||
public int getThreads() { | ||
return threads; | ||
} | ||
|
||
public String getJOB_NAME() { | ||
return JOB_NAME; | ||
} | ||
|
||
public Set<Class<?>> getRootEntities() { | ||
return rootEntities; | ||
} | ||
} |