Skip to content

Commit

Permalink
Merge pull request #7129 from vespa-engine/bjorncs/documentapi
Browse files Browse the repository at this point in the history
Remove use of finalizer
  • Loading branch information
bjorncs committed Sep 28, 2018
2 parents 47684b0 + 94e1739 commit 157c8b7
Showing 1 changed file with 8 additions and 7 deletions.
Expand Up @@ -13,6 +13,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicBoolean;

/**
* This policy implements the necessary logic to communicate with an external Vespa application and resolve its list of
Expand All @@ -30,6 +31,7 @@ public class ExternPolicy implements DocumentProtocolRoutingPolicy {
private int offset = 0;
private int generation = 0;
private final List<Hop> recipients = new ArrayList<>();
private final AtomicBoolean destroyed = new AtomicBoolean(false);

/**
* Constructs a new instance of this policy. The argument given is the connection spec to the slobrok to use for
Expand Down Expand Up @@ -110,13 +112,6 @@ private void update() {
}

@Override
@SuppressWarnings("deprecation") // finalize() is deprecated from Java 9
public void finalize() throws Throwable {
super.finalize();
mirror.shutdown();
orb.transport().shutdown().join();
}

public void select(RoutingContext ctx) {
if (error != null) {
ctx.setError(DocumentProtocol.ERROR_POLICY_FAILURE, error);
Expand All @@ -135,13 +130,19 @@ public void select(RoutingContext ctx) {
}
}

@Override
public void merge(RoutingContext ctx) {
DocumentProtocol.merge(ctx);
}

@Override
public void destroy() {
if (destroyed.getAndSet(true)) throw new RuntimeException("Already destroyed");
mirror.shutdown();
orb.transport().shutdown().join();
}

@Override
public MetricSet getMetrics() {
return null;
}
Expand Down

0 comments on commit 157c8b7

Please sign in to comment.