java.util.concurrent.Delayed Java Examples

The following examples show how to use java.util.concurrent.Delayed. 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 Project: hadoop   Author: naver   File: GridmixJob.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #2
Source Project: Android-BLE   Author: aicareles   File: Task.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 元素的先后顺序
 * @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);
}
 
Example #3
Source Project: netty-4.1.22   Author: tianheframe   File: ScheduledFutureTask.java    License: Apache License 2.0 6 votes vote down vote up
@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;
    }
}
 
Example #4
Source Project: tracing-framework   Author: brownsys   File: ThrottlingDelayQueue.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@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;
    }
}
 
Example #5
Source Project: threadly   Author: threadly   File: ThreadlyInternalAccessor.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@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;
    }
  }
}
 
Example #6
Source Project: big-c   Author: yncxcw   File: GridmixJob.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #7
Source Project: xian   Author: xiancloud   File: OperationAndData.java    License: Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #8
Source Project: jstarcraft-core   Author: HongZhaoHua   File: DelayFloat.java    License: Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #9
Source Project: jstarcraft-core   Author: HongZhaoHua   File: DelayLong.java    License: Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #10
Source Project: jstarcraft-core   Author: HongZhaoHua   File: DelayInteger.java    License: Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #11
Source Project: threadly   Author: threadly   File: TestDelayed.java    License: Mozilla Public License 2.0 6 votes vote down vote up
@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;
    }
  }
}
 
Example #12
Source Project: pravega   Author: pravega   File: NoOpScheduledExecutor.java    License: Apache License 2.0 5 votes vote down vote up
@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;
    }
}
 
Example #13
Source Project: grpc-nebula-java   Author: grpc-nebula   File: FakeClock.java    License: Apache License 2.0 5 votes vote down vote up
@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;
  }
}
 
Example #14
Source Project: spring-analysis-note   Author: Vip-Augus   File: ReschedulingRunnable.java    License: MIT License 5 votes vote down vote up
@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));
}
 
Example #15
Source Project: spring-analysis-note   Author: Vip-Augus   File: BridgeMethodResolverTests.java    License: MIT License 5 votes vote down vote up
@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));
}
 
Example #16
Source Project: openpojo   Author: OpenPojo   File: DelayedType.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #17
Source Project: threadly   Author: threadly   File: SingleThreadSchedulerServiceWrapper.java    License: Mozilla Public License 2.0 5 votes vote down vote up
@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);
}
 
Example #18
Source Project: litchi   Author: phantacix   File: DelayedSession.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #19
Source Project: flink   Author: flink-tpc-ds   File: ActorSystemScheduledExecutorAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #20
Source Project: cassandana   Author: mtsoleimani   File: Session.java    License: Apache License 2.0 5 votes vote down vote up
@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;
    }
}
 
Example #21
Source Project: big-c   Author: yncxcw   File: ContainerSimulator.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #22
Source Project: ProxyPool   Author: fengzhizi715   File: Proxy.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #23
Source Project: joyqueue   Author: chubaostream   File: TimerTaskList.java    License: Apache License 2.0 5 votes vote down vote up
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;
        }
    }
 
Example #24
Source Project: MaxKey   Author: shimingxy   File: InMemoryTokenStore.java    License: Apache License 2.0 5 votes vote down vote up
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));
}
 
Example #25
Source Project: fresco   Author: facebook   File: TestScheduledFuture.java    License: MIT License 5 votes vote down vote up
@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;
  }
}
 
Example #26
Source Project: exhibitor   Author: dcos   File: ActivityQueue.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example #27
Source Project: hbase   Author: apache   File: ReadOnlyZKClient.java    License: Apache License 2.0 5 votes vote down vote up
@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));
}
 
Example #28
Source Project: pxf   Author: greenplum-db   File: UGICache.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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());
}
 
Example #29
Source Project: spring-boot-protocol   Author: wangzihaogithub   File: MqttSession.java    License: Apache License 2.0 5 votes vote down vote up
@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;
    }
}
 
Example #30
Source Project: big-c   Author: yncxcw   File: TaskRunner.java    License: Apache License 2.0 5 votes vote down vote up
@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);
}