Class MetaContextBase

    • Constructor Summary

      Constructors 
      Constructor Description
      MetaContextBase()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected io.aether.utils.dataio.DataInOut acquireDataOut()  
      FastMetaApi<?,​?> applyLocalApiSwitch()
      Applies a previously requested local API switch at a command boundary.
      MetaContext connectionContext()
      Returns the root context representing the underlying transport connection.
      protected MetaContextBase createChildContext()  
      MetaContext findContext​(io.aether.utils.interfaces.AFunction<MetaContext,​?> factory, java.lang.Object... keys)
      Finds or creates a child context identified by the supplied composite key.
      void fireWritable​(boolean writable)
      Publishes a writability-state change to listeners associated with this context.
      void flush()
      Requests immediate processing of the outbound flush lifecycle.
      java.lang.Object getLocalApi()
      Returns the local API implementation currently installed in this context.
      void invokeLocalMethodBefore​(java.lang.String methodName, java.lang.String[] argsNames, java.lang.Object[] argsValues)
      Hook invoked immediately before a decoded local API method executes.
      boolean isActive()
      Reports whether this context is currently active.
      boolean isEmpty()
      Reports whether this context currently exposes flushable outbound data.
      protected boolean isLocallyActive()  
      boolean isLocked()
      Reports whether outbound flush/notification processing is currently suppressed by MetaContext.lock().
      java.lang.AutoCloseable lock()
      Temporarily suppresses outbound flush/notification processing.
      protected void notifyDataAdded()  
      void onFirstWritable​(io.aether.utils.interfaces.ARunnable listener)
      Registers an action that runs once when writable state is first observed.
      void onFlush​(io.aether.utils.interfaces.ARunnable flushAction)
      Installs the action invoked by this context's flush lifecycle.
      void onWritable​(it.unimi.dsi.fastutil.booleans.BooleanConsumer listener)
      Registers a listener for writability changes.
      protected void releaseDataOut​(io.aether.utils.dataio.DataInOut out)  
      byte[] remoteDataToArray()
      Drains queued outbound packets into a newly allocated byte array.
      void remoteDataToArray​(io.aether.utils.dataio.DataOut out)
      Drains queued outbound packets into the supplied output buffer.
      void retire()  
      protected void runFlushLifecycle()  
      void sendToRemote​(LazyPacket packet)
      Queues a lazily serialized packet for delivery to the remote endpoint.
      void setActivePredicate​(io.aether.utils.interfaces.ASupplierBoolean predicate)
      Sets the predicate used to determine the local active state.
      void setLocalApi​(java.lang.Object localApi)  
      void setLocalMethodBeforeListener​(io.aether.utils.interfaces.AConsumer<java.lang.String> listener)
      Installs a listener invoked before a decoded local API method executes.
      int size()
      Returns the serialized size of outbound data currently exposed by this context.
      <T,​R extends RemoteApi>
      void
      switchLocalApi​(T localApi, FastMetaApi<T,​R> meta)
      Requests replacement of the local API implementation at the next safe command boundary.
      io.aether.utils.AString toAString​(io.aether.utils.AString sb)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface io.aether.utils.ToString

        toString2
    • Field Detail

      • toRemote

        protected final java.util.Queue<LazyPacket> toRemote
      • firstWritableFlag

        protected final java.util.concurrent.atomic.AtomicBoolean firstWritableFlag
      • localApi

        public java.lang.Object localApi
      • writableListener

        protected volatile it.unimi.dsi.fastutil.booleans.BooleanConsumer writableListener
      • flushAction

        protected io.aether.utils.interfaces.ARunnable flushAction
    • Constructor Detail

      • MetaContextBase

        public MetaContextBase()
    • Method Detail

      • isLocallyActive

        protected boolean isLocallyActive()
      • setLocalMethodBeforeListener

        public void setLocalMethodBeforeListener​(io.aether.utils.interfaces.AConsumer<java.lang.String> listener)
        Description copied from interface: MetaContext
        Installs a listener invoked before a decoded local API method executes.
        Specified by:
        setLocalMethodBeforeListener in interface MetaContext
        Parameters:
        listener - listener receiving the local method name, or null to remove the listener
      • invokeLocalMethodBefore

        public void invokeLocalMethodBefore​(java.lang.String methodName,
                                            java.lang.String[] argsNames,
                                            java.lang.Object[] argsValues)
        Description copied from interface: MetaContext
        Hook invoked immediately before a decoded local API method executes.
        Specified by:
        invokeLocalMethodBefore in interface MetaContext
        Parameters:
        methodName - local method name
        argsNames - argument names, possibly null
        argsValues - argument values, possibly null
      • setActivePredicate

        public void setActivePredicate​(io.aether.utils.interfaces.ASupplierBoolean predicate)
        Description copied from interface: MetaContext
        Sets the predicate used to determine the local active state.
        Specified by:
        setActivePredicate in interface MetaContext
        Parameters:
        predicate - active-state predicate, or null to use the implementation default
      • findContext

        public MetaContext findContext​(io.aether.utils.interfaces.AFunction<MetaContext,​?> factory,
                                       java.lang.Object... keys)
        Description copied from interface: MetaContext
        Finds or creates a child context identified by the supplied composite key.

        Repeated lookups with an equal key resolve to the same live child context. The factory is used only when a child must be created or recreated.

        Specified by:
        findContext in interface MetaContext
        Parameters:
        factory - initializer for a newly created child context
        keys - values forming the child-context key
        Returns:
        existing or newly initialized child context
      • flush

        public void flush()
        Description copied from interface: MetaContext
        Requests immediate processing of the outbound flush lifecycle.

        Hierarchical implementations may delegate flushing to the connection root. A flush may be suppressed while MetaContext.lock() is active.

        Specified by:
        flush in interface MetaContext
      • runFlushLifecycle

        protected void runFlushLifecycle()
      • getLocalApi

        public java.lang.Object getLocalApi()
        Description copied from interface: MetaContext
        Returns the local API implementation currently installed in this context.

        A pending switch is not visible here until MetaContext.applyLocalApiSwitch() applies it.

        Specified by:
        getLocalApi in interface MetaContext
        Returns:
        current local API implementation, or null when none is installed
      • setLocalApi

        public void setLocalApi​(java.lang.Object localApi)
      • switchLocalApi

        public <T,​R extends RemoteApi> void switchLocalApi​(T localApi,
                                                                 FastMetaApi<T,​R> meta)
        Description copied from interface: MetaContext
        Requests replacement of the local API implementation at the next safe command boundary.

        The switch is deliberately deferred. The command that requests the switch always finishes using the local API and META with which it started. The new local implementation and its target META form one coherent switch request and must never be changed independently.

        Generated local decoders call MetaContext.applyLocalApiSwitch() after a complete command. If unread bytes remain in the same input payload, decoding may continue immediately with meta, allowing a V0 command and commands from an unrelated V1 API to coexist in one payload.

        The target META is not persistent transport decoder state. Each later isolated UDP/TCP payload must select its initial META again from application-level negotiated state.

        Specified by:
        switchLocalApi in interface MetaContext
        Type Parameters:
        T - local API type
        R - matching remote API type
        Parameters:
        localApi - new local API implementation
        meta - META that decodes commands for localApi
      • applyLocalApiSwitch

        public FastMetaApi<?,​?> applyLocalApiSwitch()
        Description copied from interface: MetaContext
        Applies a previously requested local API switch at a command boundary.

        The implementation must flush bytes produced by the old local API before replacing it so those bytes retain the routing and flush policy of the API that produced them.

        The returned META is intended only for unread bytes remaining in the current input payload. It must not become persistent decoder state for subsequent transport payloads.

        Specified by:
        applyLocalApiSwitch in interface MetaContext
        Returns:
        META for decoding the remainder of the current payload, or null when no switch is pending
      • onFlush

        public void onFlush​(io.aether.utils.interfaces.ARunnable flushAction)
        Description copied from interface: MetaContext
        Installs the action invoked by this context's flush lifecycle.
        Specified by:
        onFlush in interface MetaContext
        Parameters:
        flushAction - action to run when the context is flushed
      • toAString

        public io.aether.utils.AString toAString​(io.aether.utils.AString sb)
        Specified by:
        toAString in interface io.aether.utils.ToString
      • isLocked

        public boolean isLocked()
        Description copied from interface: MetaContext
        Reports whether outbound flush/notification processing is currently suppressed by MetaContext.lock().
        Specified by:
        isLocked in interface MetaContext
        Returns:
        true while flush suppression is active
      • lock

        public java.lang.AutoCloseable lock()
        Description copied from interface: MetaContext
        Temporarily suppresses outbound flush/notification processing.

        This is not a mutual-exclusion lock and must not be used to serialize writers. Closing the returned scope releases suppression and allows queued data to re-enter the normal flush lifecycle. Implementations may reject nested or concurrent acquisition.

        Specified by:
        lock in interface MetaContext
        Returns:
        scope whose close operation releases flush suppression
      • sendToRemote

        public void sendToRemote​(LazyPacket packet)
        Description copied from interface: MetaContext
        Queues a lazily serialized packet for delivery to the remote endpoint.
        Specified by:
        sendToRemote in interface MetaContext
        Parameters:
        packet - packet to serialize during outbound draining
      • notifyDataAdded

        protected void notifyDataAdded()
      • isEmpty

        public boolean isEmpty()
        Description copied from interface: MetaContext
        Reports whether this context currently exposes flushable outbound data.

        An implementation may intentionally appear empty while flush suppression is active.

        Specified by:
        isEmpty in interface MetaContext
        Returns:
        true when no outbound data is currently flushable
      • isActive

        public boolean isActive()
        Description copied from interface: MetaContext
        Reports whether this context is currently active.

        Hierarchical implementations may require both the local context and all of its parents to be active.

        Specified by:
        isActive in interface MetaContext
        Returns:
        true when the context is active
      • connectionContext

        public MetaContext connectionContext()
        Description copied from interface: MetaContext
        Returns the root context representing the underlying transport connection.

        A root context returns itself; child contexts resolve through their parent chain.

        Specified by:
        connectionContext in interface MetaContext
        Returns:
        connection-level root context
      • onWritable

        public void onWritable​(it.unimi.dsi.fastutil.booleans.BooleanConsumer listener)
        Description copied from interface: MetaContext
        Registers a listener for writability changes.

        Implementations should invoke the listener immediately with the current state and subsequently when that state changes.

        Specified by:
        onWritable in interface MetaContext
        Parameters:
        listener - writability listener
      • onFirstWritable

        public void onFirstWritable​(io.aether.utils.interfaces.ARunnable listener)
        Description copied from interface: MetaContext
        Registers an action that runs once when writable state is first observed.
        Specified by:
        onFirstWritable in interface MetaContext
        Parameters:
        listener - action to run on first writability
      • fireWritable

        public void fireWritable​(boolean writable)
        Description copied from interface: MetaContext
        Publishes a writability-state change to listeners associated with this context.
        Specified by:
        fireWritable in interface MetaContext
        Parameters:
        writable - new writability state
      • size

        public int size()
        Description copied from interface: MetaContext
        Returns the serialized size of outbound data currently exposed by this context.
        Specified by:
        size in interface MetaContext
        Returns:
        queued outbound byte count
      • acquireDataOut

        protected io.aether.utils.dataio.DataInOut acquireDataOut()
      • releaseDataOut

        protected void releaseDataOut​(io.aether.utils.dataio.DataInOut out)
      • remoteDataToArray

        public byte[] remoteDataToArray()
        Description copied from interface: MetaContext
        Drains queued outbound packets into a newly allocated byte array.
        Specified by:
        remoteDataToArray in interface MetaContext
        Returns:
        serialized outbound bytes, possibly empty
      • remoteDataToArray

        public void remoteDataToArray​(io.aether.utils.dataio.DataOut out)
        Description copied from interface: MetaContext
        Drains queued outbound packets into the supplied output buffer.
        Specified by:
        remoteDataToArray in interface MetaContext
        Parameters:
        out - destination for serialized outbound bytes
      • retire

        public void retire()