1 22 package org.jboss.util.threadpool; 23 24 import java.io.Serializable ; 25 import java.io.ObjectStreamException ; 26 27 32 public class BlockingMode implements Serializable 33 { 34 35 private static final long serialVersionUID = -9102277941374138830L; 36 37 public static final int RUN_TYPE = 0; 38 public static final int WAIT_TYPE = 1; 39 public static final int DISCARD_TYPE = 2; 40 public static final int DISCARD_OLDEST_TYPE = 3; 41 public static final int ABORT_TYPE = 4; 42 43 46 public static final BlockingMode RUN = new BlockingMode("run", RUN_TYPE); 47 51 public static final BlockingMode WAIT = new BlockingMode("wait", WAIT_TYPE); 52 55 public static final BlockingMode DISCARD = new BlockingMode("discard", DISCARD_TYPE); 56 59 public static final BlockingMode DISCARD_OLDEST = 60 new BlockingMode("discardOldest", DISCARD_OLDEST_TYPE); 61 64 public static final BlockingMode ABORT = new BlockingMode("abort", ABORT_TYPE); 65 66 67 private final transient String name; 68 69 private final int type; 70 71 75 public static final BlockingMode toBlockingMode(String name) 76 { 77 BlockingMode mode = null; 78 if( name == null ) 79 { 80 mode = null; 81 } 82 else if( name.equalsIgnoreCase("run") ) 83 { 84 mode = RUN; 85 } 86 else if( name.equalsIgnoreCase("wait") ) 87 { 88 mode = WAIT; 89 } 90 else if( name.equalsIgnoreCase("discard") ) 91 { 92 mode = DISCARD; 93 } 94 else if( name.equalsIgnoreCase("discardOldest") ) 95 { 96 mode = DISCARD_OLDEST; 97 } 98 else if( name.equalsIgnoreCase("abort") ) 99 { 100 mode = ABORT; 101 } 102 return mode; 103 } 104 105 private BlockingMode(String name, int type) 106 { 107 this.name = name; 108 this.type = type; 109 } 110 111 public String toString() 112 { 113 return name; 114 } 115 116 124 Object readResolve() throws ObjectStreamException 125 { 126 BlockingMode mode = ABORT; 128 switch( type ) 129 { 130 case RUN_TYPE: 131 mode = RUN; 132 break; 133 case WAIT_TYPE: 134 mode = RUN; 135 break; 136 case DISCARD_TYPE: 137 mode = RUN; 138 break; 139 case DISCARD_OLDEST_TYPE: 140 mode = RUN; 141 break; 142 case ABORT_TYPE: 143 mode = RUN; 144 break; 145 } 146 return mode; 147 } 148 } 149 | Popular Tags |