Class GenerateEntryPointTask

java.lang.Object
org.gradle.api.internal.AbstractTask
org.gradle.api.DefaultTask
dev.gmitch215.bytebox.gradle.GenerateEntryPointTask
All Implemented Interfaces:
Comparable<org.gradle.api.Task>, org.gradle.api.internal.DynamicObjectAware, org.gradle.api.internal.TaskInternal, org.gradle.api.Named, org.gradle.api.plugins.ExtensionAware, org.gradle.api.Task, org.gradle.util.Configurable<org.gradle.api.Task>

@CacheableTask public abstract class GenerateEntryPointTask extends org.gradle.api.DefaultTask
Writes the Java class the compiled module exports its handlers from.

A separate class rather than a member of the handler, because a static method exported as fetch cannot sit beside the instance fetch that Worker declares. Keeping the generated glue out of the handler also leaves the handler a plain Java class with no annotations on it.

Each exported method hands JavaScript a promise straight away and starts the handler on a fiber. That shape is what makes a blocking handler possible: a promise executor cannot suspend, and an entry point returning a value would return before the handler's suspensions finished.

The module's start-up work gets the same treatment. main starts a fiber that builds the handler and registers the codecs, so a lock, a join or a get reached from the handler's constructor or from a static initialiser it triggers can block. Run straight from main it would trap, because a method TeaVM compiled as asynchronous needs a fiber under it. For the same reason the handler is a plain field and not a static final one: an initialiser that can suspend would make every export asynchronous too, and JavaScript cannot call those.

A Durable Object or a Workflow is built the same way: the export hands a factory to DurableHandlers or WorkflowHandlers, which call it on the fiber they start, so the constructor may block.

Since:
1.0.0
  • Nested Class Summary

    Nested classes/interfaces inherited from interface org.gradle.api.Named

    org.gradle.api.Named.Namer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The generated class's simple name.
    static final String
    The class that installs %t for String.format, which has to run before the handler exists.
    static final String
    The package the generated entry point lives in.
    static final String
    The class that installs the recorded timezone history, which has to run before the handler exists.

    Fields inherited from interface org.gradle.api.Task

    TASK_ACTION, TASK_CONSTRUCTOR_ARGS, TASK_DEPENDS_ON, TASK_DESCRIPTION, TASK_GROUP, TASK_NAME, TASK_OVERWRITE, TASK_TYPE
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Writes the entry point.
    abstract org.gradle.api.provider.Property<Boolean>
    Returns whether the entry point installs the %t conversions.
    abstract org.gradle.api.provider.ListProperty<String>
    Returns the Java classes exposed as Durable Objects.
    abstract org.gradle.api.provider.Property<String>
    Returns the handler class to route to.
    abstract org.gradle.api.file.ConfigurableFileCollection
    Returns where to find the handler, so its interfaces can be read.
    abstract org.gradle.api.file.DirectoryProperty
    Returns where the generated source goes.
    abstract org.gradle.api.provider.ListProperty<String>
    Returns the Java classes exposed as Workflows.
    abstract org.gradle.api.provider.Property<Boolean>
    Returns whether the entry point registers the recorded timezone history.

    Methods inherited from class org.gradle.api.DefaultTask

    compareTo, configure, dependsOn, doFirst, doFirst, doFirst, doLast, doLast, doLast, finalizedBy, getActions, getAnt, getDependsOn, getDescription, getDestroyables, getDidWork, getEnabled, getExtensions, getFinalizedBy, getGroup, getInputs, getLocalState, getLogger, getLogging, getMustRunAfter, getName, getOutputs, getPath, getProject, getShouldRunAfter, getState, getTaskDependencies, getTemporaryDir, getTimeout, hasProperty, mustRunAfter, onlyIf, onlyIf, onlyIf, property, setActions, setDependsOn, setDescription, setDidWork, setEnabled, setFinalizedBy, setGroup, setMustRunAfter, setOnlyIf, setOnlyIf, setOnlyIf, setProperty, setShouldRunAfter, shouldRunAfter, usesService

    Methods inherited from class org.gradle.api.internal.AbstractTask

    acceptServiceReferences, appendParallelSafeAction, doNotTrackState, doNotTrackStateIf, getAsDynamicObject, getIdentityPath, getImpliesSubProjects, getLifecycleDependencies, getOnlyIf, getReasonNotToTrackState, getReasonsNotToTrackState, getReasonTaskIsIncompatibleWithConfigurationCache, getRequiredServices, getServices, getSharedResources, getStandardOutputCapture, getTaskActions, getTaskIdentity, getTemporaryDirFactory, hasTaskActions, injectIntoNewInstance, isCompatibleWithConfigurationCache, isEnabled, isHasCustomActions, notCompatibleWithConfigurationCache, prependParallelSafeAction, restoreOnlyIf, restoreTaskActions, setImpliesSubProjects

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.gradle.api.Task

    doNotTrackState, notCompatibleWithConfigurationCache
  • Field Details

    • PACKAGE

      public static final String PACKAGE
      The package the generated entry point lives in.
      See Also:
    • CLASS_NAME

      public static final String CLASS_NAME
      The generated class's simple name.
      See Also:
    • ZONE_HISTORY

      public static final String ZONE_HISTORY
      The class that installs the recorded timezone history, which has to run before the handler exists.
      See Also:
    • DATES

      public static final String DATES
      The class that installs %t for String.format, which has to run before the handler exists.
      See Also:
  • Constructor Details

    • GenerateEntryPointTask

      public GenerateEntryPointTask()
  • Method Details

    • getHandlerClass

      @Input public abstract org.gradle.api.provider.Property<String> getHandlerClass()
      Returns the handler class to route to.
      Returns:
      the handler class to route to
    • getDurableObjectClasses

      @Input public abstract org.gradle.api.provider.ListProperty<String> getDurableObjectClasses()
      Returns the Java classes exposed as Durable Objects.
      Returns:
      the Java classes exposed as Durable Objects
    • getWorkflowClasses

      @Input public abstract org.gradle.api.provider.ListProperty<String> getWorkflowClasses()
      Returns the Java classes exposed as Workflows.
      Returns:
      the Java classes exposed as Workflows
    • getZoneHistory

      @Input public abstract org.gradle.api.provider.Property<Boolean> getZoneHistory()
      Returns whether the entry point registers the recorded timezone history.
      Returns:
      whether the entry point registers the recorded timezone history
    • getDateFormat

      @Input public abstract org.gradle.api.provider.Property<Boolean> getDateFormat()
      Returns whether the entry point installs the %t conversions.
      Returns:
      whether the entry point installs the %t conversions
    • getHandlerClasspath

      @Classpath public abstract org.gradle.api.file.ConfigurableFileCollection getHandlerClasspath()
      Returns where to find the handler, so its interfaces can be read.
      Returns:
      where to find the handler, so its interfaces can be read
    • getOutputDirectory

      @OutputDirectory public abstract org.gradle.api.file.DirectoryProperty getOutputDirectory()
      Returns where the generated source goes.
      Returns:
      where the generated source goes
    • generate

      public void generate()
      Writes the entry point.