类java.util.concurrent.Delayed源码实例Demo

下面列出了怎么用java.util.concurrent.Delayed的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: hadoop   文件: GridmixJob.java
@Override
public int compareTo(Delayed other) {
  if (this == other) {
    return 0;
  }
  if (other instanceof GridmixJob) {
    final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
    if (otherNanos < submissionTimeNanos) {
      return 1;
    }
    if (otherNanos > submissionTimeNanos) {
      return -1;
    }
    return id() - ((GridmixJob)other).id();
  }
  final long diff =
    getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
  return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
 
源代码2 项目: Android-BLE   文件: Task.java
/**
 * 元素的先后顺序
 * @param other
 * @return
 */
@Override
public int compareTo(Delayed other) {
    if (other == this) // compare zero ONLY if same object
        return 0;
    if (other instanceof Task) {
        Task x = (Task) other;
        long diff = timeOut - x.timeOut;
        if (diff < 0)
            return -1;
        else if (diff > 0)
            return 1;
        else if (sequenceNum < x.sequenceNum)
            return -1;
        else
            return 1;
    }
    long d = (getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS));
    return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
}
 
源代码3 项目: netty-4.1.22   文件: ScheduledFutureTask.java
@Override
public int compareTo(Delayed o) {
    if (this == o) {
        return 0;
    }

    ScheduledFutureTask<?> that = (ScheduledFutureTask<?>) o;
    long d = deadlineNanos() - that.deadlineNanos();
    if (d < 0) {
        return -1;
    } else if (d > 0) {
        return 1;
    } else if (id < that.id) {
        return -1;
    } else if (id == that.id) {
        throw new Error();
    } else {
        return 1;
    }
}
 
源代码4 项目: tracing-framework   文件: ThrottlingDelayQueue.java
@Override
public int compareTo(Delayed other) {
    if (other instanceof ThrottlingDelayQueue.TenantThrottler) {
        long onext = ((ThrottlingDelayQueue.TenantThrottler) other).next;
        if (next < onext)
            return -1;
        else if (next == onext)
            return 0;
        else
            return 1;
    } else {
        long odelay = other.getDelay(TimeUnit.NANOSECONDS);
        long tdelay = this.getDelay(TimeUnit.NANOSECONDS);
        if (tdelay < odelay)
            return -1;
        else if (tdelay == odelay)
            return 0;
        else
            return 1;
    }
}
 
源代码5 项目: threadly   文件: ThreadlyInternalAccessor.java
@Override
public int compareTo(Delayed o) {
  if (this == o) {
    return 0;
  } else if (o instanceof DelayedTaskWrapper) {
    return (int)(task.getRunTime() - ((DelayedTaskWrapper)o).task.getRunTime());
  } else {
    long thisDelay = this.getDelay(TimeUnit.MILLISECONDS);
    long otherDelay = o.getDelay(TimeUnit.MILLISECONDS);
    if (thisDelay == otherDelay) {
      return 0;
    } else if (thisDelay > otherDelay) {
      return 1;
    } else {
      return -1;
    }
  }
}
 
源代码6 项目: big-c   文件: GridmixJob.java
@Override
public int compareTo(Delayed other) {
  if (this == other) {
    return 0;
  }
  if (other instanceof GridmixJob) {
    final long otherNanos = ((GridmixJob)other).submissionTimeNanos;
    if (otherNanos < submissionTimeNanos) {
      return 1;
    }
    if (otherNanos > submissionTimeNanos) {
      return -1;
    }
    return id() - ((GridmixJob)other).id();
  }
  final long diff =
    getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS);
  return 0 == diff ? 0 : (diff > 0 ? 1 : -1);
}
 
源代码7 项目: xian   文件: OperationAndData.java
@Override
public int compareTo(Delayed o)
{
    if ( o == this )
    {
        return 0;
    }

    long diff = getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS);
    if ( diff == 0 )
    {
        if ( o instanceof OperationAndData )
        {
            diff = ordinal.get() - ((OperationAndData)o).ordinal.get();
        }
    }

    return (diff < 0) ? -1 : ((diff > 0) ? 1 : 0);
}
 
源代码8 项目: jstarcraft-core   文件: DelayFloat.java
@Override
public int compareTo(Delayed that) {
    long thisDelay = this.getDelay(TimeUnit.MILLISECONDS);
    long thatDelay = that.getDelay(TimeUnit.MILLISECONDS);
    if (thisDelay < thatDelay) {
        return -1;
    }
    if (thisDelay > thatDelay) {
        return 1;
    }
    // 时间判断无法区分时,执行如下判断(用于维持 compareTo 的使用约束)
    if (this.equals(that)) {
        return 0;
    } else {
        return this.hashCode() - that.hashCode();
    }
}
 
源代码9 项目: jstarcraft-core   文件: DelayLong.java
@Override
public int compareTo(Delayed that) {
    long thisDelay = this.getDelay(TimeUnit.MILLISECONDS);
    long thatDelay = that.getDelay(TimeUnit.MILLISECONDS);
    if (thisDelay < thatDelay) {
        return -1;
    }
    if (thisDelay > thatDelay) {
        return 1;
    }
    // 时间判断无法区分时,执行如下判断(用于维持 compareTo 的使用约束)
    if (this.equals(that)) {
        return 0;
    } else {
        return this.hashCode() - that.hashCode();
    }
}
 
源代码10 项目: jstarcraft-core   文件: DelayInteger.java
@Override
public int compareTo(Delayed that) {
    long thisDelay = this.getDelay(TimeUnit.MILLISECONDS);
    long thatDelay = that.getDelay(TimeUnit.MILLISECONDS);
    if (thisDelay < thatDelay) {
        return -1;
    }
    if (thisDelay > thatDelay) {
        return 1;
    }
    // 时间判断无法区分时,执行如下判断(用于维持 compareTo 的使用约束)
    if (this.equals(that)) {
        return 0;
    } else {
        return this.hashCode() - that.hashCode();
    }
}
 
源代码11 项目: threadly   文件: TestDelayed.java
@Override
public int compareTo(Delayed o) {
  if (this == o) {
    return 0;
  } else if (o instanceof TestDelayed) {
    return (int)(delayInMs - ((TestDelayed)o).delayInMs);
  } else {
    long thisDelay = this.getDelay(TimeUnit.MILLISECONDS);
    long otherDelay = o.getDelay(TimeUnit.MILLISECONDS);
    if (thisDelay == otherDelay) {
      return 0;
    } else if (thisDelay > otherDelay) {
      return 1;
    } else {
      return -1;
    }
  }
}
 
源代码12 项目: pravega   文件: NoOpScheduledExecutor.java
@Override
public int compareTo(Delayed other) {
    DummyScheduledFuture otherTask = (DummyScheduledFuture) other;
    if (this.value > otherTask.getValue()) {
        return 1;
    } else if (this.value < otherTask.getValue()) {
        return -1;
    } else {
        return 0;
    }
}
 
源代码13 项目: grpc-nebula-java   文件: FakeClock.java
@Override public int compareTo(Delayed other) {
  ScheduledTask otherTask = (ScheduledTask) other;
  if (dueTimeNanos > otherTask.dueTimeNanos) {
    return 1;
  } else if (dueTimeNanos < otherTask.dueTimeNanos) {
    return -1;
  } else {
    return 0;
  }
}
 
@Override
public int compareTo(Delayed other) {
	if (this == other) {
		return 0;
	}
	long diff = getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS);
	return (diff == 0 ? 0 : ((diff < 0)? -1 : 1));
}
 
@Test
public void testWithSingleBoundParameterizedOnInstantiate() throws Exception {
	Method bridgeMethod = DelayQueue.class.getMethod("add", Object.class);
	assertTrue(bridgeMethod.isBridge());
	Method actualMethod = DelayQueue.class.getMethod("add", Delayed.class);
	assertFalse(actualMethod.isBridge());
	assertEquals(actualMethod, BridgeMethodResolver.findBridgedMethod(bridgeMethod));
}
 
源代码16 项目: openpojo   文件: DelayedType.java
public int compareTo(Delayed o) {
  if (System.identityHashCode(this) > System.identityHashCode(o))
    return 1;
  if (System.identityHashCode(this) < System.identityHashCode(o))
    return -1;
  return 0;
}
 
@Override
protected <V> ListenableScheduledFuture<V> schedule(Callable<V> callable, long delayInMillis) {
  ListenableFutureTask<V> lft = new ListenableFutureTask<>(false, callable, singleThreadScheduler);
  Delayed d = ThreadlyInternalAccessor.doScheduleAndGetDelayed(singleThreadScheduler, 
                                                               lft, taskPriority, delayInMillis);
  
  return new ScheduledFutureDelegate<>(lft, d);
}
 
源代码18 项目: litchi   文件: DelayedSession.java
@Override
public int compareTo(Delayed o) {
    if (o.getDelay(TimeUnit.MILLISECONDS) < this.getDelay(TimeUnit.MILLISECONDS)) {
        return 1;
    } else if (o.getDelay(TimeUnit.MILLISECONDS) > this.getDelay(TimeUnit.MILLISECONDS)) {
        return -1;
    }
    return 0;
}
 
@Override
public int compareTo(@Nonnull Delayed o) {
	if (o == this) {
		return 0;
	}

	long diff = getDelay(TimeUnit.NANOSECONDS) - o.getDelay(TimeUnit.NANOSECONDS);
	return (diff < 0L) ? -1 : (diff > 0L) ? 1 : 0;
}
 
源代码20 项目: cassandana   文件: Session.java
@Override
public int compareTo(Delayed o) {
    if ((this.startTime - ((InFlightPacket) o).startTime) == 0) {
        return 0;
    }
    if ((this.startTime - ((InFlightPacket) o).startTime) > 0) {
        return 1;
    } else {
        return -1;
    }
}
 
源代码21 项目: big-c   文件: ContainerSimulator.java
@Override
public int compareTo(Delayed o) {
  if (!(o instanceof ContainerSimulator)) {
    throw new IllegalArgumentException(
            "Parameter must be a ContainerSimulator instance");
  }
  ContainerSimulator other = (ContainerSimulator) o;
  return (int) Math.signum(endTime - other.endTime);
}
 
源代码22 项目: ProxyPool   文件: Proxy.java
@Override
public int compareTo(Delayed o) {
    Proxy element = (Proxy)o;
    if (successfulAverageTime == 0.0d ||element.successfulAverageTime == 0.0d){
        return 0;
    }
    return successfulAverageTime > element.successfulAverageTime ? 1:(successfulAverageTime < element.successfulAverageTime ? -1 : 0);
}
 
源代码23 项目: joyqueue   文件: TimerTaskList.java
public int compareTo(Delayed d) {

        TimerTaskList other = (TimerTaskList) d;

        if (getExpiration() < other.getExpiration()) {
            return -1;
        } else if (getExpiration() > other.getExpiration()) {
            return 1;
        } else {
            return 0;
        }
    }
 
源代码24 项目: MaxKey   文件: InMemoryTokenStore.java
public int compareTo(Delayed other) {
	if (this == other) {
		return 0;
	}
	long diff = getDelay(TimeUnit.MILLISECONDS) - other.getDelay(TimeUnit.MILLISECONDS);
	return (diff == 0 ? 0 : ((diff < 0) ? -1 : 1));
}
 
源代码25 项目: fresco   文件: TestScheduledFuture.java
@Override
public int compareTo(Delayed delayed) {
  long me = getDelay(TimeUnit.MILLISECONDS);
  long other = delayed.getDelay(TimeUnit.MILLISECONDS);
  if (me < other) {
    return -1;
  }
  if (me > other) {
    return 1;
  } else {
    return 0;
  }
}
 
源代码26 项目: exhibitor   文件: ActivityQueue.java
@Override
// Note: this class has a natural ordering that is inconsistent with equals
public int compareTo(Delayed rhs)
{
    if ( rhs == this )
    {
        return 0;
    }

    long    diff = getDelay(TimeUnit.MILLISECONDS) - rhs.getDelay(TimeUnit.MILLISECONDS);
    return (diff == 0) ? 0 : ((diff < 0) ? -1 : 1);
}
 
源代码27 项目: hbase   文件: ReadOnlyZKClient.java
@Override
public int compareTo(Delayed o) {
  Task that = (Task) o;
  int c = Long.compare(time, that.time);
  if (c != 0) {
    return c;
  }
  return Integer.compare(System.identityHashCode(this), System.identityHashCode(that));
}
 
源代码28 项目: pxf   文件: UGICache.java
/**
 * Compare the expiry time of this cache entry to another cache entry's expiry time.
 *
 * @param other a UGICache.Entry (passing any other kind of Delayed produces an error)
 * @see java.lang.Comparable<>#compareTo(java.lang.Comparable<>)
 */
@Override
public int compareTo(Delayed other) {
    if (!(other instanceof Entry)) return 1;

    Entry that = (Entry) other;
    return Long.compare(this.getDelayMillis(), that.getDelayMillis());
}
 
源代码29 项目: spring-boot-protocol   文件: MqttSession.java
@Override
public int compareTo(Delayed o) {
    if ((this.startTime - ((InFlightPacket) o).startTime) == 0) {
        return 0;
    }
    if ((this.startTime - ((InFlightPacket) o).startTime) > 0) {
        return 1;
    } else {
        return -1;
    }
}
 
源代码30 项目: big-c   文件: TaskRunner.java
@Override
public int compareTo(Delayed o) {
  if (!(o instanceof Task)) {
    throw new IllegalArgumentException("Parameter must be a Task instance");
  }
  Task other = (Task) o;
  return (int) Math.signum(nextRun - other.nextRun);
}
 
 类所在包
 同包方法