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
ConstructorsModifierConstructorDescriptionprotectedThis 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 TypeMethodDescriptionvoidThis implementation does nothing.voidThis implementation does nothing.static DefaultContextReturns 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 argumentswas 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.voidThis implementation does nothing.voidupdateProgress(double readyPart, boolean force) This implementation callsupdateStatus(String, boolean)with the first argument alike Math.round(readyPart*100)+"%" and the second argument force.voidupdateStatus(String message) This implementation callsupdateStatus(message, true).voidupdateStatus(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 factoryand 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 newInterruptionException();- Specified by:
checkInterruptionin interfaceInterruptionContext
-
addInterruptionListener
This implementation does nothing.- Specified by:
addInterruptionListenerin interfaceInterruptionContext- Parameters:
listener- is ignored.
-
removeInterruptionListener
This implementation does nothing.- Specified by:
removeInterruptionListenerin 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 argumentswas used.- Specified by:
getMemoryModelin 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:
getMemoryModelin interfaceArrayMemoryContext- Parameters:
elementType- the required element type.- Returns:
- the desired memory model.
-
getMemoryModel
This implementation callsgetMemoryModel()and returns its result.- Specified by:
getMemoryModelin 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:
getThreadPoolFactoryin 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:
updateProgressin 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:
updateStatusin interfaceStatusUpdater- Parameters:
message- some information message.
-
updateStatus
This implementation does nothing.- Specified by:
updateStatusin interfaceStatusUpdater- Parameters:
message- some information message.force- whether this information must be shown always (true) or may be lost (false).
-