Skip to content

Commit

Permalink
fix godoc format
Browse files Browse the repository at this point in the history
  • Loading branch information
jolestar committed Jan 3, 2016
1 parent 3661a2e commit 273039a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 57 deletions.
8 changes: 4 additions & 4 deletions factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,23 @@ type PooledObjectFactory interface {
/**
* Ensures that the instance is safe to be returned by the pool.
*
* return <code>false</code> if <code>object</code> is not valid and should
* be dropped from the pool, <code>true</code> otherwise.
* return false if object is not valid and should
* be dropped from the pool, true otherwise.
*/
ValidateObject(object *PooledObject) bool

/**
* Reinitialize an instance to be returned by the pool.
*
* return error if there is a problem activating <code>object</code>,
* return error if there is a problem activating object,
* this error may be swallowed by the pool.
*/
ActivateObject(object *PooledObject) error

/**
* Uninitialize an instance to be returned to the idle object pool.
*
* return error if there is a problem passivating <code>obj</code>,
* return error if there is a problem passivating obj,
* this exception may be swallowed by the pool.
*/
PassivateObject(object *PooledObject) error
Expand Down
3 changes: 0 additions & 3 deletions object.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ type PooledObject struct {
state PooledObjectState
BorrowedCount int32
lock sync.Mutex
// //void setLogAbandoned(boolean var1);
// //void printStackTrace(PrintWriter var1);
}

func NewPooledObject(object interface{}) *PooledObject {
Expand Down Expand Up @@ -107,7 +105,6 @@ func (this *PooledObject) doAllocate() bool {
return false
}

//synchronized
func (this *PooledObject) Allocate() bool {
this.lock.Lock()
result := this.doAllocate()
Expand Down
82 changes: 32 additions & 50 deletions pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,9 @@ func NewObjectPoolWithDefaultConfig(factory PooledObjectFactory) *ObjectPool {
return NewObjectPool(factory, NewDefaultPoolConfig())
}

/**
* Create an object using the PooledObjectFactory factory, passivate it, and then place it in
* the idle object pool. <code>AddObject</code> is useful for "pre-loading"
* a pool with idle objects. (Optional operation).
*
*/
// Create an object using the PooledObjectFactory factory, passivate it, and then place it in
// the idle object pool. AddObject is useful for "pre-loading"
// a pool with idle objects. (Optional operation).
func (this *ObjectPool) AddObject() error {
if this.IsClosed() {
return NewIllegalStatusErr("Pool not open")
Expand All @@ -97,34 +94,29 @@ func (this *ObjectPool) addIdleObject(p *PooledObject) {
}
}

/**
* Obtains an instance from this pool.
*
* Instances returned from this method will have been either newly created
* with PooledObjectFactory.MakeObject or will be a previously
* idle object and have been activated with
* PooledObjectFactory.ActivateObject and then validated with
* PooledObjectFactory.ValidateObject.
*
* By contract, clients <strong>must</strong> return the borrowed instance
* using <code>ReturnObject</code>, <code>InvalidateObject</code>
*/
//Obtains an instance from this pool.
//
// Instances returned from this method will have been either newly created
// with PooledObjectFactory.MakeObject or will be a previously
// idle object and have been activated with
// PooledObjectFactory.ActivateObject and then validated with
// PooledObjectFactory.ValidateObject.
//
// By contract, clients must return the borrowed instance
// using ReturnObject, InvalidateObject
func (this *ObjectPool) BorrowObject() (interface{}, error) {
return this.borrowObject(this.Config.MaxWaitMillis)
}

/**
* Return the number of instances currently idle in this pool. This may be
* considered an approximation of the number of objects that can be
* BorrowObject borrowed without creating any new instances.
*/
//Return the number of instances currently idle in this pool. This may be
//considered an approximation of the number of objects that can be
//BorrowObject borrowed without creating any new instances.
func (this *ObjectPool) GetNumIdle() int {
return this.idleObjects.Size()
}

/**
* Return the number of instances currently borrowed from this pool.
*/

//Return the number of instances currently borrowed from this pool.
func (this *ObjectPool) GetNumActive() int {
return this.allObjects.Size() - this.idleObjects.Size()
}
Expand Down Expand Up @@ -358,10 +350,8 @@ func (this *ObjectPool) IsClosed() bool {
return this.closed
}

/**
* Return an instance to the pool. By contract, <code>object</code>
* <strong>must</strong> have been obtained using <code>BorrowObject()</code>
*/
// Return an instance to the pool. By contract, object
// must have been obtained using BorrowObject()
func (this *ObjectPool) ReturnObject(object interface{}) error {
if debug_pool {
fmt.Printf("pool ReturnObject %v \n", object)
Expand Down Expand Up @@ -436,11 +426,9 @@ func (this *ObjectPool) ReturnObject(object interface{}) error {
return nil
}

/**
* Clears any objects sitting idle in the pool, releasing any associated
* resources (optional operation). Idle objects cleared must be
* PooledObjectFactory.DestroyObject(PooledObject) .
*/
//Clears any objects sitting idle in the pool, releasing any associated
//resources (optional operation). Idle objects cleared must be
//PooledObjectFactory.DestroyObject(PooledObject) .
func (this *ObjectPool) Clear() {
p, ok := this.idleObjects.Poll().(*PooledObject)

Expand All @@ -450,15 +438,13 @@ func (this *ObjectPool) Clear() {
}
}

/**
* Invalidates an object from the pool.
*
* By contract, <code>object</code> <strong>must</strong> have been obtained
* using BorrowObject.
* <p>
* This method should be used when an object that has been borrowed is
* determined (due to an exception or other problem) to be invalid.
*/
// Invalidates an object from the pool.
//
// By contract, object must have been obtained
// using BorrowObject.
//
// This method should be used when an object that has been borrowed is
// determined (due to an exception or other problem) to be invalid.
func (this *ObjectPool) InvalidateObject(object interface{}) error {
p, ok := this.allObjects.Get(object).(*PooledObject)
if !ok {
Expand All @@ -478,9 +464,7 @@ func (this *ObjectPool) InvalidateObject(object interface{}) error {
return nil
}

/**
* Close this pool, and free any resources associated with it.
*/
//Close this pool, and free any resources associated with it.
func (this *ObjectPool) Close() {
if this.IsClosed() {
return
Expand All @@ -503,9 +487,7 @@ func (this *ObjectPool) Close() {
this.closeLock.Unlock()
}

/**
if ObjectPool.Config.TimeBetweenEvictionRunsMillis change, should call this method to let it to take effect.
*/
//if ObjectPool.Config.TimeBetweenEvictionRunsMillis change, should call this method to let it to take effect.
func (this *ObjectPool) StartEvictor() {
this.startEvictor(this.Config.TimeBetweenEvictionRunsMillis)
}
Expand Down

0 comments on commit 273039a

Please sign in to comment.