-
-
Notifications
You must be signed in to change notification settings - Fork 266
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- useloadedExtensionsinstead. -
getJarPaths- no longer needed now that applets are dead. -
getSource- useworkspace.getSourceinstead. -
getFile- useworkspace.fileManager.getFile(workspace.attachModelDir)instead. -
profilingEnabled- check if the profiler extension is one of theloadedExtensionsinstead. -
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, seeresolvePathabove, otherwise useworkspace.attachModelDirornew 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.Seqis used for list representations instead ofjava.util.List. -
Programs 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. -
userGlobalsandinterfaceGlobalsare available as separate methods or combined in theglobalsmethod along with observer variables. - Since the breeds are no longer
AgentSets,AgentSets 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:
-
AgentSets (and their builders) take anAgentKind. -
Agenthas akindmethod which returns the kind of that agent.
The following were formerly fields on nvm.Procedure and are now methods:
topLevelcodeargs-
fileName(available as an alias forfilename) namedisplayNamelocalsCountposend
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
-
getReporterTaskhas been renamed togetReporter -
getCommandTaskhas been renamed togetCommand
-
Syntax.ReporterTaskTypehas been renamed toSyntax.ReporterType -
Syntax.CommandTaskTypehas 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
worldmethod has been added toExtensionContextfor easy access to theworld. - The
logCustomMessageandlogCustomGlobalsmethods 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.Femtoshould switch toorg.nlogo.core.Femto.org.nlogo.util.Femtois 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.LogoHashObjecthas been removed. Useorg.nlogo.api.LogoHashObjectinstead -
org.nlogo.agent.Topology.getPatchAthas been removed. Useorg.nlogo.agent.World.getPatchAtinstead -
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 methodsgetAgentBitorgetAgentClass. Useorg.nlogo.agent.Agent.kindinstead. -
org.nlogo.agent.Agentno longer definesgetObserverVariable/setObserverVariable. -
org.nlogo.agent.Worldis 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.Worldin 6.0.1 can be replaced by uses oforg.nlogo.agent.World2Din 6.0.1 (except in those cases where NetLogo 3D is concerned, which will require the use oforg.nlogo.agent.World3Dinstead). -
org.nlogo.agent.Worldis now a Scala abstract class (Java authors may see it as an interface instead) which defines many of the same methods defined onWorldin 6.0.1, but missing those methods which assumed a 2D world. -
org.nlogo.agent.CoreWorldandorg.nlogo.agent.WorldKernelare 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.Turtlewas a concrete class in 6.0.1, but in 6.0.2 has been split into several classes (likeWorld).-
org.nlogo.agent.Turtlecontains shared methods between 2D and 3D - When instantiating a turtle, instantiate
org.nlogo.agent.Turtle2Dororg.nlogo.agent.Turtle3D. - 2D/3D-specific turtle methods should not be accessed before checking whether the turtle is actually a
Turtle2Dor 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.variablesis now a method instead of a field -
org.nlogo.agent.Agent.idis now a method instead of a field -
org.nlogo.agent.Agent.getVariableCountis no longer a method. Useorg.nlogo.agent.Agent.variables().length. - The constraint methods
assertVariableConstraintandvariableConstrainthave 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.Doubleor anorg.nlogo.core.LogoList. -
org.nlogo.agent.World.ZEROandorg.nlogo.agent.World.ONEhave been removed. Useorg.nlogo.agent.World.Zero()andorg.nlogo.agent.World.One()instead. -
org.nlogo.agent.Worldhas had the following fields converted to methods:tickCounterinRadiusOrConetieManagerlinkManagerlinkBreedShapes
- 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.AnonymousProcedureandorg.nlogo.nvm.AnonymousCommandboth 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.multilineno longer exists.multilineis still defined onorg.nlogo.core.StringInput. We try to avoid breaking changes to thecoreandapimodules 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.openURLis now deprecated. We advise that extension authors use theopenPathoropenURImethods (also defined onBrowserLauncher) instead. - Various changes to classes in
org.nlogo.app,org.nlogo.prim, andorg.nlogo.workspacewhich 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.ValueSetandorg.nlogo.api.EnumeratedValueSetare now deprecated. Useorg.nlogo.api.RefValueSetandorg.nlogo.api.RefEnumeratedValueSetinstead.
- Consolidate
AbstractWorkspaceandAbstractWorkspaceScalainto a unifiedAbstractWorkspace -
org.nlogo.workspace.ExtensionManagerno longer has a method to access the workspace (this method was formerlyworkspace). Proposed replacement is to use the workspace provided by theContextpassed into each primitive at execution. -
org.nlogo.api.HubNetWorkspaceInterfaceno longer implementsCompilerServices, has a fieldcompilerServiceswhich provides those services. -
org.nlogo.api.VersionHistoryno longer has the methodsolderThan3DPreview3,olderThan3DPreview4,olderThan3DPreview5. -
org.nlogo.app.Appno longer has the following methods:-
logger(ReferenceApp.app.loggerinstead) -
makeWidget(callmakeWidgeton the interfacePanel instead) -
commandLine* methods. InterrogateApp.app.paramsinstead
-
- The following methods are deprecated (need to add suggestions for replacement):
org.nlogo.api.Version.is3Dorg.nlogo.api.ModelReader.modelSuffixorg.nlogo.api.ModelReader.emptyModelPath
-
org.nlogo.api.WorldDimensions3Dis deprecated. Useorg.nlogo.core.WorldDimensions3Dinstead. -
ModelSaveris deprecated -
org.nlogo.util.Picohas 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.PreviewCommandsno longer extendModelSections.ModelSaveable(and thus no longer have anupdateModel(Model): Modelmethod. 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
- NetLogo Project Ideas
- Syntax Highlighting
- Building with IntelliJ
- Code Formatting
- Localization
- XML File Format
- Pre‐7.0.0 File Format (.nlogo) and Widget Format
- Benchmarking
- Releasing/Publishing
- 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
- Touch API Proposal
- Why isn't NetLogo "Parallel"?
- Potential Speedups
- Tortoise
- SimServer, WebStart, and NetLogo in Classrooms