-
-
Notifications
You must be signed in to change notification settings - Fork 239
6.0 Extension and Controlling API Transition Guide
This is a guide for extension authors about how NetLogo internals have changed in NetLogo 6.0.
A number of classes have been renamed. The following is a list of top-level, public classes known to have changed. If your extension depended on inner classes or package-private classes, those will not be listed here.
-
api.CompilerException
->core.CompilerException
-
api.ErrorSource
->core.ErrorSource
-
api.File
->core.File
-
api.FileMode
->core.FileMode
-
api.I18N
->core.I18N
-
api.Instruction
->core.Instruction
-
api.Let
->core.Let
-
api.LogoList
->core.LogoList
-
api.Nobody
->core.Nobody
-
api.PlotPenInterface
->core.PlotPenInterface
(some changes) -
api.Primitive
->core.Primitive
-
api.Program
->core.Program
-
api.Shape
->core.Shape
-
api.ShapeList
->core.ShapeList
-
api.Task
->api.AnonymousProcedure
-
api.CommandTask
->api.AnonymousCommand
-
api.ReporterTask
->api.AnonymousReporter
-
api.Token
->core.Token
(several fields renamed as well) -
api.TokenType
->core.TokenType
-
api.TokenizerInterface
->core.TokenizerInterface
-
api.WorldDimensions
->core.WorldDimensions
(now immutable) -
compiler.Instantiator
->core.Instantiator
-
util.MersenneTwisterFast
->api.MersenneTwisterFast
-
util.Exceptions
->api.Exceptions
-
nvm.Workspace.UpdateMode
->core.UpdateMode
-
nvm.Workspace.OutputDestination
->api.OutputDestination
- More renames are likely to be listed in the future...
- Many swing classes are now generic
-
Thread.stop()
now errors
Java 3D is not supported in Java 8. We upgraded JOGL in the 5.3 series of releases and it is also updated here.
The primary difference is the package formerly known as javax.media.opengl
is now com.jogamp.opengl
.
More complex refactors will be needed in some cases involving scala due to the way scala handles static interface members.
Those cases can usually be resolved by changing the name of a class or interface from something like GL
to something like GL2
or GL2ES3
.
The following methods have been removed from api.ExtensionManager
:
-
getExtensionNames
- useloadedExtensions
instead. -
getJarPaths
- no longer needed now that applets are dead. -
getSource
- useworkspace.getSource
instead. -
getFile
- useworkspace.fileManager.getFile(workspace.attachModelDir)
instead. -
profilingEnabled
- check if the profiler extension is one of theloadedExtensions
instead. -
addToLibraryPath
- avoid using if possible, but if needed useorg.nlogo.api.JavaLibraryPath.setLibraryPath(classManager.getClass, directoryName)
. -
resolvePath
- usenew java.io.File(workspace.attachModelDir(path))
if needed. -
resolvePathAsURL
- this was most useful for applets. If you need a file, seeresolvePath
above, otherwise useworkspace.attachModelDir
ornew java.net.URL
.
In addition, ExtensionManager
has been split into core.ExtensionManager
and api.ExtensionManager
.
This split is purely for interface segregation and extension code should continue to use api.ExtensionManager
.
The representation of a NetLogo Program has changed dramatically.
The class representing a program is now located in the org.nlogo.core
package.
Users are advised to consult the source code for a more thorough look at the changes, but the following are some highlights:
-
scala.collection.Seq
is used for list representations instead ofjava.util.List
. -
Program
s now contain a "dialect", a container for miscellaneous information about the environment (3D vs 2D, Desktop vs Web). - The handling of breeds is quite different. Breeds are now represented as case classes (see
org.nlogo.core.Breed
) which are stored in a map by name. -
userGlobals
andinterfaceGlobals
are available as separate methods or combined in theglobals
method along with observer variables. - Since the breeds are no longer
AgentSet
s,AgentSet
s containing the agents within a breed should be retrieved from theWorld
.
The following table shows replacements:
5.x java | hexy java | 5.x scala | hexy scala |
---|---|---|---|
Class<? extends Agent> |
org.nlogo.core.AgentKind |
Class[_ <: Agent] |
org.nlogo.core.AgentKind |
Patch.class |
org.nlogo.core.AgentKindJ.Patch() |
classOf[Patch] |
org.nlogo.core.AgentKind.Patch |
Turtle.class |
org.nlogo.core.AgentKindJ.Turtle() |
classOf[Turtle] |
org.nlogo.core.AgentKind.Turtle |
Link.class |
org.nlogo.core.AgentKindJ.Link() |
classOf[Link] |
org.nlogo.core.AgentKind.Link |
Observer.class |
org.nlogo.core.AgentKindJ.Observer() |
classOf[Observer] |
org.nlogo.core.AgentKind.Observer |
<agent>.getClass() |
<agent>.kind() |
<agent>.getClass |
<agent>.kind |
<agentset>.type() |
<agentset>.kind() |
<agentset>.`type` |
<agentset>.kind |
Additionally, the following points are worth noticing:
-
AgentSet
s (and their builders) take anAgentKind
. -
Agent
has akind
method which returns the kind of that agent.
The following were formerly fields on nvm.Procedure
and are now methods:
topLevel
code
args
-
fileName
(available as an alias forfilename
) name
displayName
localsCount
pos
end
No longer available:
topLevel
Renamed:
-
taskFormals
->lambdaFormals
-
getTaskFormal
->getLambdaFormal
-
isTask
->isLambda
-
usableBy
->agentClassString
-
tyype
->isReporter
(also changed from an enum to a boolean)
-
innerSource(String)
has been changed toinnerSource_=(String)
(scala) andinnerSource_$eq(String)
java
-
getReporterTask
has been renamed togetReporter
-
getCommandTask
has been renamed togetCommand
-
Syntax.ReporterTaskType
has been renamed toSyntax.ReporterType
-
Syntax.CommandTaskType
has been renamed toSyntax.CommandType
Instead of org.nlogo.api.DefaultCommand
and org.nlogo.api.DefaultReporter
, use org.nlogo.api.Command
and org.nlogo.api.Reporter
. In addition to renaming the superclass, if your primitive overrides getAgentClassString
set that in the Syntax
returned by getSyntax
. If you use core.Syntax
in scala, provide the appropriate named parameter and if you use core.SyntaxJ
in java, call any of the methods which take agentClassString
as a parameter.
When constructing an AgentSet
, a world is no longer needed.
The world
method has been removed from AgentSet
.
A world
method has been added to ExtensionContext
for easy access to the world
.
- A
world
method has been added toExtensionContext
for easy access to theworld
. - The
logCustomMessage
andlogCustomGlobals
methods have been removed fromExtensionContext
. These can be replaced by calls to the appropriate methods on the workspace.
org.nlogo.core.Syntax
replaces org.nlogo.api.Syntax
methods.
core.SyntaxJ
is recommended for Java users, but it returns the same core.Syntax
objects produced by core.Syntax
.
If your code depends on the perspective and/or location of the observer, you should review the changes made to org.nlogo.api.Observer
.
The primary change is the extraction of orientation into a scala.Option
.
This has been done to allow headless code to share the API for observer with NetLogo GUI without tracking irrelevant observer location information.
api.World
has had an interface - api.WorldRenderable
extracted from it which has various methods on world dealing with rendering updates.
If your use of world depends on any of the methods in api.WorldRenderable
, you should modify your extension to check that the world you are using implements WorldRenderable
before performing those operations on it.
- Extension code which formerly made use of
org.nlogo.util.Femto
should switch toorg.nlogo.core.Femto
.org.nlogo.util.Femto
is likely to be removed in a future release.
api.Context
now has world
and workspace
methods which make it possible to access the current world and workspace without needing to cast the Context
to an ExtensionContext
. It is recommended that extensions which do cast to an ExtensionContext
rely on Context.workspace
and the methods on api.Workspace
if possible.
api.Workspace
was introduced in 6.0 and makes available a wealth of functionality which formerly was only available on nvm.Workspace
. Since it's part of the api
package, api.Workspace
should remain binary-compatible for the duration of the 6.0 extensions API.
LogoList
was moved from org.nlogo.api
to org.nlogo.core
.
api.LogoList
implemented java.util.AbstractSequentialList<AnyRef>
while core.LogoList
does not implement it.
It is possible to turn a LogoList
into an AbstractSequentialList
by using toJava
(see table below).
LogoList
now implements scala.collection.IndexedSeq[AnyRef]
, giving it access to a number of powerful features accessible from Scala extensions.
It also had a substantial number of method renames, see the table below:
5.x name | hexy name | type |
---|---|---|
iterator |
javaIterator |
java.util.Iterator<AnyRef> |
scalaIterator |
iterator |
scala.collection.Iterator[AnyRef] |
- | javaIterable |
java.lang.Iterable[AnyRef] |
- | apply(i: Int) |
AnyRef |
- | toJava |
java.util.AbstractSequentialList<AnyRef> |
Moving from 6.0.1 to 6.0.2 brought some fairly large changes to non-API classes.
Note that while a great deal of code (especially Scala code) using classes which have changed (per the below listing) will remain source-compatible, it is very likely to require recompilation before working 6.0.2 because of binary incompatibility. This will be true for most code which called methods on org.nlogo.agent.World
or org.nlogo.agent.Turtle
. Extensions which used only the API classes (org.nlogo.api.Turtle
/ org.nlogo.api.World
) are unlikely to need recompilation for 6.0.2.
Following is a more complete listing of changes:
-
org.nlogo.agent.LogoHashObject
has been removed. Useorg.nlogo.api.LogoHashObject
instead -
org.nlogo.agent.Topology.getPatchAt
has been removed. Useorg.nlogo.agent.World.getPatchAt
instead -
org.nlogo.agent.Agent
(and its subclasses) no longer implementjava.util.Observable
. Useorg.nlogo.agent.World.addWatcher
(and related methods) instead. -
org.nlogo.agent.Agent
(and its subclasses) no longer have the methodsgetAgentBit
orgetAgentClass
. Useorg.nlogo.agent.Agent.kind
instead. -
org.nlogo.agent.Agent
no longer definesgetObserverVariable
/setObserverVariable
. -
org.nlogo.agent.World
is no longer a concrete class and has been split into a hierarchy of classes and traits. Most of these are implementation details, but the general structure is as follows:- Most uses of
org.nlogo.agent.World
in 6.0.1 can be replaced by uses oforg.nlogo.agent.World2D
in 6.0.1 (except in those cases where NetLogo 3D is concerned, which will require the use oforg.nlogo.agent.World3D
instead). -
org.nlogo.agent.World
is now a Scala abstract class (Java authors may see it as an interface instead) which defines many of the same methods defined onWorld
in 6.0.1, but missing those methods which assumed a 2D world. -
org.nlogo.agent.CoreWorld
andorg.nlogo.agent.WorldKernel
are base classes oforg.nlogo.agent.World
. Extension authors (and controlling API authors) should avoid using them as they are very likely to change in future releases
- Most uses of
-
org.nlogo.agent.Turtle
was a concrete class in 6.0.1, but in 6.0.2 has been split into several classes (likeWorld
).-
org.nlogo.agent.Turtle
contains shared methods between 2D and 3D - When instantiating a turtle, instantiate
org.nlogo.agent.Turtle2D
ororg.nlogo.agent.Turtle3D
. - 2D/3D-specific turtle methods should not be accessed before checking whether the turtle is actually a
Turtle2D
or aTurtle3D
.
-
-
org.nlogo.agent.Observer.perspective(Perspective)
was renamed tosetPerspective(Perspective)
- The constraint methods on observer have been renamed as follows:
-
assertVariableConstraint
->assertConstraint
-
variableConstraint(int)
->constraint(int)
-
variableConstraint(int, ValueConstraint)
->setConstraint(int, ValueConstraint)
-
-
org.nlogo.agent.Agent.variables
is now a method instead of a field -
org.nlogo.agent.Agent.id
is now a method instead of a field -
org.nlogo.agent.Agent.getVariableCount
is no longer a method. Useorg.nlogo.agent.Agent.variables().length
. - The constraint methods
assertVariableConstraint
andvariableConstraint
have been removed fromorg.nlogo.agent.Agent
. They are still available onorg.nlogo.agent.Observer
- The
org.nlogo.agent.Patch.pcolorDouble()
method has been removed. Useorg.nlogo.agent.Patch.pcolor()
instead and check the result, which can be either ajava.lang.Double
or anorg.nlogo.core.LogoList
. -
org.nlogo.agent.World.ZERO
andorg.nlogo.agent.World.ONE
have been removed. Useorg.nlogo.agent.World.Zero()
andorg.nlogo.agent.World.One()
instead. -
org.nlogo.agent.World
has had the following fields converted to methods:tickCounter
inRadiusOrCone
tieManager
linkManager
linkBreedShapes
- The following methods no longer exist on
org.nlogo.agent.World
. Although some of them are methods onWorld2D
, we recommend against using them if at all possible:rememberOldProgram()
compiler()
compiler_=(Compiler)
program(Program)
-
org.nlogo.nvm.AnonymousProcedure
andorg.nlogo.nvm.AnonymousCommand
both are now initialized with an additional 5th parameter which contains the source code used to create them. Extension authors who instantiate these classes should provide a string indicating something about the contents of the anonymous procedure (and preferably the name of the extension that created it). -
org.nlogo.core.BoxedValue.multiline
no longer exists.multiline
is still defined onorg.nlogo.core.StringInput
. We try to avoid breaking changes to thecore
andapi
modules between releases. We made a change here because we believe no extensions will be affected. - There are various changes to core primitive classes in
org.nlogo.core.prim
(and subpackages). -
org.nlogo.swing.BrowserLauncher.openURL
is now deprecated. We advise that extension authors use theopenPath
oropenURI
methods (also defined onBrowserLauncher
) instead. - Various changes to classes in
org.nlogo.app
,org.nlogo.prim
, andorg.nlogo.workspace
which should not affect most extensions. - The Pegdown library is no longer included with NetLogo. NetLogo now uses the flexmark-java library instead for markdown processing. If your extension relied on having the Pegdown library on the classpath, upgrade it to use flexmark.
-
org.nlogo.api.ValueSet
andorg.nlogo.api.EnumeratedValueSet
are now deprecated. Useorg.nlogo.api.RefValueSet
andorg.nlogo.api.RefEnumeratedValueSet
instead.
- Consolidate
AbstractWorkspace
andAbstractWorkspaceScala
into a unifiedAbstractWorkspace
-
org.nlogo.workspace.ExtensionManager
no longer has a method to access the workspace (this method was formerlyworkspace
). Proposed replacement is to use the workspace provided by theContext
passed into each primitive at execution. -
org.nlogo.api.HubNetWorkspaceInterface
no longer implementsCompilerServices
, has a fieldcompilerServices
which provides those services. -
org.nlogo.api.VersionHistory
no longer has the methodsolderThan3DPreview3
,olderThan3DPreview4
,olderThan3DPreview5
. -
org.nlogo.app.App
no longer has the following methods:-
logger
(ReferenceApp.app.logger
instead) -
makeWidget
(callmakeWidget
on the interfacePanel instead) -
commandLine
* methods. InterrogateApp.app.params
instead
-
- The following methods are deprecated (need to add suggestions for replacement):
org.nlogo.api.Version.is3D
org.nlogo.api.ModelReader.modelSuffix
org.nlogo.api.ModelReader.emptyModelPath
-
org.nlogo.api.WorldDimensions3D
is deprecated. Useorg.nlogo.core.WorldDimensions3D
instead. -
ModelSaver
is deprecated -
org.nlogo.util.Pico
has been moved toorg.nlogo.api.Pico
. Note that we do not recommend extension authors use this class (and have marked itprivate[nlogo]
to that end). -
api.AggregateManagerInterface
,api.HubNetInterface
, andapi.PreviewCommands
no longer extendModelSections.ModelSaveable
(and thus no longer have anupdateModel(Model): Model
method. We do not expect this to affect extension authors.
- Extensions
- NetLogo Libraries
- Controlling API
- Extensions API
- 6.0 Extension and Controlling API Transition-Guide
- Optimizing NetLogo Runs
- Setting English as the Default Language when Running NetLogo
- Unofficial Features
- Advanced Installation
- Optimization List
- Java System Properties and how to use them
- NetLogo on ARM Devices
- Multiple Views via HubNet
- Branches
- Building
- Tests
- Windows Setup
- Continuous Integration
- Draft: How to Help
- Google Summer of Code Ideas List
- Syntax Highlighting
- Building with IntelliJ
- Code Formatting
- Localization
- File (.nlogo) and Widget Format
- Benchmarking
- Releasing
- Preparing the Models Library for Release
- Documentation
- NetLogo Bundled Java Versions
- JOGL
- Plugins API
- Architecture
- LazyAgentset
- Model Runs and Review Tab
- Model Runs: To Do and Code Overview
- Notes on in Radius
- Archived Branches
- The nlogox format
- Touch API Proposal
- Why isn't NetLogo "Parallel"?
- Potential Speedups
- Tortoise
- SimServer, WebStart, and NetLogo in Classrooms