List of usage examples for org.joda.time Duration getMillis
public long getMillis()
From source file:io.druid.metadata.SQLMetadataSegmentManager.java
License:Apache License
@LifecycleStart public void start() { synchronized (lock) { if (started) { return; }/*ww w. j a v a2 s .c o m*/ exec = MoreExecutors .listeningDecorator(Execs.scheduledSingleThreaded("DatabaseSegmentManager-Exec--%d")); final Duration delay = config.get().getPollDuration().toStandardDuration(); future = exec.scheduleWithFixedDelay(new Runnable() { @Override public void run() { try { poll(); } catch (Exception e) { log.makeAlert(e, "uncaught exception in segment manager polling thread").emit(); } } }, 0, delay.getMillis(), TimeUnit.MILLISECONDS); started = true; } }
From source file:io.druid.query.materializedview.DerivativeDataSourceManager.java
License:Apache License
@LifecycleStart public void start() { log.info("starting derivatives manager."); synchronized (lock) { if (started) { return; }//from w w w.j ava 2 s . com exec = MoreExecutors .listeningDecorator(Execs.scheduledSingleThreaded("DerivativeDataSourceManager-Exec-%d")); final Duration delay = config.getPollDuration().toStandardDuration(); future = exec.scheduleWithFixedDelay(new Runnable() { @Override public void run() { try { updateDerivatives(); } catch (Exception e) { log.makeAlert(e, "uncaught exception in derivatives manager updating thread").emit(); } } }, 0, delay.getMillis(), TimeUnit.MILLISECONDS); started = true; } log.info("Derivatives manager started."); }
From source file:io.mesosphere.mesos.frameworks.cassandra.scheduler.util.Futures.java
License:Apache License
/** * Will throw a RuntimeException wrapping any exception that may happen * java.util.concurrent.ExecutionException * java.lang.InterruptedException/*from w w w.j av a2 s. co m*/ * java.util.concurrent.TimeoutException */ public static <A> A await(@NotNull final Future<A> f, @NotNull final Duration timeout) { try { return f.get(timeout.getMillis(), TimeUnit.MILLISECONDS); } catch (InterruptedException | ExecutionException | TimeoutException e) { throw new RuntimeException(e); } }
From source file:io.v.android.impl.google.rpc.protocols.bt.Bluetooth.java
License:Open Source License
static Connection dial(String btAddr, Duration timeout) throws VException { String macAddr = getMACAddress(btAddr); int port = getPortNumber(btAddr); BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddr); try {/*from ww w. j ava 2 s.c om*/ // Create a socket to the remote device. // NOTE(spetrovic): Android's public methods currently only allow connection to a // UUID, which goes through SDP. Since we already have a remote port number, we // connect to it directly. Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] { int.class }); final BluetoothSocket socket = (BluetoothSocket) m.invoke(device, port); // Connect. Timer timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { try { socket.close(); } catch (IOException e) { System.err.println("Couldn't close BluetoothSocket."); } } }, timeout.getMillis()); try { socket.connect(); } catch (IOException e) { throw new VException("Couldn't connect: " + e.getMessage()); } finally { timer.cancel(); } // There is no way currently to retrieve the local port number for the connection, // but that's probably OK. String localAddr = String.format("%s/%d", BluetoothAdapter.getDefaultAdapter().getAddress(), 0); String remoteAddr = String.format("%s/%d", macAddr, port); return new Connection(socket, localAddr, remoteAddr); } catch (Exception e) { throw new VException("Couldn't invoke createInsecureRfcommSocket: " + e.getMessage()); } }
From source file:io.v.android.impl.google.rpc.protocols.bt.BluetoothWithPort.java
License:Open Source License
static Stream dial(VContext ctx, String btAddr, Duration timeout) throws Exception { String macAddr = getMACAddress(ctx, btAddr); int port = getPortNumber(btAddr); BluetoothDevice device = BluetoothAdapter.getDefaultAdapter().getRemoteDevice(macAddr); // Create a socket to the remote device. // NOTE(spetrovic): Android's public methods currently only allow connection to // a UUID, which goes through SDP. Since we already have a remote port number, // we connect to it directly, invoking a hidden method using reflection. Method m = device.getClass().getMethod("createInsecureRfcommSocket", new Class[] { int.class }); final BluetoothSocket socket = (BluetoothSocket) m.invoke(device, port); // Connect.//from w ww . j a va 2 s . c o m Timer timer = null; if (timeout.getMillis() != 0) { timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { try { socket.close(); } catch (IOException e) { } } }, timeout.getMillis()); } try { socket.connect(); } catch (IOException e) { socket.close(); throw e; } finally { if (timer != null) { timer.cancel(); } } // There is no way currently to retrieve the local port number for the // connection, but that's probably OK. String localAddr = String.format("%s/%d", localMACAddress(ctx), 0); String remoteAddr = String.format("%s/%d", macAddr, port); return new Stream(socket, localAddr, remoteAddr); }
From source file:io.v.android.impl.google.rpc.protocols.bt.BluetoothWithSdp.java
License:Open Source License
static Stream dial(VContext ctx, String address, Duration timeout) throws Exception { String macAddress = getMacAddress(ctx, address); int port = getPortNumber(address); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); if (adapter == null) { throw new IOException("BluetoothAdapter not available"); }/*w w w.j a v a 2s .c om*/ BluetoothDevice device = adapter.getRemoteDevice(macAddress); UUID uuid = getSdpUuidFromPort(port); final BluetoothSocket socket = device.createInsecureRfcommSocketToServiceRecord(uuid); Timer timer = null; if (timeout.getMillis() != 0) { timer = new Timer(); timer.schedule(new TimerTask() { @Override public void run() { try { socket.close(); } catch (IOException e) { } } }, timeout.getMillis()); } try { socket.connect(); } catch (IOException e) { socket.close(); throw e; } finally { if (timer != null) { timer.cancel(); } } // There is no way currently to retrieve the local port number for the // connection, but that's probably OK. String localAddress = String.format("%s/0", getLocalMacAddress(ctx)); String remoteAddress = String.format("%s/%d", macAddress, port); return new Stream(socket, localAddress, remoteAddress); }
From source file:io.v.impl.google.lib.discovery.DeviceCache.java
License:Open Source License
public DeviceCache(final Duration maxAge) { this.maxAge = maxAge; this.timer = Executors.newSingleThreadScheduledExecutor(); long periodicity = maxAge.getMillis() / 2; timer.scheduleAtFixedRate(new Runnable() { @Override//from w w w . j a v a 2 s. c o m public void run() { removeStaleEntries(); } }, periodicity, periodicity, TimeUnit.MILLISECONDS); }
From source file:io.v.rx.RxMountState.java
License:Open Source License
public static Observable<Stream<MountStatus>> poll(final Server s, final Duration interval) { return Observable.interval(0, interval.getMillis(), TimeUnit.MILLISECONDS) .map(i -> J8Arrays.stream(s.getStatus().getMounts())); }
From source file:io.v.rx.RxPublisherState.java
License:Open Source License
public static Observable<Stream<PublisherEntry>> poll(final Server s, final Duration interval) { return Observable.interval(0, interval.getMillis(), TimeUnit.MILLISECONDS) .map(i -> J8Arrays.stream(s.getStatus().getPublisherStatus())); }
From source file:io.v.rx.RxTestCase.java
License:Open Source License
public static long verificationDelay(final Duration nominal) { return 2 * nominal.getMillis(); }