Skip to content

Commit

Permalink
Simplify ProducerState.
Browse files Browse the repository at this point in the history
  • Loading branch information
bernardladenthin committed Mar 18, 2024
1 parent e5a8544 commit 0140d78
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ public void initProducer() {
}

@Override
public void releaseProducers() {
this.state = ProducerState.RELEASED;
public void releaseProducer() {
}

@Override
Expand Down Expand Up @@ -167,7 +166,6 @@ void setLogger(Logger logger) {

@Override
public void interrupt() {
state = ProducerState.INTERRUPTED;
shouldRun.set(false);
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/ladenthin/bitcoinaddressfinder/Finder.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.util.Map;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -149,7 +148,7 @@ public void interrupt() {
for (Producer producer : getAllProducers()) {
producer.interrupt();
producer.waitTillProducerNotRunning();
producer.releaseProducers();
producer.releaseProducer();
}

if (consumerJava != null) {
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/net/ladenthin/bitcoinaddressfinder/Producer.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public interface Producer extends Runnable, Interruptable, ProducerStateProvider
* {@link #produceKeys(int, java.util.Random)} continuously.
*/
void initProducer();

/**
* Release the producer.
*/
void releaseProducer();

/**
* Create multiple keys for a specific bit length using {@link Random} and
Expand All @@ -49,11 +54,6 @@ public interface Producer extends Runnable, Interruptable, ProducerStateProvider
*/
void processSecretBase(BigInteger secretBase);

/**
* Release the producers.
*/
void releaseProducers();

/**
* Blocks till the producer is not running anymore.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void logProgress() {
}

@Override
public void releaseProducers() {
public void releaseProducer() {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,10 @@ int getFreeThreads() {
}

@Override
public void releaseProducers() {
public void releaseProducer() {
if (openCLContext != null) {
openCLContext.release();
openCLContext = null;
this.state = ProducerState.RELEASED;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@
package net.ladenthin.bitcoinaddressfinder;

public enum ProducerState {
UNINITIALIZED, INITIALIZED, RUNNING, INTERRUPTED, NOT_RUNNING, RELEASED;
UNINITIALIZED, INITIALIZED, RUNNING, NOT_RUNNING;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void releaseProducers_notInitialized_noExceptionThrown() throws IOExcepti
ProducerOpenCL producerOpenCL = new ProducerOpenCL(cProducerOpenCL, mockConsumer, keyUtility, mockSecretFactory, new MockProducerCompletionCallback());

// act
producerOpenCL.releaseProducers();
producerOpenCL.releaseProducer();
}

@Test
Expand All @@ -97,7 +97,7 @@ public void releaseProducers_initialized_noExceptionThrownAndOpenCLContextFreed(
assertThat(producerOpenCL.openCLContext, notNullValue());

// act
producerOpenCL.releaseProducers();
producerOpenCL.releaseProducer();

// assert
assertThat(producerOpenCL.openCLContext, nullValue());
Expand Down

0 comments on commit 0140d78

Please sign in to comment.