Pool objects must now be non-null
parent
c5fb855234
commit
0ef9e4a17b
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2020 dorkbox, llc
|
||||
* Copyright 2023 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -17,8 +17,9 @@ package dorkbox.objectPool
|
|||
|
||||
/**
|
||||
* @author Abinav Janakiraman
|
||||
* @author dorkbox, llc
|
||||
*/
|
||||
abstract class BoundedPoolObject<T>: PoolObject<T>() {
|
||||
abstract class BoundedPoolObject<T: Any>: PoolObject<T>() {
|
||||
/**
|
||||
* Called when an object is removed from the pool. Useful for logging how many objects are being removed
|
||||
*/
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2020 dorkbox, llc
|
||||
* Copyright 2023 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package dorkbox.objectPool
|
||||
|
||||
abstract class PoolObject<T> {
|
||||
abstract class PoolObject<T: Any> {
|
||||
/**
|
||||
* Called when an object is returned to the pool, useful for resetting an objects state, for example.
|
||||
*/
|
||||
|
|
|
@ -18,7 +18,7 @@ package dorkbox.objectPool
|
|||
/**
|
||||
* @author dorkbox, llc
|
||||
*/
|
||||
interface SuspendingPool<T> {
|
||||
interface SuspendingPool<T: Any> {
|
||||
/**
|
||||
* Takes an object from the pool. If the pool is a [SuspendingPool], this will wait until an item is available in
|
||||
* the pool.
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2020 dorkbox, llc
|
||||
* Copyright 2023 dorkbox, llc
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
@ -15,7 +15,7 @@
|
|||
*/
|
||||
package dorkbox.objectPool
|
||||
|
||||
abstract class SuspendingPoolObject<T> {
|
||||
abstract class SuspendingPoolObject<T: Any> {
|
||||
/**
|
||||
* Called when an object is returned to the pool, useful for resetting an objects state, for example.
|
||||
*/
|
||||
|
|
|
@ -25,7 +25,7 @@ import java.util.concurrent.BlockingQueue
|
|||
*
|
||||
* @author dorkbox, llc
|
||||
*/
|
||||
internal class BlockingPool<T> constructor(
|
||||
internal class BlockingPool<T: Any>(
|
||||
private val poolObject: PoolObject<T>,
|
||||
private val queue: BlockingQueue<T>,
|
||||
size: Int) : Pool<T> {
|
||||
|
|
|
@ -24,7 +24,7 @@ import java.util.concurrent.*
|
|||
*
|
||||
* @author dorkbox, llc
|
||||
*/
|
||||
internal class BlockingPoolCollection<T> constructor(
|
||||
internal class BlockingPoolCollection<T: Any>(
|
||||
private val queue: BlockingQueue<T>,
|
||||
collection: Collection<T>) : Pool<T> {
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.concurrent.atomic.*
|
|||
*
|
||||
* @author dorkbox, llc; Abinav Janakiraman
|
||||
*/
|
||||
internal class BoundedNonBlockingPool<T>(
|
||||
internal class BoundedNonBlockingPool<T: Any>(
|
||||
private val poolObject: BoundedPoolObject<T>,
|
||||
private val maxSize: Int,
|
||||
private val queue: Queue<T>) : NonBlockingPool<T>(poolObject, queue) {
|
||||
|
|
|
@ -29,7 +29,7 @@ import java.util.*
|
|||
*
|
||||
* @author dorkbox, llc
|
||||
*/
|
||||
internal open class NonBlockingPool<T>(
|
||||
internal open class NonBlockingPool<T: Any>(
|
||||
private val poolObject: PoolObject<T>,
|
||||
private val queue: Queue<T>) : Pool<T> {
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
|
|||
*
|
||||
* @author dorkbox, llc
|
||||
*/
|
||||
internal class NonBlockingSoftPool<T>(
|
||||
internal class NonBlockingSoftPool<T: Any>(
|
||||
private val poolObject: PoolObject<T>,
|
||||
private val queue: Queue<SoftReference<T>>) : Pool<T> {
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import kotlinx.coroutines.runBlocking
|
|||
*
|
||||
* @author dorkbox, llc
|
||||
*/
|
||||
internal class SuspendingPool<T> constructor(
|
||||
internal class SuspendingPool<T: Any>(
|
||||
private val poolObject: SuspendingPoolObject<T>,
|
||||
size: Int,
|
||||
private val queue: SuspendingQueue<T>) : SuspendingPool<T> {
|
||||
|
|
|
@ -25,7 +25,7 @@ import kotlinx.coroutines.runBlocking
|
|||
*
|
||||
* @author dorkbox, llc
|
||||
*/
|
||||
internal class SuspendingPoolCollection<T> constructor(
|
||||
internal class SuspendingPoolCollection<T: Any>(
|
||||
private val queue: SuspendingQueue<T>,
|
||||
collection: Collection<T>) : SuspendingPool<T> {
|
||||
|
||||
|
|
|
@ -16,13 +16,12 @@
|
|||
|
||||
package dorkbox.objectPool.suspending
|
||||
|
||||
import java.util.Collection
|
||||
import java.util.concurrent.*
|
||||
|
||||
/**
|
||||
* A limited version of a [BlockingQueue] that suspends instead of blocking
|
||||
*/
|
||||
interface SuspendingQueue<E> {
|
||||
interface SuspendingQueue<E: Any> {
|
||||
/**
|
||||
* Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions, returning
|
||||
* `true` upon success and throwing an `IllegalStateException` if no space is currently available.
|
||||
|
|
Loading…
Reference in New Issue