Package co.paralleluniverse.strands
Class StrandFactoryBuilder
- java.lang.Object
-
- co.paralleluniverse.strands.StrandFactoryBuilder
-
public class StrandFactoryBuilder extends java.lang.ObjectEasily createsStrandFactorys. You can construct a new instance of this builder and use the builder pattern (call the setter methods followed bybuild()) to create a newStrandFactory, or use one of the staticfrommethods to convert aThreadFactoryorFiberFactoryinto aStrandFactory. When using the builder pattern, eithersetFiberorsetThreadmust be called prior to callingbuild().
-
-
Constructor Summary
Constructors Constructor Description StrandFactoryBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StrandFactorybuild()Creates and returns theStrandFactorythat will create new strands based on this builder's settings.static StrandFactoryfrom(FiberFactory ff)Converts aFiberFactoryinto aStrandFactory.static StrandFactoryfrom(java.util.concurrent.ThreadFactory tf)Converts aThreadFactoryinto aStrandFactory.StrandFactoryBuildersetFiber(FiberScheduler fs)Makes the resultingStrandFactoryproduce fibers.StrandFactoryBuildersetNameFormat(java.lang.String nameFormat)Sets the naming format to use when naming strands (Strand.setName(java.lang.String)) which are created with this StrandFactory.StrandFactoryBuildersetPriority(int priority)Sets the priority for strands created by theStrandFactory.StrandFactoryBuildersetStackSize(int stackSize)Suggests a stack size of strands created by the resulting StrandFactory.StrandFactoryBuildersetThread(boolean daemon)Makes the resultingStrandFactoryproduce threads.StrandFactoryBuildersetUncaughtExceptionHandler(Strand.UncaughtExceptionHandler ueh)Sets theStrand.UncaughtExceptionHandlerfor new threads created with this ThreadFactory.
-
-
-
Method Detail
-
from
public static StrandFactory from(java.util.concurrent.ThreadFactory tf)
Converts aThreadFactoryinto aStrandFactory.
-
from
public static StrandFactory from(FiberFactory ff)
Converts aFiberFactoryinto aStrandFactory.
-
setThread
public StrandFactoryBuilder setThread(boolean daemon)
Makes the resultingStrandFactoryproduce threads.- Parameters:
daemon- whether or not the new threads are daemon threads.- Returns:
this
-
setFiber
public StrandFactoryBuilder setFiber(FiberScheduler fs)
Makes the resultingStrandFactoryproduce fibers.- Parameters:
fs- theFiberSchedulerto use for the new fibers, ornullfor the default scheduler.- Returns:
this
-
setNameFormat
public StrandFactoryBuilder setNameFormat(java.lang.String nameFormat)
Sets the naming format to use when naming strands (Strand.setName(java.lang.String)) which are created with this StrandFactory.- Parameters:
nameFormat- aString.format(String, Object...)-compatible format String, to which a unique integer (0, 1, etc.) will be supplied as the single parameter. This integer will be unique to the built instance of the StrandFactory and will be assigned sequentially. For example,"rpc-pool-%d"will generate strand names like"rpc-pool-0","rpc-pool-1","rpc-pool-2", etc.- Returns:
this
-
setStackSize
public StrandFactoryBuilder setStackSize(int stackSize)
Suggests a stack size of strands created by the resulting StrandFactory. The stack size used might be an approximation of the given value, or even ignore the passed value completely.- Parameters:
stackSize- the stack size, in bytes- Returns:
this
-
setPriority
public StrandFactoryBuilder setPriority(int priority)
Sets the priority for strands created by theStrandFactory. Priority currently applies only to thread, and even then the JVM and the OS are free to ignore it.- Parameters:
priority- the priority- Returns:
this
-
setUncaughtExceptionHandler
public StrandFactoryBuilder setUncaughtExceptionHandler(Strand.UncaughtExceptionHandler ueh)
Sets theStrand.UncaughtExceptionHandlerfor new threads created with this ThreadFactory.- Parameters:
ueh- the uncaught exception handler- Returns:
this
-
build
public StrandFactory build()
Creates and returns theStrandFactorythat will create new strands based on this builder's settings.- Returns:
- a new
StrandFactory.
-
-