提交 95043db7 编写于 作者: S Stephen Connolly

Merge pull request #1991 from andresrc/JENKINS-32517

[JENKINS-32517] Deprecate Queue#getApproximateItemsQuickly
......@@ -171,13 +171,6 @@ import org.kohsuke.stapler.interceptor.RequirePOST;
@ExportedBean
public class Queue extends ResourceController implements Saveable {
/**
* Defines the refresh period for of the internal cache ({@link #itemsView}).
* Data should be defined in milliseconds, default value - 1000;
* @since 1.577
*/
private static int CACHE_REFRESH_PERIOD = Integer.getInteger(Queue.class.getName() + ".cacheRefreshPeriod", 1000);
/**
* Items that are waiting for its quiet period to pass.
*
......@@ -218,41 +211,6 @@ public class Queue extends ResourceController implements Saveable {
*/
private final Cache<Long,LeftItem> leftItems = CacheBuilder.newBuilder().expireAfterWrite(5*60, TimeUnit.SECONDS).build();
private final CachedItemList itemsView = new CachedItemList();
/**
* Maintains a copy of {@link Queue#getItems()}
*
* @see Queue#getApproximateItemsQuickly()
*/
private class CachedItemList {
/**
* The current cached value.
*/
@CopyOnWrite
private volatile List<Item> itemsView = Collections.emptyList();
/**
* When does the cache info expire?
*/
private final AtomicLong expires = new AtomicLong();
List<Item> get() {
long t = System.currentTimeMillis();
long d = expires.get();
if (t>d) {// need to refresh the cache
long next = t+CACHE_REFRESH_PERIOD;
if (expires.compareAndSet(d,next)) {
// avoid concurrent cache update via CAS.
// if the getItems() lock is contended,
// some threads will end up serving stale data,
// but that's OK.
itemsView = ImmutableList.copyOf(getItems());
}
}
return itemsView;
}
}
/**
* Data structure created for each idle {@link Executor}.
* This is a job offer from the queue to an executor.
......@@ -864,9 +822,11 @@ public class Queue extends ResourceController implements Saveable {
* This method is primarily added to make UI threads run faster.
*
* @since 1.483
* @deprecated Use {@link #getItems()} directly. As of 1.607 the approximation is no longer needed.
*/
@Deprecated
public List<Item> getApproximateItemsQuickly() {
return itemsView.get();
return Arrays.asList(getItems());
}
public Item getItem(long id) {
......
......@@ -480,6 +480,11 @@ public abstract class View extends AbstractModelObject implements AccessControll
return filterQueue(Arrays.asList(Jenkins.getInstance().getQueue().getItems()));
}
/**
* @deprecated Use {@link #getQueueItems()}. As of 1.607 the approximation is no longer needed.
* @return The items in the queue.
*/
@Deprecated
public List<Queue.Item> getApproximateQueueItemsQuickly() {
return filterQueue(Jenkins.getInstance().getQueue().getApproximateItemsQuickly());
}
......
......@@ -63,7 +63,7 @@ public class BuildHistoryWidget<T> extends HistoryWidget<Task,T> {
*/
public List<Item> getQueuedItems() {
LinkedList<Item> list = new LinkedList<Item>();
for (Item item : Jenkins.getInstance().getQueue().getApproximateItemsQuickly()) {
for (Item item : Jenkins.getInstance().getQueue().getItems()) {
if (item.task == owner) {
list.addFirst(item);
}
......
......@@ -36,7 +36,7 @@ THE SOFTWARE.
<l:task href="new" icon="icon-new-computer icon-md" permission="${createPermission}" title="${%New Node}"/>
<l:task href="configure" icon="icon-setting icon-md" permission="${app.ADMINISTER}" title="${%Configure}"/>
</l:tasks>
<t:queue items="${app.queue.approximateItemsQuickly}" />
<t:queue items="${app.queue.items}" />
<t:executors />
</l:side-panel>
</j:jelly>
\ No newline at end of file
......@@ -28,6 +28,6 @@ THE SOFTWARE.
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:s="/lib/form">
<l:ajax>
<t:queue items="${it.approximateQueueItemsQuickly}" filtered="${it.isFilterQueue()}" />
<t:queue items="${it.queueItems}" filtered="${it.isFilterQueue()}" />
</l:ajax>
</j:jelly>
\ No newline at end of file
......@@ -2,4 +2,4 @@ package jenkins.widgets.BuildQueueWidget;
def t = namespace(lib.JenkinsTagLib.class)
t.queue(items:view.approximateQueueItemsQuickly, it:view, filtered:view.filterQueue)
t.queue(items:view.queueItems, it:view, filtered:view.filterQueue)
......@@ -28,7 +28,7 @@ THE SOFTWARE.
Displays the build queue as &lt;l:pane>
<st:attribute name="items" use="required">
Queue items to be displayed. Normally you should specify ${app.queue.approximateItemsQuickly},
Queue items to be displayed. Normally you should specify ${app.queue.items},
but for example you can specify a sublist after some filtering to narrow down
the list.
</st:attribute>
......
......@@ -404,7 +404,7 @@ public class QueueTest {
try {
build = m.scheduleBuild2(0).get(60, TimeUnit.SECONDS);
} catch (TimeoutException x) {
throw (AssertionError) new AssertionError(r.jenkins.getQueue().getApproximateItemsQuickly().toString()).initCause(x);
throw (AssertionError) new AssertionError(r.jenkins.getQueue().getItems().toString()).initCause(x);
}
r.assertBuildStatusSuccess(build);
assertEquals("", build.getBuiltOnStr());
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册