Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 //  The contents of this file are subject to the Mozilla Public License
 //  Version 1.1 (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.mozilla.org/MPL/
 //
 //  Software distributed under the License is distributed on an "AS IS"
 //  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
 //  the License for the specific language governing rights and
 //  limitations under the License.
//
//  The Original Code is RabbitMQ.
//
//  The Initial Developer of the Original Code is VMware, Inc.
//  Copyright (c) 2011 VMware, Inc.  All rights reserved.
package com.rabbitmq.client.impl;
final class ConsumerWorkService {
    private static final int MAX_RUNNABLE_BLOCK_SIZE = 16;
    private final ExecutorService executor;
    private final WorkPool<ChannelRunnableworkPool;
    public ConsumerWorkService(ExecutorService executor) {
        this. = executor;
        this. = new WorkPool<ChannelRunnable>();
    }

    
Stop executing all consumer work
    public void shutdown() {
        this..unregisterAllKeys();
        this..shutdown();
    }

    
Stop executing all consumer work for a particular channel
    public void stopWork(Channel channel) {
        this..unregisterKey(channel);
    }
    public void registerKey(Channel channel) {
        this..registerKey(channel);
    }
    public void addWork(Channel channelRunnable runnable) {
        if (this..addWorkItem(channelrunnable)) {
            this..execute(new WorkPoolRunnable());
        }
    }
    private final class WorkPoolRunnable implements Runnable {
        public void run() {
            int size = ;
            List<Runnableblock = new ArrayList<Runnable>(size);
            try {
                Channel key = ConsumerWorkService.this..nextWorkBlock(blocksize);
                if (key == nullreturn// nothing ready to run
                try {
                    for (Runnable runnable : block) {
                        runnable.run();
                    }
                } finally {
                    if (ConsumerWorkService.this..finishWorkBlock(key)) {
                        ConsumerWorkService.this..execute(new WorkPoolRunnable());
                    }
                }
            } catch (RuntimeException e) {
                Thread.currentThread().interrupt();
            }
        }
    }
New to GrepCode? Check out our FAQ X