Package co.paralleluniverse.strands
Class StrandFactoryBuilder
- java.lang.Object
-
- co.paralleluniverse.strands.StrandFactoryBuilder
-
public class StrandFactoryBuilder extends java.lang.Object
Easily createsStrandFactory
s. 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 staticfrom
methods to convert aThreadFactory
orFiberFactory
into aStrandFactory
. When using the builder pattern, eithersetFiber
orsetThread
must 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 StrandFactory
build()
Creates and returns theStrandFactory
that will create new strands based on this builder's settings.static StrandFactory
from(FiberFactory ff)
Converts aFiberFactory
into aStrandFactory
.static StrandFactory
from(java.util.concurrent.ThreadFactory tf)
Converts aThreadFactory
into aStrandFactory
.StrandFactoryBuilder
setFiber(FiberScheduler fs)
Makes the resultingStrandFactory
produce fibers.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.StrandFactoryBuilder
setPriority(int priority)
Sets the priority for strands created by theStrandFactory
.StrandFactoryBuilder
setStackSize(int stackSize)
Suggests a stack size of strands created by the resulting StrandFactory.StrandFactoryBuilder
setThread(boolean daemon)
Makes the resultingStrandFactory
produce threads.StrandFactoryBuilder
setUncaughtExceptionHandler(Strand.UncaughtExceptionHandler ueh)
Sets theStrand.UncaughtExceptionHandler
for new threads created with this ThreadFactory.
-
-
-
Method Detail
-
from
public static StrandFactory from(java.util.concurrent.ThreadFactory tf)
Converts aThreadFactory
into aStrandFactory
.
-
from
public static StrandFactory from(FiberFactory ff)
Converts aFiberFactory
into aStrandFactory
.
-
setThread
public StrandFactoryBuilder setThread(boolean daemon)
Makes the resultingStrandFactory
produce threads.- Parameters:
daemon
- whether or not the new threads are daemon threads.- Returns:
this
-
setFiber
public StrandFactoryBuilder setFiber(FiberScheduler fs)
Makes the resultingStrandFactory
produce fibers.- Parameters:
fs
- theFiberScheduler
to use for the new fibers, ornull
for 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.UncaughtExceptionHandler
for new threads created with this ThreadFactory.- Parameters:
ueh
- the uncaught exception handler- Returns:
this
-
build
public StrandFactory build()
Creates and returns theStrandFactory
that will create new strands based on this builder's settings.- Returns:
- a new
StrandFactory
.
-
-