Class DefaultContext
- All Implemented Interfaces:
ArrayMemoryContext
,ArrayThreadPoolContext
,Context
,InterruptionContext
,ProgressUpdater
,StatusUpdater
An adapter class containing the simplest ("empty") implementations of the following standard contexts:
InterruptionContext
, ArrayMemoryContext
, ArrayThreadPoolContext
,
ProgressUpdater
, StatusUpdater
.
See comments to the methods of this class to clarify behavior of this implementation.
This class is an inheritor of AbstractContext
,
and all its constructors calls the superconstructor
with the argument useServiceLoader=true.
So, this class can serve requests not only for the standard context listed above,
but also for any other contexts, that are specified in
service providers
for Context
interface.
This class is a good possible superclass for implementation custom behavior of the contexts or for overriding the behavior of an existing context, specified as a service provider.
- Author:
- Daniel Alievsky
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.algart.contexts.InterruptionContext
InterruptionContext.Event, InterruptionContext.Listener
-
Field Summary
Fields inherited from class net.algart.contexts.AbstractContext
useServiceLoader
-
Constructor Summary
ModifierConstructorDescriptionprotected
This constructor prevents direct instantiation of this class.DefaultContext
(MemoryModel memoryModel) Creates an instance of this context with the specified memory model, which will be returned bygetMemoryModel()
method. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This implementation does nothing.void
This implementation does nothing.static DefaultContext
Returns an instance of this class, created by "newDefaultContext
(){}" call.This implementation returns the memory model, specified by the argument of thecorresponding constructor
, orArrays.SystemSettings.globalMemoryModel()
if theconstructor without arguments
was used.getMemoryModel
(Class<?> elementType) This implementation returns mm.isElementTypeSupported
(elementType) ? mm :SimpleMemoryModel.getInstance()
, where mm is the result ofgetMemoryModel()
method.getMemoryModel
(String settings) This implementation callsgetMemoryModel()
and returns its result.This implementation returns an instance ofDefaultThreadPoolFactory
.void
This implementation does nothing.void
updateProgress
(double readyPart, boolean force) This implementation callsupdateStatus(String, boolean)
with the first argument alike Math.round(readyPart*100)+"%" and the second argument force.void
updateStatus
(String message) This implementation callsupdateStatus(message, true)
.void
updateStatus
(String message, boolean force) This implementation does nothing.Methods inherited from class net.algart.contexts.AbstractContext
as, is
-
Constructor Details
-
DefaultContext
protected DefaultContext()This constructor prevents direct instantiation of this class. Please usegetInstance()
method instead. -
DefaultContext
Creates an instance of this context with the specified memory model, which will be returned bygetMemoryModel()
method.- Parameters:
memoryModel
- desired memory model.
-
-
Method Details
-
getInstance
Returns an instance of this class, created by "newDefaultContext
(){}" call. This instance can be used as a simplest default implementation of most standard contexts, offered by this package:InterruptionContext
,ArrayMemoryContext
,ArrayThreadPoolContext
,StatusUpdater
,ProgressUpdater
. This implementation does not allow interrupt modules, provides the defaultglobal memory model
, thedefault thread pool factory
and does nothing while attempts to show the status line or execution progress.The result of this method is probably a singleton: all calls of this method may return the same instance.
- Returns:
- the default instance of this class.
-
checkInterruption
public void checkInterruption()This implementation does nothing. So, this context does not allow to interrupt long-working algorithms.The simplest possible implementation of this method in your subclass, allowing to interrupt algorithsm, may be the following:
if (Thread.interrupted()) throw new
InterruptionException
();- Specified by:
checkInterruption
in interfaceInterruptionContext
-
addInterruptionListener
This implementation does nothing.- Specified by:
addInterruptionListener
in interfaceInterruptionContext
- Parameters:
listener
- is ignored.
-
removeInterruptionListener
This implementation does nothing.- Specified by:
removeInterruptionListener
in interfaceInterruptionContext
- Parameters:
listener
- is ignored.
-
getMemoryModel
This implementation returns the memory model, specified by the argument of thecorresponding constructor
, orArrays.SystemSettings.globalMemoryModel()
if theconstructor without arguments
was used.- Specified by:
getMemoryModel
in interfaceArrayMemoryContext
- Returns:
- the desired memory model.
-
getMemoryModel
This implementation returns mm.isElementTypeSupported
(elementType) ? mm :SimpleMemoryModel.getInstance()
, where mm is the result ofgetMemoryModel()
method.- Specified by:
getMemoryModel
in interfaceArrayMemoryContext
- Parameters:
elementType
- the required element type.- Returns:
- the desired memory model.
-
getMemoryModel
This implementation callsgetMemoryModel()
and returns its result.- Specified by:
getMemoryModel
in interfaceArrayMemoryContext
- Parameters:
settings
- additional desires about the required memory model.- Returns:
- the desired memory model.
- Throws:
NullPointerException
- if the argument is null.
-
getThreadPoolFactory
This implementation returns an instance ofDefaultThreadPoolFactory
.- Specified by:
getThreadPoolFactory
in interfaceArrayThreadPoolContext
- Returns:
- the desired thread tool factory.
-
updateProgress
public void updateProgress(double readyPart, boolean force) This implementation callsupdateStatus(String, boolean)
with the first argument alike Math.round(readyPart*100)+"%" and the second argument force.- Specified by:
updateProgress
in interfaceProgressUpdater
- Parameters:
readyPart
- the part of calculations that is already done (from 0.0 to 1.0).force
- whether this information must be shown always (true) or may be lost (false).
-
updateStatus
This implementation callsupdateStatus(message, true)
.- Specified by:
updateStatus
in interfaceStatusUpdater
- Parameters:
message
- some information message.
-
updateStatus
This implementation does nothing.- Specified by:
updateStatus
in interfaceStatusUpdater
- Parameters:
message
- some information message.force
- whether this information must be shown always (true) or may be lost (false).
-