001: /**
002: * Sequoia: Database clustering technology.
003: * Copyright (C) 2005 AmicoSoft, Inc. dba Emic Networks
004: * Contact: sequoia@continuent.org
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * Initial developer(s): Emmanuel Cecchet.
019: * Contributor(s): ______________________.
020: */package org.continuent.sequoia.controller.loadbalancer;
021:
022: import java.util.LinkedList;
023:
024: import org.continuent.sequoia.controller.loadbalancer.tasks.AbstractTask;
025:
026: /**
027: * This class defines a BackendTaskQueueEntry that is an element of a queue in
028: * BackendTaskQueues.
029: *
030: * @see org.continuent.sequoia.controller.loadbalancer.BackendTaskQueues
031: * @author <a href="mailto:emmanuel.cecchet@emicnetworks.com">Emmanuel Cecchet</a>
032: * @version 1.0
033: */
034: public class BackendTaskQueueEntry {
035: AbstractTask task;
036: private LinkedList queue;
037: BackendWorkerThread processingThread;
038: private boolean isACommitOrRollback;
039: private long timestamp;
040:
041: /**
042: * Creates a new <code>BackendTaskQueueEntry</code> object
043: *
044: * @param task the task to put in the entry
045: * @param queue the queue in which the task has been posted
046: * @param isACommitOrRollback true if the task is a commit or a rollback
047: */
048: public BackendTaskQueueEntry(AbstractTask task, LinkedList queue,
049: boolean isACommitOrRollback) {
050: this .task = task;
051: this .queue = queue;
052: this .processingThread = null;
053: this .isACommitOrRollback = isACommitOrRollback;
054: this .timestamp = System.currentTimeMillis();
055: }
056:
057: /**
058: * Returns the processingThread value (null if no BackendWorkerThread is
059: * currently processing the task).
060: *
061: * @return Returns the processingThread.
062: */
063: public final BackendWorkerThread getProcessingThread() {
064: return processingThread;
065: }
066:
067: /**
068: * Returns the isACommitOrRollback value.
069: *
070: * @return Returns the isACommitOrRollback.
071: */
072: public final boolean isACommitOrRollback() {
073: return isACommitOrRollback;
074: }
075:
076: /**
077: * Sets the processingThread value.
078: *
079: * @param processingThread The processingThread to set.
080: */
081: public final void setProcessingThread(
082: BackendWorkerThread processingThread) {
083: this .processingThread = processingThread;
084: }
085:
086: /**
087: * Returns the queue in which the task has been posted.
088: *
089: * @return Returns the queue holding the query.
090: */
091: public final LinkedList getQueue() {
092: return queue;
093: }
094:
095: /**
096: * Returns the task value.
097: *
098: * @return Returns the task.
099: */
100: public final AbstractTask getTask() {
101: return task;
102: }
103:
104: /**
105: * Sets the queue value.
106: *
107: * @param queue The queue to set.
108: */
109: public void setQueue(LinkedList queue) {
110: this .queue = queue;
111: }
112:
113: /**
114: * <strong>for debug purpose only</strong>
115: * @see java.lang.Object#toString()
116: */
117: public String toString() {
118: long timeInSeconds = (System.currentTimeMillis() - timestamp) / 1000;
119: return getTask().toString() + " (" + timeInSeconds + ")";
120: }
121: }
|