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 File: ScheduledFutureTask.java    From netty-4.1.22 with 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 #2
Source File: OperationAndData.java    From xian with 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 #3
Source File: GridmixJob.java    From hadoop with 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 #4
Source File: DelayFloat.java    From jstarcraft-core with 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 #5
Source File: DelayLong.java    From jstarcraft-core with 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 #6
Source File: DelayInteger.java    From jstarcraft-core with 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 #7
Source File: TestDelayed.java    From threadly with 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 #8
Source File: GridmixJob.java    From big-c with 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 #9
Source File: ThreadlyInternalAccessor.java    From threadly with 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 #10
Source File: Task.java    From Android-BLE with 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 #11
Source File: ThrottlingDelayQueue.java    From tracing-framework with 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 #12
Source File: LocalLockMediator.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Delayed o) {
    if (this.expiryTime.getTimestamp(TimeUnit.NANOSECONDS) < ((ExpirableKeyColumn) o).expiryTime.getTimestamp(TimeUnit.NANOSECONDS)) {
        return -1;
    }
    if (this.expiryTime.getTimestamp(TimeUnit.NANOSECONDS) > ((ExpirableKeyColumn) o).expiryTime.getTimestamp(TimeUnit.NANOSECONDS)) {
        return 1;
    }
    return 0;
}
 
Example #13
Source File: ReadOnlyZKClient.java    From hbase with 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 #14
Source File: MqttSession.java    From spring-boot-protocol with 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 #15
Source File: UGICache.java    From pxf with 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 #16
Source File: LocalDataCenterEndPointProvider.java    From emodb with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Delayed o) {
    if (o == this || ((DelayedInvalidationCheck) o)._executeAtMs == _executeAtMs) {
        return 0;
    }
    return _executeAtMs < ((DelayedInvalidationCheck) o)._executeAtMs ? -1 : 1;
}
 
Example #17
Source File: Cpt8_TimeoutManager.java    From Zebra with MIT License 5 votes vote down vote up
/**
    * 对比方法,按照从大到小的顺序
    * 在offer的时候只调用compareTo方法
    */
@Override
public int compareTo(Delayed o) {
	Session dt=(Session)o;
	System.out.println("compareTo()方法被调用....id:"+id+"\t currentTime:"+System.currentTimeMillis());
	return (this.triger.get()>dt.triger.get()?1:(this.triger.get()<dt.triger.get()?-1:0));
}
 
Example #18
Source File: TaskRunner.java    From big-c with 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);
}
 
Example #19
Source File: DelayedResponseTest.java    From vespa with Apache License 2.0 5 votes vote down vote up
@Test
public void basic() {
    ConfigTester tester = new ConfigTester();
    final long returnTime = System.currentTimeMillis();
    final long timeout = 1;
    final String configName = "foo";
    final JRTServerConfigRequest request = tester.createRequest(configName, configId, namespace, timeout);
    DelayedResponse delayedResponse = new DelayedResponse(request, returnTime);
    assertThat(delayedResponse.getRequest(), is(request));
    assertThat(delayedResponse.getReturnTime(), is(returnTime));
    assertTrue(delayedResponse.getDelay(TimeUnit.SECONDS) < returnTime);

    DelayedResponse before = new DelayedResponse(request, returnTime - 1000L);
    DelayedResponse after = new DelayedResponse(request, returnTime + 1000L);

    assertThat(delayedResponse.compareTo(delayedResponse), is(0));
    assertThat(delayedResponse.compareTo(before), is(1));
    assertThat(delayedResponse.compareTo(after), is(-1));
    assertThat(delayedResponse.compareTo(new Delayed() {
        @Override
        public long getDelay(TimeUnit unit) {
            return 0;
        }

        @Override
        public int compareTo(Delayed o) {
            return 0;
        }
    }), is(0));
}
 
Example #20
Source File: TimerManagerTaskScheduler.java    From lams with GNU General Public License v2.0 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 #21
Source File: TaskRunner.java    From hadoop with 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);
}
 
Example #22
Source File: ReschedulingRunnable.java    From spring4-understanding with Apache License 2.0 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 #23
Source File: NoOpScheduledExecutor.java    From pravega with 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 #24
Source File: DelayItem.java    From DBus with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Delayed o) {
    int ret = 0;
    DelayItem target = (DelayItem) o;
    if (this.trigger - target.trigger > 0) {
        ret = 1;
    } else if (this.trigger - target.trigger < 0) {
        ret = -1;
    }
    return ret;
}
 
Example #25
Source File: ActivityQueue.java    From exhibitor with 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 #26
Source File: TestScheduledFuture.java    From fresco with 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 #27
Source File: InMemoryTokenStore.java    From MaxKey with 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 #28
Source File: TimerTaskList.java    From joyqueue with 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 #29
Source File: Proxy.java    From ProxyPool with 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 #30
Source File: ContainerSimulator.java    From big-c with 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);
}