Class AbstractKernel

java.lang.Object
com.jme3.network.kernel.AbstractKernel
All Implemented Interfaces:
Kernel
Direct Known Subclasses:
SelectorKernel, UdpKernel

public abstract class AbstractKernel extends Object implements Kernel
Base implementation of the Kernel interface providing several useful default implementations of some methods. This implementation assumes that the kernel will be managing its own internal threads and queuing any results for the caller to retrieve on their own thread.
Author:
Paul Speed
  • Constructor Details

    • AbstractKernel

      protected AbstractKernel()
      Creates a kernel base with empty event and envelope queues.
  • Method Details

    • reportError

      protected void reportError(Exception e)
      Reports an internal kernel error.
      Parameters:
      e - the error to report
    • wakeupReader

      protected void wakeupReader()
      Wakes a waiting reader by enqueueing the Kernel.EVENTS_PENDING marker if needed.
    • nextEndpointId

      protected long nextEndpointId()
      Returns the next unique endpoint identifier.
      Returns:
      the next endpoint id
    • hasEnvelopes

      public boolean hasEnvelopes()
      Returns true if there are waiting envelopes.
      Specified by:
      hasEnvelopes in interface Kernel
      Returns:
      true if at least one envelope is queued
    • read

      public Envelope read() throws InterruptedException
      Removes one envelope from the received messages queue or blocks until one is available.
      Specified by:
      read in interface Kernel
      Returns:
      the next queued envelope
      Throws:
      InterruptedException - if interrupted while waiting for an envelope
    • nextEvent

      public EndpointEvent nextEvent()
      Removes and returns one endpoint event from the event queue or null if there are no endpoint events.
      Specified by:
      nextEvent in interface Kernel
      Returns:
      the next endpoint event, or null if none are queued
    • addEvent

      protected void addEvent(EndpointEvent e)
      Adds an endpoint event to the pending event queue.
      Parameters:
      e - the event to enqueue
    • addEnvelope

      protected void addEnvelope(Envelope env)
      Adds an envelope to the pending message queue.
      Parameters:
      env - the envelope to enqueue