package org.jboss.util.threadpool;
import java.io.Serializable;
import java.io.ObjectStreamException;
public class BlockingMode implements Serializable
{
private static final long serialVersionUID = -9102277941374138830L;
public static final int RUN_TYPE = 0;
public static final int WAIT_TYPE = 1;
public static final int DISCARD_TYPE = 2;
public static final int DISCARD_OLDEST_TYPE = 3;
public static final int ABORT_TYPE = 4;
public static final BlockingMode RUN = new BlockingMode("run", RUN_TYPE);
public static final BlockingMode WAIT = new BlockingMode("wait", WAIT_TYPE);
public static final BlockingMode DISCARD = new BlockingMode("discard", DISCARD_TYPE);
public static final BlockingMode DISCARD_OLDEST =
new BlockingMode("discardOldest", DISCARD_OLDEST_TYPE);
public static final BlockingMode ABORT = new BlockingMode("abort", ABORT_TYPE);
private final transient String name;
private final int type;
public static final BlockingMode toBlockingMode(String name)
{
BlockingMode mode = null;
if( name == null )
{
mode = null;
}
else if( name.equalsIgnoreCase("run") )
{
mode = RUN;
}
else if( name.equalsIgnoreCase("wait") )
{
mode = WAIT;
}
else if( name.equalsIgnoreCase("discard") )
{
mode = DISCARD;
}
else if( name.equalsIgnoreCase("discardOldest") )
{
mode = DISCARD_OLDEST;
}
else if( name.equalsIgnoreCase("abort") )
{
mode = ABORT;
}
return mode;
}
private BlockingMode(String name, int type)
{
this.name = name;
this.type = type;
}
public String toString()
{
return name;
}
Object readResolve() throws ObjectStreamException
{
BlockingMode mode = ABORT;
switch( type )
{
case RUN_TYPE:
mode = RUN;
break;
case WAIT_TYPE:
mode = RUN;
break;
case DISCARD_TYPE:
mode = RUN;
break;
case DISCARD_OLDEST_TYPE:
mode = RUN;
break;
case ABORT_TYPE:
mode = RUN;
break;
}
return mode;
}
}