Skip to content

Commit

Permalink
Move SimpleCondition to service package, as it is a private peer clas…
Browse files Browse the repository at this point in the history
…s to SegmentRunner.

This removes the junk (*cough* utils) package.
  • Loading branch information
michaelsembwever authored and adejanovski committed Aug 28, 2017
1 parent ecd75c3 commit c9b8876
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
import com.spotify.reaper.core.RepairSegment;
import com.spotify.reaper.core.RepairUnit;
import com.spotify.reaper.storage.IDistributedStorage;
import com.spotify.reaper.utils.SimpleCondition;
import com.sun.management.UnixOperatingSystemMXBean;

public final class SegmentRunner implements RepairStatusHandler, Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.spotify.reaper.utils;
package com.spotify.reaper.service;

import java.util.Date;
import java.util.concurrent.TimeUnit;
Expand All @@ -24,61 +24,59 @@
// fulfils the Condition interface without spurious wakeup problems
// (or lost notify problems either: that is, even if you call await()
// _after_ signal(), it will work as desired.)
public class SimpleCondition implements Condition
{
final class SimpleCondition implements Condition {

private boolean set;

public synchronized void await() throws InterruptedException
{
while (!set)
@Override
public synchronized void await() throws InterruptedException {
while (!set) {
wait();
}
}

public synchronized void reset()
{
public synchronized void reset() {
set = false;
}

public synchronized boolean await(long time, TimeUnit unit) throws InterruptedException
{
@Override
public synchronized boolean await(long time, TimeUnit unit) throws InterruptedException {
long start = System.nanoTime();
long timeout = unit.toNanos(time);
long elapsed;
while (!set && (elapsed = System.nanoTime() - start) < timeout)
{
while (!set && (elapsed = System.nanoTime() - start) < timeout) {
TimeUnit.NANOSECONDS.timedWait(this, timeout - elapsed);
}
return set;
}

public void signal()
{
@Override
public void signal() {
throw new UnsupportedOperationException();
}

public synchronized void signalAll()
{
@Override
public synchronized void signalAll() {
set = true;
notifyAll();
}

public synchronized boolean isSignaled()
{
public synchronized boolean isSignaled() {
return set;
}

public void awaitUninterruptibly()
{
@Override
public void awaitUninterruptibly() {
throw new UnsupportedOperationException();
}

public long awaitNanos(long nanosTimeout) throws InterruptedException
{
@Override
public long awaitNanos(long nanosTimeout) throws InterruptedException {
throw new UnsupportedOperationException();
}

public boolean awaitUntil(Date deadline) throws InterruptedException
{
@Override
public boolean awaitUntil(Date deadline) throws InterruptedException {
throw new UnsupportedOperationException();
}
}

0 comments on commit c9b8876

Please sign in to comment.