-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
73 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
core/src/main/java/com/turn/ttorrent/common/ByteBufferPool.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.turn.ttorrent.common; | ||
|
||
import org.apache.commons.pool2.BasePooledObjectFactory; | ||
import org.apache.commons.pool2.PooledObject; | ||
import org.apache.commons.pool2.impl.DefaultPooledObject; | ||
import org.apache.commons.pool2.impl.GenericObjectPool; | ||
import org.apache.commons.pool2.impl.GenericObjectPoolConfig; | ||
|
||
import java.nio.ByteBuffer; | ||
|
||
public class ByteBufferPool { | ||
|
||
private final GenericObjectPool<ByteBuffer> pool; | ||
|
||
public GenericObjectPool<ByteBuffer> getPool() { | ||
return pool; | ||
} | ||
|
||
public ByteBufferPool(int amount, int length) { | ||
final GenericObjectPoolConfig gopc = new GenericObjectPoolConfig(); | ||
gopc.setMinIdle(amount); | ||
gopc.setMaxTotal(amount); | ||
|
||
pool = new GenericObjectPool<ByteBuffer>(new ByteBufferFactory(length), gopc); | ||
} | ||
|
||
private class ByteBufferFactory extends BasePooledObjectFactory<ByteBuffer> { | ||
private final int length; | ||
|
||
private ByteBufferFactory(int length) { | ||
super(); | ||
|
||
this.length = length; | ||
} | ||
|
||
@Override | ||
public ByteBuffer create() { | ||
return ByteBuffer.allocate(length); | ||
} | ||
|
||
@Override | ||
public PooledObject<ByteBuffer> wrap(ByteBuffer buffer) { | ||
return new DefaultPooledObject<ByteBuffer>(buffer); | ||
} | ||
|
||
@Override | ||
public void passivateObject(PooledObject<ByteBuffer> pooledObject) { | ||
pooledObject.getObject().clear(); | ||
} | ||
} | ||
} |
41 changes: 0 additions & 41 deletions
41
core/src/main/java/com/turn/ttorrent/common/ByteBufferRentalService.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters