/* * Copyright 2020 The Netty Project * * The Netty Project licenses this file to you under the Apache License, * version 2.0 (the "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at: * * https://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations * under the License. */ package io.netty.buffer.api; import java.util.ArrayDeque; /** * A scope is a convenient mechanism for capturing the life cycles of multiple reference counted objects. Once the scope * is closed, all the added objects will also be closed in reverse insert order. That is, the most recently added * object will be closed first. *
* Scopes can be reused. After a scope has been closed, new objects can be added to it, and they will be closed when the * scope is closed again. *
* Objects will not be closed multiple times if the scope is closed multiple times, unless said objects are also added * multiple times. *
* Note that scopes are not thread-safe. They are intended to be used from a single thread.
*/
public final class Scope implements AutoCloseable {
private final ArrayDeque