Class PooledViews

java.lang.Object
org.eclipse.emf.cdo.spi.server.PooledViews
All Implemented Interfaces:
AutoCloseable

public final class PooledViews extends Object implements AutoCloseable
Allocates reusable IDs for genuine server-side views and transactions associated with one session. The utility never pools view instances: each call opens a new view or transaction, and the returned object is closed through its ordinary lifecycle API.

A session must have only one PooledViews owner, and callers must not concurrently open views outside this utility. The session API has no atomic ID reservation operation. Existing views are detected and skipped when an ID is selected, but exclusive ownership is required to prevent a concurrent external open from racing that check.

Allocation and session-event processing are thread-safe. Only positive IDs are allocated; zero is reserved for the session's temporary view mechanism. Released IDs are reused before new positive IDs are allocated. An ID becomes reusable only after the session has removed its view and finished close processing. The positive ID space is limited to 1 through Integer.MAX_VALUE.

Since:
4.27
Author:
Eike Stepper
  • Constructor Details

    • PooledViews

      public PooledViews(InternalSession session)
      Creates an ID allocator for an active internal session.

      The caller owns the session and must ensure that no other component concurrently opens views on it with IDs that this allocator may select. Views that were already open when this object is created are skipped during allocation. Closing the allocator removes its session listener and prevents future allocations; active views remain owned by their callers and are closed through their ordinary lifecycle API.

      Parameters:
      session - the active internal session whose view IDs are allocated
      Throws:
      NullPointerException - if session is null
      IllegalStateException - if session is not active
  • Method Details

    • openView

      public IView openView(CDOBranchPoint branchPoint)
      Opens a new server-side read view at the supplied branch point with a reusable ID.

      The returned view is a normal session view. Callers close it through its ordinary lifecycle API when the request-specific work is complete. Its ID becomes reusable only after the session has completed view removal.

      Parameters:
      branchPoint - the branch point to view
      Returns:
      a newly created view with a positive ID unique among currently open views in the owned session
      Throws:
      NullPointerException - if branchPoint is null
      IllegalStateException - if this allocator or its session is closed, or the positive ID space is exhausted
    • openTransaction

      public InternalTransaction openTransaction(CDOBranchPoint branchPoint)
      Opens a new server-side transaction at the supplied branch point with a reusable ID.

      The returned transaction has fresh state and is closed through its ordinary lifecycle API. The transaction object itself is never reused.

      Parameters:
      branchPoint - the branch point to modify
      Returns:
      a newly created transaction with a positive ID unique among currently open views in the owned session
      Throws:
      NullPointerException - if branchPoint is null
      IllegalStateException - if this allocator or its session is closed, or the positive ID space is exhausted
    • close

      public void close()
      Stops ID allocation and removes the session listener. Active views remain owned by their callers and must still be closed through their ordinary lifecycle API. A repository context should close this utility after all request leases have finished and before deactivating its session.
      Specified by:
      close in interface AutoCloseable