001:/*
002: * The contents of this file are subject to the Sapient Public License
003: * Version 1.0 (the "License"); you may not use this file except in compliance
004: * with the License. You may obtain a copy of the License at
005: * http://carbon.sf.net/License.html.
006: *
007: * Software distributed under the License is distributed on an "AS IS" basis,
008: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
009: * the specific language governing rights and limitations under the License.
010: *
011: * The Original Code is The Carbon Component Framework.
012: *
013: * The Initial Developer of the Original Code is Sapient Corporation
014: *
015: * Copyright (C) 2003 Sapient Corporation. All Rights Reserved.
016: */
017:package org.sape.carbon.services.threadpool;
018:
019:import java.io.ObjectStreamException;
020:
021:import org.sape.carbon.core.util.enum.BaseEnum;
022:import org.sape.carbon.core.util.enum.EnumNotFoundException;
023:
024:/**
025: * This Class enumerates the different policies that can be used when the
026: * thread pool queue is full and a client attempts to queue a task.
027: *
028: * Copyright 2003 Sapient
029: * @since carbon 2.1
030: * @author Douglas Voet, Nov 17, 2003
031: * @version $Revision: 1.2 $($Author: dvoet $ / $Date: 2003/11/20 18:49:59 $)
032: */
033:public class QueueFullPolicyEnum extends BaseEnum {
034:
035: public static final int RUN_ORDINAL = 1;
036: /**
037: * Run signals that the ThreadPool should run the given task on client
038: * thread (i.e. the thread that called the execute method)
039: */
040: public static final QueueFullPolicyEnum RUN =
041: new QueueFullPolicyEnum("run", RUN_ORDINAL);
042:
043: public static final int WAIT_ORDINAL = 2;
044: /**
045: * Wait signals that the ThreadPool should block the client
046: * thread (i.e. the thread that called the execute method) until there is
047: * room on the queue. This option could potentially lead to lockups
048: */
049: public static final QueueFullPolicyEnum WAIT =
050: new QueueFullPolicyEnum("wait", WAIT_ORDINAL);
051:
052: public static final int ABORT_ORDINAL = 3;
053: /**
054: * Abort signals ThreadPool to throw a RuntimeException.
055: */
056: public static final QueueFullPolicyEnum ABORT =
057: new QueueFullPolicyEnum("abort", ABORT_ORDINAL);
058:
059: public static final int DISCARD_ORDINAL = 4;
060: /**
061: * Discard signals the ThreadPool to discard the current task.
062: */
063: public static final QueueFullPolicyEnum DISCARD =
064: new QueueFullPolicyEnum("discard", DISCARD_ORDINAL);
065:
066: public static final int DISCARD_OLDEST_ORDINAL = 5;
067: /**
068: * Discard-oldest signals the ThreadPool to discard the task at the head
069: * of the queue.
070: */
071: public static final QueueFullPolicyEnum DISCARD_OLDEST =
072: new QueueFullPolicyEnum("discard-oldest", DISCARD_OLDEST_ORDINAL);
073:
074: private QueueFullPolicyEnum(String name, int ordinal) {
075: super (QueueFullPolicyEnum.class, name, ordinal);
076: }
077:
078: /**
079: * Strongly typed enum retriever
080: */
081: public static final TaskStatusEnum getByName(String name)
082: throws QueueFullPolicyEnumNotFoundException {
083:
084: TaskStatusEnum status =
085: (TaskStatusEnum) BaseEnum.getByName(name, QueueFullPolicyEnum.class);
086:
087: if (status == null) {
088: throw new QueueFullPolicyEnumNotFoundException(
089: QueueFullPolicyEnum.class,
090: name);
091: }
092:
093: return status;
094: }
095:
096:
097: /**
098: * Strongly typed enum retriever
099: */
100: public static final TaskStatusEnum getByOrdinal(int ordinal)
101: throws QueueFullPolicyEnumNotFoundException {
102:
103: TaskStatusEnum status =
104: (TaskStatusEnum) BaseEnum.getByOrdinal(
105: ordinal,
106: QueueFullPolicyEnum.class);
107:
108: if (status == null) {
109: throw new QueueFullPolicyEnumNotFoundException(
110: QueueFullPolicyEnum.class,
111: new Integer(ordinal).toString());
112: }
113:
114: return status;
115: }
116:
117:
118: /**
119: * Overrides part of serialization to return a reference to an existing
120: * static Enumeration
121: */
122: final Object readResolve() throws ObjectStreamException {
123: return super .getByOrdinal(this .ordinal, this .getClass());
124: }
125:
126:
127: /**
128: * This class is a typesafe retriever exception for an enumeration
129: */
130: public static class QueueFullPolicyEnumNotFoundException
131: extends EnumNotFoundException {
132: /**
133: * Constructor for QueueFullPolicyEnumNotFoundException.
134: * @param sourceClass
135: * @param name
136: */
137: public QueueFullPolicyEnumNotFoundException(Class sourceClass, String name) {
138: super(sourceClass, name);
139: }
140: }
141:
142:}
|