Java Code Examples for java.util.concurrent.Delayed#getDelay()

The following examples show how to use java.util.concurrent.Delayed#getDelay() . 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: MicroDelayItem.java    From nh-micro with Apache License 2.0 6 votes vote down vote up
public int compareTo(Delayed other) {
    if (other == this) // compare zero ONLY if same object
        return 0;
    if (other instanceof MicroDelayItem) {
    	MicroDelayItem x = (MicroDelayItem) other;
        long diff = time - x.time;
        if (diff < 0)
            return -1;
        else if (diff > 0)
            return 1;
        else if (sequenceNumber < x.sequenceNumber)
            return -1;
        else
            return 1;
    }
    long d = (getDelay(TimeUnit.NANOSECONDS) - other.getDelay(TimeUnit.NANOSECONDS));
    return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
}
 
Example 2
Source File: QueuedAudit.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public int compareTo( Delayed delayed )
{
    if ( delayed == this )
    {
        return 0;
    }

    if ( delayed instanceof QueuedAudit )
    {
        long diff = delay - ((QueuedAudit) delayed).delay;
        return ((diff == 0) ? 0 : ((diff < 0) ? -1 : 1));
    }

    long d = (getDelay( TimeUnit.MILLISECONDS ) - delayed.getDelay( TimeUnit.MILLISECONDS ));

    return ((d == 0) ? 0 : ((d < 0) ? -1 : 1));
}
 
Example 3
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 4
Source File: SQSScheduledExecutorService.java    From amazon-sqs-java-temporary-queues-client with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(Delayed other) {
    if (other == this) { // compare zero if same object
        return 0;
    }
    if (other instanceof ScheduledSQSFutureTask) {
        ScheduledSQSFutureTask<?> x = (ScheduledSQSFutureTask<?>)other;
        long diff = time - x.time;
        if (diff < 0) {
            return -1;
        } else if (diff > 0) {
            return 1;
        } else {
            return 0;
        }
    }
    long d = getDelay(TimeUnit.NANOSECONDS) -
            other.getDelay(TimeUnit.NANOSECONDS);
    return (d == 0) ? 0 : ((d < 0) ? -1 : 1);
}
 
Example 5
Source File: GridmixJob.java    From RDFS 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 6
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 7
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 8
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 9
Source File: ScheduledMessageImpl.java    From elasticactors with Apache License 2.0 6 votes vote down vote up
@Override
public int compareTo(Delayed other) {
    if (other == this)
        return 0;
    long d = (getDelay(TimeUnit.MILLISECONDS) -
            other.getDelay(TimeUnit.MILLISECONDS));
    if(d != 0) {
        return (d < 0) ? -1 : 1;
    } else {
        // use the ordering of the id as well in case the other Delayed is a ScheduledMessage as well
        if(other instanceof ScheduledMessage) {
            return getId().compareTo(((ScheduledMessage)other).getId());
        } else {
            return 0;
        }
    }
}
 
Example 10
Source File: DelayedSession.java    From litchi with 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 11
Source File: ReschedulingRunnable.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 12
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 13
Source File: ReschedulingRunnable.java    From java-technology-stack with 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 14
Source File: LeaseManager.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Delayed o) {
  long delta = this.getDelay(TimeUnit.MILLISECONDS) -
    o.getDelay(TimeUnit.MILLISECONDS);

  return this.equals(o) ? 0 : (delta > 0 ? 1 : -1);
}
 
Example 15
Source File: RequestProcessor.java    From netbeans with Apache License 2.0 5 votes vote down vote up
@Override
public int compareTo(Delayed o) {
    long other = o.getDelay(TimeUnit.MILLISECONDS);
    long ours = getDelay(TimeUnit.MILLISECONDS);
    //Might overflow on, say, ms compared to Long.MAX_VALUE, TimeUnit.DAYS
    return (int) (ours - other);
}
 
Example 16
Source File: ActorSystemScheduledExecutorAdapter.java    From Flink-CEPplus with 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 17
Source File: TimerManagerTaskScheduler.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 18
Source File: RefCountedClient.java    From exhibitor with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(Delayed o)
{
    long            diff = getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS);
    return (diff < 0) ? -1 : ((diff > 0) ? 1 : 0);
}
 
Example 19
Source File: ConstantDelayQueue.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Override
public int compareTo(Delayed o) {
  long cmp = getDelay(TimeUnit.MILLISECONDS) - o.getDelay(TimeUnit.MILLISECONDS);
  return cmp == 0 ? 0 : ( cmp < 0 ? -1 : 1);
}
 
Example 20
Source File: PingKeepalive.java    From sissi with Apache License 2.0 4 votes vote down vote up
public int compareTo(Delayed o) {
	return o.getDelay(TimeUnit.MILLISECONDS) >= this.getDelay(TimeUnit.MILLISECONDS) ? 1 : -1;
}