Java Code Examples for scala.runtime.BoxedUnit#UNIT

The following examples show how to use scala.runtime.BoxedUnit#UNIT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: hostTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final String override = "localhost:9410";

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(host$.Flag.isDefined()).isTrue();
      assertThat(host$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  host$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 2
Source File: ZKSessionLockFactory.java    From distributedlog with Apache License 2.0 6 votes vote down vote up
@Override
public Future<SessionLock> createLock(String lockPath,
                                      DistributedLockContext context) {
    AtomicInteger numRetries = new AtomicInteger(lockCreationRetries);
    final AtomicReference<Throwable> interruptedException = new AtomicReference<Throwable>(null);
    Promise<SessionLock> createPromise =
            new Promise<SessionLock>(new com.twitter.util.Function<Throwable, BoxedUnit>() {
        @Override
        public BoxedUnit apply(Throwable t) {
            interruptedException.set(t);
            return BoxedUnit.UNIT;
        }
    });
    createLock(
            lockPath,
            context,
            interruptedException,
            numRetries,
            createPromise,
            0L);
    return createPromise;
}
 
Example 3
Source File: bootstrapServersTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final List<InetSocketAddress> override = singletonList(new InetSocketAddress("zipkin", 9092));

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(bootstrapServers$.Flag.isDefined()).isTrue();
      assertThat(bootstrapServers$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  bootstrapServers$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 4
Source File: topicTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final String override = "zipkin-dev";

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(topic$.Flag.isDefined()).isTrue();
      assertThat(topic$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  topic$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 5
Source File: initialSampleRateTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final float override = 1.0f;

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(initialSampleRate$.Flag.isDefined()).isTrue();
      assertThat(initialSampleRate$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  initialSampleRate$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 6
Source File: localServiceNameTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final String override = "favstar";

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(localServiceName$.Flag.isDefined()).isTrue();
      assertThat(localServiceName$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  localServiceName$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 7
Source File: compressionEnabledTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final boolean override = false;

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(compressionEnabled$.Flag.isDefined()).isTrue();
      assertThat(compressionEnabled$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  compressionEnabled$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 8
Source File: hostTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final String override = "foo:9411";

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(host$.Flag.isDefined()).isTrue();
      assertThat(host$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  host$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 9
Source File: hostHeaderTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final String override = "amazon";

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(hostHeader$.Flag.isDefined()).isTrue();
      assertThat(hostHeader$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  hostHeader$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 10
Source File: tlsEnabledTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final boolean override = true;

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(tlsEnabled$.Flag.isDefined()).isTrue();
      assertThat(tlsEnabled$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  tlsEnabled$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 11
Source File: tlsValidationEnabledTest.java    From zipkin-finagle with Apache License 2.0 6 votes vote down vote up
@Test public void letOverridesDefault() {
  final boolean override = false;

  final AtomicBoolean ran = new AtomicBoolean();
  Function0<BoxedUnit> fn0 = new AbstractFunction0<BoxedUnit>() {
    @Override public BoxedUnit apply() {
      ran.set(true); // used to verify this block is executed.
      assertThat(tlsValidationEnabled$.Flag.isDefined()).isTrue();
      assertThat(tlsValidationEnabled$.Flag.apply()).isEqualTo(override);
      return BoxedUnit.UNIT;
    }
  };
  tlsValidationEnabled$.Flag.let(override, fn0);

  assertThat(ran.get()).isTrue();
}
 
Example 12
Source File: ReadAheadWorker.java    From distributedlog with Apache License 2.0 5 votes vote down vote up
<T> Function1<T, BoxedUnit> submit(final Function1<T, BoxedUnit> function) {
    return new AbstractFunction1<T, BoxedUnit>() {
        @Override
        public BoxedUnit apply(final T input) {
            submit(new Runnable() {
                @Override
                public void run() {
                    function.apply(input);
                }
            });
            return BoxedUnit.UNIT;
        }
    };
}
 
Example 13
Source File: CucumberReportAdapter.java    From openCypher with Apache License 2.0 5 votes vote down vote up
private <T> AbstractFunction1<T, BoxedUnit> adapt(Consumer<T> procedure) {
    return new AbstractFunction1<T, BoxedUnit>() {
        @Override
        public BoxedUnit apply(T v1) {
            procedure.accept(v1);
            return BoxedUnit.UNIT;
        }
    };
}
 
Example 14
Source File: NameServerSet.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
private BoxedUnit respondToChanges(Addr addr) {
    ImmutableSet<ServiceInstance> oldHostSet = ImmutableSet.copyOf(hostSet);

    ImmutableSet<ServiceInstance> newHostSet = oldHostSet;

    if (addr instanceof Addr.Bound) {
        scala.collection.immutable.Set<Address> endpointAddresses = ((Addr.Bound) addr).addrs();
        scala.collection.Iterator<Address> endpointAddressesIterator = endpointAddresses.toIterator();
        HashSet<ServiceInstance> serviceInstances = new HashSet<ServiceInstance>();
        while (endpointAddressesIterator.hasNext()) {
            serviceInstances.add(endpointAddressToServiceInstance(endpointAddressesIterator.next()));
        }
        newHostSet = ImmutableSet.copyOf(serviceInstances);

    } else if (addr instanceof Addr.Failed) {
        logger.error("Name resolution failed", ((Addr.Failed) addr).cause());
        newHostSet = ImmutableSet.of();
    } else if (addr.toString().equals("Pending")) {
        logger.info("Name resolution pending");
        newHostSet = oldHostSet;
    } else if (addr.toString().equals("Neg")) {
        newHostSet = ImmutableSet.of();
    } else {
        logger.error("Invalid Addr type: {}", addr.getClass().getName());
        throw new UnsupportedOperationException("Invalid Addr type:" + addr.getClass().getName());
    }

    // Reference comparison is valid as the sets are immutable
    if (oldHostSet != newHostSet) {
        logger.info("NameServerSet updated: {} -> {}", hostSetToString(oldHostSet), hostSetToString(newHostSet));
        resolutionPending.set(false);
        hostSet = newHostSet;
        synchronized (watchers) {
            for (HostChangeMonitor<ServiceInstance> watcher: watchers) {
                watcher.onChange(newHostSet);
            }
        }

    }

    return BoxedUnit.UNIT;
}
 
Example 15
Source File: FutureUtils.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Override
public BoxedUnit apply(Throwable cause) {
    interrupted = true;
    return BoxedUnit.UNIT;
}
 
Example 16
Source File: NameServerSet.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
private BoxedUnit respondToChanges(Addr addr) {
    ImmutableSet<ServiceInstance> oldHostSet = ImmutableSet.copyOf(hostSet);

    ImmutableSet<ServiceInstance> newHostSet = oldHostSet;

    if (addr instanceof Addr.Bound) {
        scala.collection.immutable.Set<Address> endpointAddresses = ((Addr.Bound)addr).addrs();
        scala.collection.Iterator<Address> endpointAddressesIterator = endpointAddresses.toIterator();
        HashSet<ServiceInstance> serviceInstances = new HashSet<ServiceInstance>();
        while (endpointAddressesIterator.hasNext()) {
            serviceInstances.add(endpointAddressToServiceInstance(endpointAddressesIterator.next()));
        }
        newHostSet = ImmutableSet.copyOf(serviceInstances);

    } else if (addr instanceof Addr.Failed) {
        logger.error("Name resolution failed", ((Addr.Failed)addr).cause());
        newHostSet = ImmutableSet.of();
    } else if (addr.toString().equals("Pending")) {
        logger.info("Name resolution pending");
        newHostSet = oldHostSet;
    } else if (addr.toString().equals("Neg")) {
        newHostSet = ImmutableSet.of();
    } else {
        logger.error("Invalid Addr type: {}", addr.getClass().getName());
        throw new UnsupportedOperationException("Invalid Addr type:" + addr.getClass().getName());
    }

    // Reference comparison is valid as the sets are immutable
    if (oldHostSet != newHostSet) {
        logger.info("NameServerSet updated: {} -> {}", hostSetToString(oldHostSet), hostSetToString(newHostSet));
        resolutionPending.set(false);
        hostSet = newHostSet;
        synchronized (watchers) {
            for (HostChangeMonitor<ServiceInstance> watcher: watchers) {
                watcher.onChange(newHostSet);
            }
        }

    }

    return BoxedUnit.UNIT;
}
 
Example 17
Source File: ZKSessionLock.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a distributed lock using the given {@code zkClient} to coordinate locking.
 *
 * @param zkClient The ZooKeeper client to use.
 * @param lockPath The path used to manage the lock under.
 * @param clientId client id use for lock.
 * @param lockStateExecutor executor to execute all lock state changes.
 * @param lockOpTimeout timeout of lock operations
 * @param statsLogger stats logger
 */
public ZKSessionLock(ZooKeeperClient zkClient,
                     String lockPath,
                     String clientId,
                     OrderedScheduler lockStateExecutor,
                     long lockOpTimeout,
                     StatsLogger statsLogger,
                     DistributedLockContext lockContext)
        throws IOException {
    this.zkClient = zkClient;
    try {
        this.zk = zkClient.get();
    } catch (ZooKeeperClient.ZooKeeperConnectionException zce) {
        throw new ZKException("Failed to get zookeeper client for lock " + lockPath,
                KeeperException.Code.CONNECTIONLOSS);
    } catch (InterruptedException e) {
        throw new DLInterruptedException("Interrupted on getting zookeeper client for lock " + lockPath, e);
    }
    this.lockPath = lockPath;
    this.lockId = Pair.of(clientId, this.zk.getSessionId());
    this.lockContext = lockContext;
    this.lockStateExecutor = lockStateExecutor;
    this.lockState = new StateManagement();
    this.lockOpTimeout = lockOpTimeout;

    this.tryStats = statsLogger.getOpStatsLogger("tryAcquire");
    this.tryTimeouts = statsLogger.getCounter("tryTimeouts");
    this.unlockStats = statsLogger.getOpStatsLogger("unlock");

    // Attach interrupt handler to acquire future so clients can abort the future.
    this.acquireFuture = new Promise<Boolean>(new com.twitter.util.Function<Throwable, BoxedUnit>() {
        @Override
        public BoxedUnit apply(Throwable t) {
            // This will set the lock state to closed, and begin to cleanup the zk lock node.
            // We have to be careful not to block here since doing so blocks the ordered lock
            // state executor which can cause deadlocks depending on how futures are chained.
            ZKSessionLock.this.asyncUnlock(t);
            // Note re. logging and exceptions: errors are already logged by unlockAsync.
            return BoxedUnit.UNIT;
        }
    });
}
 
Example 18
Source File: FutureUtils.java    From distributedlog with Apache License 2.0 4 votes vote down vote up
@Override
public BoxedUnit apply(Throwable cause) {
    interrupted = true;
    return BoxedUnit.UNIT;
}
 
Example 19
Source File: AbsFunc4.java    From Apache-Spark-2x-for-Java-Developers with MIT License 3 votes vote down vote up
@Override
public BoxedUnit apply(EdgeContext<String, String, Integer> arg0) {
	
	
	arg0.sendToDst(1);
	return BoxedUnit.UNIT;
}