Package com.blackrook.rookscript
Class ScriptInstanceFactory
java.lang.Object
com.blackrook.rookscript.ScriptInstanceFactory
Factory class for assembling script instances.
This factory pools
ScriptInstanceStack
s, since creating and destroying them could be costly on the GC.- Author:
- Matthew Tropiano
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
-
Constructor Summary
ConstructorDescriptionScriptInstanceFactory
(Script script, int activationDepth, int stackDepth, ScriptEnvironment environment) Creates a new instance factory.ScriptInstanceFactory
(Script script, int activationDepth, int stackDepth, ScriptEnvironment environment, int runawayLimit) Creates a new instance factory.ScriptInstanceFactory
(Script script, int activationDepth, int stackDepth, ScriptWaitHandler waitHandler, ScriptEnvironment environment) Creates a new instance factory.ScriptInstanceFactory
(Script script, int activationDepth, int stackDepth, ScriptWaitHandler waitHandler, ScriptEnvironment environment, int runawayLimit) Creates a new instance factory.ScriptInstanceFactory
(Script script, ScriptEnvironment environment) Creates a new instance factory, default depths. -
Method Summary
Modifier and TypeMethodDescriptioncreate()
Creates a new instance.create
(ScriptEnvironment environment) Creates a new instance.int
Gets how many stacks were created but not in use.void
release
(ScriptInstance instance) Destroys an instance and releases pooled objects.
-
Field Details
-
DEFAULT_ACTIVATION_DEPTH
public static final int DEFAULT_ACTIVATION_DEPTH- See Also:
-
DEFAULT_STACK_DEPTH
public static final int DEFAULT_STACK_DEPTH- See Also:
-
DEFAULT_RUNAWAY_LIMIT
public static final int DEFAULT_RUNAWAY_LIMIT- See Also:
-
-
Constructor Details
-
ScriptInstanceFactory
Creates a new instance factory, default depths.- Parameters:
script
- the script to use for each instance.environment
- the script environment to use for each instance.- See Also:
-
ScriptInstanceFactory
public ScriptInstanceFactory(Script script, int activationDepth, int stackDepth, ScriptEnvironment environment) Creates a new instance factory.- Parameters:
script
- the script to use for each instance.activationDepth
- the activation stack depth for new instances.stackDepth
- the value stack depth for new instances.environment
- the script environment to use for each instance.
-
ScriptInstanceFactory
public ScriptInstanceFactory(Script script, int activationDepth, int stackDepth, ScriptEnvironment environment, int runawayLimit) Creates a new instance factory.- Parameters:
script
- the script to use for each instance.activationDepth
- the activation stack depth for new instances.stackDepth
- the value stack depth for new instances.environment
- the script environment to use for each instance.runawayLimit
- the amount of commands to run before the endless loop protection triggers.
-
ScriptInstanceFactory
public ScriptInstanceFactory(Script script, int activationDepth, int stackDepth, ScriptWaitHandler waitHandler, ScriptEnvironment environment) Creates a new instance factory.- Parameters:
script
- the script to use for each instance.activationDepth
- the activation stack depth for new instances.stackDepth
- the value stack depth for new instances.waitHandler
- the wait handler to use for each instance.environment
- the script environment to use for each instance.
-
ScriptInstanceFactory
public ScriptInstanceFactory(Script script, int activationDepth, int stackDepth, ScriptWaitHandler waitHandler, ScriptEnvironment environment, int runawayLimit) Creates a new instance factory.- Parameters:
script
- the script to use for each instance.activationDepth
- the activation stack depth for new instances.stackDepth
- the value stack depth for new instances.waitHandler
- the wait handler to use for each instance.environment
- the script environment to use for each instance.runawayLimit
- the amount of commands to run before the endless loop protection triggers.
-
-
Method Details
-
create
Creates a new instance.- Returns:
- a new instance with all of the associated resolvers and handlers attached to it.
-
create
Creates a new instance.- Parameters:
environment
- the script environment override.- Returns:
- a new instance with all of the associated resolvers and handlers attached to it.
-
release
Destroys an instance and releases pooled objects.- Parameters:
instance
- the script instance.
-
getFreeStackCount
public int getFreeStackCount()Gets how many stacks were created but not in use.- Returns:
- the amount of created stacks.
-