Class ModuleLayer.Controller
java.lang.Object
java.lang.ModuleLayer.Controller
- Enclosing class:
ModuleLayer
Controls a module layer. The static methods defined by
ModuleLayer
to create module layers return a Controller that can be used to
control modules in the layer.
Unless otherwise specified, passing a null argument to a
method in this class causes a NullPointerException to be thrown.
- API Note:
- Care should be taken with
Controllerobjects, they should never be shared with untrusted code. - Since:
- 9
-
Method Summary
Modifier and TypeMethodDescriptionaddExports(Module source, String pn, Module target) Updates modulesourcein the layer to export a package to moduletarget.Updates modulesourcein the layer to open a package to moduletarget.Updates modulesourcein the layer to read moduletarget.enableNativeAccess(Module target) Restricted.Enables native access for a module in the layer if the caller's module has native access.layer()Returns the layer that this object controls.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.toString()Answers a string containing a concise, human-readable description of the receiver.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Method Details
-
layer
-
addReads
Updates modulesourcein the layer to read moduletarget. This method is a no-op ifsourcealready readstarget.- Implementation Note:
- Read edges added by this method are weak
and do not prevent
targetfrom being GC'ed whensourceis strongly reachable. - Parameters:
source- The source moduletarget- The target module to read- Returns:
- This controller
- Throws:
IllegalArgumentException- Ifsourceis not in the module layer- See Also:
-
addExports
Updates modulesourcein the layer to export a package to moduletarget. This method is a no-op ifsourcealready exports the package to at leasttarget.Exporting a package with this method does not allow the target module to reflectively set or obtain a method handle with write access to a public final field declared in a public class in the package.
- Parameters:
source- The source modulepn- The package nametarget- The target module- Returns:
- This controller
- Throws:
IllegalArgumentException- Ifsourceis not in the module layer or the package is not in the source module- See Also:
-
addOpens
Updates modulesourcein the layer to open a package to moduletarget. This method is a no-op ifsourcealready opens the package to at leasttarget.Opening a package with this method does not allow the target module to reflectively set or obtain a method handle with write access to a final field declared in a class in the package.
- Parameters:
source- The source modulepn- The package nametarget- The target module- Returns:
- This controller
- Throws:
IllegalArgumentException- Ifsourceis not in the module layer or the package is not in the source module- See Also:
-
enableNativeAccess
enableNativeAccessis a restricted method of the Java platform.Programs can only useenableNativeAccesswhen access to restricted methods is enabled.Restricted methods are unsafe, and, if used incorrectly, might crash the JVM or result in memory corruption.Enables native access for a module in the layer if the caller's module has native access.- Parameters:
target- The module to update- Returns:
- This controller
- Throws:
IllegalArgumentException- Iftargetis not in the module layerIllegalCallerException- If the caller is in a module that does not have native access enabled- Since:
- 22
-