本文整理了Java中org.eclipse.core.internal.jobs.Queue
类的一些代码示例,展示了Queue
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Queue
类的具体详情如下:
包路径:org.eclipse.core.internal.jobs.Queue
类名称:Queue
[英]A Queue of objects.
[中]一队物品。
代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.core.jobs
/**
* If there is another semaphore with the same runnable in the
* queue, the other is returned and the new one is not added.
*/
private synchronized Semaphore enqueue(Semaphore newSemaphore) {
Semaphore semaphore = (Semaphore) operations.get(newSemaphore);
if (semaphore == null) {
operations.enqueue(newSemaphore);
return newSemaphore;
}
return semaphore;
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.jobs
/**
* Adds an object to the tail of the queue.
*/
public void enqueue(Object element) {
int newTail = increment(tail);
if (newTail == head) {
grow();
newTail = tail + 1;
}
elements[tail] = element;
tail = newTail;
}
代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.core.jobs
/**
* Removes an returns the item at the head of the queue.
*/
public Object dequeue() {
if (isEmpty())
return null;
Object result = peek();
if (!reuse)
elements[head] = null;
head = increment(head);
return result;
}
代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.core.jobs
public Iterator elements() {
/**/
if (isEmpty())
return new ArrayList(0).iterator();
/* if head < tail we can use the same array */
if (head <= tail)
return Arrays.asList(elements).iterator();
/* otherwise we need to create a new array */
Object[] newElements = new Object[size()];
int end = (elements.length - head);
System.arraycopy(elements, head, newElements, 0, end);
System.arraycopy(elements, 0, newElements, end, tail);
return Arrays.asList(newElements).iterator();
}
代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.core.jobs
@Override
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("["); //$NON-NLS-1$
if (!isEmpty()) {
Iterator it = elements();
while (true) {
sb.append(it.next());
if (it.hasNext())
sb.append(", "); //$NON-NLS-1$
else
break;
}
}
sb.append("]"); //$NON-NLS-1$
return sb.toString();
}
}
代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.core.jobs
/**
* Removes the given object from the queue. Shifts the underlying array.
*/
public boolean remove(Object o) {
int index = head;
//find the object to remove
while (index != tail) {
if (elements[index].equals(o))
break;
index = increment(index);
}
//if element wasn't found, return
if (index == tail)
return false;
//store a reference to it (needed for reuse of objects)
Object toRemove = elements[index];
int nextIndex = -1;
while (index != tail) {
nextIndex = increment(index);
if (nextIndex != tail)
elements[index] = elements[nextIndex];
index = nextIndex;
}
//decrement tail
tail = decrement(tail);
//if objects are reused, transfer the reference that is removed to the end of the queue
//otherwise set the element after the last one to null (to avoid duplicate references)
elements[tail] = reuse ? toRemove : null;
return true;
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.jobs
public Object get(Object o) {
int index = head;
while (index != tail) {
if (elements[index].equals(o))
return elements[index];
index = increment(index);
}
return null;
}
代码示例来源:origin: org.eclipse/core-jobs
/**
* This lock has just been granted to a new thread (the thread waited for it).
* Remove the request from the queue and update both the graph and the lock.
*/
private synchronized void updateCurrentOperation() {
operations.dequeue();
setCurrentOperationThread(Thread.currentThread());
}
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.jobs
/**
* Removes a semaphore from the queue of waiting operations.
*
* @param semaphore The semaphore to remove
*/
private synchronized void removeFromQueue(Semaphore semaphore) {
operations.remove(semaphore);
}
代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.core.jobs
/**
* Releases this lock from the thread that used to own it.
* Grants this lock to the next thread in the queue.
*/
private synchronized void doRelease() {
//notify hook
manager.aboutToRelease();
depth = 0;
Semaphore next = (Semaphore) operations.peek();
setCurrentOperationThread(null);
if (next != null)
next.release();
}
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.core.jobs
/**
* Attempts to acquire the lock. Returns false if the lock is not available and
* true if the lock has been successfully acquired.
*/
private synchronized boolean attempt() {
//return true if we already own the lock
//also, if nobody is waiting, grant the lock immediately
if ((currentOperationThread == Thread.currentThread()) || (currentOperationThread == null && operations.isEmpty())) {
depth++;
setCurrentOperationThread(Thread.currentThread());
return true;
}
return false;
}
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.core.jobs
public Iterator elements() {
/**/
if (isEmpty())
return new ArrayList(0).iterator();
/* if head < tail we can use the same array */
if (head <= tail)
return Arrays.asList(elements).iterator();
/* otherwise we need to create a new array */
Object[] newElements = new Object[size()];
int end = (elements.length - head);
System.arraycopy(elements, head, newElements, 0, end);
System.arraycopy(elements, 0, newElements, end, tail);
return Arrays.asList(newElements).iterator();
}
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.core.jobs
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("["); //$NON-NLS-1$
if (!isEmpty()) {
Iterator it = elements();
while (true) {
sb.append(it.next());
if (it.hasNext())
sb.append(", "); //$NON-NLS-1$
else
break;
}
}
sb.append("]"); //$NON-NLS-1$
return sb.toString();
}
}
代码示例来源:origin: org.jibx.config.3rdparty.org.eclipse/org.eclipse.core.jobs
/**
* Removes the given object from the queue. Shifts the underlying array.
*/
public boolean remove(Object o) {
int index = head;
//find the object to remove
while (index != tail) {
if (elements[index].equals(o))
break;
index = increment(index);
}
//if element wasn't found, return
if (index == tail)
return false;
//store a reference to it (needed for reuse of objects)
Object toRemove = elements[index];
int nextIndex = -1;
while (index != tail) {
nextIndex = increment(index);
if (nextIndex != tail)
elements[index] = elements[nextIndex];
index = nextIndex;
}
//decrement tail
tail = decrement(tail);
//if objects are reused, transfer the reference that is removed to the end of the queue
//otherwise set the element after the last one to null (to avoid duplicate references)
elements[tail] = reuse ? toRemove : null;
return true;
}
代码示例来源:origin: org.eclipse/core-jobs
public Object get(Object o) {
int index = head;
while (index != tail) {
if (elements[index].equals(o))
return elements[index];
index = increment(index);
}
return null;
}
代码示例来源:origin: com.github.veithen.cosmos.bootstrap/org.eclipse.core.jobs
/**
* This lock has just been granted to a new thread (the thread waited for it).
* Remove the request from the queue and update both the graph and the lock.
*/
private synchronized void updateCurrentOperation() {
operations.dequeue();
setCurrentOperationThread(Thread.currentThread());
}
代码示例来源:origin: org.eclipse/core-jobs
/**
* Removes a semaphore from the queue of waiting operations.
*
* @param semaphore The semaphore to remove
*/
private synchronized void removeFromQueue(Semaphore semaphore) {
operations.remove(semaphore);
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.jobs
/**
* Releases this lock from the thread that used to own it.
* Grants this lock to the next thread in the queue.
*/
private synchronized void doRelease() {
//notify hook
manager.aboutToRelease();
depth = 0;
Semaphore next = (Semaphore) operations.peek();
setCurrentOperationThread(null);
if (next != null)
next.release();
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.jobs
/**
* Attempts to acquire the lock. Returns false if the lock is not available and
* true if the lock has been successfully acquired.
*/
private synchronized boolean attempt() {
//return true if we already own the lock
//also, if nobody is waiting, grant the lock immediately
if ((currentOperationThread == Thread.currentThread()) || (currentOperationThread == null && operations.isEmpty())) {
depth++;
setCurrentOperationThread(Thread.currentThread());
return true;
}
return false;
}
代码示例来源:origin: org.eclipse.scout.sdk.deps/org.eclipse.core.jobs
/**
* Removes an returns the item at the head of the queue.
*/
public Object dequeue() {
if (isEmpty())
return null;
Object result = peek();
if (!reuse)
elements[head] = null;
head = increment(head);
return result;
}
内容来源于网络,如有侵权,请联系作者删除!