Hi azeez,

I  guess you meant commit this to the trunk? :)

thnaks,

On Wed, Apr 4, 2012 at 10:21 AM, <[email protected]> wrote:

> Author: azeez
> Date: Wed Apr  4 00:51:20 2012
> New Revision: 124705
> URL: http://wso2.org/svn/browse/wso2?view=rev&revision=124705
>
> Log:
> Added functionality to be able to cleanup ThreadLocals
>
>
> Added:
>
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/Axis2ThreadPoolExecutor.java
>
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/ThreadCleanup.java
>
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/ThreadCleanupContainer.java
> Modified:
>
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/NativeWorkerPool.java
>
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/watermark/WaterMarkExecutor.java
>
> Added:
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/Axis2ThreadPoolExecutor.java
> URL:
> http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/Axis2ThreadPoolExecutor.java?pathrev=124705
>
> ==============================================================================
> --- (empty file)
> +++
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/Axis2ThreadPoolExecutor.java
>  Wed Apr  4 00:51:20 2012
> @@ -0,0 +1,57 @@
> +/*
> +*  Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights
> Reserved.
> +*
> +*  WSO2 Inc. 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
> +*
> +*    http://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 org.apache.axis2.transport.base.threads;
> +
> +import java.util.concurrent.BlockingQueue;
> +import java.util.concurrent.RejectedExecutionHandler;
> +import java.util.concurrent.ThreadFactory;
> +import java.util.concurrent.ThreadPoolExecutor;
> +import java.util.concurrent.TimeUnit;
> +
> +/**
> + * TODO: class description
> + */
> +public class Axis2ThreadPoolExecutor extends ThreadPoolExecutor {
> +    public Axis2ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
> long keepAliveTime,
> +                                   TimeUnit unit, BlockingQueue<Runnable>
> workQueue) {
> +        super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
> workQueue);
> +    }
> +
> +    public Axis2ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
> long keepAliveTime,
> +                                   TimeUnit unit, BlockingQueue<Runnable>
> workQueue,
> +                                   ThreadFactory threadFactory) {
> +        super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
> workQueue, threadFactory);
> +    }
> +
> +    public Axis2ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
> long keepAliveTime,
> +                                   TimeUnit unit, BlockingQueue<Runnable>
> workQueue,
> +                                   RejectedExecutionHandler handler) {
> +        super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
> workQueue, handler);
> +    }
> +
> +    public Axis2ThreadPoolExecutor(int corePoolSize, int maximumPoolSize,
> long keepAliveTime,
> +                                   TimeUnit unit, BlockingQueue<Runnable>
> workQueue,
> +                                   ThreadFactory threadFactory,
> RejectedExecutionHandler handler) {
> +        super(corePoolSize, maximumPoolSize, keepAliveTime, unit,
> workQueue, threadFactory, handler);
> +    }
> +
> +    @Override
> +    protected void beforeExecute(Thread t, Runnable r) {
> +        ThreadCleanupContainer.cleanupAll();
> +    }
> +}
>
> Modified:
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/NativeWorkerPool.java
> URL:
> http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/NativeWorkerPool.java?rev=124705&r1=124704&r2=124705&view=diff
>
> ==============================================================================
> ---
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/NativeWorkerPool.java
> (original)
> +++
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/NativeWorkerPool.java
> Wed Apr  4 00:51:20 2012
> @@ -46,11 +46,10 @@
>         blockingQueue =
>             (queueLength == -1 ? new LinkedBlockingQueue<Runnable>()
>                                : new
> LinkedBlockingQueue<Runnable>(queueLength));
> -        executor = new ThreadPoolExecutor(
> -                core, max, keepAlive,
> -                TimeUnit.SECONDS,
> -                blockingQueue,
> -                new NativeThreadFactory(new ThreadGroup(threadGroupName),
> threadGroupId));
> +        executor = new Axis2ThreadPoolExecutor(core, max, keepAlive,
> TimeUnit.SECONDS,
> +                                               blockingQueue,
> +                                               new
> NativeThreadFactory(new ThreadGroup(threadGroupName),
> +
> threadGroupId));
>     }
>
>     public NativeWorkerPool(int core, int max, int keepAlive,
> @@ -69,7 +68,7 @@
>             blockingQueue = queue;
>         }
>
> -        executor = new ThreadPoolExecutor(
> +        executor = new Axis2ThreadPoolExecutor(
>                 core, max, keepAlive,
>                 TimeUnit.SECONDS,
>                 blockingQueue,
> @@ -93,7 +92,7 @@
>             blockingQueue = queue;
>         }
>
> -        executor = new ThreadPoolExecutor(
> +        executor = new Axis2ThreadPoolExecutor(
>                 core, max, keepAlive,
>                 TimeUnit.SECONDS,
>                 blockingQueue,
> @@ -185,7 +184,7 @@
>     public int getQueueSize() {
>         return blockingQueue.size();
>     }
> -
> +
>     public void shutdown(int timeout) throws InterruptedException {
>         executor.shutdown();
>         executor.awaitTermination(timeout, TimeUnit.MILLISECONDS);
>
> Added:
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/ThreadCleanup.java
> URL:
> http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/ThreadCleanup.java?pathrev=124705
>
> ==============================================================================
> --- (empty file)
> +++
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/ThreadCleanup.java
>    Wed Apr  4 00:51:20 2012
> @@ -0,0 +1,37 @@
> +/*
> +*  Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights
> Reserved.
> +*
> +*  WSO2 Inc. 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
> +*
> +*    http://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 org.apache.axis2.transport.base.threads;
> +
> +/**
> + * If certain Threads in a ThreadPool need to be cleaned up before being
> reused, an implementation
> + * of this interface should be provided so that the relevant cleaning up
> could be performed.
> + *
> + * An instance of the implementation class of this interface should be
> added to
> + * {@link ThreadCleanupContainer#addThreadCleanup(ThreadCleanup)}
> + *
> + * Typical items that will be cleaned up will include ThreadLocal
> variables
> + *
> + * @see ThreadCleanupContainer
> + */
> +public interface ThreadCleanup {
> +
> +    /**
> +     * Cleanup the Threads
> +     */
> +    void cleanup();
> +}
>
> Added:
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/ThreadCleanupContainer.java
> URL:
> http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/ThreadCleanupContainer.java?pathrev=124705
>
> ==============================================================================
> --- (empty file)
> +++
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/ThreadCleanupContainer.java
>   Wed Apr  4 00:51:20 2012
> @@ -0,0 +1,46 @@
> +/*
> +*  Copyright (c) 2005-2011, WSO2 Inc. (http://www.wso2.org) All Rights
> Reserved.
> +*
> +*  WSO2 Inc. 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
> +*
> +*    http://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 org.apache.axis2.transport.base.threads;
> +
> +import java.util.ArrayList;
> +import java.util.List;
> +
> +/**
> + * A container which will hold {@link ThreadCleanup} objects
> + */
> +public final class ThreadCleanupContainer {
> +    private static List<ThreadCleanup> cleanupList = new
> ArrayList<ThreadCleanup>();
> +
> +    /**
> +     * Add a new ThreadCleanup
> +     *
> +     * @param cleanup
> +     */
> +    public static void addThreadCleanup(ThreadCleanup cleanup) {
> +        cleanupList.add(cleanup);
> +    }
> +
> +    /**
> +     * Call cleanup ThreadCleanup.cleanup on all registered ThreadCleanups
> +     */
> +    public static void cleanupAll() {
> +        for (ThreadCleanup threadCleanup : cleanupList) {
> +            threadCleanup.cleanup();
> +        }
> +    }
> +}
>
> Modified:
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/watermark/WaterMarkExecutor.java
> URL:
> http://wso2.org/svn/browse/wso2/branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/watermark/WaterMarkExecutor.java?rev=124705&r1=124704&r2=124705&view=diff
>
> ==============================================================================
> ---
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/watermark/WaterMarkExecutor.java
>      (original)
> +++
> branches/carbon/3.2.0/dependencies/transports/1.1.0-wso2v6/modules/base/src/main/java/org/apache/axis2/transport/base/threads/watermark/WaterMarkExecutor.java
>      Wed Apr  4 00:51:20 2012
> @@ -19,6 +19,8 @@
>
>  package org.apache.axis2.transport.base.threads.watermark;
>
> +import org.apache.axis2.transport.base.threads.ThreadCleanupContainer;
> +
>  import java.util.concurrent.*;
>
>  /**
> @@ -58,6 +60,11 @@
>                              ThreadFactory threadFactory,
>                              RejectedExecutionHandler
> rejectedExecutionHandler) {
>         super(core, max, keepAlive, timeUnit,
> -                queue, threadFactory, new
> WaterMarkRejectionHandler(rejectedExecutionHandler));
> +              queue, threadFactory, new
> WaterMarkRejectionHandler(rejectedExecutionHandler));
> +    }
> +
> +    @Override
> +    protected void beforeExecute(Thread t, Runnable r) {
> +        ThreadCleanupContainer.cleanupAll();
>     }
>  }
> _______________________________________________
> Commits mailing list
> [email protected]
> http://wso2.org/cgi-bin/mailman/listinfo/commits
>



-- 
Supun Malinga,

Software Engineer,
WSO2 Inc.
http://wso2.com
http://wso2.org
email - [email protected] <[email protected]>
mobile - 071 56 91 321
_______________________________________________
Dev mailing list
[email protected]
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to